[R] Coefficient of determination for generalized linear models
eric.e.harper at us.abb.com
eric.e.harper at us.abb.com
Wed Apr 9 16:47:14 CEST 2008
Thanks in advance for your kind attention.
I am using R to fit empirical data to generalized linear models. AIC (Akaike
information criterion) is a measure of the goodness of fit returned by calls
to glm(). I would also like to calculate the coefficient of determination
R2, although there is no consensus about the exact definition for
generalized models
([1]http://en.wikipedia.org/wiki/Coefficient_of_determination).
I found a package â€œpsclâ€ with a pR2 function that computes pseudo-R2
measures for various GLMs. The arguments to the call are a fitted model
object of class glm, polr, or mulitnom, and then â€˜additional arguments to be
passed to or from functionsâ€™.
The example from the documentation works well.
Browse[1]> data(admit)
Browse[1]> require(MASS)
Browse[1]> ## ordered probit model
Browse[1]> op1 <- polr(score ~ gre.quant + gre.verbal + ap + pt + female,
+ Hess=TRUE,
+ data=admit,
+ method="probit")
Browse[1]> pR2(op1)
llh llhNull G2 McFadden r2ML
r2CU
-106.5088203 -151.0299826 89.0423245 0.2947836 0.5682989
0.6032041
Browse[1]>
When I try with a glm object rather than polr, I get the following error:
Browse[1]> class(fit[[2]])
[1] "glm" "lm"
Browse[1]> pR2(fit[[2]])
Error in inherits(x, "data.frame") : object "ds" not found
The ds object does exist in the environment, but I do not know how to pass
it into pR2:
Browse[1]> class(ds)
[1] "data.frame"
Browse[1]> pR2(fit[[2]], ds)
Error in inherits(x, "data.frame") : object "ds" not found
Browse[1]> pR2
function (object, ...)
{
UseMethod("pR2")
}
<environment: namespace:pscl>
Browse[1]>
Question 1: How do I find the complete argument signature for pR2 in order
to perhaps pass it the ds object?
Question 2: If pR2 does not work with glm objects (for some unknown reason),
is there another function I can use to calculate R-squared and adjusted
R-squared for a generalized linear model?
Best regards,
\Eric
References
1. http://en.wikipedia.org/wiki/Coefficient_of_determination
More information about the R-help
mailing list