depth2:

Usage Arguments Examples

Usage

1
depth2(x, pts = NA, plotit = TRUE, xlab = "VAR 1", ylab = "VAR 2")

Arguments

x
pts
plotit
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
##---- 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, pts = NA, plotit = TRUE, xlab = "VAR 1", ylab = "VAR 2") 
{
    if (ncol(x) != 2) 
        stop("x must be a matrix with 2 columns")
    x <- elimna(x)
    if (is.na(pts[1])) 
        pts <- x
    if (ncol(pts) != 2) 
        stop("Argument pts must be stored as a matrix with 2 columns")
    pts <- as.matrix(pts)
    ndepth <- NA
    for (i in 1:nrow(pts)) {
        ndepth[i] <- depth(pts[i, 1], pts[i, 2], x)
    }
    if (plotit) {
        m <- x
        plot(m, xlab = xlab, ylab = ylab)
        flag <- (ndepth == max(ndepth))
        if (sum(flag) == 1) 
            center <- m[flag, ]
        if (sum(flag) > 1) 
            center <- apply(m[flag, ], 2, mean)
        points(center[1], center[2], pch = "+")
        temp <- ndepth
        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)]), ])
    }
    ndepth
  }

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