1 | twomanbt(x, y, tr = 0.2, alpha = 0.05, nboot = 599)
|
x |
|
y |
|
tr |
|
alpha |
|
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 73 74 75 76 | ##---- 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, tr = 0.2, alpha = 0.05, nboot = 599)
{
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 one is not equal to the number for group 2")
if (sum(is.na(mat) >= 1))
stop("Missing values are not allowed.")
J <- ncol(mat)
connum <- ncol(matx)
bvec <- matrix(0, connum, nboot)
set.seed(2)
xcen <- matrix(0, nrow(matx), ncol(matx))
ycen <- matrix(0, nrow(maty), ncol(maty))
for (j in 1:connum) xcen[, j] <- matx[, j] - mean(matx[,
j], tr)
for (j in 1:connum) ycen[, j] <- maty[, j] - mean(maty[,
j], tr)
print("Taking bootstrap samples. Please wait.")
bootx <- sample(nrow(matx), size = nrow(matx) * nboot, replace = TRUE)
booty <- sample(nrow(maty), size = nrow(maty) * nboot, replace = TRUE)
matval <- matrix(0, nrow = nboot, ncol = connum)
for (j in 1:connum) {
datax <- matrix(xcen[bootx, j], ncol = nrow(matx))
datay <- matrix(ycen[booty, j], ncol = nrow(maty))
paste("Working on variable", j)
top <- apply(datax, 1, mean, tr) - apply(datay, 1, mean,
tr)
botx <- apply(datax, 1, trimse, tr)
boty <- apply(datay, 1, trimse, tr)
matval[, j] <- abs(top)/sqrt(botx^2 + boty^2)
}
bvec <- apply(matval, 1, max)
icrit <- round((1 - alpha) * nboot)
bvec <- sort(bvec)
crit <- bvec[icrit]
psihat <- matrix(0, ncol = 4, nrow = connum)
dimnames(psihat) <- list(NULL, c("con.num", "psihat", "ci.lower",
"ci.upper"))
test <- matrix(0, ncol = 3, nrow = connum)
dimnames(test) <- list(NULL, c("con.num", "test", "se"))
for (j in 1:ncol(matx)) {
temp <- yuen(matx[, j], maty[, j], tr = tr)
test[j, 1] <- j
test[j, 2] <- abs(temp$test)
test[j, 3] <- temp$se
psihat[j, 1] <- j
psihat[j, 2] <- mean(matx[, j], tr) - mean(maty[, j])
psihat[j, 3] <- mean(matx[, j], tr) - mean(maty[, j]) -
crit * temp$se
psihat[j, 4] <- mean(matx[, j], tr) - mean(maty[, j]) +
crit * temp$se
}
list(psihat = psihat, teststat = test, critical.value = crit)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.