Hi all,
After working with stan through brms I am exploring some more complex models, and this lead to me doing some simulation and testing for models with measurement error, using the example in the Stan user guide as a guideline.
Simulating some data:
N <- 1000
a <- 2
b <- 7
sigma <- 1
mu_x <- 0
sigma_x <- 5
x <- rnorm(N,mu_x,sigma_x)
y <- rnorm(N,a + b*x, sigma)
tau <- 1
x_meas <- rnorm(N,x,tau)
data_meas <- list(
x_meas=x_meas,
y=y,
N=N
)
In other words, a regression model of the form y \sim Normal(ax + b, \sigma)
but with x as a latent variable being measured with error, x_{meas} \sim Normal(x, \tau)
I tested two models, both a centered parameterization:
data {
int<lower=1> N;
vector[N] x_meas;
vector[N] y;
}
parameters {
vector[N] x;
real mu_x;
real<lower=0> sigma_x;
real<lower=0> tau;
real a;
real b;
real<lower=0> sigma;
}
model {
// Priors
tau ~ exponential(1);
sigma ~ exponential(1);
sigma_x ~ cauchy(0,5);
mu_x ~ normal(0, 1);
a ~ normal(0, 5);
b ~ normal(0, 5);
// Latent variable model (centered)
x ~ normal(mu_x, sigma_x);
// Likelihoods
x_meas ~ normal(x, tau);
y ~ normal(a + b * x, sigma);
}
and a non-centered one:
parameters {
vector[N] x_raw;
// ...
}
transformed parameters {
vector[N] x = mu_x + x_raw * sigma_x;
}
model {
// latent variable model (non-centered)
x_raw ~ normal(0, 1); // Implies x ~ normal(mu_x, sigma_x)
// ...
}
Using cmdstanr to test these models on my simulated data, I’m having a variety of issues depending on my choice of priors and/or simulating procedure - sometimes the centered version samples better, sometimes the non-centered version samples better, but in both cases, consistently, I get the E-BFMI less than 0.3
warning, nasty traceplots, and very low effective sample sizes/high rhats for at least some of the parameters, with an ess_bulk in the order of approx. 10 samples (although the sample means do usually recover the simulation parameters).
I’m wondering if there is something obvious I’m doing wrong here. Maybe the model is inherently not identifiable? Maybe my priors are wildly off? Perhaps my parameterization in both cases is wrong? Any advice would be appreciated.