lsqs2:

Usage Arguments Examples

Usage

1
lsqs2(x, y, MD = FALSE, tr = 0.05, plotit = TRUE)

Arguments

x
y
MD
tr
plotit

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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
##---- 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, MD = FALSE, tr = 0.05, plotit = TRUE) 
{
    if (is.list(x)) 
        x <- matl(x)
    if (is.list(y)) 
        y <- matl(y)
    disyx <- NA
    disxy <- NA
    if (!is.matrix(x) && !is.matrix(y)) {
        x <- x[!is.na(x)]
        y <- y[!is.na(y)]
        tempxx <- NA
        for (i in 1:length(x)) {
            tempxx[i] <- sum(x[i] <= x)/length(x)
            if (tempxx[i] > 0.5) 
                tempxx[i] <- 1 - tempxx[i]
        }
        for (i in 1:length(x)) {
            temp <- sum(x[i] <= y)/length(y)
            if (temp > 0.5) 
                temp <- 1 - temp
            disxy[i] <- mean(temp > tempxx)
        }
        tempyy <- NA
        for (i in 1:length(y)) {
            tempyy[i] <- sum(y[i] <= y)/length(y)
            if (tempyy[i] > 0.5) 
                tempyy[i] <- 1 - tempyy[i]
        }
        for (i in 1:length(y)) {
            temp <- sum(y[i] <= x)/length(x)
            if (temp > 0.5) 
                temp <- 1 - temp
            disyx[i] <- mean(temp > tempyy)
        }
        qhatxy <- mean(disyx)
        qhatyx <- mean(disxy)
        qhat <- (qhatxy + qhatyx)/2
    }
    if (is.matrix(x) && is.matrix(x)) {
        if (!MD) {
            if (ncol(x) != 2 || ncol(y) != 2) {
                tempyy <- fdepth(y)
                temp <- fdepth(y, x)
                for (i in 1:nrow(x)) {
                  disxy[i] <- mean(temp[i] > tempyy)
                }
                tempxx <- NA
                tempxx <- fdepth(x)
                temp <- fdepth(x, pts = y)
                for (i in 1:nrow(y)) {
                  disyx[i] <- mean(temp[i] > tempxx)
                }
            }
            if (ncol(x) == 2 && ncol(y) == 2) {
                if (plotit) {
                  plot(rbind(x, y), type = "n", xlab = "Var 1", 
                    ylab = "VAR 2")
                  points(x)
                  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)
                }
                tempyy <- NA
                for (i in 1:nrow(y)) tempyy[i] <- depth(y[i, 
                  1], y[i, 2], y)
                for (i in 1:nrow(x)) {
                  temp <- depth(x[i, 1], x[i, 2], y)
                  disxy[i] <- mean(temp > tempyy)
                }
                tempxx <- NA
                for (i in 1:nrow(x)) tempxx[i] <- depth(x[i, 
                  1], x[i, 2], x)
                for (i in 1:nrow(y)) {
                  temp <- depth(y[i, 1], y[i, 2], x)
                  disyx[i] <- mean(temp > tempxx)
                }
            }
        }
        if (MD) {
            mx <- apply(x, 2, median)
            my <- apply(y, 2, median)
            vx <- apply(x, 2, winval, tr = tr) - apply(x, 2, 
                mean, trim = tr) + mx
            vx <- var(vx)
            vy <- apply(y, 2, winval, tr = tr) - apply(y, 2, 
                mean, trim = tr) + my
            vy <- var(vy)
            tempxx <- 1/(1 + mahalanobis(x, mx, vx))
            tempyx <- 1/(1 + mahalanobis(y, mx, vx))
            for (i in 1:nrow(y)) {
                disyx[i] <- mean(tempyx[i] > tempxx)
            }
            tempyy <- 1/(1 + mahalanobis(y, my, vy))
            tempxy <- 1/(1 + mahalanobis(x, my, vy))
            for (i in 1:nrow(x)) {
                disxy[i] <- mean(tempxy[i] > tempyy)
            }
        }
        qhatxy <- sum(disxy)
        qhatyx <- sum(disyx)
        qhat <- (qhatxy + qhatyx)/(length(disxy) + length(disyx))
    }
    qhatyx <- mean(disyx)
    qhatxy <- mean(disxy)
    list(qhatxy, qhatyx, qhat)
  }

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