\HeaderA{gsim.cv}{Determination of the ridge regularization parameter and the bandwidth to be used for
classification with GSIM for binary data}{gsim.cv}
\begin{Description}\relax
The function \code{gsim.cv} determines the best ridge regularization parameter and bandwidth to be
used for classification with GSIM as described in Lambert-Lacroix and Peyre (2005).
\end{Description}
\begin{Usage}
\begin{verbatim}
gsim.cv(Xtrain, Ytrain,LambdaRange,hARange,hB=NULL, NbIterMax=50)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{Xtrain}] a (ntrain x p) data matrix of predictors. \code{Xtrain} must be a matrix. 
Each row corresponds to an observation and each column to a predictor variable.
\item[\code{Ytrain}] a ntrain vector of responses. \code{Ytrain} must be a vector. 
\code{Ytrain} is a {1,2}-valued vector and contains the response variable for each
observation.
\item[\code{LambdaRange}] the vector of positive real value from which the best ridge regularization parameter
has to be chosen by cross-validation.
\item[\code{hARange}] the vector of strictly positive real value from which the best bandwidth
has to be chosen by cross-validation for GSIM step A.
\item[\code{hB}] a strictly positive real value. \code{hB} is the bandwidth for 
GSIM step B. if \code{hB} is equal to NULL, then hB value is chosen using a
plug-in method.
\item[\code{NbIterMax}] a positive integer. \code{NbIterMax} is the maximal number of
iterations in the Newton-Rapson parts.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The cross-validation procedure described in Lambert-Lacroix and Peyre (2005)
is used to determine the best ridge regularization parameter and bandwidth to be
used for classification with GSIM for binary data (for categorical data see 
\code{\LinkA{mgsim}{mgsim}} and \code{\LinkA{mgsim.cv}{mgsim.cv}}).
At each cross-validation run, \code{Xtrain} is split into a pseudo training
set (ntrain - 1 samples) and a pseudo test set (1 sample) and the classification error rate is determined for each
value of ridge regularization parameter and bandwidth. Finally, the function 
\code{gsim.cv} returns the values of the ridge regularization parameter and 
bandwidth for which the mean classification error rate is minimal.
\end{Details}
\begin{Value}
A list with the following components:
\begin{ldescription}
\item[\code{Lambda}] the optimal regularization parameter.
\item[\code{hA}] the optimal bandwidth parameter.
\end{ldescription}
\end{Value}
\begin{Author}\relax
Sophie Lambert-Lacroix (\url{http://www-lmc.imag.fr/lmc-sms/Sophie.Lambert}) 
and 
Julie Peyre (\url{http://www-lmc.imag.fr/lmc-sms/Julie.Peyre/}).
\end{Author}
\begin{References}\relax
S. Lambert-Lacroix and Julie Peyre (2005). Local likelyhood regression
in  generalized linear single-index models with applications to microarray data, 
TR0563 IAP Statistics network (\url{http://www.stat.ucl.ac.be/IAP/}).
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{mgsim}{mgsim}}, \code{\LinkA{gsim}{gsim}}, \code{\LinkA{gsim.cv}{gsim.cv}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
# load plsgenomics library
library(plsgenomics)

# load Colon data
data(Colon)
IndexLearn <- c(sample(which(Colon$Y==2),12),sample(which(Colon$Y==1),8))

Xtrain <- Colon$X[IndexLearn,]
Ytrain <- Colon$Y[IndexLearn]
Xtest <- Colon$X[-IndexLearn,]

# preprocess data
resP <- preprocess(Xtrain= Xtrain, Xtest=Xtest,Threshold = c(100,16000),Filtering=c(5,500),log10.scale=TRUE,row.stand=TRUE)

# Determine optimum h and lambda
hl <- gsim.cv(Xtrain=resP$pXtrain,Ytrain=Ytrain,hARange=c(7,20),LambdaRange=c(0.1,1),hB=NULL)

# perform prediction by GSIM  
res <- gsim(Xtrain=resP$pXtrain,Ytrain=Ytrain,Xtest=resP$pXtest,Lambda=hl$Lambda,hA=hl$hA,hB=NULL)
res$Cvg
sum(res$Ytest!=Colon$Y[-IndexLearn])

\end{ExampleCode}
\end{Examples}

