Hi,
To generate the S plot, you need to compute the covariance and the correlation between the scores and the variables.
Below is the code to generate the S plot in R.
You first need to download your 2 data files 'dataMatrix.tsv', and 'sampleMetadata.tsv' from W4M to your computer.
Then read your 2 table files in your local R session:
dataMatrix <- t(as.matrix(read.table("dataMatrix.tsv",
check.names = FALSE,
header = TRUE,
row.names = 1,
sep = "\t",
stringsAsFactors = FALSE)))
sampleMetadata <- read.table("sampleMetadata.tsv",
check.names = FALSE,
header = TRUE,
row.names = 1,
sep = "\t",
stringsAsFactors = FALSE)
Get the scores of the predictive component (column of the sampleMetadata named "factor of interest_pls model_X-SCOR-p1" (or "-h1" in case of OPLS); here I use "gender_PLSDA_XSCOR-p1" as an example)
scoreVn <- sampleMetadata[, "gender_PLSDA_XSCOR-p1"]
Compute the covariance between the scores and the variables
covVn <- cov(scoreVn, dataMatrix)
Compute the correlation between the scores and the variables
corVn <- cor(scoreVn, dataMatrix)
Generate the S-plot
dev.new()
plot(covVn, corVn, main = "S-plot",
xlab = "cov(t, X)",
ylab = "cor(t, X)")
You can identify the variables of interest on the plot interactively (e.g. those with high correlation and high covariance)
selVi <- identify(covVn, corVn, labels = colnames(dataMatrix))
colnames(dataMatrix)[selVi]