Skip to content

linear predictions#28

Merged
corybrunson merged 17 commits into
mainfrom
linear-pred
Jul 18, 2026
Merged

linear predictions#28
corybrunson merged 17 commits into
mainfrom
linear-pred

Conversation

@corybrunson

@corybrunson corybrunson commented Jul 16, 2026

Copy link
Copy Markdown
Owner

This PR provides linear prediction options (predict(..., type = "linear_pred")) for the clm, lrm, orm, vglm, and ordinalNet ordinal regression engines and for the vgam generalized additive model engine. They consistently return a single column of linear predictors (without threshold contributions).

This PR depends on an enabling change in parsnip, which will be the subject of a forthcoming PR (just opened here).

…engine

Manual initialization:

Un-commented draft `parsnip::set_pred()` registration for `"linear_pred"` prediction type.

OpenCode prompt:

```
Draft a chunk of unit tests for the `linear_pred` prediction type for the `ordinalNet` engine of the `ordinal_reg` model. Check that the tests pass; if they don't, then identify, diagnose, and patch any bugs in the tests or in the source code that facilitates that prediction type.

For this task, follow the structure and style of the 'ordered' package in this directory and of the 'censored' package located at the local path '../censored/'. Focus only on files with the '.R' extension. Also follow tidyverse and tidymodels conventions, and do not use any Git commands.
```

OpenCode report:

```
Here's a summary of what was done:
Changes Made
1. Bug fix: blocked linear_pred for classification mode
R/ordinal_reg-ordinalNet.R — predict._ordinalNet() calls predict.model_fit() which uses parsnip's check_pred_type(). That function only allows linear_pred for "censored regression" mode, but ordinal_reg uses "classification" mode. Fixed by intercepting type = "linear_pred" in predict._ordinalNet() and directly calling predict_linear_pred() (which dispatches to predict_linear_pred.model_fit() using the set_pred registration).
2. Updated outdated REVIEW comment
R/ordinal_reg-data.R — Replaced the REVIEW comment about why linear_pred was restricted.
3. Added unit tests
tests/testthat/test-ordinal_reg-ordinalNet.R — Added two tests:
- linear_pred prediction — verifies output structure (tibble, correct rows/cols, column names like .pred_link_Low_Medium) and compares values against raw ordinalNet::predict.ordinalNet(type = "link")
- linear_pred prediction with single observation — verifies single-row prediction works correctly
```

Manual revisions:

1. In `check_pred_type()`, check for inheritance of `"ordinal_reg"` class rather than for `"classification"` mode. In `predict._ordinalNet()`, comment on the fix.
2. Clarify comment to remain up for review.
3. Changed object names and coerced to tibbles for consistency with other tests.
@corybrunson
corybrunson merged commit 52ff530 into main Jul 18, 2026
3 of 10 checks passed
@corybrunson
corybrunson deleted the linear-pred branch July 18, 2026 16:43
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