Skip to contents

[Experimental] Computes correlation coefficients between mcmodule inputs and outputs using tornado analysis (from the mc2d package). Supports multiple correlation methods and captures warnings generated during calculation.

Usage

mcmodule_corr(
  mcmodule,
  output = NULL,
  by_exp = FALSE,
  match_variates = TRUE,
  variates_as_nsv = FALSE,
  print_summary = TRUE,
  progress = FALSE,
  method = c("spearman", "kendall", "pearson"),
  use = "all.obs",
  lim = c(0.025, 0.975)
)

Arguments

mcmodule

(mcmodule object). Module containing simulation results.

output

(character, optional). Output node name. If NULL (default), uses the last node in mcmodule$node_list. If by_exp = TRUE, uses the last output node per expression. Default: NULL.

by_exp

(logical). If TRUE, calculate correlations by expression output; if FALSE, use global output (last node). Default: FALSE.

match_variates

(logical). If TRUE, match input nodes to output variates when data dimensions differ. Default: TRUE.

variates_as_nsv

(logical). If TRUE, combine all variates into one mc object; if FALSE, analyse each variate separately. See mcmodule_to_mc(). Default: FALSE.

print_summary

(logical). If TRUE, print correlation analysis summary. Default: TRUE.

progress

(logical). If TRUE, print progress information while running. Default: FALSE.

method

(character). Correlation coefficient type: "spearman" (default), "kendall", or "pearson". See stats::cor(). Default: "spearman".

use

(character). Method for handling missing values: "all.obs", "complete.obs", or "pairwise.complete.obs". See stats::cor(). Default: "all.obs".

lim

(numeric vector). Quantiles for credible interval computation (reserved for two-dimensional models). Default: c(0.025, 0.975).

Value

A data frame with correlation coefficients and metadata. Columns include:

  • exp: Expression name

  • exp_n: Expression number

  • variate: Variate number

  • output: Output node name

  • input: Input node name

  • value: Correlation coefficient value

  • strength: Qualitative strength of association (Very strong, Strong, Moderate, Weak, None)

  • method: Correlation method used (spearman, kendall, or pearson)

  • use: Method for handling missing values (passed to the correlation function)

  • warnings: Any warnings generated during correlation calculation (if present)

  • Additional columns for global keys (e.g., pathogen, origin)

Examples

mcmodule <- agg_totals(
  mcmodule = imports_mcmodule,
  mc_name = "no_detect_a",
  agg_keys = "pathogen"
)
#> 3 variates per group for no_detect_a
cor_results <- mcmodule_corr(mcmodule)
#> 
#> === Correlation Analysis Summary ===
#> 
#> Analysis Parameters:
#> - Analysis type: Global output
#> - Output node: no_detect_a_agg
#> - Correlation method(s): spearman
#> - Missing value handling: all.obs
#> 
#> Expression Information:
#> - Module: mcmodule
#>   - Expression: imports
#>     - Input nodes: w_prev, test_sensi
#>     - Variates analyzed: 6
#> 
#> Results Summary:
#> - Total correlations calculated: 12
#> - Top 2 most influential inputs (by absolute mean correlation):
#>   1. w_prev: 0.4780
#>   2. test_sensi: -0.0335
#> 
#> Input Correlation Strength Distribution:
#> - Very strong: 2 (16.7%)
#> - Moderate: 1 (8.3%)
#> - Weak: 1 (8.3%)
#> - None: 8 (66.7%)
#> 
#> Inputs by Correlation Strength:
#> - Very strong: w_prev
#> - Moderate: w_prev
#> - Weak: w_prev
#> - None: test_sensi, w_prev

# Use single method
cor_results_spearman <- mcmodule_corr(mcmodule, method = "spearman")
#> 
#> === Correlation Analysis Summary ===
#> 
#> Analysis Parameters:
#> - Analysis type: Global output
#> - Output node: no_detect_a_agg
#> - Correlation method(s): spearman
#> - Missing value handling: all.obs
#> 
#> Expression Information:
#> - Module: mcmodule
#>   - Expression: imports
#>     - Input nodes: w_prev, test_sensi
#>     - Variates analyzed: 6
#> 
#> Results Summary:
#> - Total correlations calculated: 12
#> - Top 2 most influential inputs (by absolute mean correlation):
#>   1. w_prev: 0.4780
#>   2. test_sensi: -0.0335
#> 
#> Input Correlation Strength Distribution:
#> - Very strong: 2 (16.7%)
#> - Moderate: 1 (8.3%)
#> - Weak: 1 (8.3%)
#> - None: 8 (66.7%)
#> 
#> Inputs by Correlation Strength:
#> - Very strong: w_prev
#> - Moderate: w_prev
#> - Weak: w_prev
#> - None: test_sensi, w_prev