The opinions & statements expressed in this presentation and on the following slides are solely of the presenters, and not necessarily those of Novartis.
After this course, you should:
brms
syntax and workflowand of course:
brms
going forward!brms
modelling workflowbrms
modelling workflowp(\theta|y) = \frac{p(y|\theta) \, p(\theta)}{p(y)}
\hat{\theta} = E[\theta|y] = \int \theta \, p(\theta|y) \, d\theta
In practice solved by Markov-Chain Monte-Carlo (MCMC) in generating draws s=1, \ldots, S
\theta_s \sim p(\theta|y)
\int \theta \, p(\theta|y) \, d\theta \approx \frac{1}{S} \sum_{s=1}^S \theta_s
formula
Varying intercept model for a single grouping factor:
Varying intercept-slope model for a single grouping factor:
Advanced non-linear terms such as Gaussian processes:
… or approximate Gaussian processes:
formula
Linear formulas for multiple distributional parameters (e.g., predict mean and overdispersion of negative binomial):
Non-linear formula for a single distributional parameter:
family
General structure:
Ensure to have at least 8 GB of RAM available for compilation step
Preferable to use the cmdstanr
backend and set cmdstanr_write_stan_file_dir
to a model binary caching directory. This avoids model recompilation with and between R sessions.
Use of the here
R package is encouraged to manage file paths. This makes all file paths relative to a common project root.
library(brms)
here::i_am("relative_path_in_project_to/rscript.R")
library(here)
options(
# how many processor cores would you like to use?
mc.cores = 4,
# how would you like to access Stan?
brms.backend = "cmdstanr",
# cache model binaries
cmdstanr_write_stan_file_dir = here::here("_brms-cache"),
# no need to normalize likelihoods
brms.normalize = FALSE
)
# create cache directory if not yet available
dir.create(here::here("_brms-cache"), FALSE)
Goal: reduce control group sample size while maintaining power
Collect historical data from relevant literature systematically
Evaluate heterogeniety of historical data
data quality, patient population, trial design
Pre-specify trial protocol
prior documentation, operating charachteristics
Prior-data conflict?
Endpoint binary ASAS20 response at week 6
Improvement = higher rates
Historical control data
8 studies with 513 patients
Bayesian design
Randomization ratio 4:1 (24 vs 6)
MAP prior:
mean | sd | 2.5% | 50% | 97.5% |
---|---|---|---|---|
0.26 | 0.09 | 0.11 | 0.25 | 0.47 |
Y is the (control) group summary data for H historical trials \begin{align*} Y_{h}|\theta_{h} &\sim f(\theta_{h}) & \forall \; h \in [1,H] \\ Y_\ast|\theta_\ast &\sim f(\theta_\ast) & \text{for new trial} \end{align*}
Exchangeability assumption: \begin{align*} g(\theta_{h})|\beta,\tau &\sim \text{Normal}(\beta, \tau^2) & \forall \; h \in [1,H] \\ g(\theta_\ast)|\beta,\tau &\sim \text{Normal}(\beta, \tau^2) & \text{for new trial} \end{align*}
RBesT
1brms
library(brms)
# use of an outcome modifier to specify number of trials
# intercept study random effect requested with (1 | study)
bmap_model <- bf(r | trials(n) ~ 1 + (1 | study),
family=binomial, center=FALSE)
bmap_model_prior <- prior(normal(0, 2), class=b, coef=Intercept) +
prior(normal(0, 1), class=sd, coef=Intercept, group=study)
bmap_mc <- brm(bmap_model,
data=RBesT::AS,
prior=bmap_model_prior,
seed=98721487,
control=list(adapt_delta=0.99)) # Stan sampling parameter
study | n | r |
---|---|---|
Study 1 | 107 | 23 |
Study 2 | 44 | 12 |
Study 3 | 51 | 19 |
Study 4 | 39 | 9 |
Study 5 | 139 | 39 |
Study 6 | 20 | 6 |
Study 7 | 78 | 9 |
Study 8 | 35 | 10 |
Family: binomial
Links: mu = logit
Formula: r | trials(n) ~ 1 + (1 | study)
Data: RBesT::AS (Number of observations: 8)
Multilevel Hyperparameters:
~study (Number of levels: 8)
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(Intercept) 0.37 0.21 0.04 0.86 1.00 1104 1126
Regression Coefficients:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept -1.11 0.19 -1.48 -0.73 1.00 1581 1753
Intercept
is the typical trial response rate on the logit scalesd(Intercept)
is the between-trial heterogeneity \tauAS_new <- data.frame(study = "new_study", n = 1)
pe <- posterior_epred(
bmap_mc, newdata = AS_new,
allow_new_levels = TRUE,
sample_new_levels = "gaussian"
)
posterior_summary(pe)
Estimate Est.Error Q2.5 Q97.5
[1,] 0.257566 0.08803654 0.1101559 0.4716962
allow_new_levels=TRUE
allows to simulate the study random effect for a new (unseen) studiessample_new_levels = "gaussian"
ensures that the simulation is done using the normal hierarchical model (the default is to bootstrap existing levels)For specifying the prior as part of a pre-specified analysis we choose a parametric approximation:
withr::with_seed(654873,
AS_region <- bind_cols(AS, region=sample(c("asia", "europe", "north_america"), 8, TRUE)))
kable(AS_region)
study | n | r | region |
---|---|---|---|
Study 1 | 107 | 23 | europe |
Study 2 | 44 | 12 | asia |
Study 3 | 51 | 19 | europe |
Study 4 | 39 | 9 | europe |
Study 5 | 139 | 39 | asia |
Study 6 | 20 | 6 | north_america |
Study 7 | 78 | 9 | europe |
Study 8 | 35 | 10 | asia |
form_AS_region <- bf(r | trials(n) ~ 1 + (1 | region/study),
family = binomial, center=FALSE)
# show which priors brms defines for this model
get_prior(form_AS_region, AS_region)
bprior_AS_region <- prior(normal(0, 2), class=b, coef=Intercept) +
prior(normal(0, 0.50), class=sd, coef=Intercept, group=region) +
prior(normal(0, 0.25), class=sd, coef=Intercept, group=region:study)
fit_AS_region <- brm(
form_AS_region, data = AS_region, prior = bprior_AS_region, seed = 29856341,
control=list(adapt_delta=0.99))
(1 | region/study)
specifies a nested random effect structure as in this example each study is run in a single region. It is equivalent to(1 | region) + (1 | region:study)
. Family: binomial
Links: mu = logit
Formula: r | trials(n) ~ 1 + (1 | region/study)
Data: AS_region (Number of observations: 8)
Multilevel Hyperparameters:
~region (Number of levels: 3)
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(Intercept) 0.28 0.22 0.01 0.86 1.00 1605 1680
~region:study (Number of levels: 8)
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(Intercept) 0.24 0.14 0.02 0.53 1.00 1648 1345
Regression Coefficients:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept -1.06 0.26 -1.57 -0.46 1.00 1643 1661
AS_region_new <- data.frame(study = "new_study_asia",
n = 1, region = "asia")
pe_region <- posterior_epred(
fit_AS_region, newdata = AS_region_new,
allow_new_levels = TRUE,
sample_new_levels = "gaussian"
)
dim(pe_region)
[1] 4000 1
Estimate Est.Error Q2.5 Q97.5
[1,] 0.2691718 0.06397847 0.1549326 0.4190814
brms
brms
using the RBesT::mixstanvar
adapter“Priors are inherently subjective”
“Priors bias your analysis”
“You should let the data speak for themselves”
“Non-Bayesian models don’t have priors and don’t need them”
“I have no idea how to set appropriate priors”
Consider using the alternative terms “contextual” or “conditional”1
Definition:
An estimator \hat{\theta} of the parameter \theta is called unbiased if \text{E}_{y}(\hat{\theta}) = \theta.
Corrollary:
If an estimator \hat{\theta} is unbiased for a given prior, it will be biased for most other priors.
Corrollary:
If an estimator \hat{\theta} is unbiased at a given scale, it will be biased for most non-linear transformations f(\hat{\theta}) (Jensen’s inequality): \text{E}_y(f(\hat{\theta})) \neq f(\theta)
Unbiasedness is fragile and often only holds in the limit
A sampling distribution is a distribution of a data-dependent variable (a “statistic”) as implied by variation in data y across the true data generating process
Consider two estimators \hat{\theta}_1 and \hat{\theta}_2 of \theta with sampling distributions given by
Which of them is better?
The RMSE can be defined as \begin{align*} \text{RMSE}_y(\hat{\theta}, \theta) & = \sqrt{\int (\hat{\theta}(y) - \theta)^2 \; p(y) \; d y} \\ & = \sqrt{\text{Var}_y{\hat{\theta}} + \text{Bias}_y(\hat{\theta}, \theta) ^2} \end{align*}
It expresses a trade-off between variance and bias
A lot of priors will help you win the bias-variance trade-off, not the race for minimal bias!
Basic multilevel model with J groups:
Is b0[j] ~ normal(b0, sd0)
a likelihood, prior, or something else?
What is the posterior?
… if the prior is \theta \sim \text{student-t}(4, 5, 1)
… and the likelihood alone implies a posterior of \theta \sim \text{normal}(-5, 1)
Respecting boundaries: use hard bounds in priors exactly where parameters have natural bounds
Expressiveness: use prior families flexible enough to express different plausible prior knowledge
Controlling complexity: If you want to be conservative, put relevant amount of prior probability at or near a conservative submodel
Scale awareness: ensure that priors take the scales of parameters into account
Reflecting structure: reflect the structure of the data in the structure of the prior
Data Informed: Use previous data to inform the current priors
The RBesT
package allows to build Meta-Analytic Predictive (MAP) priors, a special kind of data informed priors
See the ESMARConf2023 tutorial on RBesT
on Youtube
Also check out https://opensource.nibr.com/bamdd/ the for the following MAP case studies: historical control without / with stratification, treatment effects, single arm PoS
dose | group | log_est | log_stderr |
---|---|---|---|
0 | placebo | −0.400 | 0.103 |
70 | tezepelumab 70 mg q4w | −1.347 | 0.177 |
210 | tezepelumab 210 mg q4w | −1.661 | 0.222 |
560 | tezepelumab 280 mg q2w | −1.514 | 0.191 |
f(\text{dose}; \text{parameters}) = \text{E}_0 + \text{E}_\text{max} \frac{\text{dose}^h}{\text{dose}^h + \text{ED}_{50}^h}
Parameters:
brms
form_sig <- bf(
log_est | se(log_stderr) ~ E0 + Emax * dose^h /
(dose^h + ED50^h),
nlf(h ~ exp(logh)), nlf(ED50 ~ exp(logED50)),
E0 ~ 1, Emax ~ 1, logh ~ 1, logED50 ~ 1,
nl = TRUE,
family = gaussian()
)
prior_sig <- prior(normal(0,1), nlpar=E0) +
prior(normal(0,1), nlpar=logh) +
prior(normal(0,1), nlpar=Emax) +
prior(normal(4,2), nlpar=logED50)
What is more informative?
Biologically plausible values: approx. .25 < h < 4 (see prior interval probabilities).
The above prior puts roughly 1/3 above 4 and 1/3 below 0.25!
Re-writing the fraction to \left(\frac{d}{\text{ED}_{50}}\right)^h / \left(1+\left(\frac{d}{\text{ED}_{50}}\right)^h\right) makes it obvious that for h \rightarrow 0, this goes to 1/2, and for h \rightarrow \infty, either to 0 (d < \text{ED}_{50}) or 1 (d > \text{ED}_{50}).
brms
Family: gaussian
Links: mu = identity; sigma = identity
Formula: log_est | se(log_stderr) ~ E0 + Emax * dose^h/(dose^h + ED50^h)
h ~ exp(logh)
ED50 ~ exp(logED50)
E0 ~ 1
Emax ~ 1
logh ~ 1
logED50 ~ 1
Data: pathway (Number of observations: 4)
Regression Coefficients:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
E0_Intercept -0.42 0.10 -0.61 -0.21 1.00 2065 2179
Emax_Intercept -1.30 0.32 -2.11 -0.84 1.00 1172 1199
logh_Intercept -0.08 0.98 -1.90 1.92 1.00 1306 1914
logED50_Intercept 2.73 1.38 -0.27 5.32 1.00 1341 1273
Further Distributional Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 0.00 0.00 0.00 0.00 NA NA NA
tibble(dose = seq(0, 560, 1), log_stderr=1) |>
tidybayes::add_epred_rvars(object=fit_sig) |>
(\(x) x |>
left_join(x |> filter(dose==0) |> rename(pbo = .epred) |> dplyr::select(-dose),
by="log_stderr"))() |>
mutate(.delta = .epred - pbo) |>
ggplot(aes(x=dose, ydist=.delta)) +
ggdist::stat_lineribbon()
f(\text{dose}; \text{parameters}) = \text{E}_0 + \text{E}_\text{max} \; \frac{(\delta_1 + \delta_2)^{(\delta_1+\delta_2)}} {\delta_1^{\delta_1} \, \delta_2^{\delta_2}} \; \left(\frac{\text{dose}}{S}\right)^{\delta_1} \left(1-\frac{\text{dose}}{S}\right)^{\delta_2}
Parameters:
S=850
brms
form_mbeta <- bf(
log_est | se(log_stderr) ~ E0 +
Emax * (delta1+delta2)^(delta1+delta2) /
(delta1^delta1 * delta2^delta2) *
(dose/850)^delta1 * (1-dose/850)^delta2,
nlf(delta1 ~ exp(logdelta1)), nlf(delta2 ~ exp(logdelta2)),
E0 ~ 1, Emax ~ 1, logdelta1 ~ 1, logdelta2 ~ 1,
nl = TRUE,
family = gaussian()
)
prior_mbeta <- prior(normal(0,1), nlpar="E0") +
prior(normal(0,1), nlpar="Emax") +
prior(normal(0,1), nlpar="logdelta1") +
prior(normal(0,1), nlpar="logdelta2")
brms
Computed from 4000 by 4 log-likelihood matrix.
Estimate SE
elpd_loo 0.1 0.4
p_loo 2.2 0.6
looic -0.2 0.7
------
MCSE of elpd_loo is NA.
MCSE and ESS estimates assume MCMC draws (r_eff in [0.4, 0.6]).
Pareto k diagnostic values:
Count Pct. Min. ESS
(-Inf, 0.7] (good) 1 25.0% 1282
(0.7, 1] (bad) 3 75.0% <NA>
(1, Inf) (very bad) 0 0.0% <NA>
See help('pareto-k-diagnostic') for details.
brms
interfaces with the loo
R package that performs efficient approximate leave-one-out cross-validation (LOO) for Bayesian models by Pareto smoothed importance sampling (PSIS). See Vethari et al. (2017) and the loo
documentation on CRAN.loo_exact_sig <- kfold(fit_sig, folds = "loo", silent=2)
(loo_exact_mbeta <- kfold(fit_mbeta, folds = "loo", silent=2))
Based on 4-fold cross-validation.
Estimate SE
elpd_kfold -2.0 1.6
p_kfold 4.3 2.2
kfoldic 4.0 3.3
loo_compare
computes a paired estimate of the difference in ELPD to take advantage of the fact that the same set of data points was used to fit both models (and reduce the standard error). See Vethari et al. (2017) and the loo
R package manual for details.fit_sig$criteria$loo <- loo_exact_sig
fit_mbeta$criteria$loo <- loo_exact_mbeta
(w_dose <- model_weights(fit_sig, fit_mbeta, weights = "loo"))
fit_sig fit_mbeta
0.841057 0.158943
model_weights
from brms
will compute Akaike weights based on the information criterion values returned by loo
Estimate Est.Error Q2.5 Q97.5 dose
1 -0.4167663 0.08680825 -0.5816652 -0.2445850 0.000000
2 -0.8312366 0.25879835 -1.3256556 -0.3984107 5.656566
3 -0.9563272 0.25696458 -1.3977850 -0.4571903 11.313131
4 -1.0409796 0.24418232 -1.4400838 -0.5073584 16.969697
Continuous outcome measured at baseline & weeks 2, 4, 8, 12
Mixed Effects Model for Repeated Measures (MMRM) commonly used for longitudinal data (each patient measured at multiple visits)
Direct likelihood analysis that can address hypothetical estimand of all patients completing the study on treatment without doing missing data imputation first
Commonly no structure assumed for correlations between visits and different variance allowed for different visits (to avoid unnecessary assumptions)
Convergence issues with REML fit common, especially for small sample sizes, which is alleviated by Bayesian inference with (weakly-)informative priors
Bayesian approach allows us to incorporate prior information and historical data, which is very interesting for Phase I studies
brms
lets us easily add more components & structure to the model
USUBJID | TRT01P | AVISIT | ADY | AVAL | CHG | BASE |
---|---|---|---|---|---|---|
3 | 0 | visit1 | 14 | 1.18 | 0.40 | 0.78 |
3 | 0 | visit2 | 28 | 0.87 | 0.10 | 0.78 |
3 | 0 | visit3 | 56 | −0.81 | −1.59 | 0.78 |
3 | 0 | visit4 | 84 | 0.81 | 0.04 | 0.78 |
9 | 10 | visit1 | 14 | 0.95 | 0.84 | 0.11 |
9 | 10 | visit2 | 28 | 1.46 | 1.35 | 0.11 |
9 | 10 | visit3 | 56 | −0.97 | −1.08 | 0.11 |
9 | 10 | visit4 | 84 | 1.21 | 1.10 | 0.11 |
13 | 20 | visit1 | 14 | 2.38 | 0.48 | 1.90 |
13 | 20 | visit2 | 28 | 2.13 | 0.23 | 1.90 |
Patients can miss visits or drop-out of the study prior to the final visit.
Fixed effects:
Random effects:
Formally, let us assume that there are V visits. We assume that the V-dimensional response \boldsymbol{Y}_i for patient i satisfies \boldsymbol{Y}_i = \boldsymbol{X}_i \boldsymbol{\beta} + \boldsymbol{Z}_i \boldsymbol{b}_i + \boldsymbol{\epsilon}_i
with \boldsymbol{b}_i \sim \text{MVN}(\boldsymbol{0}, \boldsymbol{D}) and \boldsymbol{\epsilon}_i \sim \text{MVN}(\boldsymbol{0}, \boldsymbol{\Sigma}), where \boldsymbol{\Sigma} is a diagonal matrix. This implies \boldsymbol{Y}_i \sim \text{MVN}(\boldsymbol{X}_i \boldsymbol{\beta}, \boldsymbol{V}_i), where \boldsymbol{V}_i = \boldsymbol{Z}_i \boldsymbol{D} \boldsymbol{Z}_i^T + \boldsymbol{\Sigma}. Model the correlated Y_{ij} either by
Widely-used high-quality reference implementation
mmrm
R packageFit the model in R in a frequentist framework
Refer to https://openpharma.github.io/mmrm.
We would like to put priors on the differences from visit to visit
Setup forward difference contrasts for changes between visits:
Hard to interpret the contrast matrix directly:
visit2-visit1 visit3-visit2 visit4-visit3
visit1 -3/4 -1/2 -1/4
visit2 1/4 -1/2 -1/4
visit3 1/4 1/2 -1/4
visit4 1/4 1/2 3/4
Learn more about contrasts: https://bbolker.github.io/mixedmodels-misc/notes/contrasts.pdf
Inverting the contrast matrix reveals the dummy variables’ interpretation:
brms
Note that a single corrleation matrix is estimated while the covariance varies as per the sigma
model.
AVISIT = visit1:
TRT01P emmean lower.HPD upper.HPD
0 -0.0374 -0.2637 0.1998
10 -0.1663 -0.3601 0.0434
20 0.0597 -0.1276 0.2505
40 -0.1128 -0.2838 0.0793
AVISIT = visit4:
TRT01P emmean lower.HPD upper.HPD
0 -0.2937 -0.6172 -0.0181
10 0.2062 -0.0653 0.5070
20 0.4645 0.2035 0.7719
40 0.2955 0.0408 0.5411
Point estimate displayed: median
HPD interval probability: 0.95
To work with MCMC samples of the expected marginal means & to summarize them exactly as we want (e.g. quantile credible intervals instead of highest posterior density intervals) we can use:
AVISIT = visit1:
contrast estimate lower.HPD upper.HPD
TRT01P10 - TRT01P0 -0.1267 -0.4490 0.170
TRT01P20 - TRT01P0 0.0959 -0.2036 0.396
TRT01P40 - TRT01P0 -0.0765 -0.3619 0.222
AVISIT = visit4:
contrast estimate lower.HPD upper.HPD
TRT01P10 - TRT01P0 0.5024 0.0925 0.922
TRT01P20 - TRT01P0 0.7598 0.3540 1.155
TRT01P40 - TRT01P0 0.5932 0.2090 0.969
Point estimate displayed: median
HPD interval probability: 0.95
as.mcmc()
to work with MCMC samples of the difference, e.g.
For category c=0,\ldots,(\text{categories}-1) = C-1, the monotonic term is \text{coefficient} \times (C-1) \times \sum_{k=1}^{c} \zeta_k
\zeta_k \in [0, 1] is the percent increase and is subject to the constraint \sum_{k=1}^{C-1} \zeta_k = 1
\text{coefficient} is the mean change between adjacent categories
For more details see the respective vignette:
https://paulbuerkner.com/brms/articles/brms_monotonic.html
In the online case study on http://opensource.nibr.com/bamdd you additionally find:
# A tibble: 10 × 6
CHG BASE TRT01P AVISIT AVISITN SUBJID
<dbl> <dbl> <fct> <fct> <dbl> <dbl>
1 -2.2 16 PBO Week 1 1 1
2 -0.5 16 PBO Week 2 2 1
3 4.7 16 PBO Week 4 4 1
4 7.3 16 PBO Week 6 6 1
5 32.1 16 PBO Week 8 8 1
6 10 16 PBO Week 10 10 1
7 20.7 16 PBO Week 12 12 1
8 3.4 20.3 TRT Week 1 1 2
9 1.2 20.3 TRT Week 2 2 2
10 0.600 20.3 TRT Week 4 4 2
…
Total elapsed fitting time (seconds):
pp_check
in brms
performs posterior predictive checks with the help of the bayesplot
package (shows dens_overlay
by default).
loo_pit
(probability integral transformation). In an ideal model fit, the resulting PIT-transformed values would be uniformly distributed: i.e. the blue points and dashed lines would align with the distribution function of a Uniform(0,1) variable (solid line). See chapter 12 of BAMDD for details.
Computed from 4000 by 684 log-likelihood matrix.
Estimate SE
elpd_loo -2286.3 33.1
p_loo 102.3 9.4
looic 4572.6 66.3
------
MCSE of elpd_loo is NA.
MCSE and ESS estimates assume MCMC draws (r_eff in [0.4, 1.9]).
Pareto k diagnostic values:
Count Pct. Min. ESS
(-Inf, 0.7] (good) 681 99.6% 80
(0.7, 1] (bad) 3 0.4% <NA>
(1, Inf) (very bad) 0 0.0% <NA>
See help('pareto-k-diagnostic') for details.
kfold_split_grouped
in the loo
package.emmeans
Total elapsed fitting time:
Family: gaussian
Links: mu = identity; sigma = identity
Formula: CHG ~ BASE + TRT01P * AVISITN + (1 | SUBJID)
Data: pasi_data (Number of observations: 684)
Multilevel Hyperparameters:
~SUBJID (Number of levels: 112)
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(Intercept) 5.23 0.45 4.41 6.17 1.00 1493 2463
Regression Coefficients:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept 12.99 1.83 9.42 16.69 1.00 1275 2212
BASE -0.70 0.08 -0.85 -0.54 1.00 1282 2047
TRT01PTRT -5.96 1.35 -8.57 -3.34 1.00 1550 1953
AVISITN -0.22 0.09 -0.39 -0.05 1.00 3625 3546
TRT01PTRT:AVISITN -0.72 0.13 -0.96 -0.47 1.00 3421 3194
Further Distributional Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 6.51 0.20 6.14 6.92 1.00 4713 2555
Total elapsed fitting time:
Family: gaussian
Links: mu = identity; sigma = identity
Formula: CHG ~ BASE + TRT01P * AVISITN + (1 + AVISITN | SUBJID)
Data: pasi_data (Number of observations: 684)
Multilevel Hyperparameters:
~SUBJID (Number of levels: 112)
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(Intercept) 5.26 0.54 4.25 6.35 1.00 1578 2512
sd(AVISITN) 1.10 0.09 0.94 1.30 1.01 519 1008
cor(Intercept,AVISITN) -0.53 0.09 -0.69 -0.34 1.01 402 1128
Regression Coefficients:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept 9.21 1.71 5.85 12.47 1.00 954 1632
BASE -0.49 0.08 -0.64 -0.35 1.00 997 1908
TRT01PTRT -6.47 1.18 -8.74 -4.19 1.00 1783 2657
AVISITN -0.25 0.16 -0.56 0.06 1.00 915 1985
TRT01PTRT:AVISITN -0.70 0.23 -1.14 -0.26 1.00 760 1626
Further Distributional Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma 4.67 0.15 4.39 4.96 1.00 3107 3238
Total elapsed fitting time:
Total elapsed fitting time:
Non-centered variables are often highly correlated with their square
Centering can be done around any central value. Here we use 6 because this is the average week in the study
After centering, the correlation is drastically reduced
Total elapsed fitting time:
Total elapsed fitting time:
Computed from 4000 by 684 log-likelihood matrix.
Estimate SE
elpd_loo -2045.3 35.7
p_loo 194.4 16.1
looic 4090.7 71.4
------
MCSE of elpd_loo is NA.
MCSE and ESS estimates assume MCMC draws (r_eff in [0.3, 1.8]).
Pareto k diagnostic values:
Count Pct. Min. ESS
(-Inf, 0.7] (good) 642 93.9% 106
(0.7, 1] (bad) 36 5.3% <NA>
(1, Inf) (very bad) 6 0.9% <NA>
See help('pareto-k-diagnostic') for details.
elpd_diff se_diff
fit_long_gp 0.0 0.0
fit_long_quad_c -12.8 6.6
Recall that model comparisons may not be trustworthy.
fit_long_gp_ar <- brm(
CHG ~ BASE + gp(AVISITN_c, by = TRT01P, k=9) +
ar(AVISITN_c, gr = SUBJID, p = 1) +
(1 + (AVISITN_c + I(AVISITN_c^2)) | SUBJID),
data = pasi_data, seed = 24235,
iter = 4000, warmup = 1000,
control = list(adapt_delta = 0.95)
)
fit_long_gp_ar <- add_criterion(fit_long_gp_ar, "loo")
Total elapsed fitting time:
Some autocorrelation may be present:
Estimate Est.Error Q2.5 Q97.5
ar[1] 0.379 0.121 0.157 0.625
A more formal model comparison may be theoretically advantageous but given that we add only a single parameter (the AR1 effect), we should probably gain more than we loose by including it.
brms
is a powerful and highly flexible engine for applied modelling , facilitating straightforward model specification and inferencebrms
syntax and workflowbrms
going forward!brms
documentation: https://paul-buerkner.github.io/brms/S. Weber, L. Widmer - Hierarchical Models