Print R-squared for all of the models fit with lmList

≡放荡痞女 提交于 2019-11-28 10:30:54

Here you go:

sapply(fit,function(x) summary(x)$r.squared)
       11        12 
0.9657143 0.9657143 

Or to do everything at once:

sumfun <- function(x) c(coef(x),summary(x)$r.squared)
t(sapply(fit,sumfun))

(you need to transpose the results from sapply to get the table as specified above). Then use names() <- or setNames() to get the column names the way you want them.

using Ben Bolker's code, you can make a function that transposes the results and gives the table, all at once:

sumfun <- function(x) 
{
  aux <- function(x) c(coef(x), summary(x)$r.squared)
  t(sapply(x,aux))
}
sumfun(fit)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!