x = runif(n <- 2000)
phi = logit(-0.5 + 1*x, inverse=TRUE)
lambda = loge(0.5 + 2*x, inverse=TRUE)
y = rzipois(n, lambda, phi)
table(y)
fit = vglm(y ~ x, zipoisson, trace=TRUE)
coef(fit, matrix=TRUE) # These should agree with the above values
# Another example: data from McKendrick (1926).
y = 0:4 # Number of cholera cases per household in an Indian village
w = c(168, 32, 16, 6, 1) # Frequencies; there are 223=sum(w) households
fit = vglm(y ~ 1, zipoisson, wei=w, trace=TRUE)
coef(fit, matrix=TRUE)
cbind(actual=w, fitted= round(
dzipois(y, lambda=Coef(fit)[2], phi=Coef(fit)[1]) * sum(w), dig=2))
# Another example: data from Angers and Biswas (2003)
y = 0:7
w = c(182, 41, 12, 2, 2, 0, 0, 1)
y = y[w>0]
w = w[w>0]
fit = vglm(y ~ 1, zipoisson(lphi=probit, iphi=0.3), wei=w, tra=TRUE)
fit@misc$prob0 # Estimate of P(Y=0)
coef(fit, matrix=TRUE)
Coef(fit) # Estimate of phi and lambda
fitted(fit)
weighted.mean(y,w) # Compare this with fitted(fit)
summary(fit)
Run the code above in your browser using DataLab