[R] Nagelkerke R square for Prediction data
    Soeren.Vogel at eawag.ch 
    Soeren.Vogel at eawag.ch
       
    Mon Dec 27 16:39:47 CET 2010
    
    
  
Hello
I found some small postings dated to 22 Oct 2008 on the message subject. Recently, I have been working with binary logistic regressions. I didn't use the design package. Yet, I needed the "fit" indices. Therefore, I wrote a small function to output the Nagelkerke's R, and the Cox-&-Snell R from a fitted model. I am no professional programmer by far, yet, I hope, that the code is okay and that it may be of some use to others -- or subject to useful improvement. Please let me know, if you find errors.
Regards,
Sören
Rcsnagel <- function(mod) {
  llnull <- mod$null.deviance
  llmod <- mod$deviance
  n <- length(mod$fitted.values)
  Rcs <- 1 - exp( (mod$deviance - mod$null.deviance) / n )
  Rnagel <- Rcs / (1 - exp(-llnull/n))
  out <- list('Rcs'=Rcs, 'Rnagel'=Rnagel)
  class(out) <- c("list", "table")
  return(out)
}
y <- sample(c(T, F), 50, repl=T)
x <- sample(1:7, 50, repl=T)
mod <- glm(y ~ x, family=binomial("logit"))
Rcsnagel(mod)
-- 
Sören Vogel, Dipl.-Psych. (Univ.), PhD-Student, Eawag, Dept. SIAM
http://www.eawag.ch, http://sozmod.eawag.ch
    
    
More information about the R-help
mailing list