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

K-fold CV throws error for degenerate model space #331

Closed
fweber144 opened this issue Jul 7, 2022 · 1 comment
Closed

K-fold CV throws error for degenerate model space #331

fweber144 opened this issue Jul 7, 2022 · 1 comment

Comments

@fweber144
Copy link
Collaborator

If there is only the empty model to consider for cv_varsel() with cv_method = "kfold", an error is thrown:

set.seed(6834)
nobs <- 100L
mu <- binomial()$linkinv(-0.42 + rnorm(nobs))
trials <- sample.int(30L, size = nobs, replace = TRUE)
y <- rbinom(nobs, size = trials, prob = mu)
dat <- data.frame(y = y, trials = trials)

library(rstanarm)
options(mc.cores = parallel::detectCores(logical = FALSE))
r_fit <- stan_glm(
  cbind(y, trials - y) ~ 1,
  family = binomial(),
  data = dat,
  seed = 101
)

library(projpred)
kvs <- cv_varsel(r_fit,
                 method = "forward",
                 cv_method = "kfold",
                 K = 2,
                 seed = 12354)

(tested with projpred's CRAN version 2.1.2). The error thrown by the last call is:

Error in apply(sub_cv_summaries, 1, rbind2list) :
  dim(X) must have a positive length
@fweber144 fweber144 changed the title $K$-fold CV throws error for degenerate model space K-fold CV throws error for degenerate model space Jul 7, 2022
fweber144 added a commit to fweber144/projpred that referenced this issue Jul 7, 2022
fweber144 added a commit to fweber144/projpred that referenced this issue Jul 8, 2022
fweber144 added a commit that referenced this issue Jul 10, 2022
@fweber144
Copy link
Collaborator Author

Fixed by commit cc85462.

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

1 participant