1 |
x |
|
qval |
|
plotit |
|
xlab |
|
ylab |
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 | ##---- 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, qval = pnorm(3), plotit = TRUE, xlab = "VAR 1",
ylab = "VAR 2")
{
x = elimna(x)
x = as.matrix(x)
m = apply(x, 2, mean)
v = cov(x)
dis = mahalanobis(x, m, v)
crit <- sqrt(qchisq(qval, ncol(x)))
vec <- c(1:nrow(x))
dis[is.na(dis)] = 0
dis <- sqrt(dis)
chk <- ifelse(dis > crit, 1, 0)
id <- vec[chk == 1]
keep <- vec[chk == 0]
if (is.matrix(x)) {
if (ncol(x) == 2 && plotit) {
plot(x[, 1], x[, 2], xlab = xlab, ylab = ylab, type = "n")
flag <- rep(T, nrow(x))
flag[id] <- F
points(x[flag, 1], x[flag, 2])
if (sum(!flag) > 0)
points(x[!flag, 1], x[!flag, 2], pch = "*")
}
}
if (!is.matrix(x))
outval <- x[id]
if (is.matrix(x))
outval <- x[id, ]
list(out.val = outval, out.id = id, keep = keep, dis = dis,
crit = crit)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.