R: Correlation Matrix

corrmsrs {maxstat} | R Documentation

## Correlation Matrix

### Description

Correlation matrix of maximally selected rank statistics.

### Usage

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

### Arguments

`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.

### Details

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

### Value

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

### References

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. (2004). Assessment of Optimally Selected Prognostic Factors. Biometrical Journal, 46(3), 364–374.

### Examples

    set.seed(29)

    # matrix of hypothetical prognostic factors

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

    # this function

    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
    }

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

[Package maxstat version 0.7-25 Index]