prob = 0.5; pszero = 0.2; x = (-1):20
(ii = dzigeom(x, prob, pszero))
max(abs(cumsum(ii) - pzigeom(x, prob, pszero))) # Should be 0
table(rzigeom(1000, prob, pszero))
x = 0:10
barplot(rbind(dzigeom(x, prob, pszero), dgeom(x, prob)),
beside = TRUE, col = c("blue","orange"),
ylab = "P[Y = y]", xlab = "y", las = 1,
main = paste("zigeometric(", prob, ", pszero = ", pszero,
") (blue) vs",
" geometric(", prob, ") (orange)", sep = ""),
names.arg = as.character(x))
Run the code above in your browser using DataLab