exVarPlot: Visualize explained variance of PC-1 and PC-2 of a matrix...

Description Usage Arguments Value Examples

View source: R/exVarPlot.R

Description

To be honest, I am not entirely sure how informative this function is. I used it to see how much the explained variance of the PCs varies in the lower tail in order to choose a suitable number of the most variable CpG-probes. This number can be quite arbitrary, and if this number is in a region of the distribution that fluctuates a lot, it may be wiser to reconsider the number of most variable rows. Explained variance is calculated as the ratio of eigenvalues of PC-1 or PC-2 divided by the sum of all eigenvalues as proposed here: https://stats.stackexchange.com/questions/254592/calculating-pca-variance-explained/254598.

Usage

1
exVarPlot(mat, lowerLim, upperLim, stepSize = 10, onlyPC1 = F)

Arguments

mat

A matrix of numeric values, where rows are probes, genes, metabolites, etc. and the columns are samples.

lowerLim

The lower limit of the most variable row entries.

upperLim

The upper limit of the most variable row entries.

stepSize

The step size. By default the step size is 10.

onlyPC1

Only consider PC-1. Is "FALSE" by default.

Value

A plot and a data.frame with the explained variance of PC-1 or PC-1 + PC-2 at each step.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
A <- data.frame(rnorm(1000,0.2,0.01),runif(1000,0.2,0.75),rnorm(1000,0.75,0.05),
                          rnorm(1000,0.2,0.01),runif(1000,0.2,0.6),rnorm(1000,0.6,0.05))

rownames(A) <- paste("cg",sample(10000000:99999999,1000,replace = FALSE), sep ="")
colnames(A) <- rep(paste("Sample_",1:6,sep=""))

A <- as.matrix(A)

exVarPlot(mat=as.matrix(A),
          lowerLim = 10,
          upperLim = 1000)

LionelRohner/LRTools documentation built on Dec. 17, 2021, 1:10 a.m.