0
votes

I would like to plot a rootogram for a quasipoisson model. The countreg package works really well for poisson and for negative binomial but it says "family currently not supported" for quasipoisson models.

I know that the packages vcd and latticeExtra can also plot rootograms. Unfortunately, when I try to plot a rootogram of a quasipoisson model with these packages I receive error messages.

Here some code for all three packages:

#some data for replication)
y <- rpois(100, 3)
x1 <- c(rep(0, 50), rep(1, 50))
x2 <- rnorm(100, 1000, 300)
data <- data.frame(y, x1, x2)

library(countreg)
countreg::rootogram(glm(y~x1 +x2, data = data, family = quasipoisson))

produces error:

Error in rootogram.glm(glm(y ~ x1 + x2, data = data, family = quasipoisson)) : family currently not supported

library(vcd)
vcd::rootogram(glm(y~x1 + x2, data = data, family = quasipoisson))

produces error:

Error in rootogram.default(glm(y ~ x1 + x2, data = data, family = quasipoisson)) : argument "fitted" is missing, with no default

library(latticeExtra)
latticeExtra::rootogram(glm(y ~ x1 + x2, data = data, family = quasipoisson))

produces error:

Error in sqrt(as.vector(object)) : non-numeric argument to mathematical function

In addition: Warning message:

In rootogram.default(glm(y ~ x1 + x2, data = data, family = quasipoisson)) : NAs introduced by coercion

2

2 Answers

1
votes

Not all libraries take a model object to plot results. Take a look at the documentation of these rootogram functions.

For instance, vcd's function requires the data and predictions to make the plot. You can make the plot like so :

#some data for replication)
y <- rpois(100, 3)
x1 <- c(rep(0, 50), rep(1, 50))
x2 <- rnorm(100, 1000, 300)
data <- data.frame(y, x1, x2)

mod <- glm(y~x1 +x2, data = data, family = quasipoisson)

library(vcd)
vcd::rootogram(data[,1], predict(mod), scale = "raw")

enter image description here

As a side note, I couldn't install countreg so I don't know what's wrong on that end.

-1
votes

Try plotting a rootogram for the basic Poisson model with the same predictors. The predicted values and residuals are the same, so you can get a rough idea of the fit of your model.

On another note, @RoB, try install.packages("countreg", repos="http://R-Forge.R-project.org") to install the countreg package.