
Audit a statistical estimator via Monte Carlo calibration and fuzzing
Source:R/audit-estimator.R
audit_estimator.RdEvaluates parameter recovery (bias, RMSE, empirical vs. model SE ratio, and
confidence-interval coverage with exact Clopper-Pearson bounds accounting
for Monte Carlo error), Type-I error calibration under a null DGP,
non-convergence and singular-fit rates, and optionally Simulation-Based
Calibration (audit_sbc()) and parallel RNG invariance
(check_parallel_rng()).
Usage
audit_estimator(
dgp,
estimator,
true_params = NULL,
n_sim = 200L,
alpha = 0.05,
null_dgp = NULL,
null_params = NULL,
n_sim_null = n_sim,
sbc_prior = NULL,
sbc_dgp = NULL,
sbc_draws = NULL,
sbc_n_sim = 100L,
sbc_bins = 10L,
check_parallel = FALSE,
parallel_runner = NULL,
parallel_cores = c(1L, 2L),
parallel_n_sim = 8L,
seed = 42L,
mc_alpha = 0.01,
bias_tol_mc = 3,
se_ratio_bounds = c(0.85, 1.15),
max_fail_rate = 0.05,
warn_fail_rate = 0.01,
max_singular_rate = 0.1
)Arguments
- dgp
Data-generating function. Either
function()(0 arguments) orfunction(true_params)receivingtrue_params.- estimator
Fitting function
function(data)returning either:A named list with
estimate(required) and optionalse,ci_lower,ci_upper,p_value,converged,singular;A fitted
lm,glm,lmerMod,glmerMod, orhtestobject; orA numeric vector of point estimates.
- true_params
Named numeric vector (or scalar) of ground-truth parameter values matching names returned by
estimator. If unnamed, names are matched positionally to the estimator output.- n_sim
Integer number of Monte Carlo replications (default
200L).- alpha
Nominal significance level for confidence intervals (
1 - alpha) and Type-I error checks (default0.05).- null_dgp
Optional null data-generating function for dedicated Type-I error calibration. If
NULL, any parameters intrue_paramsequal to0are automatically audited for Type-I error.- null_params
Optional character vector of parameter names to evaluate under
null_dgp(defaults to all parameters returned byestimator).- n_sim_null
Integer number of replications for
null_dgp(defaults ton_sim).- sbc_prior
Optional prior sampler for Simulation-Based Calibration (forwarded to
audit_sbc()).- sbc_dgp
Optional likelihood simulator
function(theta)for SBC (defaults todgp).- sbc_draws
Optional posterior draw function
function(data)for SBC.- sbc_n_sim
Integer SBC replications (default
100L).- sbc_bins
Integer SBC histogram bins (default
10L).- check_parallel
Logical; if
TRUE, also runscheck_parallel_rng()to verify parallel RNG invariance. DefaultFALSE.- parallel_runner
Optional custom
function(cores, seed)forcheck_parallel_rng(). IfNULLandcheck_parallel = TRUE, automatically testsdgp+estimatorthroughstatci_parallel_apply().- parallel_cores
Integer vector of core counts to compare (default
c(1L, 2L)).- parallel_n_sim
Number of tasks used in parallel invariance check (default
8L).- seed
Integer RNG seed (default
42L).- mc_alpha
Exact binomial / Monte Carlo failure significance threshold (default
0.01).- bias_tol_mc
Monte Carlo z-score threshold (
|bias| / MCSE_bias) for failing bias recovery (default3.0).- se_ratio_bounds
Numeric length-2 target range for
mean(model_SE) / empirical_SE(defaultc(0.85, 1.15)).- max_fail_rate
Maximum tolerable error/non-convergence rate before
"fail"(default0.05).- warn_fail_rate
Error/non-convergence rate threshold for
"warn"(default0.01).- max_singular_rate
Maximum tolerable singular-fit rate before
"fail"(default0.10).
Value
An S3 object of class "statci_estimator_audit" containing
recovery, type1, convergence, sbc, parallel_rng, settings, and
overall status ("pass", "warn", or "fail").
Examples
res <- audit_estimator(
dgp = function() {
x <- rnorm(80)
data.frame(x = x, y = 0.5 * x + rnorm(80))
},
estimator = function(df) lm(y ~ x, data = df),
true_params = c(x = 0.5),
n_sim = 60L,
seed = 42L
)
res
#> [PASS] statci Estimator Audit (n_sim = 60, valid = 60, fail_rate = 0.0%,
#> singular_rate = 0.0%)
#> Parameter Recovery:
#> [PASS] x: bias = 0.0057 (z = 0.36), RMSE = 0.1214, SE ratio = 0.930, coverage =
#> 93.3%