bwpca: Determine principal components of a matrix using...

Description Usage Arguments Value Examples

View source: R/functions.R

Description

Implements a weighted PCA

Usage

1
2
3
bwpca(mat, matw = NULL, npcs = 2, nstarts = 1, smooth = 0,
  em.tol = 1e-06, em.maxiter = 25, seed = 1, center = TRUE,
  n.shuffles = 0)

Arguments

mat

matrix of variables (columns) and observations (rows)

matw

corresponding weights

npcs

number of principal components to extract

nstarts

number of random starts to use

smooth

smoothing span

em.tol

desired EM algorithm tolerance

em.maxiter

maximum number of EM iterations

seed

random seed

center

whether mat should be centered (weighted centering)

n.shuffles

optional number of per-observation randomizations that should be performed in addition to the main calculations to determine the lambda1 (PC1 eigenvalue) magnitude under such randomizations (returned in $randvar)

Value

a list containing eigenvector matrix ($rotation), projections ($scores), variance (weighted) explained by each component ($var), total (weighted) variance of the dataset ($totalvar)

Examples

1
2
3
4
5
6
set.seed(0)
mat <- matrix( c(rnorm(5*10,mean=0,sd=1), rnorm(5*10,mean=5,sd=1)), 10, 10)  # random matrix
base.pca <- bwpca(mat)  # non-weighted pca, equal weights set automatically
matw <- matrix( c(rnorm(5*10,mean=0,sd=1), rnorm(5*10,mean=5,sd=1)), 10, 10)  # random weight matrix
matw <- abs(matw)/max(matw)
base.pca.weighted <- bwpca(mat, matw)  # weighted pca

scde documentation built on Nov. 8, 2020, 6:19 p.m.