1 |
x |
|
y |
|
pts |
|
fr |
|
LP |
|
xout |
|
outfun |
|
SEED |
|
... |
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 | ##---- 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, pts, fr = 2, LP = TRUE, xout = FALSE, outfun = outpro,
SEED = TRUE, ...)
{
if (SEED)
set.seed(2)
x = as.matrix(x)
pts = as.matrix(pts)
p = ncol(x)
p1 = p + 1
xx <- elimna(cbind(x, y))
x <- xx[, 1:p]
y <- xx[, p1]
if (xout) {
m <- cbind(x, y)
flag <- outfun(x, plotit = FALSE, ...)$keep
m <- m[flag, ]
x <- m[, 1:p]
y <- m[, p1]
}
x = as.matrix(x)
library(MASS)
m = cov.mve(x)
phat <- NA
m1 = matrix(NA, nrow = nrow(pts), ncol = nrow(pts))
yhat = NULL
for (i in 1:nrow(pts)) {
d <- mahalanobis(x, pts[i, ], m$cov)
flag = sqrt(d) <= fr
w = flag * exp(-1 * d)
yhat[i] = sum(w * y)/sum(w)
}
yhat
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.