Skip to content

feat: joint margins via tuple keys in GLM.margins(at=) - #312

Merged
MamadouSDiallo merged 3 commits into
mainfrom
feat/glm-joint-margins
Oct 16, 2026
Merged

MamadouSDiallo merged 3 commits into
mainfrom
feat/glm-joint-margins

Conversation

@MamadouSDiallo

@MamadouSDiallo MamadouSDiallo commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
  • at={("a", "b"): [("a1", "b1"), ...]} gives joint predictive margins, one row per cell; None means every fitted level (full grid for a tuple key).
  • variables= with at= gives marginal effects at each cell; it was silently ignored.
  • Lists come back as GLMMarginsList (still a list): printing shows every table, to_polars() stacks them.
  • Breaking: GLMMargins.values is split into at (one column per set variable, single-variable margins included) and contrast (categorical effect labels). The value column in to_polars() becomes the variable's name, or contrast. .values raises a guiding error. A single result and a stacked list share the same columns.

Validated against R survey 4.5 + marginaleffects 0.32.0 (avg_predictions, avg_comparisons, avg_slopes), including a domain fit: estimates to 1e-6, SEs to 1e-5.

Tuple keys set several variables together, one row per cell; None
enumerates fitted levels. variables= with at= gives effects at each cell
instead of being ignored. Results gain an at field; return shapes unchanged.
at holds every set value, one column per variable, single-variable
margins included; contrast holds categorical effect labels. A single
result and a stacked list share the same columns.
@MamadouSDiallo
MamadouSDiallo merged commit 7333003 into main Oct 16, 2026
12 checks passed
@MamadouSDiallo
MamadouSDiallo deleted the feat/glm-joint-margins branch October 16, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant