[R] Binomial simulation

beetle2 samandbrendan at aapt.net.au
Sun Apr 19 03:28:34 CEST 2009


I've done some study.

And made a couple of loops to compare the dbinom() and rbinom()
 Here are the results:
The instructor only asked for 1000 trials so its not that accurate. but its
close to it.

> for(x in c(1:10))
+ {print(dbinom(x,10,.25)) }
[1] 0.1877117
[1] 0.2815676
[1] 0.2502823
[1] 0.145998
[1] 0.0583992
[1] 0.016222
[1] 0.003089905
[1] 0.0003862381
[1] 2.861023e-05
[1] 9.536743e-07
> 
> results <- rbinom(1000, 10, .25)
>  for (x in c(1:10) )
+ {d=sum(results == x)
+ df = (d/1000)
+ print(df)
+ }
[1] 0.173
[1] 0.279
[1] 0.274
[1] 0.15
[1] 0.059
[1] 0.013
[1] 0.004
[1] 0
[1] 0
[1] 0
> 


Thanks for pointing me to the rbinom() function
regards
Brendan















beetle2 wrote:
> 
> Hi Guy's
> I was wondering if someone could point me in the right direction.
> 
> dbinom(10,1,0.25)
> 
> I am using dbinom(10,1,0.25) to calculate the probabilty of 10 judges
> choosing a certain brand x times. 
> 
> I was wondering how I would go about simulating 1000 trials of each x
> value ?
> 
> regards
> Brendan
> 
> 

-- 
View this message in context: http://www.nabble.com/Binomial-simulation-tp23106347p23118881.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list