1 |
x |
|
p |
|
locfun |
|
loc.val |
|
iter |
|
SCORES |
|
gvar.fun |
|
SEED |
|
... |
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 | ##---- 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 = llocv2, loc.val = NULL,
iter = 100, SCORES = FALSE, gvar.fun = cov.mba, SEED = TRUE,
...)
{
if (SEED)
set.seed(2)
x <- elimna(x)
n <- nrow(x)
m <- ncol(x)
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
vals <- NA
z <- matrix(nrow = n, ncol = p)
bval <- array(NA, c(p, m, iter))
for (it in 1:iter) {
B <- matrix(runif(p * m), nrow = p, ncol = m)
B <- t(ortho(t(B)))
bval[, , it] <- B
for (i in 1:n) z[i, ] <- B %*% as.matrix(x[i, ])
vals[it] <- gvarg(z, var.fun = gvar.fun)
}
iord <- order(vals)
Bop <- 0 - bval[, , iord[iter]]
zval <- NULL
if (SCORES) {
for (i in 1:n) z[i, ] <- Bop %*% as.matrix(x[i, ])
zval <- z
}
list(B = Bop, gen.var = vals[iord[iter]], scores = zval)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.