1 |
x |
|
mve.flag |
|
plotit |
|
SEED |
|
outsym |
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 | ##---- 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, mve.flag = TRUE, plotit = TRUE, SEED = TRUE, outsym = "*")
{
library(MASS)
if (SEED) {
oldSeed <- .Random.seed
set.seed(12)
}
if (!is.matrix(x)) {
x <- x[!is.na(x)]
dis <- mahalanobis(x, median(x), mad(x)^2)
crit <- sqrt(qchisq(0.975, 1))
vec <- c(1:length(x))
}
if (is.matrix(x)) {
x <- elimna(x)
if (mve.flag)
mve <- cov.mve(x)
if (!mve.flag)
mve <- cov.mcd(x)
dis <- mahalanobis(x, mve$center, mve$cov)
crit <- sqrt(qchisq(0.975, ncol(x)))
vec <- c(1:nrow(x))
}
dis <- sqrt(dis)
chk <- ifelse(dis > crit, 1, 0)
id <- vec[chk == 1]
keep <- vec[chk == 0]
x <- as.matrix(x)
if (plotit && ncol(x) == 2) {
plot(x[, 1], x[, 2], xlab = "X", ylab = "Y", type = "n")
flag <- rep(T, nrow(x))
flag[id] <- F
points(x[flag, 1], x[flag, 2])
if (sum(chk) != 0)
points(x[!flag, 1], x[!flag, 2], pch = outsym)
}
if (SEED) {
assign(x = ".Random.seed", value = oldSeed, envir = .GlobalEnv)
}
list(out.id = id, keep.id = keep, dis = dis, crit = crit)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.