# sicb2013 / functions.r

 ``` 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56``` ``` #' regularization_by_thresholding #' #' Regularizes a correlation matrix by thresholding #' #' @param cor_matrix A correlation matrix #' #' @param n The number of independent observations that were used to construct #' the #' #' @return The regularized correlation matrix #' #' @references #' Bickel, P. J. & Levina, E. Covariance regularization by thresholding. #' Ann. Statist. 36, 2577–2604 (2008). http://dx.doi.org/10.1214/08-AOS600 #' regularization_by_thresholding <- function ( cor_matrix, n ) { # Regularization by thresholding # Bickel, P. J. & Levina, E. Covariance regularization by thresholding. # Ann. Statist. 36, 2577–2604 (2008). http://dx.doi.org/10.1214/08-AOS600 p <- ncol( cor_matrix ) regularized <- cor_matrix * ( abs(cor_matrix) > sqrt(log(p)/n) ) return( regularized ) } regularization_by_convex_minimization <- function (cor_matrix) { return( luo ) } test_cov_matrix <- function() { # Builds a simple character covariance matrix for simulating data G <- 100 trueCovariance = matrix(0,G,G) trueCovariance[1:10,1:10] = 0.95 trueCovariance[11:80,11:80] = 0.3 trueCovariance[81:100,81:100] = 0.7 diag(trueCovariance) = 1 return( trueCovariance ) } plot_matrix <- function(m, ... ) { nr <- nrow(m) nc <- ncol(m) image(1:nc, 1:nr, t(m[nr:1, ]), axes=F,xlab="", ylab="", ... ) } ```