PCATF: PCA Trend Filtering. From: https://github.com/Lei-D/PCATF

Description Usage Arguments Value Examples

View source: R/PCATF.R

Description

PCA Trend Filtering. From: https://github.com/Lei-D/PCATF

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
PCATF(
  X,
  X.svd = NULL,
  solve_directions = TRUE,
  K = NULL,
  lambda = 0.5,
  niter_max = 1000,
  TOL = 1e-08,
  verbose = FALSE
)

Arguments

X

A numerical data matrix (observations x variables).

X.svd

(Optional) The svd decomposition of X. Save time by providing this argument if the svd has already been computed. Default NULL.

solve_directions

Should the principal directions be solved for? These will be needed to display the leverage images for outlying observations.

K

(Optional) The number of trend-filtered PCs to solve for. If not provided, it will be set to the number of regular PCs with variance above the mean, up to 100 PCs.

lambda

The trend filtering parameter; roughly, the filtering intensity. Default is 0.5 . Can be NULL (lets algorithm decide).

niter_max

The number of iterations to use for approximating the PC.

TOL

The maximum 2-norm between iterations to accept as convergence.

verbose

Print statements about convergence?

Value

SVD The trend-filtered SVD decomposition of X (list with u, d, v).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
set.seed(12345)
U = matrix(rnorm(100*3),ncol=3)
U[20:23,1] = U[20:23,1] + 3
U[40:43,2] = U[40:43,2] - 2
U = svd(U)$u
D = diag(c(10,5,1))
V = svd(matrix(rnorm(3*20),nrow=20))$u
X = U %*% D %*% t(V)
out3 = PCATF(X, K=3, lambda=.75)
matplot(out3$u, ty='l')
out3$d
plot(rowSums(out3$u^2), ty='l')

# Orthonormalized
out3_svd = svd(out3$u)
matplot(out3_svd$u, ty='l')
out3_svd$d
plot(rowSums(out3_svd$u^2), ty='l')

muschellij2/clever documentation built on Sept. 26, 2020, 3:54 p.m.