Brms adding informaive priors

Am running a survival model with brms the default vague priors give results comparable to standard CPH model. However when I try and add an informative prior, the code just hangs - no errors, nothing. The informative prior is based on some data that suggests an increased HR of about 1.1 for the treatment so I tried adding prior = c(set_prior("normal(0.1,.05)", class = "b") as I think this needs to be entered on a log scale

head(pace4)
cox_mod <- coxph(Surv(time, status) ~ treat, data = pace4)
summary(cox_mod) # works fine
#Call:
# coxph(formula = Surv(time, status) ~ treat, data = pace4)
# n= 960, number of events= 301 
# coef exp(coef) se(coef)    z Pr(>|z|)
#treat 0.130     1.138    0.117 1.11     0.27
#exp(coef) exp(-coef) lower .95 upper .95
#treat      1.14      0.878     0.905      1.43

mod <- brms::brm(time | cens(1-status) ~treat,
                 data = pace4, family = cox(), cores =4, refresh = 0, seed =123, , backend = "cmdstanr")

summary(mod) #also works fine

# Family: cox 
#  Links: mu = log 
#Formula: time | cens(1 - status) ~ treat 
 #  Data: pace4 (Number of observations: 960) 
 #Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
  #       total post-warmup draws = 4000

#Population-Level Effects: 
#          Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
#Intercept    -0.67      0.09    -0.85    -0.51 1.00     3622     2752
#treat         0.08      0.12    -0.15     0.30 1.00     3455     2712

#informative prior
mod2 <- brms::brm(time | cens(1-status) ~treat,
                    data = pace4, refresh = 0, seed=123, family = cox(), 
                    prior = c(set_prior("normal(0.1,.05)", class = "b"), cores = 4, backend = "cmdstanr")
  
# just hangs

R version 4.3.1 (2023-06-16)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.5.2
brms_2.19.0

Thanks

Here is some simulated data to better illustrate my issue

price4 <- data.frame(trt = 1:960 > 480,
                 time = sample(1:1000, size = 960, replace = TRUE),
                 event = c(1:480 < 146, 1:480 < 155))

I think you’re missing the ) to close c( on your prior line.

library(brms)

price4 <- data.frame(trt = 1:960 > 480,
                     time = sample(1:1000, size = 960, replace = TRUE),
                     event = c(1:480 < 146, 1:480 < 155))

# "hangs" (waiting for additional input)

mod2 <- brms::brm(time | cens(1-event) ~ trt,
                  data = price4, refresh = 0, seed=123, family = cox(),
                  prior = c(set_prior("normal(0.1,.05)", class = "b"),  # HERE: missing ')' before the comma
                  cores = 4, backend = "cmdstanr")
                  
# works
mod3 <- brms::brm(time | cens(1-event) ~ trt,
                  data = price4, refresh = 0, seed=123, family = cox(),
                  prior = c(set_prior("normal(0.1,.05)", class = "b")),
                  cores = 4, backend = "cmdstanr")
1 Like

Duhh, thanks for spotting the syntax error.
This is what happens when you depend to heavily on RStudio to automatically catch your syntax errors.

1 Like

“too” heavily (my grade school teachers wouldn’t be impressed if I didn’t correct this)

1 Like

Now if only I could spot my own syntax errors… :)

If you would please tick the ‘Solution’ box, other folks can direct their attention to posts that still need help.