rbinom(50,5,c(0.48,0.24,0.16,0.12)) On Thu, 2006-09-02 at 20:02 +0100, Jan Danielsson wrote:> Hello, > > Given a probability function: p(x) = 12 / (25(x+1)) , x=0, 1, 2, 3 we > generate the following values: > > C1 C2 > 0 0.48 > 1 0.24 > 2 0.16 > 3 0.12 > > Now, I'm supposed to create 50 random values using this table. In > MiniTab, I simply selected Calc -> Random Data -> Discrete, and selected > the columns, and it created 50 random values in a new column.[1] > > How do I do the same thing in R? > > [1] You may be wondering why I'm telling you this. Well, it's because > if I were in your shoes, I'd think "Oh, someone wants me to solve his > homework.". I have already solved it using MiniTab, but I want to be > able to use R instead (since I prefer NetBSD). > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Hello, Given a probability function: p(x) = 12 / (25(x+1)) , x=0, 1, 2, 3 we generate the following values: C1 C2 0 0.48 1 0.24 2 0.16 3 0.12 Now, I'm supposed to create 50 random values using this table. In MiniTab, I simply selected Calc -> Random Data -> Discrete, and selected the columns, and it created 50 random values in a new column.[1] How do I do the same thing in R? [1] You may be wondering why I'm telling you this. Well, it's because if I were in your shoes, I'd think "Oh, someone wants me to solve his homework.". I have already solved it using MiniTab, but I want to be able to use R instead (since I prefer NetBSD). -- Kind Regards, Jan Danielsson Te audire non possum. Musa sapientum fixa est in aure. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 187 bytes Desc: OpenPGP digital signature Url : https://stat.ethz.ch/pipermail/r-help/attachments/20060209/e59910e7/signature.bin
On 2/9/2006 2:02 PM, Jan Danielsson wrote:> Hello, > > Given a probability function: p(x) = 12 / (25(x+1)) , x=0, 1, 2, 3 we > generate the following values: > > C1 C2 > 0 0.48 > 1 0.24 > 2 0.16 > 3 0.12 > > Now, I'm supposed to create 50 random values using this table. In > MiniTab, I simply selected Calc -> Random Data -> Discrete, and selected > the columns, and it created 50 random values in a new column.[1] > > How do I do the same thing in R? > > [1] You may be wondering why I'm telling you this. Well, it's because > if I were in your shoes, I'd think "Oh, someone wants me to solve his > homework.". I have already solved it using MiniTab, but I want to be > able to use R instead (since I prefer NetBSD).You want to use the sample() function. See ?sample. Duncan Murdoch
Kjetil Brinchmann Halvorsen
2006-Feb-09 21:08 UTC
[R] New user: Custom probability distribution
Jan Danielsson wrote:> Hello, > > Given a probability function: p(x) = 12 / (25(x+1)) , x=0, 1, 2, 3 we > generate the following values: > > C1 C2 > 0 0.48 > 1 0.24 > 2 0.16 > 3 0.12 > > Now, I'm supposed to create 50 random values using this table. In > MiniTab, I simply selected Calc -> Random Data -> Discrete, and selected > the columns, and it created 50 random values in a new column.[1] > > How do I do the same thing in R?sample( 0:3, 50, prob=c(0.48, 0.24, 0.26, 0.12)) Kjetil> > [1] You may be wondering why I'm telling you this. Well, it's because > if I were in your shoes, I'd think "Oh, someone wants me to solve his > homework.". I have already solved it using MiniTab, but I want to be > able to use R instead (since I prefer NetBSD). > > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Hi, you can use our package distr respectively distrEx. require(distrEx) D1 <- DiscreteDistribution(supp=0:3, prob = 12/(25*(1:4))) plot(D1) r(D1)(50) hth Matthias>Hello, > > Given a probability function: p(x) = 12 / (25(x+1)) , x=0, 1, 2, 3 we >generate the following values: > > C1 C2 > 0 0.48 > 1 0.24 > 2 0.16 > 3 0.12 > > Now, I'm supposed to create 50 random values using this table. In >MiniTab, I simply selected Calc -> Random Data -> Discrete, and selected >the columns, and it created 50 random values in a new column.[1] > >How do I do the same thing in R? > > [1] You may be wondering why I'm telling you this. Well, it's because >if I were in your shoes, I'd think "Oh, someone wants me to solve his >homework.". I have already solved it using MiniTab, but I want to be >able to use R instead (since I prefer NetBSD). > > > >------------------------------------------------------------------------ > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- StaMatS - Statistik + Mathematik Service Dr. rer. nat. Matthias Kohl Gottlieb-Keim-Stra??e 60 95448 Bayreuth Phone: +49 921 50736457 E-Mail: matthias.kohl at stamats.de Home: www.stamats.de