These functions merge posterior chains from multiple runs of Hmsc models
into unified Hmsc and coda objects, facilitating further analysis. They
check for missing or incomplete chains, optionally report these issues, and
save the processed results to disk. mod_merge_chains handles regular
models, while mod_merge_chains_cv is designed for cross-validated models.
Usage
mod_merge_chains(
model_dir = NULL,
n_cores = 8L,
strategy = "multisession",
future_max_size = 1000L,
model_info_name = NULL,
print_incomplete = TRUE,
from_json = FALSE,
out_extension = "qs2"
)
mod_merge_chains_cv(
model_dir = NULL,
n_cores = 8L,
strategy = "multisession",
future_max_size = 1000L,
cv_names = c("cv_dist", "cv_large"),
from_json = FALSE,
out_extension = "qs2"
)Arguments
- model_dir
Character. Path to the root directory where the model was fitted. For
mod_merge_chains, subdirectoriesmodel_fittedandmodel_codaare created within this path to store the mergedHmscandcodaobjects, respectively. Formod_merge_chains_cv, merged objects are stored undermodel_fitting_cv/model_fitted.- n_cores
Integer. Number of CPU cores to use for parallel processing. Defaults to 8L.
- strategy
Character. The parallel processing strategy to use. Valid options are "sequential", "multisession" (default), "multicore", and "cluster". See
future::plan()andecokit::set_parallel()for details.- future_max_size
Numeric. Maximum allowed total size (in megabytes) of global variables identified. See
future.globals.maxSizeargument of future::future.options for more details.- model_info_name
Character. Name of the file (without extension) where updated model information is saved. If
NULL, overwrites the existingmodel_info.RDatafile inmodel_dirdirectory. If specified, creates a new.RDatafile with this name inmodel_dirdirectory. Applies only tomod_merge_chains.- print_incomplete
Logical. If
TRUE, prints the names of model variants that failed to merge due to missing or incomplete chains. Defaults toTRUE.- from_json
Logical. Whether to convert loaded models from JSON format before reading. Defaults to
FALSE.- out_extension
Character. File extension (without dot) for output files containing merged
Hmscandcodaobjects. Options areqs2(faster read/write via theqs2package) orRData(standard R format). Defaults toqs2.- cv_names
Character vector. Names of cross-validation strategies to merge, matching those used during model setup. Defaults to
c("cv_dist", "cv_large"). The names should be one ofcv_dist,cv_large, orcv_sac. Applies only tomod_merge_chains_cv.
Value
Both functions return invisible(NULL) and save processed model
information and merged objects to disk in the specified locations.
Details
mod_merge_chainsmerges posterior chains from multiple runs of anHmscmodel fitted without cross-validation. It checks for missing or incomplete chains, aligns posteriors (usingalignPost = TRUE, falling back toFALSEif alignment fails), and saves a mergedHmscobject and acodaobject for MCMC diagnostics. It also records fitting time and memory usage from progress files.mod_merge_chains_cvperforms a similar merging process for cross-validatedHmscmodels, processing each fold of the specifiedcv_namesseparately. It saves mergedHmscobjects per fold but does not generatecodaobjects.