smtools                package:GeneTS                R Documentation

_S_o_m_e _T_o_o_l_s _f_o_r _S_y_m_m_e_t_r_i_c _M_a_t_r_i_c_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     'sm2vec' takes a symmetric matrix and puts the lower triagonal
     entries into a vector (cf. 'lower.tri').

     'sm.indexes' gives the corresponding x-y-indexes for each entry in
     the vector produced by 'sm2vec'.

     'vec2sm' reverses the operation by  'sm2vec' and turns the vector
     back in a symmetric matrix. If 'diag=FALSE' the diagonal of the
     resulting matrix will consist of NAs.  If 'order' is supplied then
     the input vector 'vec' will first be rearranged accordingly.

_U_s_a_g_e:

     sm2vec(m, diag = FALSE)
     sm.indexes(m, diag = FALSE)
     vec2sm(vec, diag = FALSE, order = NULL)

_A_r_g_u_m_e_n_t_s:

       m: symmetric matrix

    diag: logical. Should the diagonal be included?

     vec: vector of unique elements from a symmetric matrix

   order: order of the entries in 'vec'

_V_a_l_u_e:

     A vector ('sm2vec'), a two-column matrix with indexes
     ('sm.indexes'), or a symmetric matrix ('vec2sm').

_A_u_t_h_o_r(_s):

     Korbinian Strimmer (<URL:
     http://www.statistik.lmu.de/~strimmer/>).

_S_e_e _A_l_s_o:

     'lower.tri'.

_E_x_a_m_p_l_e_s:

     # load corpcor library
     library("corpcor")

     # covariance matrix
     m.cov <- rbind(
      c(3,1,1,0),
      c(1,3,0,1),
      c(1,0,2,0),
      c(0,1,0,2)
     )
     m.cov

     # convert into vector (including diagonals
     v <- sm2vec(m.cov, diag=TRUE)
     v.idx <- sm.indexes(m.cov, diag=TRUE)
     v
     v.idx

     # put back to symmetric matrix
     vec2sm(v, diag=TRUE)

     # vector not in the original order
     sv <- sort(v)
     sv
     ov <- order(v)
     ov
     vec2sm(sv, diag=TRUE, order=ov)

