ehrapy.plot.variable_correlations

ehrapy.plot.variable_correlations#

ehrapy.plot.variable_correlations(edata, *, layer, var_names=None, method='pearson', agg='mean', correction_method='bonferroni', alpha=0.05, width=600, height=600, cmap='RdBu_r', show_values=True, title=None)[source]#

Plot variable correlations as heatmap.

Computes a correlation matrix (Pearson or Spearman) for the selected variables from the given layer. If the layer contains a time dimension, values are first aggregated per variable across time. Cells are annotated with the correlation coefficient. An asterisk marks statistically significant correlations after correction.

Parameters:
  • edata (EHRData) – Central data object.

  • layer (str) – Layer to extract data from.

  • var_names (Sequence[str] | None, default: None) – List of variable names to compute correlation of. If None, uses all numeric variables.

  • method (Literal['spearman', 'pearson', 'kendall'], default: 'pearson') – Correlation method: “spearman”, “kendall” or “pearson”.

  • agg (Literal['mean', 'last', 'first'], default: 'mean') – How to aggregate time dimension: “mean”, “last” or “first”.

  • correction_method (Literal['bonferroni', 'fdr_bh', 'fdr_tsbh', 'holm', 'none'], default: 'bonferroni') – Multiple testing correction method: * ‘bonferroni’ conservative Bonferroni correction. * ‘fdr_bh’ Benjamini-Hochberg false discovery rate (FDR) control. * ‘fdr_tsbh’ two-stage Benjamini-Hochberg, better calibrated when many variables are truly correlated. * ‘holm’ Holm-Bonferroni correction. * ‘none’ no multiple-testing correction.

  • alpha (float, default: 0.05) – Significance threshold after correction.

  • width (int, default: 600) – Plot width in pixels.

  • height (int, default: 600) – Plot height in pixels.

  • cmap (str, default: 'RdBu_r') – Colormap for the heatmap.

  • show_values (bool, default: True) – If True, display correlation values on cells.

  • title (str | None, default: None) – Set the title of the plot.

Return type:

HeatMap | Overlay

Returns:

holoviews.element.HeatMap (if show_values=False) or holoviews.core.overlay.Overlay (if show_values=True).

Examples

>>> import ehrdata as ed
>>> import ehrapy as ep
>>> edata = ed.dt.ehrdata_blobs(n_variables=10, n_centers=5, n_observations=200, base_timepoints=3)
>>> ep.pl.variable_correlations(
...     edata, layer="tem_data", method="pearson", agg="mean", correction_method="fdr_bh", width=700
... )
../../_images/variable_correlations_heatmap.png