[R-sig-Geo] Help to save the value of "Multiple R-Squared" in a a simple regression model

Kingsford Jones kingsfordjones at gmail.com
Sun Apr 12 21:08:29 CEST 2009

On Sun, Apr 12, 2009 at 10:23 AM, gianni lavaredo
<gianni.lavaredo at gmail.com> wrote:
> Dear R User,
> "Buona Pasqua".

> I have a simple regression model
> myModel <- lm( y ~ x)
> Summary(myModel)
> I wish to save the value of "Multiple R-Squared" in a list or data.frame
> format.

Hi Gianni,

For a 'simple' regression

r2 <- cor(y,x)^2

More generally, names(summary(MyModel)) will tell you the names of the
objects in the list produced by summary.lm -- or use the 'str'
function to see a summary of the structure of the object. Since the
R-squared list element is named 'r.squared' it can be extracted with

r2 <- summary(myModel)$r.squared

As for making a data frame or list object,

lst <- list(r2)
df <- data.frame(r2)

Buona Pasqua,

Kingsford Jones

> Thanks
> Gianni
>        [[alternative HTML version deleted]]
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

More information about the R-sig-Geo mailing list