0

我想知道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
4

1 回答 1

1

感谢 Ben Bolker,我发现emmeans并且可以复制 Stata 的对比命令结果:

library(emmeans) 

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

emmeans(lm.model, pairwise ~ sex*agegroup,simple = c("sex"))
于 2020-05-14T19:27:06.917 回答