colCors              package:arrayMagic              R Documentation

_C_o_r_r_e_l_a_t_i_o_n _c_o_e_f_f_i_c_i_e_n_t_s _b_e_t_w_e_e_n _t_h_e _c_o_r_r_e_s_p_o_n_d_i_n_g _c_o_l_u_m_n_s (_r_o_w_s)
_o_f _t_w_o _m_a_t_r_i_c_e_s _t_h_a_t _h_a_v_e _t_h_e _s_a_m_e _s_i_z_e.

_D_e_s_c_r_i_p_t_i_o_n:

     Correlation coefficients between the corresponding columns (rows)
     of two matrices that have the same size.

_U_s_a_g_e:

     rowCors(x,y)
     colCors(x,y)

_A_r_g_u_m_e_n_t_s:

       x: Matrix

       y: Matrix, same size as 'x'

_D_e_t_a_i_l_s:

     The implementation is naive.

_V_a_l_u_e:

     A vector with the correlation coefficients for each row
     ('rowWiseSds'), or column  ('rowWiseSds')

_S_e_e _A_l_s_o:

     'colSums'

_E_x_a_m_p_l_e_s:

     x  = matrix(runif(1e6), ncol=100)
     y  = matrix(runif(1e6), ncol=100)

     commands = c(
       "c1 <<- colCors(x,y)",
       "c2 <<- sapply(1:ncol(x), function(i) cor(x[,i], y[,i]))",
       "c3 <<- rowCors(x,y)",
       "c4 <<- sapply(1:nrow(x), function(i) cor(x[i,], y[i,]))")
       
     times = sapply(commands, function(text) system.time(eval(parse(text=text)))[1])
     print(t(times))

     stopifnot(all(abs(c1-c2) < 1e-3))
     stopifnot(all(abs(c3-c4) < 1e-3))

