1 | ddmv(n = 100, p = 2, steps = 5, gam = 0.4, outtype = 2, est = 1)
|
n |
|
p |
|
steps |
|
gam |
|
outtype |
|
est |
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 | ##---- 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 (n = 100, p = 2, steps = 5, gam = 0.4, outtype = 2,
est = 1)
{
A <- sqrt(diag(1:p))
x <- matrix(rnorm(n * p), ncol = p, nrow = n)
val <- floor(gam * n)
tem <- 10 + 0 * 1:p
x[1:val, ] <- x[1:val, ] + tem
if (outtype == 2)
x <- x %*% A
if (est == 1) {
covs <- var(x)
mns <- apply(x, 2, mean)
}
if (est == 2) {
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, ])
}
if (est == 3) {
tem <- apply(x, 2, mad)^2
covv <- diag(tem)
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, ])
}
MD <- sqrt(mahalanobis(x, mns, covs))
for (i in 1:steps) {
md <- sqrt(mahalanobis(x, mns, covs))
medd <- median(md)
mns <- apply(x[md <= medd, ], 2, mean)
covs <- var(x[md <= medd, ])
rd <- sqrt(mahalanobis(x, mns, covs))
plot(MD, rd)
points(MD[1:val], rd[1:val], pch = 15)
identify(MD, rd)
}
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.