Skip to content

Single-draw bug fix for augmented-data and latent projection#512

Merged
fweber144 merged 1 commit into
stan-dev:masterfrom
fweber144:fix_loo_valsearchF_1draw_augdat_latent
May 3, 2025
Merged

Single-draw bug fix for augmented-data and latent projection#512
fweber144 merged 1 commit into
stan-dev:masterfrom
fweber144:fix_loo_valsearchF_1draw_augdat_latent

Conversation

@fweber144
Copy link
Copy Markdown
Collaborator

This fixes a bug for augmented-data and latent projection when using a single projected draw for performance evaluation in cv_varsel() with cv_method = "LOO" and validate_search = FALSE. Reprex:

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

devtools::load_all()

# Augmented-data projection:
refm_aug <- get_refmodel(rfit)
cvvs_aug_no_refit <- cv_varsel(refm_aug,
                               validate_search = FALSE,
                               nclusters = 1,
                               refit_prj = FALSE,
                               nterms_max = 2,
                               seed = 46782345)
cvvs_aug <- cv_varsel(refm_aug,
                      validate_search = FALSE,
                      nclusters = 1,
                      nclusters_pred = 1,
                      nterms_max = 2,
                      seed = 46782345)

# Latent projection:
refm_lat <- get_refmodel(rfit, latent = TRUE)
cvvs_lat_no_refit <- cv_varsel(refm_lat,
                               validate_search = FALSE,
                               method = "L1",
                               refit_prj = FALSE,
                               nterms_max = 2,
                               seed = 46782345)
cvvs_lat <- cv_varsel(refm_lat,
                      validate_search = FALSE,
                      method = "L1",
                      nclusters_pred = 1,
                      nterms_max = 2,
                      seed = 46782345)

This bug is fixed here by adding drop = FALSE to the relevant matrix subsetting operations. In theory, a similar bug could occur for analogous reference model quantities (that's why drop = FALSE is added there, too), but this is only a theoretical problem as a reference model with a single draw is unlikely to occur in practice.

A NEWS.md entry is still missing here. I will add it as soon as #511 (or #508) has been merged. I would propose the following text for such a NEWS.md entry (under "Bug fixes"):

* Fixed a bug that caused an error when using the augmented-data or latent projection in combination with a single projected draw for performance evaluation in `cv_varsel()` with `cv_method = "LOO"` and `validate_search = FALSE`. (GitHub: #512)

a single projected draw for performance evaluation
@fweber144 fweber144 merged commit 21f46c9 into stan-dev:master May 3, 2025
@fweber144 fweber144 deleted the fix_loo_valsearchF_1draw_augdat_latent branch May 3, 2025 18:21
fweber144 added a commit that referenced this pull request Jun 6, 2025
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

Successfully merging this pull request may close these issues.

1 participant