Generates a small number of synthetic datasets using the same internal
data-generator as brms_inla_power(), fits each dataset with both INLA
(as the package does) and brms::brm() (via Stan), and compares the
posterior mean, posterior SD, and 95 % credible-interval bounds for the
primary effect parameter.
This is a qualitative spot-check, not a formal equivalence test. Differences are expected due to the Laplace approximation used by INLA versus full MCMC in Stan, and will vary across models and priors.
validate_inla_vs_brms(
formula,
family = gaussian(),
priors = NULL,
data_generator = NULL,
effect_name,
effect_value = 0.5,
sample_size = 100L,
n_check = 5L,
brms_iter = 2000L,
brms_chains = 4L,
tolerance = NULL,
seed = 42L,
error_sd = 1,
group_sd = 0.5,
obs_per_group = 10,
predictor_means = NULL,
predictor_sds = NULL,
family_args = list(),
inla_num_threads = NULL
)A list with components:
comparisonsData frame with one row per dataset and columns
sim, inla_ok, brms_ok, inla_mean, brms_mean, diff_mean,
inla_sd, brms_sd, inla_ci_lower, inla_ci_upper,
brms_ci_lower, brms_ci_upper.
flagTRUE if any |diff_mean| exceeds tolerance.
max_abs_diffMaximum observed |diff_mean|.
toleranceThe tolerance value actually used.
settingsList of key settings for reproducibility.
Model formula (same as brms_inla_power()).
GLM family object (default gaussian()).
A brms::prior() specification or NULL for defaults.
Supported priors are translated to INLA controls where possible and audited
in the returned settings.
Optional function f(n, effect) returning a
data frame. If NULL, the automatic generator is used.
Character vector of fixed-effect names (same as
brms_inla_power()).
Numeric value (or named vector) of the true effect
size used when generating data for the comparison. Default 0.5.
Integer sample size for each comparison dataset.
Default 100.
Number of independent datasets to compare. Default 5.
Total MCMC iterations per chain passed to
brms::brm(). Default 2000.
Number of MCMC chains. Default 4.
Numeric threshold: the flag is set to TRUE when the
maximum absolute difference in posterior means exceeds tolerance.
If NULL (default), 0.1 * mean(INLA posterior SD) is used.
Integer random seed. Default 42.
Passed to the automatic data generator when data_generator = NULL
(see brms_inla_power() for details).
INLA threading string (e.g. "4:1"). Auto-
detected when NULL.
This function runs n_check full brms/Stan fits. Even with
brms_chains = 2 and brms_iter = 1000, this can take several minutes
for non-trivial models. Use n_check = 3 and brms_chains = 2 for
quick sanity checks.