getPCAObject: An interface to get PCA object from different PCA methods

Description Usage Arguments Details Value Examples

View source: R/getPCAObject.R

Description

This function evaluate a string that represents a call to a given PCA function. The function (string) is mounted in a way that data set can be processed by PCA function.

Usage

1
getPCAObject(x, pcaMethod = "prcomp", pcaParams = NULL)

Arguments

x

Data set as a data frame. Each column is a variable and each row is a sample.

pcaMethod

The name of PCA function.

pcaParams

The list of parameters to be passed to PCA function.

Details

The parameter pcaParams has a particularity. For example, if name1 need to be an integer (for example, 500), just do c(name1=500). If name1 need to be a name of function, do c(name1='func'). And, if name1 need to be a string, do c(name1='"str"')). This is necessary because of the manner that evaluation is done by R.

Value

This function returns a PCA object obteined from the evaluation of the string command.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
  # Example of simple use of getPCAObject
  x = matrix(rnorm(100), 20,5, 
             dimnames=list(NULL, paste('X', 1:5, sep='')))

  pc = getPCAObject(x, pcaMethod="prcomp", 
                    pcaParams=c(scale=TRUE))
  
  
  # Example of using pca function from pcaMethods, 
  #doing calculations with "ppca" and 4 PCs.
  #library(pcaMethods)
  
  x = matrix(rnorm(100), 20,5, 
             dimnames=list(NULL, paste('X', 1:5, sep='')))
  
  library(pcaMethods)
  pc = getPCAObject(x, pcaMethod='pca', 
                    pcaParams=c(method='"ppca"', nPcs=4))

  getLoadingsFromPCA(pc)
  
  getScoresFromPCA(pc)

juscelino-izidoro/supcavs documentation built on Jan. 2, 2022, 7:49 a.m.