1 |
x |
|
y |
|
alpha |
|
nboot |
|
crit |
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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | ##---- 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, alpha = 0.05, nboot = NA, crit = NA)
{
if (!is.list(x) && !is.matrix(x))
stop("Data must be stored in a matrix or in list mode.")
if (!is.list(y) && !is.matrix(y))
stop("Data must be stored in a matrix or in list mode.")
if (is.list(x)) {
matx <- matrix(0, length(x[[1]]), length(x))
for (j in 1:length(x)) matx[, j] <- x[[j]]
}
if (is.list(y)) {
maty <- matrix(0, length(y[[1]]), length(y))
for (j in 1:length(y)) maty[, j] <- y[[j]]
}
if (is.matrix(x)) {
matx <- x
}
if (is.matrix(y)) {
maty <- y
}
if (ncol(matx) != ncol(maty))
stop("The number of variables for group 1 is not equal to the number for group 2")
if (sum(is.na(matx) >= 1))
matx <- elimna(matx)
if (sum(is.na(maty) >= 1))
maty <- elimna(maty)
J <- ncol(matx)
connum <- ncol(matx)
if (is.na(nboot)) {
if (ncol(matx) <= 4)
nboot <- 2000
if (ncol(matx) > 4)
nboot <- 5000
}
if (ncol(matx) == 2) {
if (alpha == 0.05)
crit <- 0.0125
if (alpha == 0.025)
crit <- 0.006
if (alpha == 0.01)
crit <- 0.0015
}
if (ncol(matx) == 3) {
if (alpha == 0.05)
crit <- 0.007
if (alpha == 0.025)
crit <- 0.003
if (alpha == 0.01)
crit <- 0.001
}
if (ncol(matx) == 4) {
if (alpha == 0.05)
crit <- 0.0055
if (alpha == 0.025)
crit <- 0.002
if (alpha == 0.01)
crit <- 5e-04
}
if (ncol(matx) == 5) {
if (alpha == 0.05)
crit <- 0.0044
if (alpha == 0.025)
crit <- 0.0016
if (alpha == 0.01)
crit <- 5e-04
}
if (ncol(matx) == 6) {
if (alpha == 0.05)
crit <- 0.0038
if (alpha == 0.025)
crit <- 0.0018
if (alpha == 0.01)
crit <- 4e-04
}
if (ncol(matx) == 7) {
if (alpha == 0.05)
crit <- 0.0028
if (alpha == 0.025)
crit <- 0.001
if (alpha == 0.01)
crit <- 2e-04
}
if (ncol(matx) == 8) {
if (alpha == 0.05)
crit <- 0.0026
if (alpha == 0.025)
crit <- 0.001
if (alpha == 0.01)
crit <- 2e-04
}
if (ncol(matx) > 8) {
if (alpha == 0.025)
warning("Can't determine a critical value when alpha=.025 and the number of groups exceeds 8.")
nmin <- min(nrow(matx), nrow(maty))
if (alpha == 0.05) {
if (nmin < 100)
wval <- smmcrit(60, ncol(matx))
if (nmin >= 100)
wval <- smmcrit(300, ncol(matx))
wval <- 0 - wval
crit <- pnorm(wval)
}
if (alpha == 0.01) {
if (nmin < 100)
wval <- smmcrit01(60, ncol(matx))
if (nmin >= 100)
wval <- smmcrit01(300, ncol(matx))
wval <- 0 - wval
crit <- pnorm(wval)
}
}
if (is.na(crit))
warning("Critical values can be determined for alpha=.05, .025 and .01 only")
icl <- ceiling(crit * nboot)
icu <- ceiling((1 - crit) * nboot)
set.seed(2)
print("Taking bootstrap samples. Please wait.")
bootx <- bootdep(matx, tr = 0.2, nboot)
booty <- bootdep(maty, tr = 0.2, nboot)
test <- 1
for (j in 1:connum) {
test[j] <- sum(bootx[, j] < booty[, j])/nboot
if (test[j] > 0.5)
test[j] <- 1 - test[j]
}
output <- matrix(0, connum, 5)
dimnames(output) <- list(NULL, c("variable #", "psihat",
"test", "ci.lower", "ci.upper"))
tmeanx <- apply(matx, 2, mean, trim = 0.2)
tmeany <- apply(maty, 2, mean, trim = 0.2)
psi <- 1
for (ic in 1:connum) {
output[ic, 2] <- tmeanx[ic] - tmeany[ic]
output[ic, 1] <- ic
output[ic, 3] <- test[ic]
temp <- sort(bootx[, ic] - booty[, ic])
print(length(temp))
output[ic, 4] <- temp[icl]
output[ic, 5] <- temp[icu]
}
list(output = output, crit.value = crit)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.