# Mixtures: A debugging story

**URL:** <https://discourse.mc-stan.org/t/mixtures-a-debugging-story/33528>\
**Category:** Modeling\
**Created:** [December 7, 2023, 7:56pm UTC](https://discourse.mc-stan.org/t/mixtures-a-debugging-story/33528 "2023-12-07T19:56:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewgelman](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrewgelman/32/1577_2.png) [@andrewgelman](https://discourse.mc-stan.org/u/andrewgelman)\
**Post date:** [December 7, 2023, 7:56pm UTC](https://discourse.mc-stan.org/t/mixtures-a-debugging-story/33528/1 "2023-12-07T19:56:24Z")

</div>

This story might amuse some of you: [Mixtures: A debugging story | Statistical Modeling, Causal Inference, and Social Science](https://statmodeling.stat.columbia.edu/2023/12/07/a-short-debugging-story/)

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.

---

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [December 8, 2023, 7:47pm UTC](https://discourse.mc-stan.org/t/mixtures-a-debugging-story/33528/2 "2023-12-08T19:47:53Z")

</div>

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:

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

```

instead of the intended

```stan
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)`.

---

<div class="post-metadata">

**Author:** ![Corey.Plate](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/corey.plate/32/20600_2.png) [@Corey.Plate](https://discourse.mc-stan.org/u/Corey.Plate)\
**Post date:** [December 8, 2023, 8:10pm UTC](https://discourse.mc-stan.org/t/mixtures-a-debugging-story/33528/3 "2023-12-08T20:10:16Z")

</div>

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