| plsda | R Documentation |
Discrimination (DA) on PCA or PLS latent variables.
- Function plsda fits PLSDA models, with various DA methods.
The class membership y (unidimensional variable) for the reference (= training) observations is firstly transformed to a table Ydummy containing nclas dummy variables (with function dummy), where nclas is the number of classes in y. Then, a PLS2 is implemented on the X-data and the dummy table Ydummy (with function pls), returning PLS2 scores finally used by the DA method.
The PLS2 algorithm is defined in argument algo.
The DA method is defined in argument da. The default DA method is dalm. Other methods presently avalaible are dadis, daglm, daprob and knnda. Any other ad'hoc DA methods can be developed by the user. Note that the DA method dasdod can not be used in plsda: in this last function, the number of PLS components (that corresponds to the input data for the DA) varies from 1 to ncomp; dasdod computes PCAs from the input data (here the PLS components) which cannot be implemented when the number of PLS comoonents is equal to 1 or 2.
- Function plsdalm is a faster equivalent of plsda(..., da = dalm, ...).
- Functions pcda and pcdalm does the same (and with the same syntax) as plsda but on principal component (instead of PLS) scores.
Matrix X is centered before the analyses, but X is not column-wise scaled (there is no argument scale available). If a scaling is needed, the user has to scale X before using the functions.
Row observations can eventually be weighted (using argument weights).
pcda(Xr, Yr, Xu, Yu = NULL, ncomp, algo = NULL, da = dalm, ...)
pcdalm(Xr, Yr, Xu, Yu = NULL, ncomp, algo = NULL, ...)
plsda(Xr, Yr, Xu, Yu = NULL, ncomp, algo = NULL, da = dalm, ...)
plsdalm(Xr, Yr, Xu, Yu = NULL, ncomp, algo = NULL, ...)
Xr |
A |
Yr |
A vector of length |
Xu |
A |
Yu |
A vector of length |
ncomp |
The maximal number of PLS scores (= components = latent variables) to consider. |
algo |
For |
da |
A function defining the discriminant method used for the predictions. Default to |
... |
Optionnal arguments to pass in functions defined in |
A list of outputs (see examples), such as:
y |
Responses for the test data. |
fit |
Predictions for the test data. |
r |
Residuals for the test data. |
data(datforages)
Xr <- datforages$Xr
yr <- datforages$yr
Xu <- datforages$Xu
yu <- datforages$yu
Xr <- detrend(Xr)
Xu <- detrend(Xu)
headm(Xr)
headm(Xu)
table(yr)
table(yu)
######## PLS-DALM
ncomp <- 20
fm <- plsda(Xr, yr, Xu, yu, ncomp = ncomp)
names(fm)
headm(fm$y)
headm(fm$fit)
headm(fm$r)
z <- err(fm, ~ ncomp)
z[z$errp == min(z$errp), ]
plotmse(z, nam = "errp")
## Same with plsdalm (faster)
ncomp <- 20
fm <- plsdalm(Xr, yr, Xu, yu, ncomp = ncomp)
z <- err(fm, ~ ncomp)
z[z$errp == min(z$errp), ]
plotmse(z, nam = "errp")
######## PLS-LDA
ncomp <- 20
fm <- plsda(Xr, yr, Xu, yu, ncomp, da = daprob)
z <- err(fm, ~ ncomp)
z[z$errp == min(z$errp), ]
plotmse(z, nam = "errp")
######## PLS-QDA
ncomp <- 20
fm <- plsda(Xr, yr, Xu, yu, ncomp, da = daprob,
lda = FALSE)
z <- err(fm, ~ ncomp)
z[z$errp == min(z$errp), ]
plotmse(z, nam = "errp")
######## PLS-KNNDA
ncomp <- 15
fm <- plsda(Xr, yr, Xu, yu, ncomp, da = knnda,
diss = "mahalanobis", k = 3)
z <- err(fm, ~ ncomp + k)
z[z$errp == min(z$errp), ]
plotmse(z, nam = "errp", group = z$k)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.