| 1 | 
| x | |
| na.rm | |
| alpha | |
| grp | |
| nboot | |
| plotit | |
| SEED | |
| op | |
| tr | |
| ... | 
| 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 | ##---- 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, na.rm = TRUE, alpha = 0.05, grp = NA, nboot = 500, 
    plotit = TRUE, SEED = TRUE, op = FALSE, tr = 0.2, ...) 
{
    if (is.list(x)) {
        nv <- NA
        for (j in 1:length(x)) nv[j] <- length(x[[j]])
        if (var(nv) != 0) {
            stop("The groups are stored in list mode and appear to have different sample sizes")
        }
        temp <- matrix(NA, ncol = length(x), nrow = nv[1])
        for (j in 1:length(x)) temp[, j] <- x[[j]]
        x <- temp
    }
    J <- ncol(x)
    if (!is.na(grp[1])) {
        J <- length(grp)
        for (j in 1:J) temp[, j] <- x[, grp[j]]
        x <- temp
    }
    if (na.rm) 
        x <- elimna(x)
    bvec <- matrix(0, ncol = J, nrow = nboot)
    hval <- vector("numeric", J)
    if (SEED) 
        set.seed(2)
    if (op) 
        print("Taking bootstrap samples. Please wait.")
    n <- nrow(x)
    wt = apply(x, 2, trimse, ...)
    wt = 1/wt^2
    ut = sum(wt)
    totv <- apply(x, 2, tmean, na.rm = TRUE, ...)
    gv <- rep(sum(wt * totv)/ut, J)
    data <- matrix(sample(n, size = n * nboot, replace = TRUE), 
        nrow = nboot)
    for (ib in 1:nboot) bvec[ib, ] <- apply(x[data[ib, ], ], 
        2, tmean, na.rm = TRUE, ...)
    bplus <- nboot + 1
    m1 <- rbind(bvec, gv)
    center <- totv
    cmat <- var(bvec)
    discen <- mahalanobis(m1, totv, cmat)
    if (op) 
        print("Bootstrap complete; computing significance level")
    if (plotit && ncol(x) == 2) {
        plot(bvec, xlab = "Group 1", ylab = "Group 2")
        temp.dis <- order(discen[1:nboot])
        ic <- round((1 - alpha) * nboot)
        xx <- bvec[temp.dis[1:ic], ]
        xord <- order(xx[, 1])
        xx <- xx[xord, ]
        temp <- chull(xx)
        lines(xx[temp, ])
        lines(xx[c(temp[1], temp[length(temp)]), ])
        abline(0, 1)
    }
    sig.level <- sum(discen[bplus] <= discen)/bplus
    list(p.value = sig.level, center = totv, weighted.grand.mean = gv[1])
  }
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.