1 |
x |
|
con |
|
est |
|
alpha |
|
nboot |
|
pr |
|
... |
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 | ##---- 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, est = onestep, alpha = 0.05, nboot = 500,
pr = TRUE, ...)
{
if (pr) {
print("Note: confidence intervals are adjusted to control FWE")
print("But p-values are not adjusted to control FWE")
}
if (is.matrix(x))
x <- listm(x)
con <- as.matrix(con)
if (!is.list(x))
stop("Data must be stored in list mode.")
J <- length(x)
Jm <- J - 1
d <- (J^2 - J)/2
if (sum(con^2) == 0) {
con <- matrix(0, J, d)
id <- 0
for (j in 1:Jm) {
jp <- j + 1
for (k in jp:J) {
id <- id + 1
con[j, id] <- 1
con[k, id] <- 0 - 1
}
}
}
if (nrow(con) != length(x))
stop("The number of groups does not match the number of contrast coefficients.")
m1 <- matrix(0, J, nboot)
m2 <- 1
mval <- 1
set.seed(2)
for (j in 1:J) {
mval[j] <- est(x[[j]], ...)
xcen <- x[[j]] - est(x[[j]], ...)
data <- matrix(sample(xcen, size = length(x[[j]]) * nboot,
replace = TRUE), nrow = nboot)
m1[j, ] <- apply(data, 1, est, ...)
m2[j] <- var(m1[j, ])
}
boot <- matrix(0, ncol(con), nboot)
bot <- 1
for (d in 1:ncol(con)) {
top <- apply(m1, 2, trimpartt, con[, d])
consq <- con[, d]^2
bot[d] <- trimpartt(m2, consq)
boot[d, ] <- abs(top)/sqrt(bot[d])
}
testb <- apply(boot, 2, max)
ic <- floor((1 - alpha) * nboot)
testb <- sort(testb)
psihat <- matrix(0, ncol(con), 6)
dimnames(psihat) <- list(NULL, c("con.num", "psihat", "ci.lower",
"ci.upper", "se", "p.value"))
for (d in 1:ncol(con)) {
psihat[d, 1] <- d
psihat[d, 2] <- trimpartt(mval, con[, d])
psihat[d, 3] <- psihat[d, 2] - testb[ic] * sqrt(bot[d])
psihat[d, 4] <- psihat[d, 2] + testb[ic] * sqrt(bot[d])
psihat[d, 5] <- sqrt(bot[d])
pval <- mean((boot[d, ] < abs(psihat[d, 2])/psihat[d,
5]))
psihat[d, 6] <- 1 - pval
}
list(psihat = psihat, crit = testb[ic], con = con)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.