1 |
x |
|
tr |
|
grp |
|
g |
|
dp |
|
nboot |
|
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 | ##---- 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, tr = 0.2, grp = NA, g = NULL, dp = NULL, nboot = 599,
SEED = TRUE)
{
if (!is.null(g)) {
if (is.null(dp))
stop("Specify a value for dp, the column containing the data")
x = fac2list(x[, dp], x[, g])
}
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.")
if (is.na(grp[1]))
grp <- c(1:length(x))
J <- length(grp)
nval = NA
x = lapply(x, elimna)
nval = lapply(x, length)
xbar = lapply(x, mean, tr = tr)
bvec <- array(0, c(J, 2, nboot))
hval <- vector("numeric", J)
if (SEED)
set.seed(2)
print("Taking bootstrap samples. Please wait.")
for (j in 1:J) {
hval[j] <- length(x[[grp[j]]]) - 2 * floor(tr * length(x[[grp[j]]]))
print(paste("Working on group ", grp[j]))
xcen <- x[[grp[j]]] - mean(x[[grp[j]]], tr)
data <- matrix(sample(xcen, size = length(x[[grp[j]]]) *
nboot, replace = TRUE), nrow = nboot)
bvec[j, , ] <- apply(data, 1, trimparts, tr)
}
m1 <- bvec[, 1, ]
m2 <- bvec[, 2, ]
wvec <- 1/m2
uval <- apply(wvec, 2, sum)
blob <- wvec * m1
xtil <- apply(blob, 2, sum)/uval
blob1 <- matrix(0, J, nboot)
for (j in 1:J) blob1[j, ] <- wvec[j, ] * (m1[j, ] - xtil)^2
avec <- apply(blob1, 2, sum)/(length(x) - 1)
blob2 <- (1 - wvec/uval)^2/(hval - 1)
cvec <- apply(blob2, 2, sum)
cvec <- 2 * (length(x) - 2) * cvec/(length(x)^2 - 1)
testb <- avec/(cvec + 1)
ct <- sum(is.na(testb))
if (ct > 0)
print("Some bootstrap estimates of the test statistic could not be computed")
test <- t1way(x, tr = tr, grp = grp)
pval <- sum(test$TEST <= testb)/nboot
e.pow = t1wayv2(x)$Explanatory.Power
list(test = test$TEST, p.value = pval, Explanatory.Power = e.pow,
Effect.Size = sqrt(e.pow))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.