corrmsrs               package:maxstat               R Documentation

_C_o_r_r_e_l_a_t_i_o_n _M_a_t_r_i_x

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

     Correlation matrix of maximally selected rank statistics.

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

     corrmsrs(X, minprop=0.1, maxprop=0.9)

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

       X: the vector, matrix or data.frame of prognostic factors under
          test.

 minprop: at least 'minprop'*100% of the observations in the first
          group. 

 maxprop: not more than 'minprop'*100% of the observations in the first
          group. 

_D_e_t_a_i_l_s:

     The correlations between all two-sample rank statistics induced by
     all possible cutpoints in 'X' are computed.

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

     The correlation matrix with dimension depending on ties in 'X' is
     returned.

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

     Torsten Hothorn <Torsten.Hothorn@rzmail.uni-erlangen.de>

_R_e_f_e_r_e_n_c_e_s:

     Hothorn, T. and Lausen, B. (2003). On the Exact Distribution of
     Maximally Selected Rank Statistics.  _Computational Statistics &
     Data Analysis_, *43*,  121-137.

     Lausen, B., Hothorn, T., Bretz, F. and Schmacher, M. (2002).
     Assessment of Optimally Selected Prognostic Factors. _submitted_.
     Preprint available from <URL:
     http://www.mathpreprints.com/math/Preprint/blausen/20021007/1/>

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

     # matrix of hypothetical prognostic factors

     X <- matrix(rnorm(30), ncol=3) 

     # this function

     print(system.time(a <- corrmsrs(X, minprop=0, maxprop=0.999)))

     # coded by just typing the definition of the correlation

     testcorr <- function(X) {
       wh <- function(cut, x)
         which(x <= cut)
       index <- function(x) {
         ux <- unique(x)
         ux <- ux[ux < max(ux)]
         lapply(ux, wh, x = x)
       }
       a <- unlist(test <- apply(X, 2, index), recursive=FALSE)
       cnull <- rep(0, nrow(X))
       mycorr <- diag(length(a))
       for (i in 1:(length(a)-1)) {
         for (j in (i+1):length(a)) {
           cone <- cnull
           cone[a[[i]]] <- 1
           ctwo <- cnull
           ctwo[a[[j]]] <- 1
           sone <- sqrt(sum((cone - mean(cone))^2))
           stwo <- sqrt(sum((ctwo - mean(ctwo))^2))
           tcorr <- sum((cone - mean(cone))*(ctwo - mean(ctwo)))
           tcorr <- tcorr/(sone * stwo)
           mycorr[i,j] <- tcorr
         }
       }
       mycorr
     }

     print(system.time(tc <- testcorr(X)))
     tc <- tc + t(tc)
     diag(tc) <- 1
     stopifnot(all.equal(tc, a))

