/compPLS

An R package for Partial Least Squares analysis and plotting for (high dimensional) compositional data

Primary LanguageR

compPLS

An R package for [sparse] Partial least squares discriminant analysis and biplots for compositional data analysis.

This package is the implementation for the method developed in Lee et al. (2014) [1] for the classification of independently-sampled microbial compositions based on Helminth-infection status of a people in Malaysia. Under an assumption of model sparsity (that is, relatively few microbial populations truly correlate with Helminth-status) we get a factor analysis as well as a classifier.

Currently, this package consists of functions for compositionally-robust data transformations that you can apply prior to (sparse) partial least squares discriminant analysis: here, just wrappers to key functions from the caret package [2]. As described in the paper, I've added parameter selection via cross-validation and bootstrap-based p-value calculation to assess PLS model coefficients (for feature selection). This package also includes some methods for ggplot2-based biplots for PLS-DA output, and for a few other commonly used projection/ordination/classification methods. This code was forked from vqv's biplot package [3].

This package is still under development and I am currently adding features, based on some new and exciting microbiome data being generated by the good people at the Loke lab [4] and collaborators. Installation and example instructions will be added soon.

Installation

This development package requires the devtools package for installation. Additionally, compPLS depends on the caret and MASS packages. Suggested packages are boot, (for bootstrapping) ggplot2, grid and scales (for biplots).

 library(devtools)
 install_github('zdk123/compPLS')

Usage

Some minimal examples for running 1) PLS 2) sparse PLS and biplots for the results.

 # a too low-dim example, for code demo purposes only
 data(ArcticLake)
 # clr transform the data along row margin (1)
 ALake.clr <- clr(ArcticLake[,1:3], 1)
 res <- plsDA(ALake.clr, grouping=ArcticLake[,4], K=2)
 ggbiplot(res, grouping=ArcticLake[,4], group.ellipse=TRUE, label.loadings=TRUE, label.offset=.2, alpha=.6)
 # alternative biplot
 biplot(res)
 
 ## a higher dim example
 set.seed(1100)
 data(Hydrochem)
 Hchem.clr <- clr(Hydrochem[,6:19], 1)
 # try without bootstrapping
 res <- plsDA_main(Hchem.clr, grouping=Hydrochem$River, K=8:10, nboots=0) #, n.core=4) # if on multicore system
 ggbiplot(res$plsda, grouping=Hydrochem$River, group.ellipse=TRUE, alpha=.5, plot.loadings=FALSE, label.loadings=TRUE)
 optK <- res$plsda$ncomp
 
 # do bootstrapping, warning: this can take a long time 
  res <- plsDA_main(Hchem.clr, grouping=Hydrochem$River, K=optK, nboots=999) #, n.core=4) # if on multicore system

[1] http://www.plosntds.org/article/info%3Adoi%2F10.1371%2Fjournal.pntd.0002880

[2] http://topepo.github.io/caret/index.html

[3] https://github.com/vqv/ggbiplot

[4] http://microbiology-parasitology.med.nyu.edu/png-loke