Last data update: 2014.03.03

R: Run Principal Component Analysis (PCA) using base R svd()...
make_PCs_svdR Documentation

Run Principal Component Analysis (PCA) using base R svd() function.

Description

A simple wrapper around the base R svd() function which returns the top N eigenvectors of a matrix. Use this function to generate covariates for use with the okriging or krigr_cross_validation functions. This wrapper preserves the rownames of the original matrix.

Usage

make_PCs_svd(X, n.top = 2)

Arguments

X

A correlation matrix.

n.top

Number of top principal compenents to return

Value

A matrix of Principal Components of dimension (# of samples) x (n.top). As expected, eigenvectors are ordered by eigenvalue. Rownames are given as sample IDs.

Examples

 ## compute PC's using the  gene expression correlation matrix from vignette
 ## load gene expression values from vignette
 expressionFile <- system.file(package = "OmicKriging",
                     "doc/vignette_data/ig_gene_subset.txt.gz")
 ## compute correlation matrix
 geneCorrelationMatrix <- make_GXM(expressionFile)
 ## find top ten PC's of this matrix using SVD
 topPcs <- make_PCs_svd(geneCorrelationMatrix, n.top=10) 

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(OmicKriging)
Loading required package: doParallel
Loading required package: foreach
Loading required package: iterators
Loading required package: parallel
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/OmicKriging/make_PCs_svd.Rd_%03d_medium.png", width=480, height=480)
> ### Name: make_PCs_svd
> ### Title: Run Principal Component Analysis (PCA) using base R svd()
> ###   function.
> ### Aliases: make_PCs_svd
> ### Keywords: GRM PCA, covariate,
> 
> ### ** Examples
> 
>  ## compute PC's using the  gene expression correlation matrix from vignette
>  ## load gene expression values from vignette
>  expressionFile <- system.file(package = "OmicKriging",
+                      "doc/vignette_data/ig_gene_subset.txt.gz")
>  ## compute correlation matrix
>  geneCorrelationMatrix <- make_GXM(expressionFile)
>  ## find top ten PC's of this matrix using SVD
>  topPcs <- make_PCs_svd(geneCorrelationMatrix, n.top=10) 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>