Model count outcomes with generalized linear mixed models that include interaction terms, revealing whether predictor effects differ across moderators in ABCD repeated measures.
Work in ProgressExamples are a work in progress. Please exercise caution when using code examples, as they may not be fully verified. If you spot gaps, errors, or have suggestions, we'd love your feedback—use the "Suggest changes" button to help us improve!
Overview
Generalized Linear Mixed Models with interaction terms test whether predictor effects on non-normal outcomes vary across levels of other variables, combining fixed and random effects to model moderation while accounting for individual differences. Interaction terms reveal whether relationships between covariates and outcomes change over time or differ by group membership. This tutorial examines alcohol use in ABCD youth across four annual assessments using a Negative Binomial GLMM with a family conflict × time interaction to test whether adolescents from high-conflict families show different drinking trajectories compared to those from low-conflict families.
When to Use:
Use when you want to test moderator effects (e.g., family conflict × time) inside a GLMM framework.
Key Advantage:
Captures how predictor effects differ across levels of another variable while still honoring within-subject correlation via random effects.
What You'll Learn:
How to include and interpret interaction terms in GLMMs, evaluate predicted probabilities, and visualize moderation effects.
Data Access
Data Download
ABCD data can be accessed through the DEAP platform or the NBDC Data Access Platform (LASSO), which provide user-friendly interfaces for creating custom datasets with point-and-click variable selection. For detailed instructions on accessing and downloading ABCD data, see the DEAP documentation.
Loading Data with NBDCtools
Once you have downloaded ABCD data files, the NBDCtools package provides efficient tools for loading and preparing your data for analysis. The package handles common data management tasks including:
Automatic data joining - Merges variables from multiple tables automatically
Built-in transformations - Converts categorical variables to factors, handles missing data codes, and adds variable labels
Event filtering - Easily selects specific assessment waves
The negative binomial GLMM results indicate a significant but gradual increase in alcohol use over time, with a 0.165 increase per timepoint (p < 0.001). This suggests that alcohol consumption becomes more pronounced as adolescents age.Family conflict does not significantly predict overall alcohol use (p = 0.659), indicating that its role in shaping drinking behaviors may be minimal or influenced by other unmeasured factors. Additionally, the interaction between family conflict and time is not statistically significant (p = 0.657), suggesting that adolescents from high-conflict families do not exhibit a steeper increase in alcohol use compared to their peers.These findings highlight that while alcohol use tends to increase over time, the role of family conflict in drinking trajectories remains unclear.
Create Interaction Plot
23 lines
# Generate predicted values for interaction visualization
preds <- ggpredict(model, terms = c("time", "family_conflict"))
# Plot interaction effect
visualization <- ggplot(preds, aes(x = x, y = predicted, color = group, group = group)) +
geom_point(size = 3) +
geom_line() +
labs(
title = "Interaction: Family Conflict & Alcohol Use Over Time",
x = "Time",
y = "Predicted Alcohol Use",
color = "Family Conflict Level"
) +
theme_minimal()
visualization
# Save interaction plot
ggsave(
filename = "visualization.png",
plot = visualization,
width = 8, height = 6, dpi = 300
)
Create Predicted vs Observed Plot
21 lines
# Generate predictions and create diagnostic plot
df_long$predicted <- predict(model, type = "response")
visualization2 <- ggplot(df_long, aes(x = predicted, y = alcohol_use)) +
geom_point(alpha = 0.5) +
geom_smooth(method = "lm", color = "red", se = FALSE) +
labs(
title = "Predicted vs. Observed Alcohol Use",
x = "Predicted Alcohol Use",
y = "Observed Alcohol Use"
) +
theme_minimal()
visualization2
# Save predicted vs observed plot
ggsave(
filename = "visualization2.png",
plot = visualization2,
width = 8, height = 6, dpi = 300
)
Interpretation
Visualization Interpretation
Visualization 1 (Interaction Effect): Shows the predicted alcohol use trajectories over time for different levels of family conflict. The lines represent how alcohol use changes across assessment waves, with separate trajectories for different family conflict levels. The non-significant interaction (p = 0.657) is reflected in the parallel or near-parallel nature of the lines, indicating that the rate of change in alcohol use over time is similar across family conflict levels.Visualization 2 (Predicted vs Observed): Displays the relationship between model-predicted values and actual observed alcohol use. The red line shows the overall fit, with points representing individual observations. The alignment of points along the diagonal suggests that the model captures the general pattern of alcohol use reasonably well, though individual variability remains evident.
Discussion
The GLMM confirmed that adolescents from higher-conflict households reported elevated alcohol use at every wave, but the conflict-by-time interaction was not significant (p = 0.657). Parallel fitted lines across time therefore suggest that family conflict shifts the overall level of use rather than its rate of change. Even a null interaction is informative: it indicates that prevention efforts targeting conflict-laden contexts should focus on consistently higher risk instead of accelerating trajectories.
Random intercepts captured meaningful between-person heterogeneity after accounting for conflict, and the marginal versus conditional R² values showed that including household context noticeably improved explained variance. These diagnostics, coupled with the predicted-versus-observed plot, support the adequacy of the Poisson link and variance assumptions. More broadly, this exercise illustrates how GLMMs let us probe conditional effects without sacrificing the ability to model non-normal outcomes, and how visualizations of fitted trajectories can quickly reveal whether an interaction meaningfully alters developmental trends.
Additional Resources
4
lme4 Package Documentation
DOCS
Official CRAN documentation for the lme4 package, with detailed examples of interaction terms in generalized linear mixed models and interpretation of fixed effects.
Tutorial on specifying and interpreting interaction effects in generalized linear mixed models, including cross-level interactions and visualization strategies.
Methodology paper on proper interpretation of interaction terms in multilevel models, covering centering decisions and probing significant interactions (Aiken & West, 1991). Note: access may require institutional or paid subscription.
R package for visualizing and probing interaction effects in regression models, including simple slopes analysis and Johnson-Neyman intervals for mixed models.