# NOT RUN {
library(brms)
library(cmdstanr)
# path for storing checkpoint info
path <- create_folder(folder_name = "chkpt_folder_fit1")
# "random" intercept
fit1 <- chkpt_brms(bf(formula = count ~ zAge + zBase * Trt + (1|patient),
family = poisson()),
data = epilepsy, ,
iter_warmup = 1000,
iter_sampling = 1000,
iter_per_chkpt = 250,
path = path)
# brmsfit output
fit1
# path for storing checkpoint info
path <- create_folder(folder_name = "chkpt_folder_fit2")
# remove "random" intercept (for model comparison)
fit2 <- chkpt_brms(bf(formula = count ~ zAge + zBase * Trt,
family = poisson()),
data = epilepsy, ,
iter_warmup = 1000,
iter_sampling = 1000,
iter_per_chkpt = 250,
path = path)
# brmsfit output
fit2
# compare models
loo(fit1, fit2)
# using custom priors
path <- create_folder(folder_name = "chkpt_folder_fit3")
# priors
bprior <- prior(constant(1), class = "b") +
prior(constant(2), class = "b", coef = "zBase") +
prior(constant(0.5), class = "sd")
# fit model
fit3 <-
chkpt_brms(
bf(
formula = count ~ zAge + zBase + (1 | patient),
family = poisson()
),
data = epilepsy,
path = path,
prior = bprior,
iter_warmup = 1000,
iter_sampling = 1000,
iter_per_chkpt = 250,
)
# check priors
prior_summary(fit3)
# }
Run the code above in your browser using DataLab