Contrasts
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 114
- Forks
- 31
- PR merge metrics
- No merged PRs in 30d
Description
At least for brms-fitted reference models, factor predictor columns in the $data element of the brmsfit get an attribute contrasts assigned. This makes sense and in the future, this should probably also be respected by projpred when fitting the submodels. For now, I think the warnings produced by some predict() methods (see below) should be suppressed and some documentation should be added, stating that any contrasts attributes from the reference model's dataset are ignored.
Reprex (a bit artificial since options(projpred.glm_fitter = "fit_glm_callback") is currently a "hidden" feature, but I encountered a similar issue while trying to solve #70):
options(mc.cores = parallel::detectCores(logical = FALSE))
dat <- data.frame(
group = gl(n = 3, k = floor(41 / 3), length = 41,
labels = paste0("gr", seq_len(3)))
)
set.seed(457211)
dat$y <- rnorm(nrow(dat), mean = -4.2, sd = 4)
bfit <- brms::brm(y ~ group,
data = dat,
backend = "cmdstanr",
refresh = 0,
seed = 1140350788)
library(projpred)
options(projpred.glm_fitter = "fit_glm_callback")
prj <- project(bfit,
solution_terms = c("group"),
nclusters = 3,
seed = 46782345)
## --> Throws:
# Warning messages:
# 1: contrasts dropped from factor group
# 2: contrasts dropped from factor group
# 3: contrasts dropped from factor group
##
# Explanation:
refm <- get_refmodel(bfit)
str(refm$fetch_data())
## --> Note the `contrasts` attribute here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied reprex with the brms model and projpred::project(), then inspect get_refmodel(bfit)$fetch_data() and the predict() methods that emit the warnings. Trace where the contrasts attributes are noticed during submodel fitting and locate the relevant documentation. Done means the warnings are suppressed and the documentation states that reference-model contrasts attributes are ignored.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100