Description Usage Arguments Value Examples
inputs:
1 | project_pca(Xnew = NULL, pc = NULL)
|
Xnew: |
new data matrix to project. |
pc: |
prcomp object used for projection generated by prcomp. Must have the same number of columns as X. |
Xpc: a matrix that corresponds to the projection of X in the PCA space. Xpc[,1] is the first PC, Xpc[,2] the second PC, etc.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | set.seed(1)
data(iris)
#randomly select 100 data points from the iris data set
#to perform PCA
ix=rep(FALSE,nrow(iris))
ix[sample(nrow(iris),100)]=TRUE
# perform PCA
pc=stats::prcomp(iris[ix,1:4])
# plot the PCA
plot_pca(pc,col=iris$Species[ix])
# project the remaining 50 data points (given by !ix) in the existing PCA space
Xpc=project_pca(iris[!ix,1:4],pc)
#plot the new data points in the existing plot
points(Xpc[,1],Xpc[,2])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.