Learn R Programming

mdatools (version 0.5.3)

plsda: Partial Least Squares Discriminant Analysis

Description

plsda is used to calibrate, validate and use of partial least squares discrimination analysis (PLS-DA) model.

Usage

plsda(x, c, ncomp = 15, center = T, scale = F, cv = NULL,
    x.test = NULL, c.test = NULL, method = 'simpls', alpha = 0.05, info = '')

Arguments

x
matrix with predictors.
c
vector with class values (either class number or class name as text for each object).
ncomp
maximum number of components to calculate.
center
logical, center or not predictors and response values.
scale
logical, scale (standardize) or not predictors and response values.
cv
number of segments for cross-validation (if cv = 1, full cross-validation will be used).
x.test
matrix with predictors for test set.
c.test
vector with reference class values for test set (same format as calibration values).
method
method for calculating PLS model.
alpha
significance level for calculating statistical limits for residuals.
info
short text with information about the model.

Value

  • Returns an object of plsda class with following fields (most inherited from class pls):
  • ncompnumber of components included to the model.
  • ncomp.selectedselected (optimal) number of components.
  • xloadingsmatrix with loading values for x decomposition.
  • yloadingsmatrix with loading values for y (c) decomposition.
  • weightsmatrix with PLS weights.
  • coeffsmatrix with regression coefficients calculated for each component.
  • infoinformation about the model, provided by user when build the model.
  • calresan object of class plsdares with PLS-DA results for a calibration data.
  • testresan object of class plsdares with PLS-DA results for a test data, if it was provided.
  • cvresan object of class plsdares with PLS-DA results for cross-validation, if this option was chosen.

Details

The plsda class is based on pls with extra functions and plots covering classification functionality. All plots for pls can be used. E.g. of you want to see the real predicted values (y in PLS) instead of classes use plotPredictions.pls(model) instead of plotPredictions(model).

See Also

Specific methods for plsda class: ll{ print.plsda prints information about a pls object. summary.plsda shows performance statistics for the model. plot.plsda shows plot overview of the model. predict.plsda applies PLS-DA model to a new data. }

Methods, inherited from classmodel class: ll{ plotPredictions.classmodel shows plot with predicted values. plotSensitivity.classmodel shows sensitivity plot. plotSpecificity.classmodel shows specificity plot. plotMisclassified.classmodel shows misclassified ratio plot. } See also methods for class pls.

Examples

Run this code
### Examples for PLS-DA model class

library(mdatools)

## 1. Make a PLS-DA model with full cross-validation and show model overview

# make a calibration set from iris data (3 classes)
# use names of classes as class vector
x.cal = iris[seq(1, nrow(iris), 2), 1:4] 
c.cal = iris[seq(1, nrow(iris), 2), 5]

model = plsda(x.cal, c.cal, ncomp = 3, cv = 1, info = 'IRIS data example')
model = selectCompNum(model, 1)

# show summary and basic model plots
# misclassification will be shown only for first class
summary(model)
plot(model)

# summary and model plots for second class
summary(model, nc = 2)
plot(model, nc = 2)

# summary and model plot for specific class and number of components
summary(model, nc = 3, ncomp = 3)
plot(model, nc = 3, ncomp = 3)

## 2. Show performance plots for a model
par(mfrow = c(2, 2))
plotSpecificity(model)
plotSensitivity(model)
plotMisclassified(model)
plotMisclassified(model, nc = 2)
par(mfrow = c(1, 1))

## 3. Show both class and y values predictions
par(mfrow = c(2, 2))
plotPredictions(model)
plotPredictions(model, res = 'calres', ncomp = 2, nc = 2)
plotPredictions.pls(model)
plotPredictions.pls(model, ncomp = 2, ny = 2)
par(mfrow = c(1, 1))

## 4. All plots from ordinary PLS can be used, e.g.:
par(mfrow = c(2, 2))
plotXYScores(model)
plotYVariance(model)
plotXResiduals(model)
plotRegcoeffs(model, ny = 2)
par(mfrow = c(1, 1))

Run the code above in your browser using DataLab