pymargins.at_levels¶
- pymargins.at_levels(variable: str, *, levels, label_fmt: str | None = None, **fixed)¶
Build one scenario per level of a categorical/binary variable.
Useful for passing to
predict()to get predictions at every level, or as input to custom contrast matrices.- Parameters:
variable (str) – Variable name.
levels (list or tuple) – Levels to generate scenarios for.
label_fmt (str, optional) – Format string for labels. Defaults to
"{var}={val}".**fixed – Additional variables held constant.
- Returns:
scenarios
- Return type:
list[dict]
Examples
>>> scenarios = at_levels("region", levels=["north", "south", "east"]) >>> m.predict(scenarios=scenarios)