1 |
m |
|
MM |
|
cop |
|
dop |
|
center |
|
na.rm |
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 47 48 49 50 51 52 53 54 55 56 57 | ##---- 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 (m, MM = FALSE, cop = 3, dop = 1, center = NA, na.rm = TRUE)
{
m <- elimna(m)
m <- as.matrix(m)
if (ncol(m) == 1) {
if (is.na(center[1]))
center <- median(m)
dis <- abs(m[, 1] - center)
if (!MM) {
temp <- idealf(dis)
pdis <- dis/(temp$qu - temp$ql)
}
if (MM)
pdis <- dis/mad(dis)
}
if (ncol(m) > 1) {
if (is.na(center[1])) {
if (cop == 1)
center <- dmean(m, tr = 0.5, dop = dop)
if (cop == 2)
center <- cov.mcd(m)$center
if (cop == 3)
center <- apply(m, 2, median)
if (cop == 4)
center <- cov.mve(m)$center
if (cop == 5)
center <- smean(m)
}
dmat <- matrix(NA, ncol = nrow(m), nrow = nrow(m))
for (i in 1:nrow(m)) {
B <- m[i, ] - center
dis <- NA
BB <- B^2
bot <- sum(BB)
if (bot != 0) {
for (j in 1:nrow(m)) {
A <- m[j, ] - center
temp <- sum(A * B) * B/bot
dis[j] <- sqrt(sum(temp^2))
}
if (!MM) {
temp <- idealf(dis)
dmat[, i] <- dis/(temp$qu - temp$ql)
}
if (MM)
dmat[, i] <- dis/mad(dis)
}
}
pdis <- apply(dmat, 1, max, na.rm = na.rm)
}
pdis
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.