plsrda | R Documentation |
Discrimination (DA) based on PLS.
The training variable y
(univariate class membership) is firstly transformed to a dummy table containing nclas
columns, where nclas
is the number of classes present in y
. Each column is a dummy variable (0/1). Then, a PLS2 is implemented on the X-
data and the dummy table, returning latent variables (LVs) that are used as dependent variables in a DA model.
- plsrda
: Usual "PLSDA". A linear regression model predicts the Y-dummy table from the PLS2 LVs. This corresponds to the PLSR2 of the X-data and the Y-dummy table. For a given observation, the final prediction is the class corresponding to the dummy variable for which the prediction is the highest.
- plslda
and plsqda
: Probabilistic LDA and QDA are run over the PLS2 LVs, respectively.
plsrda(X, y, weights = NULL, nlv)
plslda(X, y, weights = NULL, nlv, prior = c("unif", "prop"))
plsqda(X, y, weights = NULL, nlv, prior = c("unif", "prop"))
## S3 method for class 'Plsrda'
predict(object, X, ..., nlv = NULL)
## S3 method for class 'Plsprobda'
predict(object, X, ..., nlv = NULL)
X |
For the main functions: Training X-data ( |
y |
Training class membership ( |
weights |
Weights ( |
nlv |
The number(s) of LVs to calculate. |
prior |
The prior probabilities of the classes. Possible values are "unif" (default; probabilities are set equal for all the classes) or "prop" (probabilities are set equal to the observed proportions of the classes in |
object |
A fitted model, output of a call to the main functions. |
... |
Optional arguments. Not used. |
See the examples.
n <- 50 ; p <- 8
Xtrain <- matrix(rnorm(n * p), ncol = p)
ytrain <- sample(c(1, 4, 10), size = n, replace = TRUE)
#ytrain <- sample(c("a", "10", "d"), size = n, replace = TRUE)
Xtest <- Xtrain[1:5, ] ; ytest <- ytrain[1:5]
#### PLSDA
nlv <- 5
fm <- plsrda(Xtrain, ytrain, nlv = nlv)
names(fm)
## The PLS2 model
zfm <- fm$fm
transform(zfm, Xtest)
transform(zfm, Xtest, nlv = 1)
summary(zfm, Xtrain)
coef(zfm)
coef(zfm, nlv = 0)
coef(zfm, nlv = 2)
## PLSDA
predict(fm, Xtest)
predict(fm, Xtest, nlv = 0:2)$pred
pred <- predict(fm, Xtest)$pred
err(pred, ytest)
#### PLS-LDA
nlv <- 5
fm <- plslda(Xtrain, ytrain, nlv = nlv)
predict(fm, Xtest)
predict(fm, Xtest, nlv = 1:2)$pred
## The PLS2 model
zfm <- fm[[1]][[1]]
class(zfm)
names(zfm)
summary(zfm, Xtrain)
transform(zfm, Xtest[1:2, ])
coef(zfm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.