ich untersuche im Moment die Funktion PcaGrid.
Vorher habe ich mit der klassischen PCA in R gearbeitet. Jedoch gibt es auch unterbestimmte Matrizen, deren Kovarianzmatrix singulär ist. Nun soll ich diese Funktion untersuchen, welche sich scheinbar einen Gittersuchalgorithmus und S3 und S4 Objekte zunutze macht und auf solche Matrizen anwendbar ist.
Code: Alles auswählen
function (x, k = 0, kmax = ncol(x), scale = FALSE, na.action = na.fail,
crit.pca.distances = 0.975, trace = FALSE, ...)
{
cl <- match.call()
if (missing(x)) {
stop("You have to provide at least some data")
}
data <- as.matrix(x)
n <- nrow(data)
p <- ncol(data)
kmax <- max(min(floor(kmax), rankMM(x)), 1)
if (trace)
cat("k=", k, ", kmax=", kmax, ".\n", sep = "")
if ((k <- floor(k)) < 0)
k <- 0
else if (k > kmax) {
warning(paste("The number of principal components k = ",
k, " is larger then kmax = ", kmax, "; k is set to ",
kmax, ".", sep = ""))
k <- kmax
}
if (k != 0)
k <- min(k, ncol(data))
else {
k <- min(kmax, ncol(data))
if (trace)
cat("The number of principal components is defined by the algorithm. It is set to ",
k, ".\n", sep = "")
}
if (is.logical(scale)) {
scale <- if (scale)
sd
else NULL
}
out <- PCAgrid(x, k, scale = scale, trace = -1, ...)
scores <- predict(out)
center <- out$center
scale <- out$scale
sdev <- out$sdev
scores <- as.matrix(scores[, 1:k])
loadings <- as.matrix(out$loadings[, 1:k])
eigenvalues <- (sdev^2)[1:k]
names(eigenvalues) <- NULL
if (is.list(dimnames(data)))
rownames(scores) <- rownames(data)
dimnames(scores)[[2]] <- paste("PC", seq_len(ncol(scores)),
sep = "")
dimnames(loadings) <- list(colnames(data), paste("PC", seq_len(ncol(loadings)),
sep = ""))
cl[[1]] <- as.name("PcaGrid")
res <- new("PcaGrid", call = cl, loadings = loadings, eigenvalues = eigenvalues,
center = center, scale = scale, scores = scores, k = k,
n.obs = n)
res <- pca.distances(res, x, p, crit.pca.distances)
return(res)
}
Wo wird was berechnet?
Ich sehe kein Vorne und Hinten. Wo genau werden Eigenwerte und -vektoren berechnet?
Was ist der Knackpunkt?
Warum können wir hier jetzt die PCA anwenden? Wodurch legitimiert sich das ganze? Ist das sowas wie eine Approximation?