Skip to contents

Returns the leading sparse principal component of a dataset using the truncated power method. As in mspca(), the data is passed as a single argument M whose interpretation is set by type: "Sigma" (default) for a covariance/correlation matrix (p x p) or "X" for a raw data matrix (n x p). See mspca() for the raw-data preprocessing controls.

Usage

tpm(
  M,
  k,
  type = c("Sigma", "X"),
  maxIter = 200,
  verbose = TRUE,
  timeLimit = 10,
  center = TRUE,
  scale = FALSE,
  divisor = c("n-1", "n"),
  checkPSD = TRUE,
  symTolerance = 1e-08,
  psdTolerance = 1e-08
)

Arguments

M

A matrix. The data, interpreted according to type: a covariance/ correlation matrix (p x p) when type = "Sigma", or a raw data matrix (n x p) when type = "X".

k

An integer. Target sparsity of the PC.

type

(optional) Either "Sigma" (default; M is a covariance/correlation matrix) or "X" (M is a raw data matrix).

maxIter

(optional) An integer. Maximum number of iterations of the algorithm. Default 200.

verbose

(optional) A Boolean. Controls console output. Default TRUE.

timeLimit

(optional) An integer. Maximum time in seconds. Default 10.

center

(optional, type = "X") A Boolean. Center the columns of M. Default TRUE.

scale

(optional, type = "X") A Boolean. Scale the columns of M to unit variance. Default FALSE.

divisor

(optional, type = "X") Either "n-1" (default) or "n".

checkPSD

(optional, type = "Sigma") A Boolean. Verify M is PSD. Default TRUE.

symTolerance

(optional, type = "Sigma") A float. Symmetry-check tolerance. Default 1e-8.

psdTolerance

(optional, type = "Sigma") A float. PSD-check tolerance. Default 1e-8.

Value

An object of class "tpm" (a list) with fields: x_best (p x 1 matrix containing the sparse PC loading), objective_value, and runtime. With type = "X" it additionally records inputType, center, scale, divisor, nObs, and p.

References

Yuan, X. T., & Zhang, T. (2013). Truncated power method for sparse eigenvalue problems. The Journal of Machine Learning Research, 14(1), 899–925.

Examples

TestMat <- cor(mtcars)
tpm(TestMat, 4)
#> $objective_value
#> [1] 3.570419
#> 
#> $runtime
#> [1] 0.001
#> 
#> $x_best
#>             [,1]
#>  [1,] -0.4994873
#>  [2,]  0.4952721
#>  [3,]  0.5096592
#>  [4,]  0.0000000
#>  [5,]  0.0000000
#>  [6,]  0.4954447
#>  [7,]  0.0000000
#>  [8,]  0.0000000
#>  [9,]  0.0000000
#> [10,]  0.0000000
#> [11,]  0.0000000
#> 
#> $inputType
#> [1] "Sigma"
#> 
#> attr(,"class")
#> [1] "tpm"