hbootindex <-
function(groups, strata, B = 199)
{
groups <- as.integer(as.factor(as.integer(groups)))
n <- length(groups)
if (missing(strata)) {
strata <- rep(1, n)
} else {
strata <- as.integer(as.factor(as.integer(strata)))
}
if (length(strata) != length(groups))
stop("lengths must equal")
ni <- seq_len(n)
ns <- length(unique(strata))
nsj <- seq_len(ns)
xyclboot <- function(i) {
if (i==1)
return(sample.int(n, n, replace=FALSE)) ## randomize order
out <- vector("list", ns)
for (j in nsj) {
g <- groups[strata==j]
g0 <- unique(g)
w0 <- table(g)
w <- w0[match(g, names(w0))]
w <- w / sum(w)
vec <- ni[strata == j]
out[[j]] <- if (length(vec) < 2)
vec else sample(vec, length(g), replace = TRUE, prob = w)
}
out <- unlist(out)
sample(out, length(out), replace=FALSE)
}
pbapply::pbsapply(1:(B+1), xyclboot)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.