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 Runtime warnings and convergence problems

# 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.