Skip to content

Fix ordinal cloglog probability transform for K>=4 categories#382

Merged
andrewherren merged 2 commits into
mainfrom
fix/ordinal-cloglog-probability-transform
May 20, 2026
Merged

Fix ordinal cloglog probability transform for K>=4 categories#382
andrewherren merged 2 commits into
mainfrom
fix/ordinal-cloglog-probability-transform

Conversation

@andrewherren
Copy link
Copy Markdown
Collaborator

The sequential ordinal cloglog model uses $P(Y=k) = \prod_{j<k} S_j * (1-S_k)$ where $S_k = \exp(-exp(\gamma_k + f(X)))$. The old code used $S_{k-1}*(1-S_k)$ for intermediate categories (k>=2), which only accidentally gave the correct answer for K=3 (where $c_1 = \gamma_1$ always), but silently produced wrong class probabilities for K>=4.

This PR replaces that faulty code with a running-product loop that tracks cumulative survival correctly across all K. We also add explicit unit tests for the K > 3 case in both R and Python that verify the predict output matches the manual formula and sums to 1.

andrewherren and others added 2 commits May 19, 2026 19:54
The sequential ordinal cloglog model uses P(Y=k) = prod_{j<k} S_j * (1-S_k)
where S_k = exp(-exp(gamma_k + f)). The old code used S_{k-1}*(1-S_k) for
intermediate categories (k>=2), which only accidentally gave the correct answer
for K=3 (where c_1 = gamma_1 always), but silently produced wrong class
probabilities for K>=4.

Replace with a running-product loop that tracks cumulative survival correctly
across all K. Add K=4 regression tests in both R and Python that verify the
predict output matches the manual formula and sums to 1.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@andrewherren andrewherren merged commit 7190d21 into main May 20, 2026
16 checks passed
@andrewherren andrewherren deleted the fix/ordinal-cloglog-probability-transform branch May 20, 2026 01:32
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