[R] rms: getting adjusted R^2 from ols object
Peter Ehlers
ehlers at ucalgary.ca
Wed Mar 9 13:11:27 CET 2011
On 2011-03-09 01:25, Martyn Byng wrote:
> Hi,
>
> If you look in the print.ols function you can see that the adjusted R^2
> is not stored in the ols object but calculated on the fly, the relevant
> code snippet from that function looks to be:
>
> x<- ols1
>
> stats<- x$stats
> resid<- x$residuals
> n<- length(resid)
> ndf<- stats["d.f."]
> df<- c(ndf, n - ndf - 1, ndf)
> r2<- stats["R2"]
> rdf<- df[2]
> rsqa<- 1 - (1 - r2) * (n - 1)/rdf
>
>
> Martyn
Or try this:
rsqa <- summary.lm(ols1)[["adj.r.squared"]]
Peter Ehlers
>
>
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Mark Seeto
> Sent: 09 March 2011 09:10
> To: r-help at r-project.org
> Subject: [R] rms: getting adjusted R^2 from ols object
>
> How can I extract the adjusted R^2 value from an ols object (using rms
> package)?
>
> library(rms)
> x<- rnorm(10)
> y<- x + rnorm(10)
> ols1<- ols(y ~ x)
>
> Typing "ols1" displays adjusted R^2 among other things, but how can I
> assign it to a variable? I tried str(ols1) but couldn't see where to
> go from there.
>
> Thanks,
> Mark Seeto
>
More information about the R-help
mailing list