# Power-scaling only top level prior in priorsense

**URL:** <https://discourse.mc-stan.org/t/power-scaling-only-top-level-prior-in-priorsense/36971>\
**Category:** Modeling\
**Created:** [October 18, 2024, 9:02pm UTC](https://discourse.mc-stan.org/t/power-scaling-only-top-level-prior-in-priorsense/36971 "2024-10-18T21:02:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kgoldfeld](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/kgoldfeld/32/6833_2.png) [@kgoldfeld](https://discourse.mc-stan.org/u/kgoldfeld)\
**Post date:** [October 18, 2024, 9:02pm UTC](https://discourse.mc-stan.org/t/power-scaling-only-top-level-prior-in-priorsense/36971/1 "2024-10-18T21:02:28Z")

</div>

I am just getting started with the new priorsense package (currently using version 1.0.3) to assess the sensitivity of my hierarchical model to the prior distribution assumptions. Based on the recommendation in the paper by Kallioinen et al (“Detecting and diagnosing prior and likelihood sensitivity with power-scaling”), I understand that only a top-level prior should be power-scaled. My question is, how should this actually implemented.

For example, if I have a vector of j cluster specific effects, and each one shares the same distribution, but the variation \sigma needs to be estimated, I want to test the sensitivity to the prior distribution assumption of \sigma only:

\mu\_j \sim N(0, \sigma)  
\sigma \sim t\_{df=3}^+(0, 2.5)

Would I accomplish this through how I define lprior in the **generated quantities** block in my **Stan** code, perhaps by excluding \mu from the calculation of the log prior? Or is this accomplished somehow in the call to _powerscale\_sensitivity()_ in **R**? There are arguments _prior\_selection_ and _likelihood\_selection_, but it is not exactly clear if that is the role those arguments take.

I’m happy to provide a clear example if that will help. Thanks in advance for any advice.

---

<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:** [October 21, 2024, 6:38pm UTC](https://discourse.mc-stan.org/t/power-scaling-only-top-level-prior-in-priorsense/36971/2 "2024-10-21T18:38:43Z")

</div>

Hi, @kgoldfeld: I don’t know what they mean by power-scaling—can you say what that means in math?

> [@kgoldfeld](#):
>
> am just getting started with the new priorsense package

This isn’t a Stan package, so we may not be the people to ask for help about it. For instance, I have no idea what `powerscale_sensitivity()` or `prior_selection` and `likelihood_selection` are.

> [@kgoldfeld](#):
>
> Would I accomplish this through how I define lpriorlpriorlprior in the **generated quantities** block in my **Stan** code, perhaps by excluding \muμ\mu from the calculation of the log prior?

You will have to put things that affect the prior in the model itself, because they affect the posterior log density. You can define some kind of scale as a data variable then set it to different values for different runs.

The generated quantities block is just for posterior predictive quantities that don’t affect parameter inference.

> [@kgoldfeld](#):
>
> I’m happy to provide a clear example if that will help.

Thanks—it pretty much always helps with a forum like this—there are just way too many stats papers for us to know them all.

---

<div class="post-metadata">

**Author:** ![n-kall](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@n-kall](https://discourse.mc-stan.org/u/n-kall)\
**Post date:** [October 22, 2024, 7:45am UTC](https://discourse.mc-stan.org/t/power-scaling-only-top-level-prior-in-priorsense/36971/3 "2024-10-22T07:45:43Z")

</div>

There are two ways to accomplish this, but both relate to the `lprior` variable in the Stan model.

Option 1: only include the priors you want to power-scale in the `lprior` calculation. e.g. in your case something like

```stan
lprior = student_t_lpdf(sigma | 3, 0, 2.5);

```

Option 2: Define `lprior` as an array. Then partition your priors into groups and add the density evaluations to elements in the array.  
Then you can use `prior_selection` in the R functions to select elements in the array to include in the power-scaling. This option is more flexible as you can then look at sensitivity to changing only some of the priors. e.g. something along the lines of

```stan
array[2] real lprior;
lprior[1] = student_t_lpdf(sigma | 3, 0, 2.5);
lprior[2] = normal_lpdf(mu | 0, sigma);

```

```r
powerscale_sensitivity(fit, prior_selection = 1)

```

Hope this helps @kgoldfeld!

---

<div class="post-metadata">

**Author:** ![kgoldfeld](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/kgoldfeld/32/6833_2.png) [@kgoldfeld](https://discourse.mc-stan.org/u/kgoldfeld)\
**Post date:** [October 22, 2024, 1:57pm UTC](https://discourse.mc-stan.org/t/power-scaling-only-top-level-prior-in-priorsense/36971/4 "2024-10-22T13:57:15Z")

</div>

Perfect - thanks so much for confirming my intuition.
