Skip to content

Error calling tidy_draws on an intercept-only binomial model fitted with rstanarm #331

@mbedward

Description

@mbedward

With tidybayes 3.0.7 the following code throws an error...

# Fitting a toy binomial model to estimate an overall probability of success

library(rstanarm)
library(tidybayes)

# Simulate some data
true_prob <- 0.25
n <- sample(10:20, 20, replace = TRUE)
y <- rbinom(20, n, true_prob)
dat <- data.frame(hits = y, misses = n - y)

# Fit an intercept-only model
m <- stan_glm(cbind(hits, misses) ~ 1, data = dat, family = binomial())

# This provokes an error...
post <- tidy_draws(m)

The problem seems to be due to this code in tidy_draws.mcmc.list()...

  draws = do.call(rbind, lapply(seq_along(model), function(chain) {
    n = nrow(model[[chain]])
    iteration = seq_len(n)

...where model is the mcmc.list object. Because the fitted model only has an intercept, the object model[[chain]] will be a vector, so nrow() will return NULL causing the seq_len(n) to crash.

I'm probably doing something wrong here (i.e. user error rather than package bug) but haven't been able to spot it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions