clmm¶
Fit a cumulative link mixed model (CLMM) with random effects via Laplace
approximation — targeting parity with R’s
ordinal::clmm().
The model is:
link(P(Y <= k | b)) = alpha_k - x'beta - z'b, k = 1,...,K-1
where alpha_1 < … < alpha_{K-1} are threshold parameters, beta are fixed-effect coefficients (no intercept — absorbed into thresholds), and b ~ N(0, sigma^2 Lambda Lambda’) are random effects.
- clmm(formula, data, groups=None, random=None, link='logit', optimizer='lbfgsb', theta0=None)¶
Fit a cumulative link mixed model (proportional odds).
- Parameters:
formula – Fixed-effects formula, e.g.
"rating ~ temp + contact". The intercept is suppressed (thresholds serve as intercepts).data – DataFrame (pandas, polars, or narwhals-compatible).
groups – Column name(s) for random intercepts.
random – lme4-style random effect specs (precedence over
groups).link – Link function:
"logit"(default),"probit","cloglog".optimizer –
"lbfgsb"(default) or"bobyqa".theta0 – Initial variance parameters. Defaults to ones.
- Return type:
CLMMResult- Returns:
CLMMResult
- Parameters:
formula (str)
data (Any)
groups (str | list[str] | None)
random (list[str] | None)
link (str)
optimizer (str)
theta0 (ndarray | None)
Key parameters¶
Parameter |
Type |
Description |
|---|---|---|
|
|
Fixed-effects formula, e.g. |
|
|
Input data (pandas, polars, or narwhals-compatible) |
|
|
Column name(s) for random intercepts |
|
|
lme4-style random-effect specs (takes precedence over |
|
|
Link function: |
|
|
|
|
|
Initial variance parameters; defaults to ones |
Supported link functions¶
Link |
CDF |
Use case |
|---|---|---|
|
Logistic |
Proportional odds (default, most common) |
|
Normal |
When normality of latent variable is assumed |
|
Complementary log-log |
Asymmetric, for grouped survival data |
Examples¶
Basic ordinal regression with random intercepts¶
import interlace
result = interlace.clmm(
formula="rating ~ temp + contact",
data=df,
groups="judge",
)
# Threshold estimates (cut points between ordinal levels)
print(result.thresholds)
# {'1|2': -1.34, '2|3': 1.25, '3|4': 3.47, '4|5': 5.01}
# Fixed-effect coefficients
print(result.fe_params)
# Between-judge variance
print(result.variance_components)
Prediction¶
# Category probabilities P(Y=k), shape (n, K)
probs = result.predict(newdata=df_new, type="prob")
# Cumulative probabilities P(Y<=k), shape (n, K-1)
cum = result.predict(newdata=df_new, type="cum.prob")
# Linear predictor x'beta + z'b, shape (n,)
eta = result.predict(newdata=df_new, type="linear.predictor")
Confidence intervals¶
ci = result.confint(level=0.95)
# DataFrame with lower/upper for both thresholds and fixed effects
Result object¶
clmm() returns a CLMMResult with the following attributes:
Attribute |
Type |
Description |
|---|---|---|
|
|
Threshold estimates, keyed by label (e.g. |
|
|
Standard errors of thresholds |
|
|
Fixed-effect coefficients |
|
|
Standard errors of fixed effects |
|
|
BLUPs per grouping factor |
|
|
Variance estimate per grouping factor |
|
|
Raw variance parameters |
|
|
Whether the optimizer converged |
|
|
Number of observations |
|
|
Laplace-approximated log-likelihood |
|
|
Akaike information criterion |
|
|
Bayesian information criterion |
|
|
Number of levels per grouping factor |
|
|
Link function name |
Methods¶
Method |
Description |
|---|---|
|
Predict probabilities, cumulative probabilities, or linear predictor |
|
Wald confidence intervals for thresholds and fixed effects |
|
Human-readable summary |
Comparison with R¶
interlace |
R (ordinal) |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
See also¶
glmer — generalised linear mixed models (continuous/binary/count)
fit — linear mixed models
CrossedLMEResult —
CrossedLMEResultattributes