Skip to content

Instantly share code, notes, and snippets.

@hauselin
Created August 12, 2015 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hauselin/7444fdfaadaef9dfff52 to your computer and use it in GitHub Desktop.
Save hauselin/7444fdfaadaef9dfff52 to your computer and use it in GitHub Desktop.
#function to compute R2s in logistic regression
logisticR2s <- function(logisticModel) {
modelDeviance <- logisticModel$deviance
nullDeviance <- logisticModel$null.deviance
n <- length(logisticModel$fitted.values)
R2HosmerLemeshow <- 1 - modelDeviance / nullDeviance
R2CoxSnell <- 1 - exp((modelDeviance - nullDeviance) / n)
R2Nagelkerke <- R2CoxSnell / (1 - exp( - (nullDeviance / n)))
col1 <- c("Hosmer and Lemeshow", "Cox and Snell", "Nagelkerke")
col2 <- c(R2HosmerLemeshow, R2CoxSnell, R2Nagelkerke)
col3 <- col2 * 100
return(data.frame(RSquaredType = col1,
Value = round(col2, 2),
Percent = round(col3, 2)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment