anova¶
Likelihood-ratio test for comparing two nested linear mixed models.
Mirrors lme4::anova.merMod() output format.
- anova(m1, m2)[source]¶
Compare two nested linear mixed models via likelihood-ratio test.
Both models must have been fitted with
method='ML'. When models differ in their fixed effects, REML-fitted models cannot be compared by LRT because the REML criterion depends on the fixed-effect structure.- Parameters:
m1, m2 – Two
CrossedLMEResultobjects. Order does not matter; the function sorts them by number of parameters (smaller model first).- Return type:
Any- Returns:
pandas.DataFrame –
Two-row table with columns matching lme4’s anova output:
Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq)
The first row corresponds to the simpler model;
Chisq,Chi Df, andPr(>Chisq)areNaNfor it.- Raises:
ValueError – If either model was fitted with
method='REML'.- Parameters:
m1 (CrossedLMEResult)
m2 (CrossedLMEResult)
Example¶
import interlace
# Both models must use method="ML"
m0 = interlace.fit("rt ~ 1", data=df, groups=["subject", "item"], method="ML")
m1 = interlace.fit("rt ~ condition", data=df, groups=["subject", "item"], method="ML")
result = interlace.anova(m0, m1)
print(result)
# Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq)
# Model 1 3 1234.56 1245.67 -614.28 1228.56
# Model 2 4 1228.12 1242.45 -610.06 1220.12 8.44 1 0.0037
Notes¶
Both models must have been fitted with method="ML". When comparing models
that differ only in their random-effect structure, REML is acceptable and
often preferred; use method="REML" in that case and pass both models with
the same fixed effects.
See also¶
fit —
method="ML"parameterModel Comparison Guide — full LRT workflow