plsda: Partial Least Squares and Sparse Partial Least Squares...

Description Usage Arguments Details Value See Also Examples

Description

plsda is used to fit standard PLS models for classification while splsda performs sparse PLS that embeds feature selection and regularization for the same purpose.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
plsda(x, ...)

## Default S3 method:
plsda(x,  y, ncomp = 2, probMethod = "softmax", prior = NULL, ...)

## S3 method for class 'plsda'
predict(object, newdata = NULL, ncomp = NULL, type = "class", ...)

splsda(x, ...)

## Default S3 method:
splsda(x, y, probMethod = "softmax", prior = NULL, ...)

## S3 method for class 'splsda'
predict(object, newdata = NULL, type = "class", ...)

Arguments

x

a matrix or data frame of predictors

y

a factor or indicator matrix for the discrete outcome. If a matrix, the entries must be either 0 or 1 and rows must sum to one

ncomp

the number of components to include in the model. Predictions can be made for models with values less than ncomp.

probMethod

either "softmax" or "Bayes" (see Details)

prior

a vector or prior probabilities for the classes (only used for probeMethod = "Bayes")

...

arguments to pass to plsr or spls. For splsda, this is the method for passing tuning parameters specifications (e.g. K, eta or kappa)

object

an object produced by plsda

newdata

a matrix or data frame of predictors

type

either "class", "prob" or "raw" to produce the predicted class, class probabilities or the raw model scores, respectively.

Details

If a factor is supplied, the appropriate indicator matrix is created.

A multivariate PLS model is fit to the indicator matrix using the plsr or spls function.

Two prediction methods can be used.

The softmax function transforms the model predictions to "probability-like" values (e.g. on [0, 1] and sum to 1). The class with the largest class probability is the predicted class.

Also, Bayes rule can be applied to the model predictions to form posterior probabilities. Here, the model predictions for the training set are used along with the training set outcomes to create conditional distributions for each class. When new samples are predicted, the raw model predictions are run through these conditional distributions to produce a posterior probability for each class (along with the prior). This process is repeated ncomp times for every possible PLS model. The NaiveBayes function is used with usekernel = TRUE for the posterior probability calculations.

Value

For plsda, an object of class "plsda" and "mvr". For splsda, an object of class splsda.

The predict methods produce either a vector, matrix or three-dimensional array, depending on the values of type of ncomp. For example, specifying more than one value of ncomp with type = "class" with produce a three dimensional array but the default specification would produce a factor vector.

See Also

plsr, spls

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
## Not run: 
data(mdrr)
set.seed(1)
inTrain <- sample(seq(along = mdrrClass), 450)
 
nzv <- nearZeroVar(mdrrDescr)
filteredDescr <- mdrrDescr[, -nzv]

training <- filteredDescr[inTrain,]
test <- filteredDescr[-inTrain,]
trainMDRR <- mdrrClass[inTrain]
testMDRR <- mdrrClass[-inTrain]
 
preProcValues <- preProcess(training)

trainDescr <- predict(preProcValues, training)
testDescr <- predict(preProcValues, test)

useBayes   <- plsda(trainDescr, trainMDRR, ncomp = 5,
                    probMethod = "Bayes")
useSoftmax <- plsda(trainDescr, trainMDRR, ncomp = 5)

confusionMatrix(predict(useBayes, testDescr),
                testMDRR)

confusionMatrix(predict(useSoftmax, testDescr),
                testMDRR)

histogram(~predict(useBayes, testDescr, type = "prob")[,"Active",]
          | testMDRR, xlab = "Active Prob", xlim = c(-.1,1.1))
histogram(~predict(useSoftmax, testDescr, type = "prob")[,"Active",]
          | testMDRR, xlab = "Active Prob", xlim = c(-.1,1.1))


## different sized objects are returned
length(predict(useBayes, testDescr))
dim(predict(useBayes, testDescr, ncomp = 1:3))
dim(predict(useBayes, testDescr, type = "prob"))
dim(predict(useBayes, testDescr, type = "prob", ncomp = 1:3))

## Using spls:
## (As of 11/09, the spls package now has a similar function with
## the same mane. To avoid conflicts, use caret:::splsda to 
## get this version)

splsFit <- caret:::splsda(trainDescr, trainMDRR, 
                          K = 5, eta = .9,
                          probMethod = "Bayes")

confusionMatrix(caret:::predict.splsda(splsFit, testDescr),
                testMDRR)

## End(Not run)

Example output

Loading required package: lattice
Loading required package: ggplot2
Confusion Matrix and Statistics

          Reference
Prediction Active Inactive
  Active       31       13
  Inactive      6       28
                                         
               Accuracy : 0.7564         
                 95% CI : (0.646, 0.8465)
    No Information Rate : 0.5256         
    P-Value [Acc > NIR] : 2.364e-05      
                                         
                  Kappa : 0.516          
                                         
 Mcnemar's Test P-Value : 0.1687         
                                         
            Sensitivity : 0.8378         
            Specificity : 0.6829         
         Pos Pred Value : 0.7045         
         Neg Pred Value : 0.8235         
             Prevalence : 0.4744         
         Detection Rate : 0.3974         
   Detection Prevalence : 0.5641         
      Balanced Accuracy : 0.7604         
                                         
       'Positive' Class : Active         
                                         
Confusion Matrix and Statistics

          Reference
Prediction Active Inactive
  Active       31       13
  Inactive      6       28
                                         
               Accuracy : 0.7564         
                 95% CI : (0.646, 0.8465)
    No Information Rate : 0.5256         
    P-Value [Acc > NIR] : 2.364e-05      
                                         
                  Kappa : 0.516          
                                         
 Mcnemar's Test P-Value : 0.1687         
                                         
            Sensitivity : 0.8378         
            Specificity : 0.6829         
         Pos Pred Value : 0.7045         
         Neg Pred Value : 0.8235         
             Prevalence : 0.4744         
         Detection Rate : 0.3974         
   Detection Prevalence : 0.5641         
      Balanced Accuracy : 0.7604         
                                         
       'Positive' Class : Active         
                                         
[1] 78
[1] 78  3
[1] 78  2  1
[1] 78  2  3
Confusion Matrix and Statistics

          Reference
Prediction Active Inactive
  Active       32       14
  Inactive      5       27
                                         
               Accuracy : 0.7564         
                 95% CI : (0.646, 0.8465)
    No Information Rate : 0.5256         
    P-Value [Acc > NIR] : 2.364e-05      
                                         
                  Kappa : 0.5173         
                                         
 Mcnemar's Test P-Value : 0.06646        
                                         
            Sensitivity : 0.8649         
            Specificity : 0.6585         
         Pos Pred Value : 0.6957         
         Neg Pred Value : 0.8438         
             Prevalence : 0.4744         
         Detection Rate : 0.4103         
   Detection Prevalence : 0.5897         
      Balanced Accuracy : 0.7617         
                                         
       'Positive' Class : Active         
                                         

caret documentation built on May 2, 2019, 5:47 p.m.

Related to plsda in caret...