predict.plsc: Predict Method for Class 'plsc' or 'plslda'

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/mt_plsc.R

Description

Prediction of test data using plsc or plslda.

Usage

1
2
3
4
## S3 method for class 'plsc'
predict(object, newdata,...)
## S3 method for class 'plslda'
predict(object, newdata,...)

Arguments

object

Object of class plsc or plslda.

newdata

A matrix or data frame of cases to be classified.

...

Arguments based from or to other methods.

Details

Two functions are methods for the generic function predict() for class plsc or plslda. If newdata is omitted, the results of training data in plsc or plslda object will be returned.

Value

A list with components:

class

The predicted class (a factor).

posterior

The posterior probabilities for the predicted classes.

x

The rotated test data by the projection matrix of PLS.

Author(s)

Wanchang Lin

See Also

plsc, plot.plsc,plslda, plot.plslda

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
data(iris3)

tr    <- sample(1:50, 25)
train <- rbind(iris3[tr,,1], iris3[tr,,2], iris3[tr,,3])
test  <- rbind(iris3[-tr,,1], iris3[-tr,,2], iris3[-tr,,3])
cl    <- factor(c(rep("s",25), rep("c",25), rep("v",25)))

## model fit using plsc and plslda without tuning of ncomp
(z.plsc       <- plsc(train, cl))
(z.plslda     <- plslda(train, cl))
## predict for test data
pred.plsc    <- predict(z.plsc, test)
pred.plslda  <- predict(z.plslda, test)

## plot the projected test data.
grpplot(pred.plsc$x, pred.plsc$class, main="PLSC: Iris") 
grpplot(pred.plslda$x, pred.plslda$class, main="PLSLDA: Iris") 

mt documentation built on Feb. 2, 2022, 1:07 a.m.