代码之家  ›  专栏  ›  技术社区  ›  computer_goblin

如何访问Anova输出列表中的“标题”

  •  0
  • computer_goblin  · 技术社区  · 2 年前

    我想找到一种方法从中获取摘要输出 anova(model) 然后把它放进桌子里。我一直找不到任何方法来做到这一点,所以我只是手动使用 gt() 和数据帧。到目前为止,我的职能是:

    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")%>%
    }
    

    我正在尝试复制这个输出,这就是我目前所拥有的。

    (目标输出)

    enter image description here

    (电流输出)

    enter image description here

    R表明,当我将方差模型保存到变量中时 heading 数据字段。

    > 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"))
    

    我将如何访问 标题 领域我正在使用 gt 图书馆和 anova() 来自MASS包。我试过用美元符号表示法

    1 回复  |  直到 2 年前
        1
  •  1
  •   Ben Bolker    2 年前

    attr(t, "heading")

    看见 unclass(t) str(t) )

    推荐文章