
Compare two or more validated spec_ir study designs side by side
Source: R/compare-specs.R
compare_specs.RdComputes analytical design efficiency metrics for two or more validated
spec_ir objects—including total sample size \(N\), the Kish /
Eldridge-Ashby-Kerry cluster design effect
$$\mathrm{DEFF} = 1 + \left(\bar{n}_j (1 + \mathrm{CV}^2) - 1\right)\mathrm{ICC},$$
effective sample size \(N_{\mathrm{eff}} = N / \mathrm{DEFF}\), level-1
and level-2 variance decomposition, AR(1) autocorrelation, synthesized UI
control counts, pairwise semantic IR diffs against the baseline scenario,
and optional bounded Monte Carlo comparative power estimates.
Usage
compare_specs(
...,
run_power = FALSE,
preview_reps = 20L,
max_preview_n = 2000L,
max_preview_seconds = 5,
seed = NULL
)Arguments
- ...
Two or more validated
spec_irobjects (named or unnamed), or a single list of two or more validatedspec_irobjects.- run_power
Logical; if
TRUE, runs a bounded comparative preview simulation via the pure-R preview simulator for each scenario and appends estimated power, bias, empirical mean SE, and CI coverage columns.- preview_reps
Positive integer number of Monte Carlo replications per scenario when
run_power = TRUE(default20L, capped at500L).- max_preview_n
Positive integer observation budget per replication when
run_power = TRUE(default2000L).- max_preview_seconds
Positive numeric wall-clock budget in seconds per scenario when
run_power = TRUE(default5).- seed
Optional integer random seed override applied to every scenario when
run_power = TRUEso scenarios share a common seed baseline.
Value
An S3 object of class spec_comparison containing:
summary:data.framewith one row per scenario and analytical (plus optional power) comparison metrics.baseline: Character scalar naming the baseline (first) scenario.diffs: Named list ofdiff_spec_ir()objects comparing each non-baseline scenario to the baseline.deltas:data.frameof numeric metric deltas relative to baseline.run_power: Logical indicating whether comparative power was run.specs: Named list of the validatedspec_irobjects compared.
Examples
s_ols <- new_spec_ir(
design_type = "monte_carlo_lm",
hierarchy = list(levels = 1L, n_obs = 400L)
)
s_mlm <- new_spec_ir(
design_type = "multilevel_sim",
hierarchy = list(levels = 2L, n_clusters = 40L, cluster_size = 10L, icc = 0.2)
)
s_unbal <- new_spec_ir(
design_type = "multilevel_sim",
hierarchy = list(
levels = 2L, n_clusters = 40L, cluster_size = 10L,
cluster_size_dist = "normal", cluster_size_sd = 4, icc = 0.2
)
)
cmp <- compare_specs(ols = s_ols, balanced_mlm = s_mlm, unbalanced_mlm = s_unbal)
cmp
#>
#> ── spec_comparison (3 scenarios; baseline = 'ols') ──
#>
#> scenario design_type total_n icc deff n_eff focal_effect
#> ols monte_carlo_lm 400 0.0 1.000 400.00 0.3
#> balanced_mlm multilevel_sim 400 0.2 2.800 142.86 0.3
#> unbalanced_mlm multilevel_sim 401 0.2 3.113 128.81 0.3
#> missingness
#> none
#> none
#> none
#> ── Differences vs. baseline ('ols')
#> • balanced_mlm: 10 IR path diff(s) | delta N_eff = -257.1, delta DEFF = +1.800
#> • unbalanced_mlm: 11 IR path diff(s) | delta N_eff = -271.2, delta DEFF =
#> +2.113
as.data.frame(cmp)[, c("scenario", "total_n", "deff", "n_eff")]
#> scenario total_n deff n_eff
#> 1 ols 400 1.000 400.00
#> 2 balanced_mlm 400 2.800 142.86
#> 3 unbalanced_mlm 401 3.113 128.81