getPC() uses irlba's partial SVD. When ncomp is at least half of the smaller dimension of X, where irlba can be inaccurate, or when the smaller dimension is at most 100, it uses a full SVD of a dense copy of X instead. On such small matrices irlba may not converge, and its result then depends on its random start; the full SVD does not.

getPC(X, ncomp, center = TRUE, scale = FALSE, sparse = FALSE)

Arguments

X

Matrix.

ncomp

Integer.

center

Logic.

scale

Logic.

sparse

Use sparse matrix or not.

Value

A list containing

scores

Score matrix for X.

loadings

Laoding matrix for X.

sdev

Standard deviations of the principal components.

totVar

Total variance of X after the requested centring and scaling.

props

Proportion of totVar explained by each component.

accuProps

Cumulative sum of props.

ncomp

Number of components.

Xmeans

Column means used for centring, or NULL.

Xscals

Column standard deviations used for scaling, or NULL.

Examples

set.seed(1)
X <- matrix(rnorm(100 * 10), 100, 10)
pc <- getPC(X, ncomp = 3)
dim(pc$scores)
pc$props