-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Hi,
I've got a model with lots of optional variables but SBC throws an error when I try to plot their ranks. Here's a reproducible example with the following Stan program called test.stan.
data {
int N, indicator;
array[N] real y;
}
parameters {
vector[indicator ? 1 : 0] mu1;
vector[indicator ? 0 : 1] mu2;
real<lower=0> sigma;
}
model {
if (indicator) {
target += normal_lpdf(y | mu1[1], sigma);
} else {
target += normal_lpdf(y | mu2[1], sigma);
}
}
And the following R script reproduces the error:
# packages
library(cmdstanr)
library(SBC)
# compile model
mod <- cmdstan_model("test.stan")
# generator function and data
generator <- function(N, indicator) {
mu <- rnorm(2)
sigma <- rexp(1)
if (indicator) {
y <- rnorm(N, mu[1], sigma)
} else {
y <- rnorm(N, mu[2], sigma)
}
list(variables = list(mu1 = mu[1],
mu2 = mu[2],
sigma = sigma),
generated = list(N = N,
indicator = indicator,
y = y))
}
gen <- SBC_generator_function(generator, N = 100, indicator = 1)
n_sim <- 10
data <- generate_datasets(gen, n_sim)
# backend and SBC
backend <- SBC_backend_cmdstan_sample(mod, chains = 3,
iter_warmup = 100, iter_sampling = 100)
sbc <- compute_SBC(data, backend)
# rank errors
plot_rank_hist(sbc)
Thanks for taking a look!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels