x = runif(n <- 1000)
p0 = logit(-1 + 1*x, inverse=TRUE)
lambda = loge(-0.3 + 2*x, inverse=TRUE)
y = ifelse(runif(n) < p0, 0, rpospois(n, lambda))
table(y)
fit = vglm(y ~ x, zapoisson, trace=TRUE)
fit = vglm(y ~ x, zapoisson, trace=TRUE, crit="c")
fitted(fit)[1:5]
predict(fit)[1:5,]
predict(fit, untransform=TRUE)[1:5,]
coef(fit, matrix=TRUE)
# 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]
yy = rep(y,w)
fit3 = vglm(yy ~ 1, zapoisson, trace=TRUE, crit="c")
coef(fit3, matrix=TRUE)
Coef(fit3) # Estimate of lambda (they get 0.6997 with standard error 0.1520)
fitted(fit3)[1:5]
mean(yy) # compare this with fitted(fit3)
Run the code above in your browser using DataLab