# Re: [R] pseudo-R by hand

From: Achim Zeileis <Achim.Zeileis_at_uibk.ac.at>
Date: Mon, 11 Apr 2011 13:10:08 +0200 (CEST)

On Mon, 11 Apr 2011, Sacha Viquerat wrote:

> hello dear list! since we want to do a model analysis and some people would
> like to see pseudo-R^2 values for different types of glm of a logistic
> regression, i've decided to write a function that computes either nagelkerkes
> normed pseudo-R or cox & snells pseudo-R. however, i am not clear as in the
> decisive step, i need to calculate the log of (maximum likelihood estimates
> of model divided by mle of null model). i am well aware of the functions
> stats::mle and stats::logLik as well as of Design::lrm.

You can look at the pR2() function in the "pscl" package which provides various flavors of pseudo R-squared for "glm", "multinom", and "polr" objects. The idea is to extract the observed log-likelihood using logLik(), then update the model to obtain the null model only and call logLik() again. From the two log-likelihoods and the associated number of observations, the pseudo R-squared are computed using pR2Work(), see pscl:::pR2.glm and pscl:::pR2Work.

hth,
Z

> however, I'm not sure
> wheter mle helps me at all and I am uncertain about the logLik call I have
> implemented:
>
> #cox&snell
> lambda<- -2*log((logLik(null.model)/logLik(model)))
> out<-1-exp(-lambda/n)
>
> #nagelkerke
> lambda<- -2*log( logLik(model)/logLik(null.model) )
> lambda2<- -2*log( logLik(model) )
> out<-(1-exp(-lambda/n))/(1-exp(-lambda2/n))
>
> can anyone help me out?
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help