Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional intercepts #52

Open
nadyamajeed opened this issue Jul 29, 2021 · 2 comments
Open

Conditional intercepts #52

nadyamajeed opened this issue Jul 29, 2021 · 2 comments

Comments

@nadyamajeed
Copy link

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
@jacob-long
Copy link
Owner

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
Copy link
Owner

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants