# Brms prior update

**URL:** <https://discourse.mc-stan.org/t/brms-prior-update/32755>\
**Category:** Modeling\
**Tags:** brms\
**Created:** [September 13, 2023, 6:38am UTC](https://discourse.mc-stan.org/t/brms-prior-update/32755 "2023-09-13T06:38:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cait1](https://avatars.discourse-cdn.com/v4/letter/c/7feea3/32.png) [@Cait1](https://discourse.mc-stan.org/u/Cait1)\
**Post date:** [September 13, 2023, 6:38am UTC](https://discourse.mc-stan.org/t/brms-prior-update/32755/1 "2023-09-13T06:38:31Z")

</div>

Hi there,

I would like to update my priors from non informative to informative based on the mean and standard deviation of my posterior draws. I am able to store the mean and sd in data frame but I cant seem to input a variable into the prior, I have tried everything and no matter what I try I get an error. I am a newbie to R so some help would be much appreciated :)

# Fit based on non-informative /default priors

fit3 ← brm(  
bf(P3 ~ s(calculated\_RUL3) + (1 | engine\_ID3)),  
prior = prior(normal(stanvar(prior\_mean), prior\_sd), class = “Intercept”),  
warmup = 2000, iter = 4000, chains = 4,  
control = list(adapt\_delta = 0.95)) # Pass the prior specification to the brm function

summary(fit3)

Family: gaussian  
Links: mu = identity; sigma = identity  
Formula: P3 ~ s(calculated\_RUL3) + (1 | engine\_ID3)  
Data: dat3 (Number of observations: 9909)  
Draws: 4 chains, each with iter = 4000; warmup = 2000; thin = 1;  
total post-warmup draws = 8000

Smooth Terms:  
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk\_ESS  
sds(scalculated\_RUL3\_1) 0.37 0.12 0.21 0.68 1.00 681  
Tail\_ESS  
sds(scalculated\_RUL3\_1) 1236

Group-Level Effects:  
~engine\_ID3 (Number of levels: 50)  
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk\_ESS Tail\_ESS  
sd(Intercept) 0.06 0.01 0.05 0.08 1.02 280 604

Population-Level Effects:  
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk\_ESS Tail\_ESS  
Intercept 0.57 0.01 0.55 0.59 1.04 110 264  
scalculated\_RUL3\_1 2.11 0.21 1.71 2.52 1.01 989 1868

Family Specific Parameters:  
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk\_ESS Tail\_ESS  
sigma 0.07 0.00 0.07 0.07 1.00 3120 4105

Draws were sampled using sampling(NUTS). For each parameter, Bulk\_ESS  
and Tail\_ESS are effective sample size measures, and Rhat is the potential  
scale reduction factor on split chains (at convergence, Rhat = 1).  
Warning message:  
There were 5 divergent transitions after warmup. Increasing adapt\_delta above 0.95 may help. See [Redirect](http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup)

# was just using this as an example

prior\_values ← as.data.frame(fixef(fit3))  
prior\_mean ← prior\_values[1:1,1]  
prior\_sd ← prior\_values[1:1,2]

fit5 ← brm(  
bf(P3 ~ s(calculated\_RUL3) + (1 | engine\_ID3)),  
prior = prior(normal(stanvar(prior\_mean), prior\_sd), class = “Intercept”),  
warmup = 2000, iter = 4000, chains = 4,  
control = list(adapt\_delta = 0.95)) # Pass the prior specification to the brm function

Compiling Stan program…  
Error in stanc(file = file, model\_code = model\_code, model\_name = model\_name, :  
0

Semantic error in ‘string’, line 44, column 44 to column 54:

Identifier ‘prior\_mean’ not in scope.

Please help I don’t know what I am doing wrong all I want to do it get my means and standard deviation from my posterior draws from my first fit, store them in a matrix and then use that matrix or data frame as my new priors for my next fit.

---

<div class="post-metadata">

**Author:** ![scholz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/scholz/32/14298_2.png) [@scholz](https://discourse.mc-stan.org/u/scholz)\
**Post date:** [September 13, 2023, 9:13am UTC](https://discourse.mc-stan.org/t/brms-prior-update/32755/2 "2023-09-13T09:13:41Z")

</div>

`as.brmsprior()` might help you here to convert from a `data.frame` to a `brmsprior` object.  
See [this issue](https://github.com/paul-buerkner/brms/issues/1491) for some example code.
