data("ships", package = "MASS")
Shipmodel <- vglm(incidents ~ type + year + period,
quasipoissonff, offset = log(service),
# trace = TRUE, model = TRUE,
data = ships, subset = (service > 0))
# Easiest form of input
fit1 <- rcam(Qvar(Shipmodel, "type"), normal1("explink"), maxit = 99)
(quasiVar <- exp(diag(fitted(fit1))) / 2) # Version 1
(quasiVar <- diag(predict(fit1)[, c(TRUE, FALSE)]) / 2) # Version 2
(quasiSE <- sqrt(quasiVar))
# Another form of input
fit2 <- rcam(Qvar(Shipmodel, coef.ind = c(0,2:5), reference.name = "typeA"),
normal1("explink"), maxit = 99)
plotqvar(fit2, col = "orange", lwd = 3, scol = "blue", slwd = 2, las = 1)
# The variance-covariance matrix is another form of input (not recommended)
fit3 <- rcam(Qvar(cbind(0, rbind(0, vcov(Shipmodel)[2:5, 2:5])),
labels = c("typeA", "typeB", "typeC", "typeD", "typeE"),
estimates = c(typeA = 0, coef(Shipmodel)[2:5])),
normal1("explink"), maxit = 99)
(QuasiVar <- exp(diag(fitted(fit3))) / 2) # Version 1
(QuasiVar <- diag(predict(fit3)[, c(TRUE, FALSE)]) / 2) # Version 2
(QuasiSE <- sqrt(quasiVar))
plotqvar(fit3)
Run the code above in your browser using DataLab