我想找到一种方法来获取 anova(model) 的摘要输出并将其放入表格中。我无法找到任何方法来执行此操作,因此我只是使用 gt() 和 data.frames 手动执行此操作。到目前为止我的功能是这样的:
anovaPrint<-function(x){
g<-data.table()
suppressWarnings(g[,':='("Response: depression"=row.names(x),Df=x$Df,'Sum Sq'=x$`Sum Sq`,'Mean Sq'=x$`Mean Sq`,'F value'=x$`F value`,'Pr(>F)'=x$`Pr(>F)`," "=symnum(x$`Pr(>F)`, corr = FALSE, na = FALSE, cutpoints = c(0,
0.001, 0.01, 0.05, 0.1, 1), symbols = c("***", "**", "*", ".", " ")))])
gt(g)%>%
tab_footnote("Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1")%>%
}
我正在尝试复制此输出,这就是我到目前为止所拥有的。
(目标输出)
(电流输出)
Rstudio 显示,当我将方差分析模型保存到变量中时,有一个标题数据字段。
> t<-anova(model)
> dput(t)
structure(list(Df = c(1L, 1L, 1L, 1L, 3130L), `Sum Sq` = c(799.229823148598,
208.833026298425, 327.319201369881, 44.9767447590518, 29756.4490194161
), `Mean Sq` = c(799.229823148598, 208.833026298425, 327.319201369881,
44.9767447590518, 9.50685272185817), `F value` = c(84.0688129427952,
21.9665784680008, 34.4298172009448, 4.73098154299174, NA), `Pr(>F)` = c(8.43085789787755e-20,
2.89282673612949e-06, 4.88082683354118e-09, 0.0296985950527817,
NA)), row.names = c("diversity", "size", "total", "density",
"Residuals"), class = c("anova", "data.frame"), heading = c("Analysis of Variance Table\n",
"Response: depression"))
如何访问标题字段?我正在使用 Mass 包中的 gt() 库和 Anova() 。我尝试过美元符号符号
attr(t, "heading")
(参见
unclass(t)
或 str(t)
)