Skip to content

Outcome, and Surv's columns named by role, for 0.3.0 - #5

Merged
jonathan-taylor merged 1 commit into
mainfrom
outcome
Oct 26, 2026
Merged

jonathan-taylor merged 1 commit into
mainfrom
outcome

Conversation

@jonathan-taylor

Copy link
Copy Markdown
Contributor

Candidate for 0.3.0, so glmstar can build y with Outcome and find its columns by name.

Outcome(response, **columns). Each keyword names an output column, so an estimator can find it by name:

Y = Outcome(Surv('time', 'status'), offset='O', weight='w', strata='inst')
y = Y.fit_transform(D)                     # columns: stop, status, offset, weight, strata
X = MS([wildcard(exclude=Y)]).fit_transform(D)   # leaves out time, status, O, w, inst
  • A keyword's value is a column of the data, taken as it is (a categorical such as strata keeps its labels), or a single-column feature fit as a term, e.g. R's offset(log(exposure)) as a derived_feature with a log transform. A feature with more than one column raises.
  • The response can be a Surv, Binomial or Multinomial, or a plain column. Its columns come first, then the others in keyword order. A name used twice raises.
  • transform(X, response=False) builds only the other columns, e.g. the offset of new data for predict(X, offset=...).
  • With Binomial(..., output='proportion'), the trials become the column weight, multiplied by any weight= given (R's prior weights of a proportion).
  • The given response object isn't modified: a copy is fit.

Breaking: Surv names its columns by role, start, stop and status (R's names, and lifelines' defaults for time-varying Cox), not after the data's columns. So Surv('time', 'status') now gives stop and status.

Also: polars and pyarrow output keeps categorical columns (as a polars Enum; pyarrow has none, so strings there).

Tests: tests/test_outcome.py. A Poisson GLM with offset=log(exposure) and a stratified PHReg with an offset match statsmodels fit directly on the data. Also covered: proportion weights, the offset of new data, errors, arrays, polars and pyarrow. The full suite gives 276 passed and 5 strict xfails.

Docs: an Outcome section on the responses page, executed locally.

For glmstar: default offset_id, weight_id and the CoxFamily ids to offset, weight, start, stop, status and strata, so CoxNet().fit(X, y) works directly.

🤖 Generated with Claude Code

- Outcome(response, **columns): each keyword names an output column,
  taken from a column of X as it is (a categorical keeps its labels) or
  from a single-column feature fit as a term, e.g. log(exposure). The
  response's columns come first.
- wildcard(exclude=outcome) leaves out every column it uses.
- transform(X, response=False) builds only the other columns, e.g. the
  offset of new data.
- With Binomial(output='proportion') the trials are the column weight,
  times any weights given.
- Surv names its columns by role: start, stop, status.
- Dataframes of other backends keep categorical columns (polars Enum).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonathan-taylor
jonathan-taylor merged commit 104d697 into main Oct 26, 2026
2 checks passed
@jonathan-taylor
jonathan-taylor deleted the outcome branch October 26, 2026 23:13
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