cv.vda.r: Choose lambda using K-fold cross validation

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

View source: R/cv.vda.r.R

Description

Choose the optimal tuning parameter λ for Vertex Discriminant Analyis by using K-fold cross validation.

Usage

1
2
cv.vda.r(x, y, k, lam.vec)
cv.vda(x, y, k, lam.vec)

Arguments

x

n x p matrix or data frame containing the cases for each feature. The rows correspond to cases and the columns to the features. Intercept column is not included in this.

y

n x 1 vector representing the outcome variable. Each element denotes which one of the k classes that case belongs to.

k

The number of folds to be used in cross-validation.

lam.vec

A vector containing the set of all values of λ, from which VDA will be conducted.

Details

K-fold cross validation to select optimal lambda for use in Vertex Disciminant Analysis (vda.r). The optimal value is considered the lamda value that retuns the lowest testing error over the cross validation. If more than one lambda value give the minumum testing error, the largest lambda is selected.

A plot of the cross validation errors can be viewed through plot.cv.vda.r.

Value

k

The value of K used for the K-fold cross validation.

lam.vec

The values of lambda tested.

mean.error

The mean error corresponding to each lambda across k-folds

lam.opt

The determined lambda value among lam.vec that returns the smallest prediction error. This value is the optimal lambda value for use in link{vda.r}.

error.cv

The prediction error matrix returned by cross validation method.

Author(s)

Edward Grant, Xia Li, Kenneth Lange, Tong Tong Wu

Maintainer: Edward Grant edward.m.grant@gmail.com

References

Lange, K. and Wu, T.T. (2008) An MM Algorithm for Multicategory Vertex Discriminant Analysis. Journal of Computational and Graphical Statistics, Volume 17, No 3, 527-544.

See Also

vda.r. plot.cv.vda.r

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
# load zoo data
# column 1 is name, columns 2:17 are features, column 18 is class
data(zoo)

# feature matrix without intercept
x <- zoo[,2:17]

# class vector
y <- zoo[,18]

# lambda vector
lam.vec <- (1:10)/10

# searching for the best lambda with 10-fold cross validation and plot cv
cv <- cv.vda.r(x, y, 10, lam.vec)
plot(cv)

# run VDA
out <- vda.r(x,y,cv$lam.opt)

# Predict five cases based on VDA
fivecases <- matrix(0,5,16)
fivecases[1,] <- c(1,0,0,1,0,0,0,1,1,1,0,0,4,0,1,0)
fivecases[2,] <- c(1,0,0,1,0,0,1,1,1,1,0,0,4,1,0,1)
fivecases[3,] <- c(0,1,1,0,1,0,0,0,1,1,0,0,2,1,1,0)
fivecases[4,] <- c(0,0,1,0,0,1,1,1,1,0,0,1,0,1,0,0)
fivecases[5,] <- c(0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0)
predict(out, fivecases)

Example output

Loading required package: rgl
Warning messages:
1: In rgl.init(initValue, onlyNULL) : RGL: unable to open X11 display
2: 'rgl_init' failed, running with rgl.useNULL = TRUE 
3: .onUnload failed in unloadNamespace() for 'rgl', details:
  call: fun(...)
  error: object 'rgl_quit' not found 
[1] 1 1 2 4 7

VDA documentation built on May 29, 2017, 6:32 p.m.