1 |
x |
|
cor |
|
loadings |
|
covlist |
|
scree |
|
SCORES |
|
ALL |
|
pval |
|
cop |
|
ADJ |
|
SEED |
|
pr |
|
STAND |
|
xlab |
|
ylab |
|
... |
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 | ##---- 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, cor = TRUE, loadings = TRUE, covlist = NULL, scree = TRUE,
SCORES = FALSE, ALL = TRUE, pval = NULL, cop = 3, ADJ = FALSE,
SEED = TRUE, pr = TRUE, STAND = TRUE, xlab = "Principal Component",
ylab = "Proportion of Variance", ...)
{
x <- elimna(x)
m <- ncol(x)
if (m > 9) {
if (pr)
print("With more than 9 variables, might want to use ADJ=T")
}
if (!ADJ)
flag <- outpro(x, cop = cop, STAND = STAND)$keep
if (ADJ)
flag <- outproad(x, cop = cop, SEED = SEED, STAND = STAND)$results$keep
remx <- x
temp2 <- princomp(remx)
x <- x[flag, ]
loc <- apply(x, 2, mean)
temp <- princomp(x, cor = cor, scores = TRUE, covlist = covlist)
if (scree) {
z = temp$sdev
pv = z^2
cs = pv/sum(pv)
cm = cumsum(cs)
plot(rep(c(1:ncol(x)), 2), c(cs, cm), type = "n", xlab = xlab,
ylab = ylab)
points(c(1:ncol(x)), cs, pch = "*")
lines(c(1:ncol(x)), cs, lty = 1)
points(c(1:ncol(x)), cm, pch = ".")
lines(c(1:ncol(x)), cm, lty = 2)
}
if (!SCORES)
temp <- summary(temp, loadings = loadings)
if (SCORES) {
if (is.null(pval))
stop("When computing scores, specify pval, number of components")
if (!ALL)
temp <- temp$scores[, 1:pval]
if (ALL) {
temp <- summary(temp, loadings = T)
B <- temp[2]$loadings[1:m, 1:m]
z <- remx
for (i in 1:nrow(z)) z[i, ] <- z[i, ] - loc
temp <- t(B) %*% t(z)
temp <- t(temp)
temp <- temp[, 1:pval]
}
}
temp
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.