ROC plot for OPLS-DA
1
0
Entering edit mode
Eddie • 0
@f2dcf917
Last seen 12 days ago
Belgium

Hi all, I run an OPLS-DA using ropls package and obtained my confusion matrix. I need to plot the ROC and I'm asking how to do that under this package or any other method in r. Thank you

Metabolomics • 263 views
0
Entering edit mode
@etiennethevenot-8285
Last seen 2 days ago
France

Hi, To build the ROC curve, you need 1) the true labels and 2) the predicted (numeric) values. You can access both of them by using the suppLs slot of the opls object. Please find below the example with the sacurine dataset and the pROC package :

Load the ropls package and the sacurine dataset:

library(ropls)
data(sacurine)
attach(sacurine)


Build the PLS-DA model of the gender response:

sac.oplsda <- opls(dataMatrix, sampleMetadata[, "gender"])


Get the true labels and the predicted values:

true_labels_numeric.vi <- round(as.numeric(sac.oplsda@suppLs[["yModelMN"]]))
predicted_values.vn <- as.numeric(sac.oplsda@suppLs[["yPreMN"]])


Load the pROC package for ROC curve plotting and AUC computation:

library(pROC)
sac.roc <- roc(true_labels_numeric.vi, predicted_values.vn)
plot(sac.roc, print.auc = TRUE)

0
Entering edit mode

Hi,

That was helpful. Thank you. How to do the same for the testing data?

0
Entering edit mode

I would suggest to concatenate your training and testing data rowwise, and to apply the opls method with the subset parameter to select the training samples. Please find the code at the end of the script below (I made a modification in the computation of the true labels):

load the ropls package and the sacurine dataset

library(ropls)
data(sacurine)
attach(sacurine)


build the PLS-DA modeling of the gender response

sac.oplsda <- opls(dataMatrix, sampleMetadata[, "gender"])


getting the true labels: getting the .char2numF function to convert the labels into integers

char2numF <- sac.oplsda@suppLs[[".char2numF"]]


application to the gender labels (in a matrix format)

sac_true.vi <- c(char2numF(matrix(sampleMetadata[, "gender"], ncol = 1)))


getting the predicted values

sac_pred.vn <- as.numeric(sac.oplsda@suppLs[["yPreMN"]])


load the pROC package for ROC curve plotting and AUC computation

library(pROC)
sac.roc <- roc(sac_true.vi,
sac_pred.vn)
plot(sac.roc, print.auc = TRUE) # AUC = 0.993


application to testing data

sub.oplsda <- opls(dataMatrix, sampleMetadata[, "gender"],
subset = 1:100) # training on the 100 first samples; testing on the 83 remaining samples
test_true.vi <- c(sub.oplsda@suppLs[[".char2numF"]](matrix(sampleMetadata[101:183, "gender"], ncol = 1)))
test_pred.vn <- as.numeric(sub.oplsda@suppLs[["yTesMN"]])
test.roc <- roc(test_true.vi,
test_pred.vn)
plot(test.roc, print.auc = TRUE) # AUC = 0.912

0
Entering edit mode

Thank you. I was able to apply this method on my testing data. However, in the " test_pred.vn" I have values above 1, other below 1 and others below zero. Are these score values and not probabilities? Would you please confirm that.

0
Entering edit mode

(O)PLS-DA works by first converting the labels to numeric and then performing an (O)PLS. The values in test_pred.vi are therefore the gender labels converted to integers (0 or 1). The test_pred.vn are the predictions by the PLS (which are mainly within [0;1] but may occasionnaly be below 0 or above 1.