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
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
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)
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Hi,
That was helpful. Thank you. How to do the same for the testing data?
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
build the PLS-DA modeling of the
gender
responsegetting the true labels: getting the
.char2numF
function to convert the labels into integersapplication to the
gender
labels (in a matrix format)getting the predicted values
load the
pROC
package for ROC curve plotting and AUC computationapplication to testing data
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.
(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 thegender
labels converted to integers (0 or 1). Thetest_pred.vn
are the predictions by the PLS (which are mainly within [0;1] but may occasionnaly be below 0 or above 1.