predict.penlda: Make PenalizedLDA predictions on a new data set.

Description Usage Arguments Value Author(s) References Examples

Description

Given output from the PenalizedLDA function, make predictions on a new data set.

Usage

1
2
## S3 method for class 'penlda'
predict(object,xte,...)

Arguments

object

A "penlda" object; this is the output of the PenalizedLDA function.

xte

A data set on which predictions should be made.

...

...

Value

ypred

A matrix with nrow(xte) rows and K columns where K is the number of discriminant vectors in the "penlda" object passed in. The first column contains predictions obtained if only the 1st discriminant vector is used, the 2nd column contains predictions obtained if the first 2 discriminant vectors are used, and so on. If there is only 1 discriminant vector in the "penlda" object passed in, then just a vector is output.

Author(s)

Daniela M. Witten

References

D Witten and R Tibshirani (2011) Penalized classification using Fisher's linear discrimint. To appear in JRSSB.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
set.seed(1)
n <- 20
p <- 100
x <- matrix(rnorm(n*p), ncol=p)
xte <- matrix(rnorm(n*p), ncol=p)
y <- c(rep(1,5),rep(2,5),rep(3,10))
x[y==1,1:10] <- x[y==1,1:10] + 2
x[y==2,11:20] <- x[y==2,11:20] - 2
xte[y==1,1:10] <- xte[y==1,1:10] + 2
xte[y==2,11:20] <- xte[y==2,11:20] - 2
out <- PenalizedLDA(x,y,xte,lambda=.14,K=2)
print(out)
plot(out)
pred.out <- predict(out,xte=xte)
cat("Predictions obtained using PenalizedLDA function and using
predict.penlda function are the same.")
print(cor(pred.out$ypred,out$ypred))

Example output

Number of discriminant vectors:  2
Number of nonzero features in discriminant vector  1 : 29
Number of nonzero features in discriminant vector  2 : 35
Total number of nonzero features:  45

Details:
Type:  standard
Lambda:  0.14
Predictions obtained using PenalizedLDA function and using
predict.penlda function are the same.          [,1]      [,2]
[1,] 1.0000000 0.8361702
[2,] 0.8361702 1.0000000

penalizedLDA documentation built on May 2, 2019, 8:36 a.m.