emmeans¶
Estimated marginal means (EMMs) for a fitted linear mixed model.
Mirrors R’s emmeans package: for each level combination of the
specified factor(s), the marginal mean of the fixed-effects predictor is computed after
averaging continuous covariates at their observed means. Standard errors and degrees of
freedom use the Satterthwaite approximation.
Reference: Lenth (2016) Least-Squares Means: The R Package lsmeans, J. Stat. Softw. 69(1).
- emmeans(model, specs, at=None, level=0.95)[source]¶
Compute estimated marginal means (EMMs) for a fitted LMM.
- Parameters:
model – A fitted
CrossedLMEResult.specs – Name of the factor (str) or list of factor names for which to compute marginal means. Each named column must appear in the fixed-effects formula.
at – Optional dict of covariate values to use in the reference grid instead of their training-data means. For example
at={"x": 0.0}centres the estimates atx = 0.level – Nominal CI coverage (default 0.95).
- Return type:
Any- Returns:
pandas.DataFrame – One row per level combination of specs, with columns:
<specs columns>,estimate,SE,df,lower,upper,t.ratio,p.value.- Parameters:
model (CrossedLMEResult)
specs (str | list[str])
at (dict[str, Any] | None)
level (float)
Examples
>>> emm = interlace.emmeans(result, specs="treatment") >>> emm
Returned columns¶
Column |
Description |
|---|---|
|
One column per specs factor showing the level combination |
|
Marginal mean (EMM) |
|
Standard error |
|
Satterthwaite denominator degrees of freedom |
|
Lower bound of the confidence interval |
|
Upper bound of the confidence interval |
|
t-statistic ( |
|
Two-tailed p-value |
The confidence interval width is controlled by the level parameter (default 0.95).
Examples¶
Single factor¶
import interlace
result = interlace.fit("rt ~ condition", data=df, groups=["subject", "item"])
emm = interlace.emmeans(result, specs="condition")
print(emm)
# condition estimate SE df lower upper t.ratio p.value
# 0 control 456.3 12.4 38.2 431.2 481.4 36.8 0.000
# 1 high 502.7 13.1 39.5 476.2 529.2 38.4 0.000
Two-way grid¶
emm2 = interlace.emmeans(result, specs=["condition", "group"])
# One row per condition × group combination
Custom covariate values with at=¶
# Centre estimates at x = 0 instead of the training mean
emm_at = interlace.emmeans(result, specs="condition", at={"x": 0.0})
Narrower confidence interval¶
emm_90 = interlace.emmeans(result, specs="condition", level=0.90)
See also¶
contrast / pairs — pairwise or custom contrasts on an EMM result
fit — fitting the model passed to
emmeansCrossedLMEResult —
CrossedLMEResultattributes