Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
`Outcome(['y1', 'y2'], offset={'y1': 'O1', 'y2': 'O2'})` gives the
columns `y1`, `y2`, `offset[y1]` and `offset[y2]`, in the order of the
responses; a missing or unknown key raises. A single column,
`offset='O'`, is still one column, the same for every response.
`offset='O'`, is still one column, the same for every response. The
dict works for any keyword, e.g. `weight={'y1': 'w1', 'y2': 'w2'}` for
weights of each response.

## 0.3.0 (2026-10-26)

Expand Down
3 changes: 2 additions & 1 deletion docs/responses.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ A multi-response model, with a linear predictor for each response,
takes an offset for each: a dict, keyed by the responses (the columns
of a list of columns, or the classes of a `Multinomial`, whatever its
output), gives the columns `offset[...]` in the order of the responses.
A single column is the same offset for every response.
A single column is the same offset for every response. The dict works
for any keyword, e.g. `weight={...}` for weights of each response.

```{code-cell} ipython3
Carseats['O'] = 0.5
Expand Down
2 changes: 2 additions & 0 deletions modelmatrix/outcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class Outcome(Response):
`offset={'y1': 'O1', 'y2': 'O2'}` gives the columns
`offset[y1]` and `offset[y2]`, in the order of the responses.
A single column, `offset='O'`, is the same for every response.
Any keyword can be a dict, e.g. `weight=` for weights of each
response.

Notes
-----
Expand Down
7 changes: 7 additions & 0 deletions tests/test_outcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,10 @@ def test_offset_for_each_response_polars(M):
y = Outcome(['y1', 'y2'], offset={'y1': 'O1', 'y2': 'O2'}).fit_transform(pl.from_pandas(M))
assert isinstance(y, pl.DataFrame)
assert y.columns == ['y1', 'y2', 'offset[y1]', 'offset[y2]']


def test_weights_for_each_response(M):
W = M.assign(w1=1.0, w2=0.5)
y = Outcome(['y1', 'y2'], offset='O', weight={'y1': 'w1', 'y2': 'w2'}).fit_transform(W)
assert list(y.columns) == ['y1', 'y2', 'offset', 'weight[y1]', 'weight[y2]']
np.testing.assert_allclose(y['weight[y2]'], 0.5)
Loading