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. thank you Johannes --
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
Hi> > 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?> summary(model_b)[[1]]$r.squared[1] 0.03650572 The result is list of 2 models, one for response b and one for response c you can get values for both by lapply or sapply sapply(summary(model_b), "[", 8) putting all together in some data frame is a matter of unlisting results and transforming them according to your wish. see ?unlist, ?coef Regards Petr In the end, I want a dataframe containing the the intercept,> slope, p-value and r.squared for all Y's of my regression. > > thank you > Johannes > -- > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Apparently Analagous Threads
- Using predict() After Adding a Factor to a glm.nb() Model
- please explain find_with_ferret, retrieve_records, :include and :conditions
- Extract R-squared from summary of lm
- extract R-squared and P-value from lm results
- R.squared in Weighted Least Square using the Lm Function