# Mixture model of truncated gaussians - toy model

I’m trying to model a mixture of truncated gaussians with fixed (known) means such that the data lies between lb and ub. Because I want to formulate this as a mixture, I don’t think the inbuilt T[lb,ub] syntax will work. Unfortunately, when I run this on simulated data the chains fail to converge. Oddly, even if I widen the range of the bounds so that the truncation should be irrelevant, the model still fails. If I run similar code for a mixture of normals but without allowing for truncation, I am able to fit appropriately simulated data. If I include only a single truncated normal, the model converges just fine, it’s only for 2 or more peaks that the inference fails. I have fixed means so I don’t think label switching will be a problem.

``````data{
int N;
int K;
vector[K] mu;
real lb;
real ub;
real<lower=lb, upper=ub> y[N];
}

parameters{
simplex[K] theta;
real<lower=0> sigma;
}

transformed parameters{
vector[K] ltheta = log(theta);
}

model{
sigma ~ normal(0.05, 0.02);

for (n in 1:N){
vector[K] lps = ltheta;
for (k in 1:K){
lps[k] += normal_lpdf(y[n]|mu[k], sigma) - log_diff_exp(
normal_lcdf(ub| mu[k], sigma),
normal_lcdf(lb| mu[k], sigma));
}
target += log_sum_exp(lps);
}
}
``````
1 Like

After some further exploration, the problem seems to be that sigma is not on unit scale. When I introduce a variable `sigma_raw` and sample as `sigma_raw ~ normal(0, 1)` and transform this as `sigma = sigma_prior_mean + sigma_prior_sigma * sigma_raw` then I see good convergence of the chains.

1 Like