1 | tbscov(x, eps = 0.001, maxiter = 20, r = 0.45, alpha = 0.05)
|
x |
|
eps |
|
maxiter |
|
r |
|
alpha |
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 | ##---- 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, eps = 0.001, maxiter = 20, r = 0.45, alpha = 0.05)
{
if (!is.matrix(x))
stop("x should be a matrix with two or more columns")
x <- elimna(x)
library(MASS)
temp <- cov.mve(x)
t1 <- temp$center
s <- temp$cov
n <- nrow(x)
p <- ncol(x)
if (p == 1)
stop("x should be a matrix with two or more columns")
c1M <- cgen.bt(n, p, r, alpha, asymp = FALSE)
c1 <- c1M$c1
if (c1 == 0)
c1 <- 0.001
M <- c1M$M
b0 <- erho.bt(p, c1, M)
crit <- 100
iter <- 1
w1d <- rep(1, n)
w2d <- w1d
while ((crit > eps) & (iter <= maxiter)) {
t.old <- t1
s.old <- s
wt.old <- w1d
v.old <- w2d
d2 <- mahalanobis(x, center = t1, cov = s)
d <- sqrt(d2)
k <- ksolve.bt(d, p, c1, M, b0)
d <- d/k
w1d <- wt.bt(d, c1, M)
w2d <- v.bt(d, c1, M)
t1 <- (w1d %*% x)/sum(w1d)
s <- s * 0
for (i in 1:n) {
xc <- as.vector(x[i, ] - t1)
s <- s + as.numeric(w1d[i]) * (xc %o% xc)
}
s <- p * s/sum(w2d)
mnorm <- sqrt(as.vector(t.old) %*% as.vector(t.old))
snorm <- eigen(s.old)$values[1]
crit1 <- max(abs(t1 - t.old))
crit <- max(abs(w1d - wt.old))/max(w1d)
iter <- iter + 1
}
s
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.