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 x.

scale

Logical value indicating whether to scale the columns of x to unit variance.

newX

A numeric matrix to be used in projection. Its structure must be similar to x.

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 stds^2/sum(stds^2).

projections

Projections matrix if newX is provided.

See Also

get.options.pca

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]