1 |
x |
|
alpha |
|
est |
|
grp |
|
nboot |
|
... |
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, alpha = 0.05, est = onestep, grp = NA, nboot = NA,
...)
{
if (!is.list(x) && !is.matrix(x))
stop("Data must be stored in a matrix or in list mode.")
if (is.list(x)) {
mat <- matrix(0, length(x[[1]]), length(x))
for (j in 1:length(x)) mat[, j] <- x[[j]]
}
if (is.matrix(x))
mat <- x
mat <- elimna(mat)
J <- ncol(mat)
Jm <- J - 1
jp <- 0
dif <- matrix(NA, nrow = nrow(mat), ncol = Jm)
for (j in 1:Jm) {
jp <- j + 1
dif[, j] <- mat[, j] - mat[, jp]
}
if (is.na(nboot)) {
nboot <- 5000
if (Jm <= 4)
nboot <- 1000
}
print("Taking bootstrap samples. Please wait.")
data <- matrix(sample(nrow(mat), size = nrow(mat) * nboot,
replace = T), nrow = nboot)
bvec <- matrix(NA, ncol = ncol(dif), nrow = nboot)
for (j in 1:ncol(dif)) {
temp <- dif[, j]
bvec[, j] <- apply(data, 1, rmanogsub, temp, est)
}
testvec <- NA
for (j in 1:Jm) {
testvec[j] <- sum(bvec[, j] > 0)/nboot
if (testvec[j] > 0.5)
testvec[j] <- 1 - testvec[j]
}
critvec <- alpha/c(1:Jm)
test <- 2 * testvec
test.sort <- order(-1 * test)
chk <- sum((test.sort <= critvec))
if (chk > 0)
print("Significant difference found")
output <- matrix(0, Jm, 6)
dimnames(output) <- list(NULL, c("con.num", "psihat", "sig",
"crit.sig", "ci.lower", "ci.upper"))
tmeans <- apply(dif, 2, est, ...)
psi <- 1
output[, 2] <- tmeans
for (ic in 1:Jm) {
output[ic, 1] <- ic
output[ic, 3] <- test[ic]
crit <- critvec[ic]
output[test.sort[ic], 4] <- crit
}
for (ic in 1:Jm) {
icrit <- output[ic, 4]
icl <- round(icrit * nboot/2) + 1
icu <- round((1 - icrit/2) * nboot)
temp <- sort(bvec[, ic])
output[ic, 5] <- temp[icl]
output[ic, 6] <- temp[icu]
}
list(output = output)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.