Re: [R] Binomial

From: Sarah Sanchez <sarah_sanchez09_at_yahoo.com>
Date: Thu, 12 May 2011 04:19:23 -0700 (PDT)


Dear R helpers,

I am raising one query regarding this "Binomial" thread with the sole intention of learning something more as I understand R forum is an ocean of knowledge.

I was going through all the responses, but wondered that original query was about generating Binomial random numbers while what the R code produced so far generates the Bernoulli Random no.s i.e. 0 and 1.

True Binomial distribution is nothing but no of Bernoulli trials. As I said I am a moron and don't understand much about Statistics. Just couldn't stop from asking my stupid question.

Regards

Sarah

From: David Winsemius <dwinsemius_at_comcast.net> Subject: Re: [R] Binomial
To: "Alexander Engelhardt" <alex_at_chaotic-neutral.de> Cc: r-help_at_r-project.org, "blutack" <x-jess-h-x_at_hotmail.co.uk>
Date: Thursday, May 12, 2011, 11:08 AM

On May 12, 2011, at 5:02 AM, Alexander Engelhardt wrote:

> Am 12.05.2011 10:46, schrieb blutack:

>> Hi, I need to create a function which generates a Binomial random number
>> without using the rbinom function. Do I need to use the choose function or
>> am I better just using a sample?
>> Thanks.

>
> I think I remember other software who generates binomial data with e.g. pi=0.7 by
>
> pi <- 0.7

I hope Allan knows this and is just being humorous here,  but for the less experienced in the audience ... Choosing a different threshold variable name might be less error prone. `pi` is one of few built-in constants in R and there may be code that depends on that fact.

> pi

[1] 3.141593
> pi <- 0.7
> pi
[1] 0.7
> rm(pi)
> pi

[1] 3.141593

> x <- runif(100)>pi
> summary(x)

Another method would be:

 x <- sample(c(0,1) , 100, replace=TRUE,  prob=c(0.7, 0.3) )

--
David Winsemius, MD
West Hartford, CT

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]


______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

Received on Thu 12 May 2011 - 12:12:44 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 12 May 2011 - 13:10:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive