1 |
x |
|
y |
|
con |
|
alpha |
|
iter |
|
se.fun |
|
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | ##---- 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, y = NA, con = 0, alpha = 0.05, iter = 1000, se.fun = bpmedse,
SEED = TRUE)
{
if (!is.na(y[1])) {
xx <- list()
xx[[1]] <- x
xx[[2]] <- y
if (is.matrix(x) || is.list(x))
stop("When y is speficied, x should not have list mode or be a matrix")
x <- xx
}
if (is.data.frame(x))
x = as.matrix(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 <- vector("numeric", J)
w <- vector("numeric", J)
nval <- vector("numeric", J)
xbar <- vector("numeric", J)
for (j in 1:J) {
xx <- !is.na(x[[j]])
val <- x[[j]]
x[[j]] <- val[xx]
xbar[j] <- median(x[[j]])
nval[j] <- length(x[[j]])
w[j] <- se.fun(x[[j]])^2
}
if (sum(con^2 != 0))
CC <- ncol(con)
if (sum(con^2) == 0) {
CC <- (J^2 - J)/2
psihat <- matrix(0, CC, 5)
dimnames(psihat) <- list(NULL, c("Group", "Group", "psihat",
"ci.lower", "ci.upper"))
test <- matrix(NA, CC, 6)
dimnames(test) <- list(NULL, c("Group", "Group", "test",
"crit", "se", "p.value"))
jcom <- 0
for (j in 1:J) {
for (k in 1:J) {
if (j < k) {
jcom <- jcom + 1
test[jcom, 3] <- abs(xbar[j] - xbar[k])/sqrt(w[j] +
w[k])
temp <- msmedsub(c(nval[j], nval[k]), se.fun = se.fun,
SEED = SEED, iter = iter)
test[jcom, 6] <- sum((test[jcom, 3] <= temp))/iter
sejk <- sqrt(w[j] + w[k])
test[jcom, 5] <- sejk
psihat[jcom, 1] <- j
psihat[jcom, 2] <- k
test[jcom, 1] <- j
test[jcom, 2] <- k
psihat[jcom, 3] <- (xbar[j] - xbar[k])
temp <- msmedsub(nval, se.fun = se.fun, SEED = SEED,
iter = iter)
ic <- round((1 - alpha) * iter)
crit <- temp[ic]
test[jcom, 4] <- crit
psihat[jcom, 4] <- psihat[jcom, 3] - crit *
test[jcom, 5]
psihat[jcom, 5] <- psihat[jcom, 3] + crit *
test[jcom, 5]
}
}
}
}
if (sum(con^2) > 0) {
if (nrow(con) != length(x))
warning("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", "crit",
"se", "p.value"))
temp <- msmedsub(nval, con = con, se.fun = se.fun, SEED = SEED,
iter = iter)
ic <- round((1 - alpha) * iter)
crit <- temp[ic]
for (d in 1:ncol(con)) {
flag <- (con[, d] == 0)
nvec <- nval[!flag]
psihat[d, 1] <- d
psihat[d, 2] <- sum(con[, d] * xbar)
sejk <- sqrt(sum(con[, d]^2 * w))
test[d, 1] <- d
test[d, 2] <- sum(con[, d] * xbar)/sejk
temp <- msmedsub(nvec, iter = iter, se.fun = se.fun,
SEED = SEED)
test[d, 3] <- crit
test[d, 4] <- sejk
test[d, 5] <- sum(abs((test[d, 2]) <= temp))/iter
psihat[d, 3] <- psihat[d, 2] - crit * sejk
psihat[d, 4] <- psihat[d, 2] + crit * sejk
}
}
list(test = test, psihat = psihat)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.