1 |
x |
|
N1 |
|
N2 |
|
tol |
|
N2p |
|
Nran |
|
Nkeep |
|
SEED |
|
op.pro |
|
SCORES |
|
pval |
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 | ##---- 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, N1 = 3, N2 = 2, tol = 0.001, N2p = 10, Nran = 50,
Nkeep = 10, SEED = TRUE, op.pro = 0.1, SCORES = FALSE, pval = NULL)
{
scores <- NULL
wt.cov <- NULL
x <- elimna(x)
if (SEED)
set.seed(2)
m <- ncol(x)
n <- nrow(x)
bot <- marpca(x, p = 0, N1 = N1, N2 = N2, tol = tol, N2p = N2p,
Nran = Nran, Nkeep = Nkeep, SEED = SEED)
bot <- bot$var.op
mn1 <- m - 1
rat <- 1
it <- 0
ratval <- NULL
if (is.null(pval)) {
ratval <- matrix(nrow = mn1, ncol = 2)
dimnames(ratval) <- list(NULL, c("p", "pro.unex.var"))
ratval[, 1] <- c(1:mn1)
for (it in 1:mn1) {
if (rat > op.pro) {
temp <- marpca(x, p = it, N1 = N1, N2 = N2, tol = tol,
N2p = N2p, Nran = Nran, Nkeep = Nkeep, SEED = SEED)
rat <- temp$var.op/bot
ratval[it, 2] <- rat
}
}
}
if (!is.null(pval)) {
if (pval >= m)
stop("This method assumes pval<ncol(x)")
temp <- marpca(x, p = pval, N1 = N1, N2 = N2, tol = tol,
N2p = N2p, Nran = Nran, Nkeep = Nkeep, SEED = SEED)
wt.cov <- temp$wt.cov
ratval <- temp$var.op/bot
}
if (SCORES) {
if (is.null(pval))
stop("When computing scores, need to specify pval")
temp2 <- marpca(x, ncol(x))
ev <- eigen(temp2$wt.cov)
ord.val <- order(ev$values)
mn1 <- m - pval + 1
Bp <- ev$vectors[, ord.val[mn1:m]]
xmmu <- x
for (j in 1:m) xmmu[, j] <- x[, j] - temp2$wt.mu[j]
scores <- matrix(ncol = pval, nrow = n)
for (i in 1:n) scores[i, ] <- t(Bp) %*% as.matrix(xmmu[i,
])
}
list(B = temp$B, a = temp$a, var.op = temp$var.op, unexplained.pro.var = ratval,
scores = scores, wt.cov = wt.cov)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.