rvlenth / emmeans

Estimated marginal means
https://rvlenth.github.io/emmeans/
364 stars 32 forks source link

Pairwise comparisons for a continuous x continuous interaction produce identical t- and p-values #452

Closed Tsode closed 1 year ago

Tsode commented 1 year ago

Explain your question

Hi! I'd like to conduct pairwise comparisons to a continuous x continuous interaction. I remember doing this with no issue sometime in the past using emtrends and choosing certain scale points from the other predictor (e.g. if I standardized the predictors, I used -1, 0 and 1).

However, now that I try this, all models and data give me identical t- and p-values for the pairwise comparisons. For instance, using HSB data from the candisc package:

model<-lm(read ~ locus*concept, data=HSB) #locus is standardized
em<-emtrends(model, ~ locus, var="concept", at=list(locus=c(-1,0,1)))
pairs(em)
contrast estimate    SE  df t.ratio p.value
 (-1) - 0    -1.80 0.807 596  -2.235  0.0662
 (-1) - 1    -3.61 1.615 596  -2.235  0.0662
 0 - 1       -1.80 0.807 596  -2.235  0.0662

or with iris data

model<-lm(Sepal.Length ~ Sepal.Width * Petal.Length, data=iris)
em<-emtrends(model, ~ Sepal.Width, var="Petal.Length", at=list(Sepal.Width=c(2.5,3,3.5)))
pairs(em)
 contrast  estimate     SE  df t.ratio p.value
 2.5 - 3     0.0385 0.0215 146   1.789  0.1769
 2.5 - 3.5   0.0770 0.0431 146   1.789  0.1769
 3 - 3.5     0.0385 0.0215 146   1.789  0.1769

The same happens with all data I have tried, my own data and inbuilt datasets and regardless of how many points I specify in the list, and regardless of if I use the pairwise command inside emtrends command or emtrends followed by pairs command.

I'm really sorry if I bother you for nothing but I didn't find an answer in the vignettes. This does not happen when I explore a categorical x continuous interaction using emtrends.

best, Sointu Leikas

rvlenth commented 1 year ago

Please note that your question is in violation of the last ground rule about not using the same names for different objects. But I will answer your question anyway.

This is nothing peculiar to emtrends(). It happens because you have specified exactly this behavior in your model. The fitted model is of the form $\hat y = a + b\cdot x_1x_2$. Taking $x_1$ in the role of var in the emtrends() call, then the trend is the derivative w.r.t. $x_1$, $t = b\cdot x_2$. If we now take $x_2$ values of $1,2,3$, we obtain $t_1,t_2,t_3 = b, 2b, 3b$ so that $t_1-t_2 = -b,$ $t_3 - t_1 = -2b$, and $t_2-t_3 = -b$ In all cases, we are testing the significance of $-b$ or a multiple thereof.

This is verified by your second model:

> model2<-lm(Sepal.Length ~ Sepal.Width * Petal.Length, data=iris)
> summary(model2)

Call:
lm(formula = Sepal.Length ~ Sepal.Width * Petal.Length, data = iris)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.99594 -0.21165 -0.01652  0.21244  0.77249 

Coefficients:
                         Estimate Std. Error t value Pr(>|t|)
(Intercept)               1.40438    0.53253   2.637  0.00926
Sepal.Width               0.84996    0.15800   5.379 2.91e-07
Petal.Length              0.71846    0.13886   5.174 7.45e-07
Sepal.Width:Petal.Length -0.07701    0.04305  -1.789  0.07571

Residual standard error: 0.3308 on 146 degrees of freedom
Multiple R-squared:  0.8436,    Adjusted R-squared:  0.8404 
F-statistic: 262.5 on 3 and 146 DF,  p-value: < 2.2e-16

Note that the $t$ ratio for Sepal.Width:Petal.Length is $-1.789$, which is the negative of what appears in your output. Your P value is different because the software is applying a Tukey adjustment (which is incorrect here because the estimates are dependent).

Tsode commented 1 year ago

Hi, thank you very much for your answer and sorry about the vio and opening a non-issue!