# Projpred error

**URL:** <https://discourse.mc-stan.org/t/projpred-error/37314>\
**Category:** Interfaces\
**Tags:** projpred\
**Created:** [November 20, 2024, 3:52am UTC](https://discourse.mc-stan.org/t/projpred-error/37314 "2024-11-20T03:52:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ssalimi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ssalimi/32/7119_2.png) [@ssalimi](https://discourse.mc-stan.org/u/ssalimi)\
**Post date:** [November 20, 2024, 3:52am UTC](https://discourse.mc-stan.org/t/projpred-error/37314/1 "2024-11-20T03:52:27Z")

</div>

I ran a model for 144 features for 749 sample size (N=749). I fit the model using rstanarm.

```no-highlight
D <- ncol(df3[, 15:158])

 
 # Prior guess 
 p0 <- 5
 # Number of observations:
 N <- nrow(df3)

 tau0 <- p0 / (D - p0) * 1 / sqrt(N)
 
  predictor_names <- colnames(df3)[15:158]
 y<-df3$age_nmr
 # Create the formula dynamically
 formula <- reformulate(predictor_names, response = "y")
 
 # Fit the model with the generated formula
 refm_fit <- stan_glm(
   formula = formula,       
   family = gaussian(),
   data = df3,              
   prior = hs(global_scale = tau0),
   chains = 4, iter = 4000,
   QR = TRUE, refresh = 0
 )

refm_obj <- get_refmodel(refm_fit)

cvvs_fast <- cv_varsel(
   refm_obj,
   validate_search = TRUE,
   method = "L1",
   refit_prj = FALSE,
   nterms_max = 144,
   verbose = TRUE
 )

```

Every thing ran ok but with the below syntax I got error:

```no-highlight
cv_fits <- run_cvfun(
   refm_obj,
   K = 10
    )

Error in `[.data.frame`(d, , all_vars, drop = FALSE) : 
  undefined columns selected

```

I appreciate any guidance.

---

<div class="post-metadata">

**Author:** ![fweber144](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/fweber144/32/15592_2.png) [@fweber144](https://discourse.mc-stan.org/u/fweber144)\
**Post date:** [November 20, 2024, 5:32am UTC](https://discourse.mc-stan.org/t/projpred-error/37314/2 "2024-11-20T05:32:40Z")

</div>

Hi Shabnam,

This sounds a bit like rstanarm issue [#551](https://github.com/stan-dev/rstanarm/issues/551), so I would try to write out the formula explicitly (will be very long in your case) or at least avoid `reformulate()` and try to use dot notation (e.g., `y ~ .`), but I’m not sure if this will actually help (given that rstanarm issue). Alternatively, it could be something like [Error message from projpred with binomial regression model fitted in rstanarm](https://discourse.mc-stan.org/t/error-message-from-projpred-with-binomial-regression-model-fitted-in-rstanarm/14856), so do you have `NA`s in your dataset?

In any case, I currently think this is related to rstanarm, so using brms or something else should avoid this.

---

<div class="post-metadata">

**Author:** ![ssalimi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ssalimi/32/7119_2.png) [@ssalimi](https://discourse.mc-stan.org/u/ssalimi)\
**Post date:** [November 20, 2024, 9:12pm UTC](https://discourse.mc-stan.org/t/projpred-error/37314/3 "2024-11-20T21:12:39Z")

</div>

@fweber144 Hi thanks for your response. There is no NA in the data and this is Gaussian family not binomial.

---

<div class="post-metadata">

**Author:** ![fweber144](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/fweber144/32/15592_2.png) [@fweber144](https://discourse.mc-stan.org/u/fweber144)\
**Post date:** [November 20, 2024, 9:25pm UTC](https://discourse.mc-stan.org/t/projpred-error/37314/4 "2024-11-20T21:25:05Z")

</div>

Thanks. Could you try with brms?

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [November 20, 2024, 9:39pm UTC](https://discourse.mc-stan.org/t/projpred-error/37314/5 "2024-11-20T21:39:59Z")

</div>

> [@fweber144](#):
>
> This sounds a bit like rstanarm issue [#551](https://github.com/stan-dev/rstanarm/issues/551),

This does seem like it could be related to this issue, which I see now is many years old and I never saw it (sorry @fweber144!). @ssalimi Are you on Windows? I’m pretty sure that particular rstanarm issue should only affect Windows users.

---

<div class="post-metadata">

**Author:** ![ssalimi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ssalimi/32/7119_2.png) [@ssalimi](https://discourse.mc-stan.org/u/ssalimi)\
**Post date:** [November 20, 2024, 10:10pm UTC](https://discourse.mc-stan.org/t/projpred-error/37314/6 "2024-11-20T22:10:21Z")

</div>

@jonah Yes, I use windows. Shall I use brms instead?

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [November 20, 2024, 10:31pm UTC](https://discourse.mc-stan.org/t/projpred-error/37314/7 "2024-11-20T22:31:50Z")

</div>

It would at least be helpful to know if the issue disappears using brms (brms uses a different package to handle the parallelization). It could potentially be a different issue than the one @fweber144 pointed out, but I’m guessing he’s right. Either way, we need to fix that bug in rstanarm (although as someone who doesn’t use Windows I’m not exactly sure what the fix is yet). Sorry for the hassle!

---

<div class="post-metadata">

**Author:** ![ssalimi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ssalimi/32/7119_2.png) [@ssalimi](https://discourse.mc-stan.org/u/ssalimi)\
**Post date:** [November 28, 2024, 1:40am UTC](https://discourse.mc-stan.org/t/projpred-error/37314/8 "2024-11-28T01:40:14Z")

</div>

@fweber144 @fweber144 using brms solved the issue. Thanks for your guidance.
