Runs ForestSearch under the null hypothesis at multiple sample sizes to calibrate \(L_{\text{eff}}\), then returns a calibration object for predicting corrected FPR.
Usage
run_null_calibration(
sim_null_fn,
fs_args,
d_eff_fn,
N_values = c(200, 500, 1000),
c1 = 1.25,
c2 = 1,
n_sims = 100L,
prop_harm = 0.3,
n_min = 60L,
seed_base = 42L,
verbose = TRUE
)Arguments
- sim_null_fn
Function. Generates one H0 dataset. Signature:
sim_null_fn(n, seed)returning a data.frame suitable forforestsearch().- fs_args
Named list. Arguments passed to
forestsearch()(excludingdf.analysis,hr.threshold,hr.consistency, andseedit, which are set by the wrapper).- d_eff_fn
Function. Computes \(d_{\text{eff}}\) for a subgroup. Signature:
d_eff_fn(n_sg)returning numeric. Example:function(n) d_eff_binary(n, 0.30).- N_values
Integer vector. Sample sizes to simulate. At least 2 required. Default:
c(200, 500, 1000).- c1
Numeric. Screening threshold for calibration. Default: 1.25.
- c2
Numeric. Consistency threshold for calibration. Default: 1.0.
- n_sims
Integer. Simulations per sample size. Default: 100.
- prop_harm
Numeric. Expected proportion in harm subgroup (for computing d_eff). Default: 0.30.
- n_min
Integer. Minimum subgroup size. Default: 60.
- seed_base
Integer. Base seed. Default: 42.
- verbose
Logical. Print progress. Default: TRUE.
Details
For each N in N_values, the function:
Generates
n_simsdatasets viasim_null_fn()Runs
forestsearch()on eachComputes the simulated FPR = proportion with any H found
Computes \(P_1\) via the GLM approximation
Calls
calibrate_L_eff()to fit the power-law model
ForestSearch is run with
parallel_args = list(plan = "sequential") to avoid
nested parallelism. The outer simulation loop is sequential.
For faster execution, wrap in foreach %dofuture%
externally.
Examples
# \donttest{
# Binary DGM under H0
sim_null <- function(n, seed) {
set.seed(seed)
data.frame(
id = seq_len(n),
treat = rbinom(n, 1, 0.5),
bm1 = as.factor(rbinom(n, 1, 0.70)),
bm2 = as.factor(rbinom(n, 1, 0.50)),
age = round(rnorm(n, 55, 10)),
ecog = as.factor(sample(0:1, n, TRUE, c(0.6, 0.4))),
progressed = rbinom(n, 1, 0.30)
)
}
fs_args <- list(
confounders.name = c("bm1", "bm2", "age", "ecog"),
outcome.name = "progressed",
event.name = "progressed",
treat.name = "treat",
id.name = "id",
outcome_type = "binary",
effect_measure = "OR",
adverse_outcome = TRUE,
pconsistency.threshold = 0.90,
fs.splits = 200,
n.min = 60,
maxk = 2,
use_lasso = FALSE,
use_grf = FALSE,
use_twostage = TRUE,
is.RCT = TRUE,
details = FALSE,
plot.sg = FALSE,
parallel_args = list(plan = "sequential",
workers = 1,
show_message = FALSE)
)
# Illustrative size only (the function requires n_sims >= 10 and at least
# two N values); a calibration for use takes n_sims of 50 or more over the
# trial sizes of interest.
cal <- run_null_calibration(
sim_null_fn = sim_null,
fs_args = fs_args,
d_eff_fn = function(n) d_eff_binary(n, 0.30),
N_values = c(200, 500),
n_sims = 10,
verbose = TRUE
)
#> Null calibration: 2 N values x 10 sims = 20 tasks
#> N = 200: FPR = 0.200 (2/10) | P1 = 0.227 | 1.7 sec
#> N = 500: FPR = 0.500 (5/10) | P1 = 0.195 | 2.6 sec
#>
#> L_eff Calibration
#> Model: L_eff = 0.157 * (N / 60)^1.421
#> R-squared: 1.000
#> Calibrated at N = 200, 500
#>
#> Implied L_eff:
#> N = 200: L_eff = 0.87 (fitted: 0.87)
#> N = 500: L_eff = 3.19 (fitted: 3.19)
print(cal)
#> L_eff Calibration
#> Model: L_eff = 0.157 * (N / 60)^1.421
#> R-squared: 1.000
#> Calibrated at N = 200, 500
#>
#> Implied L_eff:
#> N = 200: L_eff = 0.87 (fitted: 0.87)
#> N = 500: L_eff = 3.19 (fitted: 3.19)
# }