set.seed(1234)
<- 2000
n <- rep(0:1, each = n/2)
gender <- sample(0:10, n, replace = TRUE) + gender * sample(0:10, n, replace = TRUE)
y <- sample(0:10, n, replace = TRUE) + gender * y
x1 <- x1 + sample(0:10, n, replace = TRUE) + gender * y
x2 <- y + (x1 > median(x1) & x2 > median(x2) & gender == 1) * sample(0:10, n, replace = TRUE) * 2
y
<- data.frame(y = y, x1 = x1, x2 = x2, gender = gender) dat
Treatment vs. effect contrasts
regression
statistics
contrasts
Abstract
Here is a simple example to show the differences between treatment and effect contrasts.
Example dataset
Create a random dataset with criteria y
, predictors x1
, x2
and gender
.
y
andgender
are correlatedy
andx1
are correlated only if gender is 1y
andx2
are correlated only if gender is 1x1
andx2
are correlatedx1
andx2
have an interaction effect on y only if gender is 1
Descriptives
::nice_corrmatrix(dat, type = "html", numbered_columns = FALSE) wmisc
Variable | n | M | SD | y | x1 | x2 | gender |
---|---|---|---|---|---|---|---|
y | 2000 | 11.67 | 9.83 | - | |||
x1 | 2000 | 10.09 | 6.80 | .79*** | - | ||
x2 | 2000 | 20.30 | 12.88 | .82*** | .95*** | - | |
gender | 2000 | 0.50 | 0.50 | .68*** | .74*** | .79*** | - |
Note: | |||||||
✝p < .10; *p < .05; **p < .01; ***p < .001 |
Contrasts
The left part of the table is with gender as treatment contrast (0 vs. 1) and the right part with gender as effect contrast (-1 vs. 1)
# Gender has values 0 vs. 1 (treatment contrast)
<- lm(y ~ gender * x1 * x2, data = dat)
fit1
# Gender hast -1 vs. 1 (effect contrast)
$gender <- car::recode(dat$gender, "0 = -1; 1 = 1")
dat
<- lm(y ~ gender * x1 * x2, data = dat)
fit2
::tab_model(fit1, fit2, show.se = TRUE, show.ci = FALSE, col.order = c("est", "se", "std.est", "p"), digits = 4, dv.labels = c("Treatment contrast<br> for gender", "Effect contrast<br> for gender")) sjPlot
Treatment contrast for gender |
Effect contrast for gender |
|||||
Predictors | Estimates | std. Error | p | Estimates | std. Error | p |
(Intercept) | 5.2577 | 0.6189 | <0.001 | -4.6274 | 0.6427 | <0.001 |
gender | -19.7703 | 1.2853 | <0.001 | -9.8852 | 0.6427 | <0.001 |
x1 | -0.0695 | 0.1358 | 0.609 | 0.6640 | 0.0851 | <0.001 |
x2 | -0.0270 | 0.0795 | 0.734 | 0.4363 | 0.0482 | <0.001 |
gender × x1 | 1.4671 | 0.1702 | <0.001 | 0.7335 | 0.0851 | <0.001 |
gender × x2 | 0.9267 | 0.0963 | <0.001 | 0.4633 | 0.0482 | <0.001 |
x1 × x2 | 0.0056 | 0.0116 | 0.629 | -0.0124 | 0.0059 | 0.036 |
(gender × x1) × x2 | -0.0360 | 0.0118 | 0.002 | -0.0180 | 0.0059 | 0.002 |
Observations | 2000 | 2000 | ||||
R2 / R2 adjusted | 0.738 / 0.737 | 0.738 / 0.737 |
- The
intercept
in model1 (treatment contrast) is the mean ofy
for gender 0 - The
intercept
in model2 (effect contrast) is the mean ofy
for all data - All predictors in model1 without a
gender
term are effects for gender 0 while the interactions with agender
term are effects for gender 1 - All predictors in model2 without a
gender
term are effects across gender while the interactions with agender
term are the effects ofgender
(subtracted for gender 0 and added for gender 1). gender
has a significant effect ony
in both modelsx1
,x2
andx1*x2
only have a significant effect ony
in model 2- All
gender
interactions are significant in both models where the effect sizes and the standard errors of model2 are half of the corresponding values in model1, sop
is identical.
For those who love Anovas ;-)
|> car::Anova(type = "III") |> wmisc::nice_table() fit1
Sum Sq | Df | F value | Pr(>F) | |
---|---|---|---|---|
(Intercept) | 1834.702440 | 1 | 72.1670347 | 0.0000000 |
gender | 6014.888596 | 1 | 236.5924110 | 0.0000000 |
x1 | 6.660056 | 1 | 0.2619697 | 0.6088269 |
x2 | 2.943411 | 1 | 0.1157775 | 0.7336959 |
gender:x1 | 1889.686051 | 1 | 74.3297855 | 0.0000000 |
gender:x2 | 2352.201418 | 1 | 92.5225789 | 0.0000000 |
x1:x2 | 5.937356 | 1 | 0.2335427 | 0.6289624 |
gender:x1:x2 | 235.982758 | 1 | 9.2822550 | 0.0023442 |
Residuals | 50642.613736 | 1992 | NA | NA |
|> car::Anova(type = "III") |> wmisc::nice_table() fit2
Sum Sq | Df | F value | Pr(>F) | |
---|---|---|---|---|
(Intercept) | 1318.0715 | 1 | 51.845636 | 0.0000000 |
gender | 6014.8886 | 1 | 236.592411 | 0.0000000 |
x1 | 1548.5771 | 1 | 60.912449 | 0.0000000 |
x2 | 2085.6571 | 1 | 82.038201 | 0.0000000 |
gender:x1 | 1889.6861 | 1 | 74.329785 | 0.0000000 |
gender:x2 | 2352.2014 | 1 | 92.522579 | 0.0000000 |
x1:x2 | 112.2512 | 1 | 4.415342 | 0.0357425 |
gender:x1:x2 | 235.9828 | 1 | 9.282255 | 0.0023442 |
Residuals | 50642.6137 | 1992 | NA | NA |