The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
This vignette shows the results of a simulation-based calibration
(SBC) checking study to validate the implementation of the models in
brms.mmrm
. SBC checking tests the ability of a Bayesian
model to recapture the parameters used to simulate prior predictive
data. For details on SBC checking, please read Modrák et al. (2024) and the SBC
R package
(Kim et al. 2022). This particular SBC
checking study uses the targets
pipeline in the viggnettes/sbc/
subdirectory of the brms.mmrm
package source code.
From the results below, the SBC rank statistics are approximately
uniformly distributed. In other words, the posterior distribution from
the brms
/Stan MMRM modeling code matches the prior from
which the datasets were simulated. This is evidence that both the
subgroup and non-subgroup models in brms.mmrm
are
implemented correctly.
To show the SBC checking results in this vignette, we first load code from the SBC checking study, and we use custom functions to read and plot rank statistics:
library(dplyr)
library(ggplot2)
library(tibble)
library(tidyr)
source("sbc/R/prior.R")
source("sbc/R/response.R")
source("sbc/R/scenarios.R")
read_ranks <- function(path) {
fst::read_fst(path) |>
tibble::as_tibble() |>
pivot_longer(
cols = everything(),
names_to = "parameter",
values_to = "rank"
)
}
plot_ranks <- function(ranks) {
ggplot(ranks) +
geom_histogram(
aes(x = rank),
breaks = seq(from = 0, to = max(ranks$rank), length.out = 10)
) +
facet_wrap(~parameter)
}
Each section below is its own SBC checking study based on a given modeling scenario. Each scenario shows results from 1000 independent simulations from the prior.
The subgroup scenario distinguishes itself from the others by the presence of a subgroup factor. Assumptions:
Model formula:
#> response ~ group + group:subgroup + group:subgroup:time + group:time + subgroup + subgroup:time + time + continuous1 + continuous2 + balanced + unbalanced + unstr(time = time, gr = patient)
#> sigma ~ 0 + time
The prior was randomly generated and used for both simulation and analysis:
setup_prior(subgroup) |>
select(prior, class, coef, dpar) |>
as.data.frame()
#> prior class coef
#> 1 normal(0.208, 1.1058) Intercept
#> 3 normal(0.1645, 0.7774) b balancedlevel2
#> 4 normal(-0.1077, 1.0741) b balancedlevel3
#> 5 normal(-0.0115, 1.9187) b continuous1
#> 6 normal(0.0079, 2.1408) b continuous2
#> 7 normal(0.2315, 2.1) b groupgroup_2
#> 8 normal(-0.1464, 0.969) b groupgroup_2:subgroupsubgroup_2
#> 9 normal(-0.0688, 1.3739) b groupgroup_2:subgroupsubgroup_2:timetime_2
#> 10 normal(0.1806, 1.2108) b groupgroup_2:subgroupsubgroup_2:timetime_3
#> 11 normal(-0.0725, 1.3736) b groupgroup_2:timetime_2
#> 12 normal(0.0501, 2.7724) b groupgroup_2:timetime_3
#> 13 normal(-0.0027, 0.5003) b subgroupsubgroup_2
#> 14 normal(0.1151, 1.1687) b subgroupsubgroup_2:timetime_2
#> 15 normal(0.0976, 0.7009) b subgroupsubgroup_2:timetime_3
#> 16 normal(0.1038, 0.367) b timetime_2
#> 17 normal(0.0594, 2.2727) b timetime_3
#> 18 normal(0.0965, 1.3358) b unbalancedlevel2
#> 19 normal(-0.1083, 1.7843) b unbalancedlevel3
#> 20 lkj(1.2582) cortime
#> 22 normal(0.2025, 1.5685) b timetime_1
#> 23 normal(-0.2264, 2.0309) b timetime_2
#> 24 normal(-0.2269, 1.8933) b timetime_3
#> dpar
#> 1
#> 3
#> 4
#> 5
#> 6
#> 7
#> 8
#> 9
#> 10
#> 11
#> 12
#> 13
#> 14
#> 15
#> 16
#> 17
#> 18
#> 19
#> 20
#> 22 sigma
#> 23 sigma
#> 24 sigma
The following histograms show the SBC rank statistics which compare the prior parameter draws draws to the posterior draws. If the data simulation code and modeling code are both correct and consistent, then the rank statistics should be approximately uniformly distributed.
Fixed effect parameter ranks:
ranks_subgroup |>
filter(grepl("^b_", parameter)) |>
filter(!grepl("^b_sigma", parameter)) |>
plot_ranks()
Standard deviation parameter ranks:
Correlation parameter ranks:
This scenario uses unstructured correlation and does not use a subgroup variable. Assumptions:
Model formula:
#> response ~ 0 + group + time + unstr(time = time, gr = patient)
#> sigma ~ 0 + time
The prior was randomly generated and used for both simulation and analysis:
setup_prior(unstructured) |>
select(prior, class, coef, dpar) |>
as.data.frame()
#> prior class coef dpar
#> 2 normal(0.2014, 0.9262) b groupgroup_1
#> 3 normal(0.0307, 1.0648) b groupgroup_2
#> 4 normal(-0.0872, 1.3875) b groupgroup_3
#> 5 normal(0.227, 2.1638) b timetime_2
#> 6 normal(-0.0199, 1.8329) b timetime_3
#> 7 normal(-0.176, 1.5765) b timetime_4
#> 8 lkj(1.2267) cortime
#> 10 normal(-0.2196, 2.3254) b timetime_1 sigma
#> 11 normal(0.1058, 1.4523) b timetime_2 sigma
#> 12 normal(-0.0152, 2.4845) b timetime_3 sigma
#> 13 normal(-0.2046, 1.3774) b timetime_4 sigma
SBC checking rank statistics:
Fixed effect parameter ranks:
ranks_unstructured |>
filter(grepl("^b_", parameter)) |>
filter(!grepl("^b_sigma", parameter)) |>
plot_ranks()
Log-scale standard deviation parameter ranks:
Correlation parameter ranks:
This scenario uses an autoregressive moving average (ARMA) model with autoregressive order 1 and moving average order 1. Assumptions:
Model formula:
#> response ~ 0 + group + time + arma(time = time, gr = patient, p = 1L, q = 1L, cov = FALSE)
#> sigma ~ 0 + time
The prior was randomly generated and used for both simulation and analysis:
setup_prior(autoregressive_moving_average) |>
select(prior, class, coef, dpar) |>
as.data.frame()
#> prior class coef dpar
#> 1 uniform(0.1, 0.9) ar
#> 3 normal(0.0936, 2.0682) b groupgroup_1
#> 4 normal(0.1968, 2.3989) b groupgroup_2
#> 5 normal(-0.2279, 2.6832) b timetime_2
#> 6 normal(0.2453, 0.5764) b timetime_3
#> 7 uniform(0.1, 0.9) ma
#> 9 normal(0.2373, 1.4545) b timetime_1 sigma
#> 10 normal(0.154, 1.0874) b timetime_2 sigma
#> 11 normal(-0.1988, 0.754) b timetime_3 sigma
SBC checking rank statistics:
ranks_autoregressive_moving_average <- read_ranks(
"sbc/results/autoregressive_moving_average.fst"
)
Fixed effect parameter ranks:
ranks_autoregressive_moving_average |>
filter(grepl("^b_", parameter)) |>
filter(!grepl("^b_sigma", parameter)) |>
plot_ranks()
Log-scale standard deviation parameter ranks:
Correlation parameter ranks:
This scenario is the same as above, but the correlation structure is autoregressive with order 2. Model formula:
#> response ~ 0 + group + time + ar(time = time, gr = patient, p = 2L, cov = FALSE)
#> sigma ~ 0 + time
The prior was randomly generated and used for both simulation and analysis:
setup_prior(autoregressive) |>
select(prior, class, coef, dpar) |>
as.data.frame()
#> prior class coef dpar
#> 1 uniform(0.1, 0.9) ar
#> 3 normal(-0.1739, 1.3276) b groupgroup_1
#> 4 normal(-0.0084, 2.0227) b groupgroup_2
#> 5 normal(-0.0722, 2.284) b timetime_2
#> 6 normal(-0.2405, 2.4897) b timetime_3
#> 8 normal(-0.0817, 0.7979) b timetime_1 sigma
#> 9 normal(-0.1145, 1.813) b timetime_2 sigma
#> 10 normal(0.2249, 1.7786) b timetime_3 sigma
SBC checking rank statistics:
Fixed effect parameter ranks:
ranks_autoregressive |>
filter(grepl("^b_", parameter)) |>
filter(!grepl("^b_sigma", parameter)) |>
plot_ranks()
Log-scale standard deviation parameter ranks:
Correlation parameter ranks:
This scenario is the same as above, but it uses a moving average correlation structure with order 2. Model formula:
#> response ~ 0 + group + time + ma(time = time, gr = patient, q = 2L, cov = FALSE)
#> sigma ~ 0 + time
The prior was randomly generated and used for both simulation and analysis:
setup_prior(moving_average) |>
select(prior, class, coef, dpar) |>
as.data.frame()
#> prior class coef dpar
#> 2 normal(0.0588, 1.1861) b groupgroup_1
#> 3 normal(-0.0615, 1.499) b groupgroup_2
#> 4 normal(0.1373, 2.6953) b timetime_2
#> 5 normal(-0.1413, 0.7938) b timetime_3
#> 6 uniform(0.1, 0.9) ma
#> 8 normal(-0.0599, 0.5911) b timetime_1 sigma
#> 9 normal(0.1035, 1.2067) b timetime_2 sigma
#> 10 normal(-0.0595, 2.4434) b timetime_3 sigma
SBC checking rank statistics:
Fixed effect parameter ranks:
ranks_moving_average |>
filter(grepl("^b_", parameter)) |>
filter(!grepl("^b_sigma", parameter)) |>
plot_ranks()
Log-scale standard deviation parameter ranks:
Correlation parameter ranks:
This scenario is the same as above, but it uses a compound symmetry correlation structure. Model formula:
#> response ~ 0 + group + time + cosy(time = time, gr = patient)
#> sigma ~ 0 + time
The prior was randomly generated and used for both simulation and analysis:
setup_prior(compound_symmetry) |>
select(prior, class, coef, dpar) |>
as.data.frame()
#> prior class coef dpar
#> 2 normal(0.1368, 1.8315) b groupgroup_1
#> 3 normal(0.0452, 1.0818) b groupgroup_2
#> 4 normal(-0.0921, 1.6642) b timetime_2
#> 5 normal(0.1413, 0.9048) b timetime_3
#> 6 uniform(0.1, 0.9) cosy
#> 8 normal(0.2213, 2.2507) b timetime_1 sigma
#> 9 normal(0.1819, 2.738) b timetime_2 sigma
#> 10 normal(-0.0337, 2.0799) b timetime_3 sigma
SBC checking rank statistics:
Fixed effect parameter ranks:
ranks_compound_symmetry |>
filter(grepl("^b_", parameter)) |>
filter(!grepl("^b_sigma", parameter)) |>
plot_ranks()
Log-scale standard deviation parameter ranks:
Correlation parameter ranks:
This scenario is the same as above, but it uses a diagonal correlation structure (independent time points within patients). Model formula:
#> response ~ 0 + group + time
#> sigma ~ group + group:time + time
The prior was randomly generated and used for both simulation and analysis:
setup_prior(diagonal) |>
select(prior, class, coef, dpar) |>
as.data.frame()
#> prior class coef dpar
#> 2 normal(0.2457, 2.9382) b groupgroup_1
#> 3 normal(0.0367, 1.5324) b groupgroup_2
#> 4 normal(-0.084, 1.3021) b timetime_2
#> 5 normal(0.0627, 0.5811) b timetime_3
#> 6 normal(-0.1483, 1.1559) Intercept sigma
#> 8 normal(0.15, 0.9478) b groupgroup_2 sigma
#> 9 normal(0.0142, 0.9991) b groupgroup_2:timetime_2 sigma
#> 10 normal(0.2148, 2.3812) b groupgroup_2:timetime_3 sigma
#> 11 normal(-0.206, 2.2088) b timetime_2 sigma
#> 12 normal(-0.0656, 0.6082) b timetime_3 sigma
SBC checking rank statistics:
Fixed effect parameter ranks:
ranks_diagonal |>
filter(grepl("^b_", parameter)) |>
filter(!grepl("^b_sigma", parameter)) |>
plot_ranks()
Log-scale standard deviation parameter ranks:
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.