[R] compute coefficient of determination (R-squared) for GLM (maximum likelihood)

Joris Meys jorismeys at gmail.com
Mon Jun 21 10:56:49 CEST 2010

It is not available for a reason. The correct way would be to use lm()
instead, if possible. This function reports an R² in the summary. In
the case of glm, and if you're absolutely sure about what you're
doing, you can use one of the approximations that is used when looking
at prediction only, realizing very well you can't possibly use R² to
compare models with a different number of variables and realizing very
well that the R² doesn't mean what you think it does when using a link
function :

x <- 1:100
y <- 1:100 + rnorm(100)

mod <- glm(y~x)

# possibility 1
R2 <- cor(y,predict(mod))^2

# possibility 2
R2 <- 1 - (sum((y-predict(mod))^2)/sum((y-mean(y))^2))

In the case where you use a link function, you should work on the
converted data : convert the values of y, and use
predict(mod,type="link") for a correct estimate.


On Mon, Jun 21, 2010 at 12:00 AM, elaine kuo <elaine.kuo.tw at gmail.com> wrote:
> Dear,
> I want to compute coefficient of determination (R-squared) to complement AIC
> for model selection of
> multivariable GLM.
> However, I found this is not a built-in function in glm. neither is it
> available through reviewing the question in the R-help archive.
> Please kindly help and thanks a lot.
> Elaine
>        [[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Joris Meys
Statistical consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

tel : +32 9 264 59 87
Joris.Meys at Ugent.be
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

More information about the R-help mailing list