ranki:

Usage Arguments Examples

Usage

1
ranki(J, K, x, grp = c(1:p), alpha = 0.05, p = J * K)

Arguments

J
K
x
grp
alpha
p

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (J, K, x, grp = c(1:p), alpha = 0.05, p = J * K) 
{
    if (!is.list(x)) 
        stop("Data are not stored in list mode")
    if (p != length(x)) {
        print("Warning: The number of groups in your data is not equal to JK")
    }
    jtk <- J * K
    tl <- 0
    com <- x[[1]]
    for (i in 1:jtk) tl <- tl + length(x[[i]])
    for (i in 2:jtk) com <- c(com, x[[i]])
    tiex <- sum(abs(c(1:tl) - sort(rank(com))))
    if (tiex > 0) 
        print("Tied values detected. Interchanging columns might give different results. That is, comparing rows based on P(X<Y) is not necessarily the same as comparing rows based on P(X>Y)")
    ck <- (K^2 - K)/2
    cj <- (J^2 - J)/2
    tc <- ck * cj
    if (tc > 28) {
        print("Warning: The number of contrasts exceeds 28.")
        print("The critical value being used is based on 28 contrasts")
        tc <- 28
    }
    idmat <- matrix(NA, nrow = tc, ncol = 8)
    dimnames(idmat) <- list(NULL, c("row", "row", "col", "col", 
        "ci.lower", "ci.upper", "estimate", "test.stat"))
    crit <- smmcrit(300, tc)
    if (alpha != 0.05) {
        crit <- smmcrit01(300, tc)
        if (alpha != 0.01) {
            print("Warning: Only alpha = .05 and .01 are allowed,")
            print("alpha = .01 is being assumed.")
        }
    }
    phatsqse <- 0
    phat <- 0
    allit <- 0
    jcount <- 0 - K
    it <- 0
    for (j in 1:J) {
        for (jj in 1:J) {
            if (j < jj) {
                for (k in 1:K) {
                  for (kk in 1:K) {
                    if (k < kk) {
                      it <- it + 1
                      idmat[it, 1:4] <- c(j, jj, k, kk)
                    }
                  }
                }
            }
        }
        jcount <- jcount + K
        for (k in 1:K) {
            for (kk in 1:K) {
                if (k < kk) {
                  allit <- allit + 1
                  xx <- x[[grp[k + jcount]]]
                  yy <- x[[grp[kk + jcount]]]
                  temp <- rankisub(xx, yy)
                  phat[allit] <- temp$phat
                  phatsqse[allit] <- temp$sqse
                }
            }
        }
    }
    con <- matrix(0, cj, J)
    id <- 0
    Jm <- J - 1
    for (j in 1:Jm) {
        jp <- j + 1
        for (k in jp:J) {
            id <- id + 1
            con[id, j] <- 1
            con[id, k] <- 0 - 1
        }
    }
    IK <- diag(ck)
    B <- kron(con, IK)
    ntest <- ck * (J^2 - J)/2
    test <- 0
    civecl <- 0
    civecu <- 0
    for (itest in 1:ntest) {
        temp1 <- sum(B[itest, ] * phat)
        idmat[itest, 7] <- temp1
        idmat[itest, 8] <- temp1/sqrt(sum(B[itest, ]^2 * phatsqse))
        idmat[itest, 5] <- temp1 - crit * sqrt(sum(B[itest, ]^2 * 
            phatsqse))
        idmat[itest, 6] <- temp1 + crit * sqrt(sum(B[itest, ]^2 * 
            phatsqse))
    }
    nsig <- sum((abs(idmat[, 8]) > crit))
    list(phat = phat, ci = idmat, crit = crit, nsig = nsig)
  }

musto101/wilcox_R documentation built on May 23, 2019, 10:52 a.m.