jacob-long / jacob-long/interactions
Issue with inclusion of "weights"
- Dominant language
- R
- Stars
- 135
- Forks
- 19
- PR merge metrics
- No merged PRs in 30d
Description
Greetings, when running the program with lmer function (and formula for multilevel modeling), the output changes based on the inclusion (or exclusion) of "weights").
For example, when running the following, the mean, +1SD, -1SD will be incorrectly calculated:
Example 1:
```r
mod_jn <- lmer(IDAS_illtemper_SUM_final ~ LupTime + BL_Mean_BOLD_RPut_FB_Slow_Win +
fMRI_Diff_RPut_FB_Slow_Win + age + BL_Mean_BOLD_RPut_FB_Slow_Win *
LupTime + fMRI_Diff_RPut_FB_Slow_Win * LupTime + (1 | Subject),
data = mod_pred, weights = weights, REML = TRUE)
# JN analysis and plots:
jn <- probe_interaction(model=mod_jn,
pred = LupTime,
modx = fMRI_Diff_RPut_FB_Slow_Win,
digits = getOption("jtools-digits", 2),
jnplot = TRUE,
confint = TRUE
)
Slope of LupTime when fMRI_Diff_RPut_FB_Slow_Win = 0.2538121 (- 1 SD):
Est. S.E. 2.5% 97.5% t val. p
------- ------ ------- ------- -------- ------
-0.28 0.09 -0.46 -0.09 -2.97 0.00
Slope of LupTime when fMRI_Diff_RPut_FB_Slow_Win = 0.5633464 (Mean):
Est. S.E. 2.5% 97.5% t val. p
------- ------ ------- ------- -------- ------
-0.45 0.06 -0.57 -0.33 -7.20 0.00
Slope of LupTime when fMRI_Diff_RPut_FB_Slow_Win = 0.8728807 (+ 1 SD):
Est. S.E. 2.5% 97.5% t val. p
------- ------ ------- ------- -------- ------
-0.62 0.12 -0.86 -0.38 -5.14 0.00
```
If I remove "weights" from the code, the mean, +1SD, -1SD will be CORRECTLY calculated and the plot appears as expected. this doesn't represent the complete formula for my model. Additionally, weighting seems most appropriate.
Example 2:
```r
mod_jn <- lmer(IDAS_illtemper_SUM_final ~ LupTime + BL_Mean_BOLD_RPut_FB_Slow_Win +
fMRI_Diff_RPut_FB_Slow_Win + age + BL_Mean_BOLD_RPut_FB_Slow_Win *
LupTime + fMRI_Diff_RPut_FB_Slow_Win * LupTime + (1 | Subject),
data = mod_pred, REML = TRUE)
Slope of LupTime when fMRI_Diff_RPut_FB_Slow_Win = -0.36811581 (- 1 SD):
Est. S.E. 2.5% 97.5% t val. p
------- ------ ------- ------- -------- ------
-0.12 0.14 -0.39 0.14 -0.91 0.37
Slope of LupTime when fMRI_Diff_RPut_FB_Slow_Win = 0.07231536 (Mean):
Est. S.E. 2.5% 97.5% t val. p
------ ------ ------- ------- -------- ------
0.05 0.07 -0.09 0.20 0.73 0.47
Slope of LupTime when fMRI_Diff_RPut_FB_Slow_Win = 0.51274654 (+ 1 SD):
Est. S.E. 2.5% 97.5% t val. p
------ ------ ------- ------- -------- ------
0.23 0.14 -0.04 0.50 1.69 0.09
```
Finally, if I leave the full formula and attempt to fix the mod.x values, the lines appear flipped -- that is, where -1 SD should be, +1 SD is, and vice versa, on the interaction plot. This is in contrast to both Example 2 (above) and ggplots (accounting for weights).
Example 3:
```r
jn <- probe_interaction(model=mod_jn,
pred = LupTime,
modx = fMRI_Diff_RPut_FB_Slow_Win,
modx.values = c(-0.37, 0.07, 0.51),
modx.labels = c("-1 SD", "Mean", "+1 SD"),
digits = getOption("jtools-digits", 2),
jnplot = TRUE,
confint = TRUE
)
```
Any insight on what might be driving this discrepancy when using "weights" in the formula? Thank you for your time!


Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the three examples with the R lmer model and interactions::probe_interaction, comparing weighted and unweighted results. Inspect how probe_interaction derives means, standard deviations, modx.values, and plot labels for weighted models. Done means the reported values and interaction-plot lines consistently match the supplied moderator values and the expected weighted analysis.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100