interactions icon indicating copy to clipboard operation
interactions copied to clipboard

Conditional intercepts

Open nadyamajeed opened this issue 4 years ago • 2 comments

Setting cond.int = TRUE in probe_interaction when x is non-centred results in mismatching intercepts (i.e., console output from sim_slopes does not match plot output from interact_plot). This can be corrected by also setting centered = "none", but should probably be corrected or should print a warning for users who may not realise.

Reproducible example:

##### THIS IS OKAY -- x has already been centred beforehand

set.seed(0)
data1 = data.frame(x = scale(rnorm(20), center = TRUE), m = scale(rnorm(20), center = TRUE))
data1$y = 5 * data1$x * data1$m + rnorm(20)

res1 = lm(y ~ x*m, data = data1)
summary(res1)
# based on manual calculations
# when m at -1sd, int =  0.41, slope = -4.78
# when m at mean, int = -0.11, slope =  0.08
# when m at +1sd, int = -0.62, slope =  4.94

interactions::probe_interaction(res1, pred = x, modx = m, cond.int = TRUE)
# matches manual calculations

##### THIS IS NOT OKAY -- x has not been centred beforehand

set.seed(0)
data2 = data.frame(x = sample(c(0,1), 20, replace = TRUE), m = scale(rnorm(20), center = TRUE))
data2$y = 5 * data2$x * data2$m + rnorm(20)

res2 = lm(y ~ x*m, data = data2)
summary(res2)
# based on manual calculations
# when m at -1sd, int = -0.33, slope = -4.17
# when m at mean, int = -0.18, slope =  0.32
# when m at +1sd, int = -0.03, slope =  4.81

interactions::probe_interaction(res2, pred = x, modx = m, cond.int = TRUE)
# wrong cond ints in sim_slopes output but correct in interact_plot graph

interactions::probe_interaction(res2, pred = x, modx = m, cond.int = TRUE, centered = "none")
# correct cond ints

nadyamajeed avatar Jul 29 '21 14:07 nadyamajeed

Thanks for the report. I think the issue here is that the meaning of centered = "all" is different for sim_slopes() and interact_plot() which was not a good design decision by me. interact_plot() does not center either pred or modx because they are both displayed over their entire range. sim_slopes() does center pred to improve the interpretation of the slope coefficients. I'll have to think about whether and how to address this without breaking anything.

jacob-long avatar Apr 14 '22 16:04 jacob-long

Actually... it doesn't really make sense to center the predictor variable. The choice to center pred shouldn't affect the values of the slope for pred. So this is simply a case of making centered = "all" behave the same way in sim_slopes() as it currently does in interact_plot().

jacob-long avatar Apr 14 '22 16:04 jacob-long