An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100522/a1e8a6d5/attachment.pl>
Bernoulli random variable with different probability
2 messages · Carrie Li, Erik Iverson
Carrie Li wrote:
Dear R-helpers, I would like to generate a variable that takes 0 or 1, and each subject has different probabilities of taking the draw. So, which of the following code I should use ?
<snip> I don't think either. Try this: probs <- seq(0,1, by = .1) sapply(probs, function(x) sample(0:1, 1, prob = c(1-x, x))) probs will be the vector of your probabilities for obtaining a '1' per subject, so set that to whatever you want, then run the second line.