Skip to content

Allow monotonic terms in get_refmodel.brmsfit() - #1965

Merged
paul-buerkner merged 3 commits into
paul-buerkner:masterfrom
avehtari:projpred-mo
Nov 9, 2026
Merged

paul-buerkner merged 3 commits into
paul-buerkner:masterfrom
avehtari:projpred-mo

Conversation

@avehtari

@avehtari avehtari commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

The projpred PR stan-dev/projpred#591 adds support for monotonic terms mo().
This PR lets get_refmodel.brmsfit() pass mo() terms to projpred.

If the formula has mo() terms, get_refmodel.brmsfit() checks that projpred exports mo_effects(), which the projpred PR adds. The check does not use a version number, so development versions of projpred with this support also work.

This PR was assisted by Claude.

@paul-buerkner paul-buerkner left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I had one question regarding the added validation checks

Comment thread R/projpred.R Outdated
stop2("Projpred only supports standard multilevel, smoothing, and ",
"monotonic terms as well as offsets.")
}
sp_terms <- bterms$dpars$mu$sp

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You seem to only check for dpars$mu here. Are we, at this point of the code, sure that we only target mu with projpred?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted. The checks looked only at mu, and some models have no mu. get_refmodel.brmsfit() stops earlier for distributional models, except for the families with conv_cats_dpars() (categorical, multinomial and the simplex families). In these models the dpars are mu2, mu3, ..., and there is no mu. With 3 or more categories, bterms$dpars$mu is an ambiguous partial match and gives NULL, so the term-type check and the sp-term check did nothing. With 2 categories, $mu partially matched mu2, and the checks gave the correct result. A categorical model with me() or gp() passed the checks and then failed with no applicable method for `@` applied to an object of class "NULL".

New commit uses get_effect(bterms, target = ...) in the term-type check and the sp-term check, so they look at the terms of all dpars. The commit adds categorical models with me() and gp() to the monotonic-terms test in tests/local/tests.models-5.R. It also removes the second require_package("projpred"), because get_refmodel.brmsfit() calls it at the start.

With the default latent = FALSE, projpred uses the augmented-data projection for categorical models, also with mo() terms. The monotonic projection in projpred (stan-dev/projpred#591, the default) does not support the augmented-data projection yet. It stops with a message that says to use options(projpred.mo_monotone = FALSE). With that option, project() and varsel() work for a categorical model with mo(x).

@paul-buerkner paul-buerkner left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now. Thank you!

@paul-buerkner
paul-buerkner merged commit a25d513 into paul-buerkner:master Nov 9, 2026
1 of 5 checks passed
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.

2 participants