The Sediment dataset
The Sediment dataset is composed by 1884 sediment samples. Samples were divided into 2 classes on the basis of their toxicity (class 1: non toxic, class 2: toxic) and described by 9 chemical variables. The dataset was randomly divided in two sets, one training set (1413 samples) and one test set (471 samples). The dataset has been published in the following papers:
M. Alvarez-Guerra, D. Ballabio, J. M. Amigo, J. R. Viguri, R. Bro, A chemometric approach to the environmental problem of predicting toxicity in contaminated sediments, Journal of Chemometrics (2010), 24, 379-386
M. Alvarez-Guerra, D. Ballabio, J. M. Amigo, R. Bro, J. R. Viguri, Development of models for predicting toxicity from sediment chemistry by partial least squares-discriminant analysis and counter-propagation artificial neural networks, Environmental Pollution (2010), 158, 607-614
A detailed description on the analysis of this dataset by means of PLSDA is given in the following paper:
Ballabio D, Consonni V, (2013) Classification tools in chemistry. Part 1: Linear models. PLS-DA. Analytical Methods, 5, 3790-3798
In the following paragraphs, a resume of the PLSDA model built by means of the Classification toolbox for MATLAB is given. The Sediment dataset is provided together with the toolbox. It can be opened by typing:
load sediment
on the MATLAB command window. Note that original data were log transformed.
[-> top]
Working with the graphical interface
Once data have been loaded in the MATLAB workspace, you can open the graphical interface by typing the following code in the MATLAB command window:
class_gui
In order to build a classification model by means of PLSDA, we have to load data and class vector in the GUI. In order to do that, we can proceed in the following way: select "load data" in the file menu. We can select the Xtrain_log MATLAB variable (the data) and click load. The listbox of the toolbox main form will be updated with the data details (number of samples, number of variables).
Then we can follow the same procedure for loading the corresponding class vector, by clicking "load class" in the file menu. Note that the class labels can be loaded as numerical vector (class_train) or as strings cell array (class_train_string). The class details (number of classes) will be updated in the toolbox main form. Finally, we can load the sample and variable labels (samples_train and variables, by clicking "load labels" in the file menu).
We can have a look to the variable means by choosing "view->plot profiles". This will open a new window where the profiles of the variable averages (on the raw and scaled data) are shown. Since the class vector is loaded, averages are calculated on each class separately.
We can now proceed in the calculation of the PLSDA classification model. By clicking the "calculate->Partial Least Squares DA" we can choose the settings for cross validating the model and selecting the optimal number of components. The form for settings PLSDA options will appear. Here you can select the data preprocessing (no row and column pre-processing in this example), the type of assignation criterion (bayes) and the type of validation (cross validation with venetian blinds with 5 cv groups). Then, click the "optimal LV" button. The cross validation procedure for selecting the optimal components for PLSDA will produce a plot of the number of components retained in the model versus the error rate (and the ratio of not assigned samples, if any). Here we can choose 2 components.
We can now calibrate the PLSDA model by selecting again "calculate->Partial Least Squares DA". The corresponding setting form will appear. Here you can select the number of latent variables to be retained in the model (2 in this example), no row scalig, no column scaling, type of assignation criterion (bayes), and type of validation (venetian blinds with 5 cv groups). Then, click "calculate".
After the model calculation (and validation), the main form of the toolbox will be updated with the model details (type of calculated model, error rate in fitting and cross validation). In this example, the error rate of the PLSDA model is equal to 0.19 (19%) in fitting and to 0.20 in cross validation. Detailed classification results can be analysed by clicking "results->classification measures". The following form will appear.
All classification measures are shown in this form, both for calibration and validation results. Considering specificity and sensitivity, non toxic (class 1) and toxic (class 2) were partially separated. Class measures can be exported in a matrix by clicking the "view class measures" button, while the confusion matrix can be seen by clicking "view confusion matrix".
The overlap between classes is confirmed from the ROC curves of the classes. The ROC curve plots can be opened with the "results->PLSDA results->ROC curve" button.
Then, we can have a look to the PLSDA scores, by choosing "results->PLSDA results->scores". A form will appear. In this form, results related to samples can be plotted. Samples are coloured on the basis of their experimental class. The user can modify the components to be analysed on the plots, while other statistics are available in the result form, such as Q residuals, T2 Hotelling, leverages, y calculated/predicted classes. All plots can be exported as MATLAB figures. In the following plot, the score plot between the first two latent variables is shown. By selecting a reference class from the menu "class potential", one can highlight the class potential, which is defined on the basis of the distribution of the class samples in the visualised plot, as shown in the following figure for the first two latent variables of the PLSDA mode for the red class (toxic samples).



[-> top]
Working with the command line
Type:
load sediment
on the MATLAB command window to load the data. We can select the number of optimal components by using the plsdacompsel function:
res = plsdacompsel(Xtrain_log_log,class_train,'none','none','vene',5,'bayes')
We'll get the error rate in validation (and non-error rate in validation) associated to each component value. Type
res.er
on the MATLAB command window to see the error rates. We can then calculate the PLSDA model with 2 components by typing:
model = plsdafit(Xtrain_log,class_train,2,'none','none','bayes',1)
on the MATLAB command window. Once the model is calculated, we can see the model performances by typing:
model.class_param
Scores, loadings, calculated class, leverages and many other statistics are stored in the model structure. We can proceed by cross validating (with 5 venetian blind groups) the PLSDA model with 2 components:
cv = plsdacv(Xtrain_log,class_train,2,'none','none','vene',5,'bayes')
Once the validation procedure has finished, we can see the validation performances by typing:
cv.class_param
Finally, we can predict the test set samples by using the calibrated model:
pred = plsdapred(Xtest_log,model)
and finally we can calculate the classification performances on the external test set predictions:
class_param = calc_class_param(pred.class_pred,class_test)
[-> top]