1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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()
}
|