I am interested in using cross validation (leave-one-out or K-folds) to test several different negative binomial GLMs that I have created. I am using the glm.nb()
function from MASS
to run negative binomial regression.
My question is whether I can use the cv.glm()
from boot
to test this model. I am leaning towards no, but wondered if anyone knew a function that would let me perform K-folds validation (or leave one out). Or, perhaps cv.glm()
is perfectly valid for negative binomial.
Here is some data from an online example to help out. I had thought that cross-validation results ($delta
) should be bounded between 0 and 1, but this is not the case below (and possibly indicative of something gone awry)
http://www.ats.ucla.edu/stat/r/dae/nbreg.htm
I've found a few questions about interpreting the output of cv.glm()
, but not specifically about how to do cross validation with negative binomial models in R
require(foreign)
require(ggplot2)
require(MASS)
require(boot)
dat <- read.dta("http://www.ats.ucla.edu/stat/stata/dae/nb_data.dta")
dat <- within(dat, {
prog <- factor(prog, levels = 1:3, labels = c("General", "Academic","Vocational"))
id <- factor(id)
})
summary(m1 <- glm.nb(daysabs ~ math + prog, data = dat))
#This code will run, but is it valid for negative binomial GLM models?
cv.glm(dat,m1,K=10)
[I'm not sure if this question belongs here or on Cross Validated...]