School effects with a mixed model
Estimate school random intercepts with fit_lmer and show them with their conditional uncertainty.
Uses
phit
Inputs
Runningfit_lmer() fits a random intercept for each school, as lme4::lmer() does, by REML. Each school's effect is shown with a 95% interval from its conditional variance, which R reports as ranef(fit, condVar = TRUE).
use function Phit\fit_lmer;
$fit = fit_lmer('score ~ study_hours + (1 | school)', $schools, reml: true);
$fit['random'][0]['effects']; // one intercept per school
$fit['random'][0]['effects_cond_var']; // and its conditional variance
- School SD
- 4.568
- Residual σ
- 5.3939
- Schools
- 12
- Students
- 250
Fixed effects
| Term | Estimate | Std. error | z | p | 95% CI |
|---|---|---|---|---|---|
| (Intercept) | 56.4929 | 1.5408 | 36.66 | < 0.0001 | [53.473, 59.513] |
| study_hours | 2.3428 | 0.1089 | 21.52 | < 0.0001 | [2.129, 2.556] |
n = 250, σ = 5.3939, log-likelihood = -791.66, AIC = 1,591.3
School intercepts with 95% conditional intervals
Script: site/vignettes/school-effects.php in phpstats/phit@76b22f0.