1
$\begingroup$

Please pardon my ignorance, this may be a trivial question. I am fitting a simple linear model with interaction between a categorical predicator and a continuous predictor.

library(mice)
library(emmeans)

# Load dataset
data(nhanes)

# Complete case datasets
nhanes_cc <- nhanes[complete.cases(nhanes), ]

#fit linear model on complete case
fit_cc <- lm(chl ~ hyp*bmi, data = nhanes_cc)
summary(fit_cc)

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -153.528    771.386  -0.199    0.847
hyp          240.193    758.771   0.317    0.759
bmi           10.774     28.165   0.383    0.711
hyp:bmi       -7.172     27.682  -0.259    0.801

I like to understand the relation between hyp and bmi post model fit. I get different results when i use emmeans and emtrends

#emmeans interaction
#------------------------------------------------
> emmeans(fit_cc, pairwise ~ hyp|bmi  )
$emmeans
bmi = 26.5:
 hyp emmean   SE df lower.CL upper.CL
   1    182 14.9  9      148      216
   2    232 36.1  9      150      314

Confidence level used: 0.95 

$contrasts
bmi = 26.5:
 contrast    estimate   SE df t.ratio p.value
 hyp1 - hyp2    -49.8 39.1  9  -1.275  0.2341

#emtrends interaction
#------------------------------------------------
> emtrends(fit_cc, pairwise ~ hyp, var = "bmi"  )
$emtrends
 hyp bmi.trend   SE df lower.CL upper.CL
   1      3.60  3.0  9    -3.18     10.4
   2     -3.57 27.5  9   -65.82     58.7

Confidence level used: 0.95 

$contrasts
 contrast    estimate   SE df t.ratio p.value
 hyp1 - hyp2     7.17 27.7  9   0.259  0.8014

I like to know what is the difference between these estimates from emmeans and emtrends. Thanks.

$\endgroup$

1 Answer 1

3
$\begingroup$

Emmeans emmeans / contrasts and emtrends answer to different questions. The

emmeans(fit_cc, pairwise ~ hyp|bmi  )

gives you the estimated marginal means of chl at hyp1 and hyp2 when bmi is controlled for (the "emmeans" part), as well as tests for differences between these means (this is the "contrast" part).

The

emtrends(fit_cc, pairwise ~ hyp, var = "bmi"  )

gives you the slope coefficients of bmi predicting chl separately for each level of hyp (the "emtrends" part), and the test of whether the two slopes are different from each other (the "contrast" part).

$\endgroup$
1
  • 1
    $\begingroup$ Thank you very much. This is very clear to me now. $\endgroup$
    – Science11
    Commented Aug 26, 2023 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.