opregpbMC:

Usage Arguments Examples

Usage

1
opregpbMC(x, y, nboot = 1000, alpha = 0.05, om = TRUE, ADJ = TRUE, cop = 3, nullvec = rep(0, ncol(x) + 1), plotit = TRUE, opdis = 2, gval = sqrt(qchisq(0.95, ncol(x) + 1)))

Arguments

x
y
nboot
alpha
om
ADJ
cop
nullvec
plotit
opdis
gval

Examples

  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
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
##---- 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, nboot = 1000, alpha = 0.05, om = TRUE, ADJ = TRUE, 
    cop = 3, nullvec = rep(0, ncol(x) + 1), plotit = TRUE, opdis = 2, 
    gval = sqrt(qchisq(0.95, ncol(x) + 1))) 
{
    library(parallel)
    x <- as.matrix(x)
    m <- cbind(x, y)
    p1 <- ncol(x) + 1
    m <- elimna(m)
    x <- m[, 1:ncol(x)]
    x <- as.matrix(x)
    y <- m[, p1]
    if (nrow(x) != length(y)) 
        stop("Sample size of x differs from sample size of y")
    if (!is.matrix(x)) 
        stop("Data should be stored in a matrix")
    print("Taking bootstrap samples. Please wait.")
    data <- matrix(sample(length(y), size = length(y) * nboot, 
        replace = TRUE), nrow = nboot)
    bvec <- apply(data, 1, regboot, x, y, regfun = opregMC)
    bvec <- t(bvec)
    dvec <- alpha/(c(1:ncol(x)))
    test <- NA
    icl0 <- round(alpha * nboot/2)
    icl <- round(alpha * nboot/(2 * ncol(x)))
    icu0 <- nboot - icl0
    icu <- nboot - icl
    output <- matrix(0, p1, 6)
    dimnames(output) <- list(NULL, c("Param.", "sig.test", "sig.crit", 
        "ci.lower", "ci.upper", "s.e."))
    pval <- NA
    for (i in 1:p1) {
        output[i, 1] <- i - 1
        se.val <- var(bvec[, i])
        temp <- sort(bvec[, i])
        output[i, 6] <- sqrt(se.val)
        if (i == 1) {
            output[i, 4] <- temp[icl0 + 1]
            output[i, 5] <- temp[icu0]
        }
        if (i > 1) {
            output[i, 4] <- temp[icl + 1]
            output[i, 5] <- temp[icu]
        }
        pval[i] <- sum((temp > nullvec[i]))/length(temp)
        if (pval[i] > 0.5) 
            pval[i] <- 1 - pval[i]
    }
    fac <- 2
    if (ADJ) {
        nval <- length(y)
        if (nval < 20) 
            nval <- 20
        if (nval > 60) 
            nval <- 60
        fac <- 2 - (60 - nval)/40
    }
    pval[1] <- 2 * pval[1]
    pval[2:p1] <- fac * pval[2:p1]
    output[, 2] <- pval
    temp2 <- order(0 - pval[2:p1])
    zvec <- dvec[1:ncol(x)]
    sigvec <- (test[temp2] >= zvec)
    output[temp2 + 1, 3] <- zvec
    output[1, 3] <- NA
    output[, 2] <- pval
    om.pval <- NA
    temp <- opregMC(x, y)$coef
    if (om && ncol(x) > 1) {
        temp2 <- rbind(bvec[, 2:p1], nullvec[2:p1])
        if (opdis == 1) 
            dis <- pdisMC(temp2, pr = FALSE, center = temp[2:p1])
        if (opdis == 2) {
            cmat <- var(bvec[, 2:p1] - apply(bvec[, 2:p1], 2, 
                mean) + temp[2:p1])
            dis <- mahalanobis(temp2, temp[2:p1], cmat)
        }
        om.pval <- sum((dis[nboot + 1] <= dis[1:nboot]))/nboot
    }
    nval <- length(y)
    if (nval < 20) 
        nval <- 20
    if (nval > 60) 
        nval <- 60
    adj.pval <- om.pval/2 + (om.pval - om.pval/2) * (nval - 20)/40
    if (ncol(x) == 2 && plotit) {
        plot(bvec[, 2], bvec[, 3], xlab = "Slope 1", ylab = "Slope 2")
        temp.dis <- order(dis[1:nboot])
        ic <- round((1 - alpha) * nboot)
        xx <- bvec[temp.dis[1:ic], 2:3]
        xord <- order(xx[, 1])
        xx <- xx[xord, ]
        temp <- chull(xx)
        lines(xx[temp, ])
        lines(xx[c(temp[1], temp[length(temp)]), ])
    }
    list(output = output, om.pval = om.pval, adj.om.pval = adj.pval)
  }

musto101/wilcox_R documentation built on May 23, 2019, 10:52 a.m.