Re: [R] rms: getting adjusted R^2 from ols object

From: Peter Ehlers <ehlers_at_ucalgary.ca>
Date: Wed, 09 Mar 2011 04:11:27 -0800

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
>



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 Mar 2011 - 12:13:23 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 Mar 2011 - 12:20:20 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