I'd like to compact the creation of a vector y
. It is the rowsum of some binary binomials with a probability each. With rbinom()
I tried to define all probabilities at once but I get different results. Here I show the means, but most important to me are the PDFs.
set.seed(8659)
n <- 1e3
a <- rbinom(n, 1, .7)
b <- rbinom(n, 1, .6)
c <- rbinom(n, 1, .05)
df1 <- data.frame(a, b, c, y = a + b + c)
mean(df1$y)
# [1] 1.303
# failed attempt to do this in one command
y <- rbinom(n, 3, c(.7, .6, .05))
mean(y)
# [1] 1.376
Aucun commentaire:
Enregistrer un commentaire