warmup draws omitted from stanfit objects
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 1.1k
- Forks
- 266
- Avg merge
- 2h 56m
- Merged PRs (30d)
- 1
Description
Right now, the conversion of stanfit objects into the draws format relies on the as.array function from Rstan. It would be great to document this somewhere and I would actually expect the function to convert all draws in the stanfit object, but the function drops the warmup samples without a way to influence this as the following example demonstrates:
library(rstan)
library(posterior)
ex_model_code <- '
parameters {
real alpha[2,3];
real beta[2];
}
model {
for (i in 1:2) for (j in 1:3)
alpha[i, j] ~ normal(0, 1);
for (i in 1:2)
beta ~ normal(0, 2);
}
'
## fit the model
fit <- stan(model_code = ex_model_code, chains = 4)
## we sampled and kept the warmup samples
fit
draws_post <- as_draws(fit)
## but converting to draws will omit the warmup draws! There is no way
## to get the warmup draws, since "as.array" is called. The as.array
## call will by default use "extract(x, permuted = FALSE, inc_warmup =
## FALSE)" such that warmup is always dropped.
draws_post
## I think, the default should be to return the warmup draws like so:
draws_post_alt <- as_draws(rstan::extract(fit, permuted = FALSE, inc_warmup = TRUE))
draws_post_alt
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 by tracing as_draws(fit) through the RStan as.array conversion and compare it with rstan::extract(..., inc_warmup = TRUE) in the issue example. Check how warmup draws are retained in a stanfit object and where conversion behavior is documented. Done means the conversion can include warmup draws as requested and the behavior or option is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100