# Highly variable prior predictive check. Even y is changing

**URL:** https://discourse.mc-stan.org/t/highly-variable-prior-predictive-check-even-y-is-changing/20229
**Category:** brms
**Tags:** techniques, specification
**Created:** [January 13, 2021, 9:48pm UTC](https://discourse.mc-stan.org/t/highly-variable-prior-predictive-check-even-y-is-changing/20229 "2021-01-13T21:48:44Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![JLC](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jlc/32/12520_2.png) [@JLC](https://discourse.mc-stan.org/u/JLC)
#### Post date: [January 13, 2021, 9:48pm UTC](https://discourse.mc-stan.org/t/highly-variable-prior-predictive-check-even-y-is-changing/20229/1 "2021-01-13T21:48:44Z")

</div>

I’m trying to refine a distributional model using a Student distribution for the outcome, but am seeing highly variable prior predictive checks. I have defined _y_ from the data, but even the plot of _y_ is moving all over the place.

Just wondering what I might be doing wrong with my specification.

```
fmla <- bf(y ~ 0 + Intercept + 
                                             Pred1.c +
                                             Pred2.c +
                                             Pred3.c +
                                             Pred4.c +
                                             Pred5.c +
                                             (1|Grp1) +
                                             (1|Grp2) +
                                             (1|Grp3) +
                                             (1|Grp4/Grp5),
                                     center = TRUE,
                                     sigma ~ 0 + (1|Grp2) + (1|Grp1),
                                     nu ~ 0 + (1|Grp2) + (1|Grp1))

## Set priors
priors <- c(
        set_prior("normal(10,5)",
                  class = "b",
                  coef = "Intercept" ),
        
        set_prior("normal(0,1)",
                  class = "b"),
        
        set_prior("normal(0,1)",
                  class = "sd",
                  coef = "Intercept",
                  group = "Grp3"),
        
        set_prior("normal(1,1)",
                  class = "sd",
                  coef = "Intercept",
                  group = "Grp4"),
        
        set_prior("normal(0,1)",
                  class = "sd",
                  coef = "Intercept",
                  group = "Grp5:Grp5"),
        
        set_prior("normal(0,3)",
                  class = "sd",
                  coef = "Intercept",
                  group = Grp1"),
        
        set_prior("normal(0,0.5)",
                  class = "sd",
                  coef = "Intercept",
                  group = "Grp1",
                  dpar = "sigma"),
        
        set_prior("normal(0,0.5)",
                  class = "sd",
                  coef = "Intercept",
                  group = "Grp2",
                  dpar = "sigma"),

        set_prior("normal(0,1/sqrt(4))",
                  class = "sd",
                  coef = "Intercept",
                  group = "Grp1",
                  dpar = "nu"),
        
        set_prior("normal(0,1/sqrt(4))",
                  class = "sd",
                  coef = "Intercept",
                  group = "Grp2",
                  dpar = "nu") 
)

Mod <- brm(
       fmla,
        Data,
        family = student(link_nu = "logm1"),
        prior = priors,
        inits = 0,
        iter = 5000,
        warmup = 2500,
        chains = 4,
        cores = ncores,
        sample_prior = "only",
        save_pars = save_pars(all = TRUE),
        control = list(max_treedepth = 14,
                       adapt_delta = 0.999)
)

```

With separate runs of yrep, the plot of _y_ also changes a lot.

```
y <- Data$y
yrep <- posterior_predict(Mod ,nsamples = 100)

ppc_dens_overlay(y, 
                 yrep) + 
        coord_cartesian(xlim = c(-50, 50))

```

 ![Check1](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/e/e591e8e75d332773ed3c564004e4c0a8307cf16b.png) ![Check2](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/4/41d168f20b89a55fa8090d4712a8ffd23cf71a6b.png) ![Check3](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/4/4ddde1fc75841bf1dccecefe6a9c2c81b4ae9300.jpeg)

Am I calling something incorrectly?

---

<div class="post-metadata">

### Author: ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)
#### Post date: [January 14, 2021, 6:14am UTC](https://discourse.mc-stan.org/t/highly-variable-prior-predictive-check-even-y-is-changing/20229/2 "2021-01-14T06:14:16Z")

</div>

Try to remove the `coord_cartesian(xlim=c(-50,50))` to get a feeling for what happens. Is y count data, i.e., -n,..,-3,-2,-1,0,1,2,3,..n?

---

<div class="post-metadata">

### Author: ![JLC](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jlc/32/12520_2.png) [@JLC](https://discourse.mc-stan.org/u/JLC)
#### Post date: [January 14, 2021, 12:50pm UTC](https://discourse.mc-stan.org/t/highly-variable-prior-predictive-check-even-y-is-changing/20229/3 "2021-01-14T12:50:22Z")

</div>

Thanks, @torkar

_y_ is continuous and unbounded in a practical sense. I put the limits on the x-axis because the predictions are so broad that it’s difficult to see anything without the limits:

 ![No_Limits](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/c/c5c3153ec7fb12be8be379f2e3d766aa00f29ba0.png)

I’m curious about why the plot of _y_ would change when it’s a static vector from the data.

---

<div class="post-metadata">

### Author: ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)
#### Post date: [January 14, 2021, 12:56pm UTC](https://discourse.mc-stan.org/t/highly-variable-prior-predictive-check-even-y-is-changing/20229/4 "2021-01-14T12:56:49Z")

</div>

Hi,

try `scale_x_continuous(trans="log")`. You have random draws from the posterior, so perhaps increase it to `nsamples=500` to get a better feel for the variability?

---

<div class="post-metadata">

### Author: ![JLC](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jlc/32/12520_2.png) [@JLC](https://discourse.mc-stan.org/u/JLC)
#### Post date: [January 14, 2021, 9:14pm UTC](https://discourse.mc-stan.org/t/highly-variable-prior-predictive-check-even-y-is-changing/20229/5 "2021-01-14T21:14:02Z")

</div>

Thank you! That certainly gives a better and more stable view:

 ![5001](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/a/ad8c775f6169f3d308bf0355ddf26d6b1cfde67b.png) ![5002](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/b/bb5875cb46a658630aa45ca2f90c1a10ef9bbf98.png)
