I want to extract the deviance from a list of GLM models using ldply()
Example data (from R base installation):
library(reshape2)
library(plyr)
mtcars.1 <- mtcars[, c("am", "qsec" , "drat") ]
mtcars.m <- melt(mtcars.1, id= 1 )
glm.cars <- dlply( mtcars.m , .(variable) ,
glm, formula= am ~ value , family=binomial )
Got this far:
ldply( glm.cars , summarise , "Null Deviance" = null.deviance ,
"Residual Deviance" = deviance , "Deviance"= "??" )
Which gives this:
variable Null Deviance Residual Deviance Deviance
1 qsec 43.22973 41.46512 ??
2 drat 43.22973 21.65003 ??
Deviance is missing! How do I extract it?
So how do I extract the deviance in the example above?
Off course i could just do null.deviance + deviance , but I just dont feel like doing it that way. I guess the reason I that I want to get better acquainted with the G statistic. I feel I go through the steops of extracting, subtracting and doing the chisqr, I will learn it better.
PS I was very confused to find that glm.model$devianc