1 |
x |
|
p |
|
locfun |
|
loc.val |
|
SCORES |
|
gvar.fun |
|
pr |
|
SEED |
|
gcov |
|
SCALE |
|
... |
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 | ##---- 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, p = ncol(x) - 1, locfun = L1medcen, loc.val = NULL,
SCORES = FALSE, gvar.fun = cov.mba, pr = TRUE, SEED = TRUE,
gcov = rmba, SCALE = TRUE, ...)
{
x = as.matrix(x)
x <- elimna(x)
n <- nrow(x)
m <- ncol(x)
xdat = c(n, m, p, as.vector(x))
if (!SCALE) {
if (is.null(loc.val))
info <- locfun(x, ...)$center
if (!is.null(loc.val))
info <- loc.val
for (i in 1:n) x[i, ] <- x[i, ] - info
}
if (SCALE) {
ms = gcov(x)
for (i in 1:n) x[i, ] <- x[i, ] - ms$center
for (j in 1:m) x[, j] <- x[, j]/sqrt(ms$cov[j, j])
}
vals <- NA
z <- matrix(nrow = n, ncol = p)
np = p * m
B = robpca(x, pval = p, plotit = FALSE, pr = pr, SEED = SEED,
scree = FALSE)$P
B = t(B)
Bs = nelderv2(xdat, np, NMpca, START = B)
Bop = matrix(Bs, nrow = p, ncol = m)
Bop = t(ortho(t(Bop)))
z <- matrix(nrow = n, ncol = p)
zval <- NULL
for (i in 1:n) z[i, ] <- Bop %*% as.matrix(x[i, ])
if (SCORES)
zval <- z
val = gvarg(z)
list(B = Bop, gen.sd = sqrt(val), scores = zval)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.