My project uses logistic regression and I needed to calculate pseudo r squared to understand the explanatory power of each model.
I have been using the formula below to calculate what I thought was equivalent to pseudo R squared by comparing a null model using just the intercept to the full specified model to be measured.
mod1 <- glm(yn~hinctnta+hincfel+uemp5yr+stfeco+gincdif, data=euro,family = "binomial")
summary(mod1)
nullmod1 <- glm(yn~1, data=euro, family="binomial")
1-logLik(mod1)/logLik(nullmod1)
I noticed that some of the results were higher than expected. Therefore I sought out additional ways to calculate R2 and used the following function which calculates Hosmer and Lemeshows R squared as well as Nagelkerke and Cox and Snell. Testing 5 different models showed very different (lower) results than those showed by my first attempt using the simple null model.
My question therefore is what is the theoretical difference between the two approaches and is there any validity in just using the first simpler approach to report pseudo r squared?
Function to calculate R squared:
logisticPseudoR2s <- function(LogModel) {
dev <- LogModel$deviance
nullDev <- LogModel$null.deviance
modelN <- length(LogModel$fitted.values)
R.l <- 1 - dev / nullDev
R.cs <- 1 - exp ( -(nullDev - dev)/ modelN)
R.n <- R.cs / ( 1 - (exp (-(nullDev / modelN))))
cat("Pseudo R^2 for logistic regression\n")
cat("Hosmer and lemeshow R^2", round(R.l, 3), "\n")
cat("Cox and Snell R^2", round(R.cs, 3), "\n")
cat("Nagelkerke R^2", round(R.n, 3), "\n")
}
logisticPseudoR2s(mod)