View source: R/simulation-studies.R
| runShiftRecoverySimulationStudy | R Documentation |
Repeatedly simulate known-shift datasets from a
createSimulationTemplate() object and analyze
each replicate with searchOptimalConfiguration() to estimate expected shift
recovery performance. The default "original" generator reproduces the
published simulation operations. The "empirical" generator remains
available explicitly for full-covariance draws and an empirically calibrated
integration-rate robustness scenario.
runShiftRecoverySimulationStudy(
template,
n_replicates,
tree_tip_count = NULL,
simulation_options = list(),
search_options = list(),
fuzzy_distance = 2,
weighted = TRUE,
num_cores = 1,
seed = NULL
)
template |
A |
n_replicates |
Integer number of simulation replicates to run. |
tree_tip_count |
Optional integer tip count for random subtree sampling.
If |
simulation_options |
Named list of additional arguments passed to
|
search_options |
Named list of arguments passed to
|
fuzzy_distance |
Integer node distance used for fuzzy matching in
|
weighted |
Logical; if |
num_cores |
Integer number of workers used across replicate analyses.
When greater than one, outer replicate parallelism takes precedence and
each inner search is forced to |
seed |
Optional integer random seed. When supplied, the wrapper restores the caller's previous RNG state before returning. |
By default, the search configuration uses uncertaintyweights_par = TRUE
when weighted = TRUE, so shift-recovery summaries can report both
unweighted and IC-weighted metrics.
Regardless of the global calibration model used to build template, the
downstream search is intentionally restricted to intercept-only formulas.
This keeps the study focused on shift recovery in the simulated response
block rather than re-estimating predictor effects within each replicate. The
simulated trait_data supplied to each search result therefore contains only
the regenerated response variables.
Templates calibrated with covariates are supported; those covariates influence
the fitted means and residual covariance used to generate each response block,
but they are not re-fit within each simulated search replicate.
Failed search replicates are retained in the output, but their inferred-shift
metrics are recorded as NA and excluded from recovery evaluation. Their
error messages and candidate counts remain available for diagnosis, and
completion and failure rates are reported separately. Reproducibility for
replicated studies is controlled by the wrapper-level seed argument. A
supplied seed deterministically creates separate per-replicate simulation
and search streams, so serial and parallel runs use the same replicate-level
random draws. Parallel execution also uses future.seed = TRUE;
per-replicate simulator seeds are intentionally disallowed here.
When num_cores > 1, namespace-level workers receive only their current
replicate and compact shared settings; replicate call records use a literal
template placeholder so the complete calibration template is not serialized
again inside every simulated object.
A list of class bifrost_simulation_study containing the simulated
datasets, raw search results, per-replicate summaries, a study-level
recovery summary, and the output of evaluateShiftRecovery().
simulateShiftedDataset(), evaluateShiftRecovery(),
runFalsePositiveSimulationStudy()
set.seed(1)
tr <- ape::rtree(16)
X <- matrix(rnorm(16 * 2), ncol = 2)
rownames(X) <- tr$tip.label
tmpl <- createSimulationTemplate(tr, X, formula = "trait_data ~ 1", method = "LL")
recovery_study <- runShiftRecoverySimulationStudy(
tmpl,
n_replicates = 1,
tree_tip_count = 14,
simulation_options = list(
num_shifts = 1,
min_shift_tips = 2,
max_shift_tips = 5,
scale_mode = "proportional",
scale_factor_range = c(5, 8),
exclude_range = c(5.5, 6),
buffer = 0
),
search_options = list(
formula = "trait_data ~ 1",
min_descendant_tips = 2,
shift_acceptance_threshold = 5,
num_cores = 1,
IC = "GIC",
method = "LL",
plot = FALSE,
progress = FALSE,
verbose = FALSE,
store_model_fit_history = FALSE
),
weighted = FALSE,
num_cores = 1,
seed = 2
)
recovery_study$per_replicate[
, c("n_true_shifts", "n_inferred_shifts", "status")
]
unlist(recovery_study$evaluation$strict)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.