1 |
x |
|
y |
|
xout |
|
outfun |
|
... |
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 | ##---- 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, xout = FALSE, outfun = out, ...)
{
if (is.matrix(x)) {
if (ncol(x) >= 2)
stop("Only a single predicor is allowed")
x <- as.vector(x)
}
xy = cbind(x, y)
xy = elimna(xy)
if (xout) {
flag <- outfun(xy[, 1], plotit = FALSE, ...)$keep
xy <- xy[flag, ]
}
x = xy[, 1]
y = xy[, 2]
ord <- order(x)
xs <- x[ord]
ys <- y[ord]
vec1 <- outer(ys, ys, "-")
vec2 <- outer(xs, xs, "-")
v1 <- vec1[vec2 > 0]
v2 <- vec2[vec2 > 0]
slope <- v1/v2
vec3 <- outer(ys, ys, "+")
vec4 <- outer(xs, xs, "+")
v3 <- vec3[vec2 > 0]
v4 <- vec4[vec2 > 0]
deep <- NA
inter <- v3/2 - slope * v4/2
temp <- matrix(c(inter, slope), ncol = 2)
deep <- apply(temp, 1, rdepth, x, y)
best <- max(deep)
coef <- NA
coef[2] <- mean(slope[deep == best])
coef[1] <- mean(inter[deep == best])
res <- y - coef[2] * x - coef[1]
list(coef = coef, residuals = res)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.