[R] Coefficient of determination for generalized linear models

From: <eric.e.harper_at_us.abb.com>
Date: Wed, 09 Apr 2008 10:47:14 -0400

   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

   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


   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, ...)




   <environment: namespace:pscl>


   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,



  1. http://en.wikipedia.org/wiki/Coefficient_of_determination

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. Received on Wed 09 Apr 2008 - 15:09:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 Apr 2008 - 15:30:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive