Skip to main content

regression_diagnostics/mixed/
mod.rs

1//! **Mixed / hierarchical** linear models — regression for grouped (clustered,
2//! repeated-measures, multilevel) data, where observations within a group are
3//! correlated and ordinary least squares would understate the uncertainty.
4//!
5//! * [`LinearMixedModel`] — a **random-intercept** model
6//!   `yᵢⱼ = xᵢⱼᵀβ + bⱼ + εᵢⱼ` with one grouping factor, fit by REML (default) or
7//!   ML. Because there is a single random intercept the marginal covariance
8//!   inverts in closed form per group, so estimation is a one-dimensional search
9//!   over the variance ratio `λ = σ²_b/σ²_e` — no general optimizer needed.
10//! * [`MixedModel`] — the **general** Gaussian LMM: one or more
11//!   [`RandomEffect`] terms giving **random slopes** and/or **crossed / nested**
12//!   grouping factors. Profiles `β` and `σ²_e` out and optimizes the relative
13//!   covariance parameters with Nelder–Mead over a dense Cholesky solve; it
14//!   reduces to [`LinearMixedModel`] exactly for a single intercept term.
15//! * [`GlmmFit`] — a **generalized** linear mixed model (random intercept,
16//!   Poisson or Bernoulli) via the **Laplace approximation**: an inner Newton
17//!   loop for the conditional modes inside an outer search over `β` and `σ_b`.
18//!
19//! The diagnostics that matter here are the ones OLS cannot express: the
20//! **variance components**, the **intraclass correlation** `ICC` (how much of the
21//! variance is between groups), the shrinkage **BLUPs** of the group effects, and
22//! fixed-effect standard errors that account for the within-group correlation.
23//!
24//! # Scope and scale
25//!
26//! The general models use a dense `O(n³)` solve — appropriate for the grouped
27//! datasets these diagnostics target, not for very large `n`. The random-intercept
28//! [`LinearMixedModel`] is exact: for a **balanced** one-way design its REML
29//! variance components equal the classical ANOVA estimators (`tests/mixed.rs`).
30
31mod general;
32mod glmm;
33mod lmm;
34
35pub use general::{MixedModel, RandomEffect};
36pub use glmm::{GlmmFamily, GlmmFit};
37pub use lmm::{LinearMixedModel, Method};