jacob-long / jacob-long/interactions

Conditional intercepts

Open
#52 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
R
Stars
135
Forks
19
PR merge metrics
No merged PRs in 30d

Description

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
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the reproducible examples in the issue and trace probe_interaction, sim_slopes, and interact_plot, comparing their conditional intercept calculations for centred and non-centred x. Done means the non-centred example produces matching intercepts across the console and plot, or clearly warns users when centered is required, without changing the already-correct centred case.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
analytics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.