1 | concsim(n = 100, p = 2, steps = 5, gam = 0.4, runs = 20)
|
n |
|
p |
|
steps |
|
gam |
|
runs |
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 75 76 | ##---- 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, runs = 20)
{
A <- sqrt(diag(1:p))
mbact <- 0
fmcdct <- 0
mbct <- 0
madct <- 0
dgkct <- 0
for (i in 1:runs) {
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
x <- x %*% A
out <- covmba(x, csteps = steps)
center <- out$center
cov <- out$cov
rd2 <- mahalanobis(x, center, cov)
if (min(rd2[1:val]) > max(rd2[(val + 1):n]))
mbact <- mbact + 1
covs <- var(x)
mns <- apply(x, 2, mean)
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)
if (min(rd2[1:val]) > max(rd2[(val + 1):n]))
dgkct <- dgkct + 1
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)
if (min(rd2[1:val]) > max(rd2[(val + 1):n]))
mbct <- mbct + 1
tem <- apply(x, 2, mad)^2
covv <- diag(tem)
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)
if (min(rd2[1:val]) > max(rd2[(val + 1):n]))
madct <- madct + 1
out <- cov.mcd(x)
center <- out$center
cov <- out$cov
rd2 <- mahalanobis(x, center, cov)
if (min(rd2[1:val]) > max(rd2[(val + 1):n]))
fmcdct <- fmcdct + 1
}
list(mbact = mbact, fmcdct = fmcdct, dgkct = dgkct, mbct = mbct,
madct = madct)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.