Skip to content
Prev 259604 / 398502 Next

Binomial

On 12-May-11 09:02:45, Alexander Engelhardt wrote:
That needs to be the other way round (and perhaps also convert
it to 0/1):

  x <- 1*(runif(100) < pi)

since Prob(runif > pi) = (1 - pi).

Comparison:

  pi <- 0.7
  x <- runif(100)>pi
  x[1:10]
  #  [1] FALSE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE
  sum(x)/100
  # [1] 0.36

  x <- 1*(runif(100) < pi)
  x[1:10]
  # [1] 0 0 1 1 1 1 1 0 1 0
  sum(x)/100
  # [1] 0.62

Ted

--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at wlandres.net>
Fax-to-email: +44 (0)870 094 0861
Date: 12-May-11                                       Time: 10:21:26
------------------------------ XFMail ------------------------------