【问题标题】:Equivalent to contrast (Stata) in R相当于R中的对比度(Stata)
【发布时间】:2020-05-14 02:18:57
【问题描述】:

我想知道R中是否有与Stata的contrast命令等效的东西。

特别是我对sex@agegroup#group2感兴趣

我知道包 margins 可以计算模型对象的边际(或部分)效应。

我从 Stata 网页中提取了一个示例: https://www.stata.com/features/overview/contrasts/

regress y agegroup##sex

contrast r.sex@agegroup
Contrasts of marginal linear predictions

Margins      : asbalanced
                                         df           F        P>F

          sex@agegroup       

(female vs male) 10-19                    1        1.13     0.2945

(female vs male) 20-29                    1        3.36     0.0743

(female vs male) 30-39                    1        5.00     0.0310

(female vs male) 40-59                    1        0.41     0.5279

(female vs male) 60-79                    1        2.71     0.1076

                 Joint                    5        2.52     0.0448                           

            Denominator                  40

                                   Contrast   Std. Err.     [95% Conf. Interval]

             sex@agegroup        

(female vs male) 10-19             6.841855   6.441542     -6.176987     19.8607

(female vs male) 20-29            -11.80631   6.441542     -24.82515    1.212534

(female vs male) 30-39            -14.40607   6.441542     -27.42491   -1.387228

(female vs male) 40-59            -4.101691   6.441542     -17.12053    8.917151

(female vs male) 60-79            -10.60137   6.441542     -23.62022    2.417469

【问题讨论】:

  • 试试emmeans 包?
  • 谢谢 Ben,我会试试 emmeans 包。

标签: r stata anova compare-contrast


【解决方案1】:

感谢 Ben Bolker,我找到了 emmeans,我可以复制 Stata 的对比命令结果:

library(emmeans) 

lm.model= lm(y ~ agegroup*sex,data= df)

emmeans(lm.model, pairwise ~ sex*agegroup,simple = c("sex"))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-11
    相关资源
    最近更新 更多