depthg2:

Usage Arguments Examples

Usage

1
depthg2(x, y, alpha = 0.05, nboot = 500, MD = FALSE, plotit = TRUE, op = FALSE, fast = FALSE, SEED = TRUE, xlab = "VAR 1", ylab = "VAR 2")

Arguments

x
y
alpha
nboot
MD
plotit
op
fast
SEED
xlab
ylab

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
104
105
106
107
##---- 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, alpha = 0.05, nboot = 500, MD = FALSE, plotit = TRUE, 
    op = FALSE, fast = FALSE, SEED = TRUE, xlab = "VAR 1", ylab = "VAR 2") 
{
    if (SEED) 
        set.seed(2)
    x = elimna(x)
    y = elimna(y)
    x = as.matrix(x)
    y = as.matrix(y)
    if (is.matrix(x) && is.matrix(y)) {
        nv1 <- nrow(x)
        nv2 <- nrow(y)
        if (ncol(x) != ncol(y)) 
            stop("Number of columns of x is not equal to number for y")
        if (ncol(x) > 2) 
            MD <- T
        if (ncol(x) == 2 && plotit) {
            plot(rbind(x, y), type = "n", xlab = xlab, ylab = ylab)
            points(x, pch = "*")
            points(y, pch = "o")
            temp <- NA
            for (i in 1:nrow(x)) {
                temp[i] <- depth(x[i, 1], x[i, 2], x)
            }
            flag <- (temp >= median(temp))
            xx <- x[flag, ]
            xord <- order(xx[, 1])
            xx <- xx[xord, ]
            temp <- chull(xx)
            xord <- order(xx[, 1])
            xx <- xx[xord, ]
            temp <- chull(xx)
            lines(xx[temp, ])
            lines(xx[c(temp[1], temp[length(temp)]), ])
            temp <- NA
            for (i in 1:nrow(y)) {
                temp[i] <- depth(y[i, 1], y[i, 2], y)
            }
            flag <- (temp >= median(temp))
            xx <- y[flag, ]
            xord <- order(xx[, 1])
            xx <- xx[xord, ]
            temp <- chull(xx)
            flag <- (temp >= median(temp))
            xord <- order(xx[, 1])
            xx <- xx[xord, ]
            temp <- chull(xx)
            lines(xx[temp, ], lty = 2)
            lines(xx[c(temp[1], temp[length(temp)]), ], lty = 2)
        }
        print("Taking bootstrap samples. Please wait.")
        data1 <- matrix(sample(nv1, size = nv1 * nboot, replace = TRUE), 
            nrow = nboot)
        data2 <- matrix(sample(nv2, size = nv2 * nboot, replace = TRUE), 
            nrow = nboot)
        qhatd <- NA
        dhatb <- NA
        for (ib in 1:nboot) {
            if (op) 
                print(paste("Bootstrap sample ", ib, " of ", 
                  nboot, "is complete."))
            if (!fast) 
                temp <- lsqs2(x[data1[ib, ], ], y[data2[ib, ], 
                  ], plotit = FALSE, MD = MD)
            if (fast) 
                temp <- lsqs2.for(x[data1[ib, ], ], y[data2[ib, 
                  ], ], plotit = FALSE, MD = MD)
            qhatd[ib] <- temp[[1]] - temp[[2]]
        }
        temp <- sort(qhatd)
        lv <- round(alpha * nboot/2)
        uv <- nboot - lv
        difci <- c(temp[lv + 1], temp[uv])
    }
    if (!is.matrix(x) && !is.matrix(y)) {
        nv1 <- length(x)
        nv2 <- length(y)
        print("Taking bootstrap samples. Please wait.")
        data1 <- matrix(sample(nv1, size = nv1 * nboot, replace = TRUE), 
            nrow = nboot)
        data2 <- matrix(sample(nv2, size = nv2 * nboot, replace = TRUE), 
            nrow = nboot)
        qhatd <- NA
        dhatb <- NA
        for (ib in 1:nboot) {
            if (!fast) 
                temp <- lsqs2(x[data1[ib, ]], y[data2[ib, ]], 
                  plotit = FALSE, MD = MD)
            if (fast) 
                temp <- lsqs2.for(x[data1[ib, ]], y[data2[ib, 
                  ]], plotit = FALSE, MD = MD)
            qhatd[ib] <- temp[[1]] - temp[[2]]
            dhatb[ib] <- (temp[[1]] + temp[[2]])/2
        }
    }
    temp <- sort(qhatd)
    temp2 <- sort(dhatb)
    lv <- round(alpha * nboot/2)
    uv <- nboot - lv
    difci <- c(temp[lv + 1], temp[uv])
    list(difci = difci)
  }

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