[R] Extract r.squared using cbind in lm
peter dalgaard
pdalgd at gmail.com
Thu Sep 8 15:10:02 CEST 2011
On Sep 8, 2011, at 14:53 , Johannes Radinger wrote:
> Hello,
>
> I am using cbind in a lm-model. For standard lm-models
> the r.squared can be easily extracted with summary(model)$r.squared,
> but that is not working in in the case with cbind.
>
> Here an example to illustrate the problem:
> a <- c(1,3,5,2,5,3,1,6,7,2,3,2,6)
> b <- c(12,15,18,10,18,22,9,7,9,23,12,17,13)
> c <- c(22,26,32,33,32,28,29,37,34,29,30,32,29)
>
> data <- data.frame(a,b,c)
>
> model_a <-lm(b~a,data=data)
> model_b <-lm(cbind(b,c)~a,data=data)
>
> summary(model_a)$r.squared
> summary(model_b)$r.squared
>
>
> How can I access r.squared in my case? Is there any option?
> In the end, I want a dataframe containing the the intercept,
> slope, p-value and r.squared for all Y's of my regression.
>
summary(model_b) is a list of one-dimensional summaries, so extract for each element:
> summary(model_b)$`Response b`$r.squared
[1] 0.03650572
Or you can get fancy and do things along the following lines:
> lapply(summary(model_b),"[[","r.squared")
$`Response b`
[1] 0.03650572
$`Response c`
[1] 0.348667
> thank you
> Johannes
--
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help
mailing list