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

Unnecessary variables required in newdata for predictions in projpred #1457

Closed
fweber144 opened this issue Feb 14, 2023 · 1 comment
Closed

Comments

@fweber144
Copy link
Contributor

When performing predictions with new data in projpred, brms reference models require newdata to contain the response (and in fact all variables from the original dataset), which is not necessary after projecting onto a smaller model:

library(brms)
options(mc.cores = parallel::detectCores())
ref_fit <- brm(
  formula = rate ~ conc + state,
  data = Puromycin,
  backend = "cmdstanr",
  seed = 2052109,
  refresh = 0
)

library(projpred)
soltrms <- "conc"
prj <- project(ref_fit, solution_terms = soltrms, ndraws = 40)
Puromycin_new <- as.data.frame(sapply(Puromycin[soltrms], quantile))
prj_linpred <- proj_linpred(prj, newdata = Puromycin_new)

with the last line throwing

Error: Response variables must be specified in 'newdata'.
Missing variables: 'rate'

(Tested with projpred 2.4.0 and brms's GitHub version, commit b31fcee.)

This also came up in The Stan Forums and seems to be a long-standing bug, probably related to the extract_model_data() function defined in brms and passed to projpred::init_refmodel() (the extract_model_data argument was introduced in projpred 2.0.0, so quite some time ago). I will try to fix this and then create a PR.

@paul-buerkner
Copy link
Owner

paul-buerkner commented Feb 14, 2023 via email

fweber144 added a commit to fweber144/brms that referenced this issue Feb 14, 2023
This is achieved by not ignoring `extract_y` anymore (ignoring this was already
undesirable from a conceptual point of view) and by setting `check_response`
and `req_vars` appropriately.
fweber144 added a commit to fweber144/projpred that referenced this issue Feb 16, 2023
…t.refmodel()` and

all other `extract_model_data()` calls where appropriate. This
will avoid an issue similar to paul-buerkner/brms#1457, but with respect to
`predict.refmodel()`.
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

No branches or pull requests

2 participants