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

是否有方法打印模型摘要的特定部分?

r
  •  0
  • Joe  · 技术社区  · 3 年前

    我希望在查看我的模型时打印总结的一部分(更多以节省空间和更清晰的输出),是否有必要这样做?所有需要的是如下圆圈所示的差异表

    enter image description here

    使用的型号;

    pupils_test_model = lmer(IQ ~ ses + (1 | Class), 
                        data = pupils) 
    
    1 回复  |  直到 3 年前
        1
  •  2
  •   G5W    3 年前

    如果你只想得到这些线路,你可以使用 capture.output 然后选择相关行。

    temp = capture.output(summary(model))
    Start = grep("Random effects", temp)
    End   = grep("Number of obs", temp)
    print(unname(temp[Start:End]))
    
    [1] "Random effects:"                                  
    [2] " Groups       Name        Variance Std.Dev. Corr "
    [3] " Petal.Length (Intercept) 2.16667  1.4720        "
    [4] "              Petal.Width 0.62156  0.7884   -0.91"
    [5] " Residual                 0.08241  0.2871        "
    [6] "Number of obs: 150, groups:  Petal.Length, 43"