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

Error when projecting with non-NULL solution_terms. #79

Closed
fweber144 opened this issue Mar 2, 2021 · 0 comments
Closed

Error when projecting with non-NULL solution_terms. #79

fweber144 opened this issue Mar 2, 2021 · 0 comments

Comments

@fweber144
Copy link
Collaborator

fweber144 commented Mar 2, 2021

Applying project() with non-NULL argument solution_terms leads to an error. I'll create a PR for fixing this. Below is a reproducible example.

# Based on <https://github.com/stan-dev/projpred/blob/master/README.md>.

library(projpred)
library(rstanarm)
options(mc.cores = parallel::detectCores(logical = FALSE))

data("df_gaussian", package = "projpred")
df_gaussian <- df_gaussian[1:40, ]
mydat <- cbind("y" = df_gaussian$y, as.data.frame(df_gaussian$x))
mydat$mygroup <- gl(n = 8, k = floor(nrow(mydat) / 8), labels = paste0("gr", seq_len(8)))
set.seed(457211)
mydat$noise <- rnorm(nrow(mydat))
mygroup_icpts_truth <- rnorm(nlevels(mydat$mygroup), sd = 6)
mygroup_V1_truth <- rnorm(nlevels(mydat$mygroup), sd = 6)
mydat$y <- mydat$y + mygroup_icpts_truth[as.numeric(mydat$mygroup)]
mydat$y <- mydat$y + mygroup_V1_truth[as.numeric(mydat$mygroup)] * mydat$V1

myfit <- stan_glmer(y ~ V1 + V2 + V3 + V4 + V5 + noise + (1 + V1 | mygroup),
                    data = mydat,
                    seed = 1140350788)

cvs <- cv_varsel(myfit)
solution_terms(cvs)

C_proj <- project(myfit,
                  solution_terms = solution_terms(cvs)[1:3],
                  ndraws = ceiling(0.05 * nrow(as.matrix(myfit))))

The last call throws an error:

Error in project(myfit, solution_terms = solution_terms(cvs)[1:3], ndraws = ceiling(0.05 *  :
  solution_terms contains an index larger than the number ofvariables in the model.
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