Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Imports:
posterior (>= 1.0.1),
withr,
cli,
vctrs
vctrs,
abind
Suggests:
knitr,
testthat,
Expand Down
4 changes: 2 additions & 2 deletions R/tidy_draws.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ tidy_draws.data.frame = function(model, ...) {
#' @export
tidy_draws.mcmc.list = function(model, ...) {
draws = do.call(rbind, lapply(seq_along(model), function(chain) {
n = nrow(model[[chain]])
n = coda::niter(model[[chain]])
iteration = seq_len(n)

add_column(
Expand Down Expand Up @@ -181,7 +181,7 @@ tidy_draws.stanreg = function(model, ...) {
#so we dont' just do tidy_draws(model$stanfit)
sample_matrix = as.array(model) #[iteration, chain, variable]
n_chain = dim(sample_matrix)[[2]]
mcmc_list = as.mcmc.list(lapply(seq_len(n_chain), function(chain) as.mcmc(sample_matrix[, chain, ]))) # nolint
mcmc_list = as.mcmc.list(lapply(seq_len(n_chain), function(chain) as.mcmc(abind::adrop(sample_matrix[, chain, , drop=FALSE], drop = 2)))) # nolint
draws = tidy_draws(mcmc_list, ...)
draws = add_rstan_sampler_param_draws(draws, model$stanfit)

Expand Down
Binary file added tests/models/models.rstanarm.one_var.rds
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/testthat/test.tidy_draws.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ test_that("tidy_draws works with rstanarm", {
expect_equal(tidy_draws(m_ranef), draws_tidy)
})

test_that("tidy_draws works with rstanarm models with one variable", {
skip_if_not_installed("rstanarm")

m_one_var = readRDS(test_path("../models/models.rstanarm.one_var.rds"))
expect_contains(colnames(tidy_draws(m_one_var)), "(Intercept)")
})


# rstan -------------------------------------------------------------------
test_that("tidy_draws works with rstan", {
Expand Down