【问题标题】:Print (display) reference category in R's lm summary?在 R 的 lm 摘要中打印(显示)参考类别?
【发布时间】:2017-07-24 16:25:14
【问题描述】:

当分类/名义变量输入线性模型时,如何打印使用的参考类别。这是一个例子:

summary(lm(data = iris, Sepal.Length ~ Species))

Coefficients:
                  Estimate Std. Error t value Pr(>|t|)    
(Intercept)         5.0060     0.0728   68.76  < 2e-16 ***
Speciesversicolor   0.9300     0.1030    9.03  8.8e-16 ***
Speciesvirginica    1.5820     0.1030   15.37  < 2e-16 ***

这是我想要的:

                  Estimate Std. Error t value Pr(>|t|)    
(Intercept)         5.0060     0.0728   68.76  < 2e-16 ***
**Reference: Speciessetosa**
Speciesversicolor   0.9300     0.1030    9.03  8.8e-16 ***
Speciesvirginica    1.5820     0.1030   15.37  < 2e-16 ***

如果有一种方法可以使这项工作普遍进行(当有多个分类预测变量时,每个参考组都很容易识别),那将是最好的。如果有办法使格式特别清晰,那将是双倍的好(我不感谢上面的示例格式)。

【问题讨论】:

    标签: r printing display lm summary


    【解决方案1】:

    您可以指定截距为零。

    summary(lm(Sepal.Length ~ Species + 0, data = iris))
    #Coefficients:
    #                  Estimate Std. Error t value Pr(>|t|)    
    #Speciessetosa       5.0060     0.0728   68.76   <2e-16 ***
    #Speciesversicolor   5.9360     0.0728   81.54   <2e-16 ***
    #Speciesvirginica    6.5880     0.0728   90.49   <2e-16 ***
    

    【讨论】:

    • 谢谢,但这会改变结果。我希望显示参考组 NAME,而不是没有拦截的结果。
    猜你喜欢
    • 1970-01-01
    • 2016-01-04
    • 1970-01-01
    • 2011-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    • 1970-01-01
    相关资源
    最近更新 更多