`kfold()` does not work for `stan_polr()` fit
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 401
- Forks
- 136
- PR merge metrics
- No merged PRs in 30d
Description
Summary:
There seems to be a bug in kfold.stanreg() when applied to a stan_polr() fit.
Description:
When calling kfold.stanreg() on a stan_polr() fit, the error
Error in x$z[omitted_k, , drop = FALSE] : incorrect number of dimensions
is thrown. This is probably due to the fact that in lines https://github.com/stan-dev/rstanarm/blob/3dab09cabb4c889ae9fab2f98351757bfb267a84/R/loo-kfold.R#L196, https://github.com/stan-dev/rstanarm/blob/3dab09cabb4c889ae9fab2f98351757bfb267a84/R/loo-kfold.R#L219, and https://github.com/stan-dev/rstanarm/blob/3dab09cabb4c889ae9fab2f98351757bfb267a84/R/loo-kfold.R#L241, x$z is expanded to x$zeta.
Reproducible Steps:
options(mc.cores = parallel::detectCores(logical = FALSE))
data(inhaler, package = "brms")
inhaler$rating <- paste0("rtg", inhaler$rating)
library(rstanarm)
rfit <- stan_polr(rating ~ period + carry + treat,
data = inhaler,
prior = R2(location = 0.5, what = "median"),
seed = 1140350788)
rkfold <- kfold(rfit, K = 2, cores = 1)
RStanARM Version:
2.21.3
R Version:
4.1.3
Operating System:
Ubuntu 20.04.4 LTS
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in R/loo-kfold.R at the referenced lines 196, 219, and 241, then reproduce the failure with the stan_polr() and kfold() example in the issue. Compare how x$z is handled for this fit and verify that the example completes without the incorrect-number-of-dimensions error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100