stan-dev / projpred

Projection predictive variable selection
https://mc-stan.org/projpred/
Other
110 stars 26 forks source link

Fix bug for augmented-data projection with subsampled LOO #433

Closed fweber144 closed 1 year ago

fweber144 commented 1 year ago

This fixes a bug for the augmented-data projection in combination with subsampled PSIS-LOO CV: When subsetting the rows of an augmented-rows matrix (class augmat) or the elements of an augmented-length vector (class augvec), attribute nobs_orig was not adapted, so by this PR, it is adapted correctly.

Reprex:

data(inhaler, package = "brms")
inhaler$rating <- paste0("rtg", inhaler$rating)
inhaler$rating <- as.factor(inhaler$rating)
library(rstanarm)
rfit <- stan_polr(rating ~ period + carry + treat,
                  data = inhaler,
                  prior = R2(location = 0.5, what = "median"),
                  chains = 1,
                  iter = 500,
                  seed = 1140350788,
                  refresh = 0)

### If the desired version is not installed:
devtools::load_all(".")
###
### If the desired version is installed:
# library(projpred)
###

cvvs <- cv_varsel(rfit,
                  validate_search = FALSE,
                  nloo = 141,
                  nclusters = 3,
                  nclusters_pred = 5,
                  nterms_max = 2,
                  seed = 46782345)

Previously (i.e., before this PR), this reprex failed (with Error in augmat2arr(mu) : is_wholenumber(n_discr) is not TRUE). With this PR, this reprex runs through.

Nevertheless, subsampled PSIS-LOO CV is still an experimental feature, see #94.