Skip to contents

Compares true synergies with estimated synergies by computing and visualizing the correlation matrix between them. This extends the existing plot_synergy_correlation() function to compare true vs estimated synergies rather than comparing between clusters.

Usage

plot_synergy_correlation_comparison(
  W_true,
  W_est,
  z_true,
  z_est,
  cluster_id = NULL,
  method = "pearson",
  theme_base_size = 12
)

Arguments

W_true

List of true basis matrices (e.g., sim$Lambda_list). Each matrix should be M x r.

W_est

List of estimated basis matrices (e.g., from fitted model). Each matrix should be M x r.

z_true

Vector of true cluster assignments (length N).

z_est

Vector of estimated cluster assignments (length N).

cluster_id

Integer specifying which cluster to analyze. If NULL, analyzes all clusters separately. Default is NULL.

method

Correlation method: "pearson", "kendall", or "spearman". Default is "pearson".

theme_base_size

Base font size for the plot theme. Default is 12.

Value

A ggplot object showing correlation heatmap(s) between true and estimated synergies.

Details

This function computes the correlation between true synergy patterns (from simulation data) and estimated synergy patterns (from fitted models). For each cluster, it creates a correlation matrix where:

  • Rows represent true synergies (components)

  • Columns represent estimated synergies (components)

  • Cell values show correlation between true component i and estimated component j

Perfect recovery produces a diagonal matrix with high correlations (close to 1) on the diagonal and low correlations off-diagonal. This indicates that each estimated component correctly matches its corresponding true component.

Common failure patterns:

  • Permuted components: High correlations off-diagonal (alignment failure)

  • Low correlations everywhere: Poor decomposition quality

  • Mixed patterns: Some components recovered, others not

Examples

if (FALSE) { # \dontrun{
# Simulate data
sim <- simulate_dynamic_synergy_data(N=30, K=3, r=3, M=8, T_each=200)

# Fit Two-step baseline
fit <- fit_two_step_baseline(
  sim$list_of_data, r=3, K=3, method="PCA",
  z_true=sim$z_true, align_basis=TRUE
)

# Compare true and estimated synergies
plot_synergy_correlation_comparison(
  sim$Lambda_list, fit$W_list,
  sim$z_true, fit$z_est
)

# Analyze specific cluster
plot_synergy_correlation_comparison(
  sim$Lambda_list, fit$W_list,
  sim$z_true, fit$z_est,
  cluster_id = 1
)
} # }