Repository navigation
Allow monotonic terms in get_refmodel.brmsfit() - #1965
Conversation
paul-buerkner
left a comment
There was a problem hiding this comment.
Thanks! I had one question regarding the added validation checks
| stop2("Projpred only supports standard multilevel, smoothing, and ", | ||
| "monotonic terms as well as offsets.") | ||
| } | ||
| sp_terms <- bterms$dpars$mu$sp |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Looks good now. Thank you!
The projpred PR stan-dev/projpred#591 adds support for monotonic terms
mo().This PR lets
get_refmodel.brmsfit()passmo()terms to projpred.If the formula has
mo()terms,get_refmodel.brmsfit()checks that projpred exportsmo_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.