1 |
x |
|
con |
|
alpha |
|
q |
|
mop |
|
nboot |
|
SEED |
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 | ##---- 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 (x, con = 0, alpha = 0.05, q = 0.5, mop = FALSE, nboot = 100,
SEED = TRUE)
{
if (mop && SEED)
set.seed(2)
if (is.list(x)) {
x <- matl(x)
x <- elimna(x)
}
if (is.matrix(x))
x <- listm(x)
if (!is.list(x))
stop("Data must be stored in a matrix or in list mode.")
con <- as.matrix(con)
J <- length(x)
h <- length(x[[1]])
w <- vector("numeric", J)
xbar <- vector("numeric", J)
for (j in 1:J) {
if (!mop)
xbar[j] <- qest(x[[j]], q = q)
if (mop)
xbar[j] <- median(x[[j]])
}
if (sum(con^2) == 0) {
temp <- qdmcp(x, alpha = alpha, q = q, pr = FALSE)
test <- temp$test
psihat <- temp$psihat
num.sig <- temp$num.sig
}
if (sum(con^2) > 0) {
ncon <- ncol(con)
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 (nrow(con) != length(x)) {
stop("The number of groups does not match the number of contrast coefficients.")
}
psihat <- matrix(0, ncol(con), 4)
dimnames(psihat) <- list(NULL, c("con.num", "psihat",
"ci.lower", "ci.upper"))
test <- matrix(0, ncol(con), 5)
dimnames(test) <- list(NULL, c("con.num", "test", "p.value",
"crit.p.value", "se"))
df <- length(x[[1]]) - 1
if (!mop)
w <- covmmed(x, q = q)
if (mop)
w <- bootcov(x, nboot = nboot, pr = FALSE)
for (d in 1:ncol(con)) {
psihat[d, 1] <- d
psihat[d, 2] <- sum(con[, d] * xbar)
cvec <- as.matrix(con[, d])
sejk <- sqrt(t(cvec) %*% w %*% cvec)
test[d, 1] <- d
test[d, 2] <- sum(con[, d] * xbar)/sejk
test[d, 3] <- 2 * (1 - pt(abs(test[d, 2]), df))
test[d, 5] <- sejk
}
temp1 <- test[, 3]
temp2 <- order(0 - temp1)
zvec <- dvec[1:ncon]
test[temp2, 4] <- zvec
psihat[, 3] <- psihat[, 2] - qt(1 - test[, 4]/2, df) *
test[, 5]
psihat[, 4] <- psihat[, 2] + qt(1 - test[, 4]/2, df) *
test[, 5]
num.sig <- sum(test[, 3] <= test[, 4])
}
list(test = test, psihat = psihat, num.sig = num.sig)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.