Mixtures: A debugging story

This story might amuse some of you: Mixtures: A debugging story | Statistical Modeling, Causal Inference, and Social Science

When I first realized I had a problem, I had the hope that once I figured it out, it could be good for the workflow book. But the bug ended up being so trivial, there was nothing much to say about it! Except to tell the story, which I did.

3 Likes

This is a common error source. I think we may have tried to deal with it in “pedantic” mode, but I’m not sure we can deal with the problem in the parameters as opposed to the variate. The usual failure is this one:

vector[N] y;
...
for (n in 1:N)
  y ~ normal(mu, sigma);

instead of the intended

vector[N] y;
...
for (n in 1:N)
  y[n] ~ normal(mu, sigma);

The former copies each data item N times. In this case, the estimates of mu and sigma will be right, but their posterior will be overconcentrated by a factor of sqrt(N).

1 Like

This was the sort of mistake that broke my code in the most recent thread I made!