Exports optimized symptom combinations to a human-readable JSON file. This enables sharing of derived combinations across research groups without needing to share raw data, supporting reproducible derivation-validation workflows.
Usage
write_combinations(
combinations,
file,
n_required = 4,
clusters = NULL,
n_symptoms = NULL,
score_by = NULL,
description = ""
)Arguments
- combinations
A list of integer vectors specifying symptom combinations, or the full result object from
optimize_combinations/optimize_combinations_clusters(which contains$best_symptoms).- file
Character string. Path to the output JSON file.
- n_required
Integer specifying how many symptoms must be present for a positive diagnosis (default: 4). This value is stored in the file so that
read_combinationscan retrieve it.- clusters
NULL(default) for non-hierarchical combinations, or a named list of integer vectors defining the cluster structure for hierarchical combinations. Stored in the file for use withapply_symptom_combinations.- n_symptoms
Integer or
NULL. Number of symptoms per combination. IfNULL(default), inferred from the length of the first combination.- score_by
Character or
NULL. The scoring criterion used during optimization ("false_cases"or"newly_nondiagnosed"). Stored as metadata for reproducibility. IfNULL(default), omitted from the file.- description
Character string. Optional free-text description of the derivation context (e.g., sample characteristics, dataset name). Default is an empty string.
Value
The file path (invisibly), following the convention of
write.csv.
Details
The JSON file contains the combinations alongside metadata needed to apply
them via apply_symptom_combinations: the required symptom
threshold (n_required) and optional cluster structure
(clusters). Additional fields (score_by, n_symptoms,
description) provide context for reproducibility.
The combinations argument can be either:
A list of integer vectors (e.g., from
results$best_symptoms)The full result object from
optimize_combinationsoroptimize_combinations_clusters(the function automatically extracts$best_symptoms)
See also
read_combinations to import combinations from a JSON file.
optimize_combinations and
optimize_combinations_clusters for deriving optimal
combinations.
apply_symptom_combinations for applying imported combinations
to new data.
Examples
# Create example combinations
my_combos <- list(
c(1, 6, 8, 10, 15, 19),
c(2, 7, 9, 11, 16, 20)
)
# Write to a temporary file
tmp <- tempfile(fileext = ".json")
write_combinations(my_combos, tmp, n_required = 4,
score_by = "false_cases",
description = "Example non-hierarchical combinations")
#> Combinations written to /tmp/RtmpGlFb3Z/file1ca2f124738.json
# Can also pass a full optimization result directly:
# write_combinations(optimization_result, tmp, n_required = 4)
# Clean up
unlink(tmp)
