1 | rdepth(d, x, y, sortx = T)
|
d |
|
x |
|
y |
|
sortx |
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 | ##---- 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 (d, x, y, sortx = T)
{
if (!is.vector(x) || !is.vector(y))
stop("x and y should be vectors")
n <- length(x)
if (n < 2)
stop("you need at least two observations")
xy <- cbind(x, y)
b <- d[1]
a <- d[2]
if (sortx)
xy <- xy[order(xy[, 1], xy[, 2]), ]
res <- xy[, 2] - a * xy[, 1] - b
res[abs(res) < 1e-07] <- 0
posres <- res >= 0
negres <- res <= 0
lplus <- cumsum(posres)
rplus <- lplus[n] - lplus
lmin <- cumsum(negres)
rmin <- lmin[n] - lmin
depth <- pmin(lplus + rmin, rplus + lmin)
min(depth)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.