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
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: