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")

nullmod1 <- glm(yn~1, data=euro, family="binomial")

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")


marked as duplicate by kjetil b halvorsen, Michael Chernick, Peter Flom Apr 6 at 11:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from stackoverflow.com May 7 '17 at 19:26

This question came from our site for professional and enthusiast programmers.


You know that there are some already implemented functions for pseudo-R2 in R? I used PseudoR2 from the package BaylorEdPsych in the past. That way you could check if your pseudo R2 calculation is correct.

For differences between the pseudo R2s you can read this blogpost from Paul Allison, he's one of the most wellknown statisticians of our time http://statisticalhorizons.com/r2logistic

  • 1
    $\begingroup$ good to know about that package, I like that it reports as many as 6 different Pseudo R2s. I'm wondering if anybody can unpack for me what the formula 1-logLik(mod1)/logLik(nullmod1) does and whether this can be seen as a form of R2 itself? $\endgroup$ – Henry Cann May 7 '17 at 12:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.