easystats / modelbased

:chart_with_upwards_trend: Estimate effects, contrasts and means based on statistical models
https://easystats.github.io/modelbased/
GNU General Public License v3.0
234 stars 19 forks source link

Pairwise paired contrasts? #237

Open jmgirard opened 12 months ago

jmgirard commented 12 months ago

This may be an {emmeans} question, but if I run a one-way repeated measures ANOVA and give it to estimate_contrasts(), is it doing paired t-tests for each pair? I'm confused by the dfs listed.

data("selfesteem", package = "datarium")
selfesteem
#>    id       t1       t2       t3
#> 1   1 4.005027 5.182286 7.107831
#> 2   2 2.558124 6.912915 6.308434
#> 3   3 3.244241 4.443434 9.778410
#> 4   4 3.419538 4.711696 8.347124
#> 5   5 2.871243 3.908429 6.457287
#> 6   6 2.045868 5.340549 6.653224
#> 7   7 3.525992 5.580695 6.840157
#> 8   8 3.179425 4.370234 7.818623
#> 9   9 3.507964 4.399808 8.471229
#> 10 10 3.043798 4.489376 8.581100
library(easystats)
#> # Attaching packages: easystats 0.6.0
#> ✔ bayestestR  0.13.1   ✔ correlation 0.8.4 
#> ✔ datawizard  0.9.0    ✔ effectsize  0.8.6 
#> ✔ insight     0.19.5   ✔ modelbased  0.8.6 
#> ✔ performance 0.10.5   ✔ parameters  0.21.2
#> ✔ report      0.5.7    ✔ see         0.8.0
sel <- data_to_long(selfesteem, select = c(t1, t2, t3))
fit <- aov(value ~ name + Error(id), data = sel)
estimate_contrasts(fit, contrast = "name", method = "pairwise")
#> Warning: Could not recover model data from environment. Please make sure your
#>   data is available in your workspace.
#>   Trying to retrieve data from the model frame now.
#> Note: re-fitting model with sum-to-zero contrasts
#> Marginal Contrasts Analysis
#> 
#> Level1 | Level2 | Difference |         95% CI |   SE | t(26.00) |      p
#> ------------------------------------------------------------------------
#> t1     |     t2 |      -1.79 | [-2.83, -0.76] | 0.40 |    -4.45 | < .001
#> t1     |     t3 |      -4.50 | [-5.53, -3.46] | 0.40 |   -11.16 | < .001
#> t2     |     t3 |      -2.70 | [-3.73, -1.67] | 0.40 |    -6.71 | < .001
#> 
#> Marginal contrasts estimated at name
#> p-value adjustment method: Holm (1979)

Created on 2023-10-07 with reprex v2.0.2

If each contrast is a paired $t$-test, then shouldn't its df be the number of paired differences minus 1 (e.g., 9 in this case)? Instead, it lists the df as 26 (presumably n - g - 1). Is this a mistake or am I misunderstanding something about how contrasts work?