Orthogonal Partial Least Squares-Discriminant Analysis (OPLS-DA) in R
This is an example showing how to use the R package (ropls) that was developed by Etienne Thévenot.
The R package (ropls) includes a lot of functionalities, but here I am describing how to get the predictive model and the variable importance in projection (VIP) scores of metabolites that are responsible for samples separation.
- To install the required package, start R and enter
source("https://bioconductor.org/biocLite.R")
biocLite("ropls")
- To load the library
library(ropls)
- Reading in the table that have the samples in the rows and the metabolites in the columns. Make sure the first column has the sample names and the second has the group names.
data = read.csv("table.csv", header=T, row.names = 1)
class = data[, 1]
dataMatrix = data[, 2:dim(data)[2]]
- Building the OPLS-DA model and generate basic plots
data.oplsda = opls(dataMatrix, class, predI = 1, orthoI = NA)
- To extract the VIP scores of all metabolites
write.csv(getVipVn(data.oplsda), "VIPscores.csv")