elaine kuo
2010-Jun-20 22:00 UTC
[R] compute coefficient of determination (R-squared) for GLM (maximum likelihood)
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]]
Joris Meys
2010-Jun-21 08:56 UTC
[R] compute coefficient of determination (R-squared) for GLM (maximum likelihood)
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 <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
KateR
2011-May-04 10:46 UTC
[R] compute coefficient of determination (R-squared) for GLM (maximum likelihood)
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 -- View this message in context: http://r.789695.n4.nabble.com/compute-coefficient-of-determination-R-squared-for-GLM-maximum-likelihood-tp2261975p3495108.html Sent from the R help mailing list archive at Nabble.com.