1 | ddcomp(x, steps = 5)
|
x |
|
steps |
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | ##---- 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, steps = 5)
{
p <- dim(x)[2]
par(mfrow = c(2, 2))
center <- apply(x, 2, mean)
cov <- var(x)
md2 <- mahalanobis(x, center, cov)
MD <- sqrt(md2)
md2 <- mahalanobis(x, center, cov)
medd2 <- median(md2)
mns <- center
covs <- cov
for (i in 1:steps) {
md2 <- mahalanobis(x, mns, covs)
medd2 <- median(md2)
mns <- apply(x[md2 <= medd2, ], 2, mean)
covs <- var(x[md2 <= medd2, ])
}
rd2 <- mahalanobis(x, mns, covs)
rd <- sqrt(rd2)
const <- sqrt(qchisq(0.5, p))/median(rd)
RDdgk <- const * rd
plot(MD, RDdgk)
abline(0, 1)
identify(MD, RDdgk)
title("DGK DD Plot")
out <- covmba(x)
center <- out$center
cov <- out$cov
rd2 <- mahalanobis(x, center, cov)
rd <- sqrt(rd2)
const <- sqrt(qchisq(0.5, p))/median(rd)
RDm <- const * rd
plot(MD, RDm)
abline(0, 1)
identify(MD, RDm)
title("MBA DD Plot")
out <- cov.mcd(x)
center <- out$center
cov <- out$cov
rd2 <- mahalanobis(x, center, cov)
rd <- sqrt(rd2)
const <- sqrt(qchisq(0.5, p))/median(rd)
RDf <- const * rd
plot(MD, RDf)
abline(0, 1)
identify(MD, RDf)
title("FMCD DD Plot")
covv <- diag(p)
med <- apply(x, 2, median)
md2 <- mahalanobis(x, center = med, covv)
medd2 <- median(md2)
mns <- apply(x[md2 <= medd2, ], 2, mean)
covs <- var(x[md2 <= medd2, ])
for (i in 1:steps) {
md2 <- mahalanobis(x, mns, covs)
medd2 <- median(md2)
mns <- apply(x[md2 <= medd2, ], 2, mean)
covs <- var(x[md2 <= medd2, ])
}
rd2 <- mahalanobis(x, mns, covs)
rd <- sqrt(rd2)
const <- sqrt(qchisq(0.5, p))/median(rd)
RDmb <- const * rd
plot(MD, RDmb)
abline(0, 1)
identify(MD, RDmb)
title("Med Ball DD Plot")
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.