Tabulate coefficients from lm

后端 未结 5 1623
失恋的感觉
失恋的感觉 2021-01-25 17:32

I have 10 linear models where I only need some information, namely: r-squared, p-value, coefficients of slope and intercept. I managed to extract these values (via ridiculously

5条回答
  •  长情又很酷
    2021-01-25 18:03

    Another solution, with lme4::lmList. The summary() method for objects produced by lmList does almost everything you want (although it doesn't store p-values, that's something I had to add below).

    m <- lme4::lmList(Qend~Rainfall|CatChro,data=d)
    s <- summary(m)
    pvals <- apply(s$fstatistic,1,function(x) pf(x[1],x[2],x[3],lower.tail=FALSE))
    data.frame(intercept=coef(s)[,"Estimate","(Intercept)"],
               slope=coef(s)[,"Estimate","Rainfall"],
               r.squared=s$r.squared,
               adj.r.squared=unlist(s$adj.r.squared),
               p.value=pvals)
    

提交回复
热议问题