mcp2a:

Usage Arguments Examples

Usage

1
mcp2a(J, K, x, est = mom, con = NULL, alpha = 0.05, nboot = NA, grp = NA, ...)

Arguments

J
K
x
est
con
alpha
nboot
grp
...

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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
##---- 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, est = mom, con = NULL, alpha = 0.05, nboot = NA, 
    grp = NA, ...) 
{
    JK <- J * K
    if (is.matrix(x)) 
        x <- listm(x)
    if (!is.na(grp)) {
        yy <- x
        for (j in 1:length(grp)) x[[j]] <- yy[[grp[j]]]
    }
    if (!is.list(x)) 
        stop("Data must be stored in list mode or a matrix.")
    mvec <- NA
    tempn = 0
    for (j in 1:JK) {
        xx <- x[[j]]
        x[[j]] <- xx[!is.na(xx)]
        mvec[j] <- est(x[[j]], ...)
        tempn[j] = length(x[[j]])
    }
    nmax = max(tempn)
    if (JK != length(x)) 
        warning("The number of groups does not match the number of contrast coefficients.")
    set.seed(2)
    if (is.na(nboot)) {
        nboot <- 5000
        if (J <= 8) 
            nboot <- 4000
        if (J <= 3) 
            nboot <- 2000
    }
    bvec <- matrix(NA, nrow = JK, ncol = nboot)
    for (j in 1:JK) {
        data <- matrix(sample(x[[j]], size = length(x[[j]]) * 
            nboot, replace = TRUE), nrow = nboot)
        bvec[j, ] <- apply(data, 1, est, ...)
    }
    outvec <- list()
    if (!is.null(con)) 
        stop("Use linconm when specifying the linear contrast coefficients")
    temp3 <- con2way(J, K)
    for (jj in 1:3) {
        con <- temp3[[jj]]
        con <- as.matrix(con)
        ncon <- ncol(con)
        if (alpha == 0.05) {
            dvec <- c(0.025, 0.025, 0.0169, 0.0127, 0.0102, 0.00851, 
                0.0073, 0.00639, 0.00568, 0.00511)
            if (ncon > 10) {
                avec <- 0.05/c(11:ncon)
                dvec <- c(dvec, avec)
            }
        }
        if (alpha == 0.01) {
            dvec <- c(0.005, 0.005, 0.00334, 0.00251, 0.00201, 
                0.00167, 0.00143, 0.00126, 0.00112, 0.00101)
            if (ncon > 10) {
                avec <- 0.01/c(11:ncon)
                dvec <- c(dvec, avec)
            }
        }
        if (nmax > 80) {
            if (alpha == 0.05) {
                dvec <- c(0.05, 0.025, 0.0169, 0.0127, 0.0102, 
                  0.00851, 0.0073, 0.00639, 0.00568, 0.00511)
                if (ncon > 10) {
                  avec <- 0.05/c(11:ncon)
                  dvec <- c(dvec, avec)
                }
            }
            if (alpha == 0.01) {
                dvec <- c(0.01, 0.005, 0.00334, 0.00251, 0.00201, 
                  0.00167, 0.00143, 0.00126, 0.00112, 0.00101)
                if (ncon > 10) {
                  avec <- 0.01/c(11:ncon)
                  dvec <- c(dvec, avec)
                }
            }
            if (alpha != 0.05 && alpha != 0.01) {
                dvec <- alpha/c(1:ncon)
            }
        }
        if (alpha != 0.05 && alpha != 0.01) 
            dvec <- alpha/c(1:ncon)
        test <- NA
        bcon <- t(con) %*% bvec
        tvec <- t(con) %*% mvec
        for (d in 1:ncon) {
            test[d] <- sum(bcon[d, ] > 0)/nboot
            if (test[d] > 0.5) 
                test[d] <- 1 - test[d]
        }
        output <- matrix(0, ncon, 6)
        dimnames(output) <- list(NULL, c("con.num", "psihat", 
            "sig.test", "sig.crit", "ci.lower", "ci.upper"))
        temp2 <- order(0 - test)
        zvec <- dvec[1:ncon]
        sigvec <- (test[temp2] >= zvec)
        if (sum(sigvec) < ncon) {
            dd <- ncon - sum(sigvec)
            ddd <- sum(sigvec) + 1
            zvec[ddd:ncon] <- dvec[ddd]
        }
        output[temp2, 4] <- zvec
        icl <- round(dvec[ncon] * nboot) + 1
        icu <- nboot - icl - 1
        for (ic in 1:ncol(con)) {
            output[ic, 2] <- tvec[ic, ]
            output[ic, 1] <- ic
            output[ic, 3] <- test[ic]
            temp <- sort(bcon[ic, ])
            output[ic, 5] <- temp[icl]
            output[ic, 6] <- temp[icu]
        }
        outvec[[jj]] <- output
    }
    list(FactorA = outvec[[1]], FactorB = outvec[[2]], Interactions = outvec[[3]], 
        conA = temp3[[1]], conB = temp3[[2]], conAB = temp3[[3]])
  }

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