Learn R Programming

LorMe (version 1.1.0)

Dimension_reduction: Dimension_reduction: PCA, PCOA, and NMDS Analysis

Description

Performs dimension reduction analysis using PCA, PCOA, or NMDS.

Usage

Dimension_reduction(inputframe, group, format)

Value

A list containing data frames and other statistics for dimension reduction analysis.

Arguments

inputframe

An OTU/gene/taxa table with all numeric variables and no NA/NAN/inf values.

group

Group information with the sample order the same as in inputframe.

format

The format of analysis: 1 for PCA, 2 for PCOA, 3 for NMDS.

Author

Wang Ningqi 2434066068@qq.com

Examples

Run this code
### Data preparation ###
data(testotu)
rownames(testotu) <- testotu[, 1]
inputotu <- testotu[, -c(1, ncol(testotu))]
head(inputotu)

groupinformation1 <- data.frame(
  group = c(rep("a", 10), rep("b", 10)),
  factor1 = rnorm(10),
  factor2 = rnorm(mean = 100, 10)
)

### PCA ###
PCAresult <- Dimension_reduction(inputotu, groupinformation1, 1)
PCAframe <- PCAresult$outframe   # Extract data for visualization
head(PCAresult$data.pca$rotation,5)  # OTU coordinates

### PCOA ###
PCOAresult <- Dimension_reduction(inputotu, groupinformation1, 2)
PCOAframe <- PCOAresult$outframe  # Extract data for visualization
head(PCOAresult$PCOA$values,2)  # Explanation of first two axis

### NMDS ###
NMDSresult <- Dimension_reduction(inputotu, groupinformation1, 3)
NMDSframe <- NMDSresult$outframe  # Extract data for visualization
# Here we got a warning of `stress is (nearly) zero: you may have insufficient data`,
# so make sure you have sufficient data for NMDS
print(NMDSresult$NMDSstat$stress)  # Extract stress of NMDS

Run the code above in your browser using DataLab