s.pca {ldt} | R Documentation |
Principal Component Analysis
Description
This function performs PCA on the columns of a matrix.
Usage
s.pca(x, center = TRUE, scale = TRUE, newX = NULL)
Arguments
x |
A numeric matrix with variables in the columns. |
center |
Logical value indicating whether to demean the columns of |
scale |
Logical value indicating whether to scale the columns of |
newX |
A numeric matrix to be used in projection.
Its structure must be similar to |
Details
The main purpose of exporting this statistics helper method is to show the inner calculations of the package.
Value
A list with the following items:
removed0Var |
An integer vector showing the zero-based indices of removed columns with zero variances. |
directions |
Directions matrix. |
stds |
An integer vector showing the standard deviation of the principal components. |
stds2Ratio |
Shows |
projections |
Projections matrix if |
See Also
Examples
set.seed(340)
data <- matrix(rnorm(500), nrow = 50, ncol = 10)
# using prcomp function
resR = prcomp(data, center = TRUE, scale. = TRUE)
# using s.pca in this package
res = s.pca(data,TRUE,TRUE,data)
# res$projections and resR$x must be equal
# res$directions and t(resR$rotation) must be equal
# ----- ANOTHER EXAMPLE: PCA where there is a constant variable:
data <- data.frame( x = rnorm(100), y = rnorm(100), z = rep(0, 100))
# using s.pca in this package
res <- s.pca(data)
# using prcomp function
res_invalid <- try(prcomp(data, center = TRUE,
scale. = TRUE))
# Fails, we should remove 'z' first
[Package ldt version 0.5.3 Index]