prob = 0.2
size = 10
phi = 0.5
(i = dzibinom(0:size, size, prob, phi=phi))
cumsum(i) - pzibinom(0:size, size, prob, phi=phi) # Should be 0s
table(rzibinom(100, size, prob, phi=phi))
table(qzibinom(runif(100), size, prob, phi=phi))
round(dzibinom(0:10, size, prob, phi=phi) * 100) # Should be similar
x = 0:size
plot(x, dzibinom(x, size, prob, phi=phi), type="h", ylab="Probability",
main=paste("ZIB(", size, ", ", prob, ", phi=", phi, ") (blue) vs",
" Binomial(", size, ", ", prob, ") (red & shifted slightly)", sep=""),
lwd=2, col="blue", las=1)
lines(x+0.05, dbinom(x, size, prob), type="h", lwd=2, col="red")
Run the code above in your browser using DataLab