pca_loocv | R Documentation |
Principal component analysis "leave-one-out" cross-validation
pca_loocv(X, npc.max = ncol(X))
X |
Matrix to be subjected to svd |
npc.max |
The maximum number of principal components to test. Default=ncol(X) |
Matrix of square error values for each element in X
http://stats.stackexchange.com/a/115477/10675
X <- as.matrix(iris[,1:4]) res <- pca_loocv(X) res2 <- lapply(res, colSums) res2 COL <- 2:4 LTY <- 1:3 op <- par(mar=c(4,4,2,1), tcl=-0.25, mgp=c(2.5,0.5,0)) for(i in seq(res)){ if(i==1) { plot(res2[[i]], t="n", ylim=range(unlist(res2)), main="iris", xlab="n PCs", ylab="PRESS") grid() } lines(res2[[i]], t="b", bg=c(NaN,COL[i])[(res2[[i]]==min(res2[[i]])) + 1], col=COL[i], lty=LTY[i], pch=21) } legend("topright", legend=c("naive", "approximate", "pseudoinverse"), col=COL, lty=LTY, pch=21, bty="n") par(op)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.