Anova¶
car::Anova()-style ANOVA table for a fitted linear mixed model.
Produces per-term F- or chi-square statistics with Satterthwaite denominator degrees of
freedom. Mirrors the interface of car::Anova() in R.
- Anova(model, type='III', test='F')[source]¶
car::Anova()-style ANOVA table for a fitted LMM.
- Parameters:
model – A fitted
CrossedLMEResult, or a list of two such results for likelihood-ratio test (LRT) comparison. When a list is supplied, type and test are ignored and the LRT table frominterlace.anova()is returned.type – ANOVA type:
'II'or'III'(default). Ignored when model is a list.test – Test statistic:
'F'(default) or'Chisq'.'F'returns the same table asanova_type2()/anova_type3().'Chisq'converts to Wald chi-square statistics (Chisq = F * df1) and reports chi-square p-values. Ignored when model is a list.
- Return type:
Any- Returns:
pandas.DataFrame – For
test='F': columns["term", "df1", "df2", "F", "Pr(>F)"]. Fortest='Chisq': columns["term", "df", "Chisq", "Pr(>Chisq)"]. For a list of models: LRT table frominterlace.anova().- Raises:
ValueError – If type is not
'II'or'III', test is not'F'or'Chisq', or if a list of REML-fitted models is passed.- Parameters:
model (Any)
type (str)
test (str)
Returned columns¶
test='F' (default)¶
Column |
Description |
|---|---|
|
Fixed-effect term name |
|
Numerator degrees of freedom (number of columns for this term) |
|
Satterthwaite denominator degrees of freedom |
|
Wald F-statistic |
|
p-value from the F distribution |
test='Chisq'¶
Column |
Description |
|---|---|
|
Fixed-effect term name |
|
Degrees of freedom ( |
|
Wald chi-square statistic ( |
|
p-value from the chi-square distribution |
Choosing between Type II and Type III¶
Type |
Use when |
|---|---|
|
Interpreting main effects in the presence of interactions; matches |
|
Additive models (no interactions), or when you want hierarchical marginal tests; requires ML refit internally |
For additive models (no interactions) the two types produce identical results because the hypothesis matrices coincide. The distinction matters only when interactions are present.
Examples¶
Basic Type III F-table¶
import interlace
result = interlace.fit("rt ~ condition + load", data=df, groups=["subject", "item"])
tbl = interlace.Anova(result)
print(tbl)
# term df1 df2 F Pr(>F)
# 0 condition 1 38.2 31.2 0.0000
# 1 load 1 41.5 8.9 0.0048
Type II¶
tbl2 = interlace.Anova(result, type="II")
Chi-square statistics¶
tbl_chisq = interlace.Anova(result, test="Chisq")
# term df Chisq Pr(>Chisq)
# 0 condition 1 31.2 0.0000
# 1 load 1 8.9 0.0028
LRT comparison (two-model form)¶
When a list of two models is passed, Anova() delegates to the LRT-based
anova function (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")
interlace.Anova([m0, m1]) # LRT table, same as interlace.anova(m0, m1)