Learn R Programming

mcmodule (version 1.2.0)

mcmodule_corr: Calculate Correlation Coefficients Between Inputs and Outputs

Description

[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)
)

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)

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).

Examples

Run this code
mcmodule <- agg_totals(
  mcmodule = imports_mcmodule,
  mc_name = "no_detect_a",
  agg_keys = "pathogen"
)
cor_results <- mcmodule_corr(mcmodule)

# Use single method
cor_results_spearman <- mcmodule_corr(mcmodule, method = "spearman")

Run the code above in your browser using DataLab