Last data update: 2014.03.03

R: NIPALS PCA implemented in R
RnipalsPcaR Documentation

NIPALS PCA implemented in R

Description

PCA by non-linear iterative partial least squares

Usage

RnipalsPca(Matrix, nPcs = 2, varLimit = 1, maxSteps = 5000,
  threshold = 1e-06, verbose = interactive(), ...)

Arguments

Matrix

Pre-processed (centered, scaled) numerical matrix samples in rows and variables as columns.

nPcs

Number of components that should be extracted.

varLimit

Optionally the ratio of variance that should be explained. nPcs is ignored if varLimit < 1

maxSteps

Defines how many iterations can be done before algorithm should abort (happens almost exclusively when there were some wrong in the input data).

threshold

The limit condition for judging if the algorithm has converged or not, specifically if a new iteration is done if (T_{old} - T)^T(T_{old} - T) > code{limit}.

verbose

Show simple progress information.

...

Only used for passing through arguments.

Details

Can be used for computing PCA on a numeric matrix using either the NIPALS algorithm which is an iterative approach for estimating the principal components extracting them one at a time. NIPALS can handle a small amount of missing values. It is not recommended to use this function directely but rather to use the pca() wrapper function. There is a C++ implementation given as nipalsPca which is faster.

Value

A pcaRes object.

Author(s)

Henning Redestig

References

Wold, H. (1966) Estimation of principal components and related models by iterative least squares. In Multivariate Analysis (Ed., P.R. Krishnaiah), Academic Press, NY, 391-420.

See Also

prcomp, princomp, pca

Examples

data(metaboliteData)
mat <- prep(t(metaboliteData))
## c++ version is faster
system.time(pc <- RnipalsPca(mat, method="rnipals", nPcs=2))
system.time(pc <- nipalsPca(mat, nPcs=2))
## better use pca()
pc <- pca(t(metaboliteData), method="rnipals", nPcs=2)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(pcaMethods)
Loading required package: Biobase
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.


Attaching package: 'pcaMethods'

The following object is masked from 'package:stats':

    loadings

> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/pcaMethods/RnipalsPca.Rd_%03d_medium.png", width=480, height=480)
> ### Name: RnipalsPca
> ### Title: NIPALS PCA implemented in R
> ### Aliases: RnipalsPca
> ### Keywords: multivariate
> 
> ### ** Examples
> 
> data(metaboliteData)
> mat <- prep(t(metaboliteData))
> ## c++ version is faster
> system.time(pc <- RnipalsPca(mat, method="rnipals", nPcs=2))
   user  system elapsed 
  0.044   0.000   0.042 
> system.time(pc <- nipalsPca(mat, nPcs=2))
   user  system elapsed 
  0.004   0.000   0.002 
> ## better use pca()
> pc <- pca(t(metaboliteData), method="rnipals", nPcs=2)
> ## Don't show: 
> stopifnot(sum((fitted(pc) - t(metaboliteData))^2, na.rm=TRUE) < 200)
> ## End(Don't show)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>