# Setting Priors for splines with \`by\` variables

**URL:** <https://discourse.mc-stan.org/t/setting-priors-for-splines-with-by-variables/13118>\
**Category:** brms\
**Created:** [February 13, 2020, 11:16pm UTC](https://discourse.mc-stan.org/t/setting-priors-for-splines-with-by-variables/13118 "2020-02-13T23:16:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sapsi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/sapsi/32/3902_2.png) [@sapsi](https://discourse.mc-stan.org/u/sapsi)\
**Post date:** [February 13, 2020, 11:16pm UTC](https://discourse.mc-stan.org/t/setting-priors-for-splines-with-by-variables/13118/1 "2020-02-13T23:16:16Z")

</div>

I have a model with the term `s(nvc,m=1,by=os)`. In the model summary, I see

```
Smooth Terms:
                        Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sds(snvcosDarwin_1) 0.16 0.09 0.06 0.38 1.00 1865 2139
sds(snvcosLinux_1) 0.35 0.27 0.08 1.03 1.00 2180 2867
sds(snvcosWindows_NT_1) 0.11 0.06 0.04 0.26 1.00 1734 2173

```

How to specify priors for the smooth terms? In `prior_summary` I only see

```
                  prior class coef group resp dpar nlpar bound
1 b
...
...
7 sds s(nvc,m=1,by=os)

```

Thanks much

---

<div class="post-metadata">

**Author:** ![HugoBotha](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/hugobotha/32/7160_2.png) [@HugoBotha](https://discourse.mc-stan.org/u/HugoBotha)\
**Post date:** [February 14, 2020, 1:12am UTC](https://discourse.mc-stan.org/t/setting-priors-for-splines-with-by-variables/13118/2 "2020-02-14T01:12:39Z")

</div>

If you do get\_prior(your\_model\_formula,your\_data,your\_family) it should give you the answer.

It’ll be something like

```
prior<- prior_string("normal(0,3)",class="b",coef="snvc:osLinux_1")+
  prior_string("normal(0,3)",class="b",coef="snvc:osWindows_NT_1")+
  prior_string("student_t(10,0,5)",class="sds")...

```

You can use paste() or paste0() to make it simpler if you have lots of levels to your factor

```
prior<-prior_string("normal(0,3)",class="b",coef=paste0(paste("snvc",unique(model_data$os),sep=":")"_1"))+...

```

You get the idea :)

**Edit**

Btw, setting priors on these can be hard. So, best to set them and then sample from the prior by specifying sample\_prior=“only” in the brm call. Then you can see if it’s reasonable by looking at spaghetti plots with marginal/conditional effects. You don’t want priors that allow completely unrealistic associations etc.

---

<div class="post-metadata">

**Author:** ![sapsi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/sapsi/32/3902_2.png) [@sapsi](https://discourse.mc-stan.org/u/sapsi)\
**Post date:** [February 14, 2020, 4:34am UTC](https://discourse.mc-stan.org/t/setting-priors-for-splines-with-by-variables/13118/3 "2020-02-14T04:34:27Z")

</div>

Nice idea! thanks
