tune.func | R Documentation |
Tune appropriate number of components (ncomp
) for plsc
,
plslda
or pcalda
.
tune.plsc(x,y, pls="simpls",ncomp=10, tune.pars,...)
tune.plslda(x,y, pls="simpls",ncomp=10, tune.pars,...)
tune.pcalda(x,y, ncomp=NULL, tune.pars,...)
x |
A matrix or data frame containing the explanatory variables if no formula is given as the principal argument. |
y |
A factor specifying the class for each observation if no formula principal argument is given. |
pls |
A method for calculating PLS scores and loadings. The following methods are supported:
For details, see |
ncomp |
The number of components to be used in the classification. |
tune.pars |
A list of parameters using by the resampling method.
See |
... |
Further parameters passed to |
A list including:
ncomp |
The best number of components. |
acc.tune |
Accuracy rate of components. |
Wanchang Lin
plsc
, plslda
, pcalda
,valipars
## Not run:
data(abr1)
cl <- factor(abr1$fact$class)
dat <- preproc(abr1$pos , y=cl, method=c("log10"),add=1)[,110:500]
## divide data as training and test data
idx <- sample(1:nrow(dat), round((2/3)*nrow(dat)), replace=FALSE)
## construct train and test data
train.dat <- dat[idx,]
train.t <- cl[idx]
test.dat <- dat[-idx,]
test.t <- cl[-idx]
## tune the best number of components
ncomp.plsc <- tune.plsc(dat,cl, pls="simpls",ncomp=20)
ncomp.plslda <- tune.plslda(dat,cl, pls="simpls",ncomp=20)
ncomp.pcalda <- tune.pcalda(dat,cl, ncomp=60)
## model fit
(z.plsc <- plsc(train.dat,train.t, ncomp=ncomp.plsc$ncomp))
(z.plslda <- plslda(train.dat,train.t, ncomp=ncomp.plslda$ncomp))
(z.pcalda <- pcalda(train.dat,train.t, ncomp=ncomp.pcalda$ncomp))
## or indirect use tune function in model fit
z.plsc <- plsc(train.dat,train.t, ncomp=20, tune=TRUE)
z.plslda <- plslda(train.dat,train.t, ncomp=20, tune=TRUE)
z.pcalda <- pcalda(train.dat,train.t, ncomp=60, tune=TRUE)
## predict test data
pred.plsc <- predict(z.plsc, test.dat)$class
pred.plslda <- predict(z.plslda, test.dat)$class
pred.pcalda <- predict(z.pcalda, test.dat)$class
## classification rate and confusion matrix
cl.rate(test.t, pred.plsc)
cl.rate(test.t, pred.plslda)
cl.rate(test.t, pred.pcalda)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.