Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8672911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:19:14+00:00 2026-06-12T19:19:14+00:00

How do you define your own distributions in R? If I have a distribution

  • 0

How do you define your own distributions in R? If I have a distribution that looks something like this:

P(D=0)=2/4, P(D=1)=1/4, P(D=2)=1/4

How do I turn that into a distribution I can work with?

In the end, I want to be able to use these and do things involving cdfs, icdfs and pmfs. Like find the probability of 1 through a cdf type thing. And I also need to find out how to graph things. But I was going to ask in smaller steps and try to figure things out in between.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:19:15+00:00Added an answer on June 12, 2026 at 7:19 pm

    If you just need to generate random variates from the distribution, this should suffice:

    rMydist <- function(n) {
        sample(x = c(0,1,2), size = n, 
               prob = c(.5, .25, .25), replace=T)
    }
    
    rMydist(20)
    # [1] 1 0 2 0 2 1 1 0 2 2 0 0 2 1 0 0 0 0 0 1
    
    prop.table(table(rMydist(1e6)))
    #        0        1        2 
    # 0.500555 0.250044 0.249401 
    

    For something more fancy, try out the distr package. In addition to random number generation, it’ll get you the density, distribution, and quantile functions associated with your distribution:

    library(distr)
    ## For more info, type: vignette("newDistributions")  
    
    # Define full suite of functions (d*, p*, q*, r*) for your distribution
    D <- DiscreteDistribution (supp = c(0, 1, 2) , prob = c(0.5, .25, .25))
    dD <- d(D)  ## Density function
    pD <- p(D)  ## Distribution function
    qD <- q(D)  ## Quantile function
    rD <- r(D)  ## Random number generation
    
    # Take them for a spin
    dD(-1:3)
    # [1] 0.00 0.50 0.25 0.25 0.00
    pD(-1:3)
    # [1] 0.00 0.50 0.75 1.00 1.00
    qD(seq(0,1,by=0.1))
    # [1] 0 0 0 0 0 0 1 1 2 2 2
    rD(20)
    # [1] 0 0 2 2 1 0 0 1 0 1 0 2 0 0 0 0 1 2 1 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know of a google maps library that you can define your own
I was wondering if you can define your own attributes in HTML. For example
Is there a way to define your own operators in F#? If so can
In .NET configuration, you can write your own configuration section and have quite a
In NSB 2.6 when you define your publisher you can specify the <DBSubscriptionStorageConfig/> configuration
Currently the HashSet<T> constructor that allows you to define your equality comparison yourself is
It's possible to define your own custom templates for normal project types, such as
How and where do you define your own Exception hierarchy in Java? My main
I am trying to create a program that allows you to create your own
I would like to have my own contexts for some CDI-based projects. I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.