Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contrasts #283

Open
fweber144 opened this issue Mar 2, 2022 · 1 comment
Open

Contrasts #283

fweber144 opened this issue Mar 2, 2022 · 1 comment
Labels
enhancement Enhancements of existing features, but also new feature requests.

Comments

@fweber144
Copy link
Collaborator

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.
@fweber144
Copy link
Collaborator Author

Removed the fixed in develop label because #284 was just a quick fix suppressing the warnings. As explained above, in the future, contrasts attributes should also be respected by projpred when fitting the submodels.

@fweber144 fweber144 added the enhancement Enhancements of existing features, but also new feature requests. label Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancements of existing features, but also new feature requests.
Projects
None yet
Development

No branches or pull requests

2 participants