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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

elaine kuo
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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: compute coefficient of determination (R-squared) for GLM (maximum likelihood)

Joris FA Meys
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.

Cheers
Joris

On Mon, Jun 21, 2010 at 12:00 AM, elaine kuo <[hidden email]> 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]]
>
> ______________________________________________
> [hidden email] 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
[hidden email]
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: compute coefficient of determination (R-squared) for GLM (maximum likelihood)

KateR
Dear mr Joris Meys

I would like to know, where to find this formulas in books or articles.
# possibility 1
R2 <- cor(y,predict(mod))^2

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

The first calculation seems OK, it gives the logicala values in models (from 0 to 1),  
but the second gives the negative values; higher corelation between the y and prediction gives more neagtive R2 value (up to -85).  


And my second question, looks logical but I need more teoretical answer;
why R^2 (r-square) values are not appropriate for use with non-linear regression models (like exponential)?

Thank you for your answers.  
 
Greetings, Kate