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",
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",
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_Fitted
andModel_Coda
are created within this path to store the mergedHmsc
andcoda
objects, 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.- model_info_name
Character. Name of the file (without extension) where updated model information is saved. If
NULL
, overwrites the existingModel_Info.RData
file inmodel_dir
directory. If specified, creates a new.RData
file with this name inmodel_dir
directory. 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
Hmsc
andcoda
objects. Options areqs2
(faster read/write via theqs2
package) 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_chains
merges posterior chains from multiple runs of anHmsc
model fitted without cross-validation. It checks for missing or incomplete chains, aligns posteriors (usingalignPost = TRUE
, falling back toFALSE
if alignment fails), and saves a mergedHmsc
object and acoda
object for MCMC diagnostics. It also records fitting time and memory usage from progress files.mod_merge_chains_CV
performs a similar merging process for cross-validatedHmsc
models, processing each fold of the specifiedCV_names
separately. It saves mergedHmsc
objects per fold but does not generatecoda
objects.