n = 3000
mu1 = exp(2.4) # also known as lambda1
mu2 = exp(3.1)
phi = 0.3
y = ifelse(runif(n) < phi, rpois(n, mu1), rpois(n, mu2))
fit = vglm(y ~ 1, mix2poisson, maxit=200) # good idea to have trace=TRUE
coef(fit, matrix=TRUE)
Coef(fit) # the estimates
c(phi, mu1, mu2) # the truth
# Plot the results
ty = table(y)
plot(names(ty), ty, type="h", main="Red=estimate, blue=truth")
abline(v=Coef(fit)[-1], lty=2, col="red")
abline(v=c(mu1, mu2), lty=2, col="blue")
Run the code above in your browser using DataLab