1 |
x |
|
nboot |
|
grp |
|
est |
|
... |
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 | ##---- 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, nboot = 1000, grp = NA, est = onestep, ...)
{
if (is.matrix(x))
x <- listm(x)
if (!is.list(x))
stop("Data must be stored in list mode or in matrix mode.")
if (!is.na(sum(grp))) {
xx <- list()
for (i in 1:length(grp)) xx[[i]] <- x[[grp[1]]]
x <- xx
}
J <- length(x)
tempn <- 0
vecm <- 0
for (j in 1:J) {
temp <- x[[j]]
temp <- temp[!is.na(temp)]
tempn[j] <- length(temp)
x[[j]] <- temp
vecm[j] <- est(x[[j]], ...)
}
xcen <- list()
flag <- rep(T, J)
for (j in 1:J) {
flag[j] <- F
temp <- mean(vecm[flag])
xcen[[j]] <- x[[j]] - temp
flag[j] <- T
}
icrit <- round((1 - alpha) * nboot)
bvec <- matrix(NA, nrow = J, ncol = nboot)
set.seed(2)
print("Taking bootstrap samples. Please wait.")
for (j in 1:J) {
paste("Working on group ", j)
data <- matrix(sample(xcen[[j]], size = length(x[[j]]) *
nboot, replace = TRUE), nrow = nboot)
bvec[j, ] <- apply(data, 1, est, ...)
}
vvec <- NA
for (j in 1:J) {
vvec[j] <- sum((bvec[j, ] - vecm[j])^2)/(nboot - 1)
}
dis <- NA
for (i in 1:nboot) {
dis[i] <- sum((bvec[, i] - vecm)^2/vvec)
}
tvec <- sum((0 - vecm)^2/vvec)
dis <- sort(dis)
print(tvec)
print(dis[icrit])
print(vecm)
sig <- 1 - sum((tvec >= dis))/nboot
list(p.value = sig)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.