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))

