Exercise: Separate participant and item variation#
The same participants respond to the same words. Compare models that make different assumptions about this crossed structure and examine prediction for participants never used in fitting.
See the shared submission guidance and rubric. Run from book/exercises; the setup below supplies data, not completed answers.
# Shared simulator and small utility functions; no live service is called.
source("../R/course.R")
library(lme4)
d <- simulate_trials(seed=114,n_subjects=30,n_items=24)
split <- split_groups(d$subject, proportion=.8, seed=114)
train <- droplevels(d[split$train, ]); test <- d[split$test, ]
1. Draw the grouping structure#
Count trials per participant and per item, and draw a small participant-by-item diagram. Explain why items are crossed with participants rather than nested. State the target for a frequency coefficient and the target for prediction in test.
# Check balance and show that participants are disjoint but items overlap.
Your explanation and evidence:
2. Fit three explanations of dependence#
Fit pooled lm, participant-intercept lmer, and crossed participant/item-intercept lmer with the same fixed effects frequency + length and the same training rows. Use REML=FALSE for comparable lmer likelihoods. Report coefficient estimates/SEs, variance components, convergence messages, and singularity. Compare AIC descriptively; do not apply an ordinary chi-square reference test uncritically to a zero random-effect variance.
# Fit the three models and construct a readable comparison table.
Your explanation and evidence:
3. Predict an unseen participant#
Compare test MSE for the three models. For the crossed model, compare population-level predictions (re.form=NA) with predictions retaining known item effects and assigning zero effects to new participants (allow.new.levels=TRUE). Explain why these answer different questions. Add the training-mean baseline.
# Calculate explicitly labeled prediction variants and baseline MSE.
Your explanation and evidence:
4. Plan a random slope#
Explain whether frequency varies within participants and within items in this dataset. Propose a participant-specific frequency slope and discuss the design needed to estimate it. Optionally fit it and report singularity; the generator contains no random slope, so a boundary estimate is not automatically a coding failure.
# Optional random-slope model; retain any diagnostic warnings in the report.
Your explanation and evidence:
What to submit#
A grouping diagram, model/diagnostic table, and new-participant prediction comparison. Explain what additional holdout would be required to assess new words too.