diff options
| author | Chris Sobczak <chris@sobczak.family> | 2026-06-10 20:02:05 -0700 |
|---|---|---|
| committer | Chris Sobczak <chris@sobczak.family> | 2026-06-10 20:02:05 -0700 |
| commit | 9f8518e1ef17fd23b5923bc37a50ccddcbeb299d (patch) | |
| tree | b449e172cf9a7314235d2b0d1a9b97cc209cffcc /R/plot_snr.R | |
| parent | a59013743eff2e2cfce1b77640ddb31d14bf5679 (diff) | |
Add stability_score and signal to noise ratio plot functions
Diffstat (limited to 'R/plot_snr.R')
| -rw-r--r-- | R/plot_snr.R | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/R/plot_snr.R b/R/plot_snr.R new file mode 100644 index 0000000..3fb1f9c --- /dev/null +++ b/R/plot_snr.R @@ -0,0 +1,39 @@ +#' Plot Signal to Noise Ratio +#' +#' Compute the stability scores for each entry and plot it +#' against the estimate correlation coefficients. +#' +#' @param X The data matrix to operate on +#' @param method Required to select a correlation method +#' +#' @return ggplot object +plot_snr <- function( + X, + method = c('rmad', 'pearson', 'spearman', 'kendall') +) { + method <- match.arg(method) + # Compute reference correlation + R <- if(method == 'rmad'){ + rmad(X) + }else{ + cor(X, method = method) + } + + W <- stability_score(X) + + idx <- which(upper.tri(W), arr.ind = TRUE) + w <- W[upper.tri(W)] + r <- R[upper.tri(R)] + + df <- data.frame(r = r, w = w) + + ggplot2::ggplot(data = df, ggplot2::aes(x = r, y = w)) + + ggplot2::geom_point(alpha = 0.5) + + ggplot2::geom_smooth(se = FALSE) + + ggplot2::labs( + title = paste('Weighted vs', method, 'correlation'), + x = paste(method, 'correlation'), + y = 'Weight' + ) + + ggplot2::theme_classic() +} |
