% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cv.l0ara.R
\name{cv.l0ara}
\alias{cv.l0ara}
\title{Cross-validation for l0ara}
\usage{
cv.l0ara(x, y, family, lam, measure, nfolds, maxit, eps, seed)
}
\arguments{
\item{x}{Input matrix as in \code{l0ara}.}

\item{y}{Response variable as in \code{l0ara}.}

\item{family}{Model family as in \code{l0ara}.}

\item{lam}{A user-supplied sequence of candidate penalty values. At least two
values are required.}

\item{measure}{Criterion used to compare folds. Use \code{"mse"} or
\code{"mae"} for any supported family. Use \code{"class"} or
\code{"auc"} only with \code{family = "logit"}.}

\item{nfolds}{Number of folds. Default value is 10. Smallest value is 3.}

\item{maxit}{Maximum number of iterations passed to each call to
\code{l0ara()}.}

\item{eps}{Convergence threshold. Default value is \code{1e-4}.}

\item{seed}{Optional random seed used to generate the fold assignments.}
}
\value{
An object with S3 class "cv.l0ara" containing:
 \item{cv.error}{Mean cross-validation score for each value in
   \code{lambda}.}
 \item{cv.std}{Estimated standard error of \code{cv.error}.}
 \item{lam.min}{The selected penalty value.}
 \item{lambda}{The supplied sequence of penalty values.}
 \item{measure}{The measure used for model selection.}
 \item{family}{The fitted model family.}
 \item{x}{The original design matrix.}
 \item{y}{The original response vector.}
 \item{name}{A printable label for \code{measure}.}
 \item{fit.min}{A \code{"l0ara"} object refit on the full data using
   \code{lam.min}.}
}
\description{
Perform k-fold cross-validation over a supplied sequence of
  penalty values and return the value selected by the chosen measure.
}
\details{
For each fold, the function fits one model per value in
  \code{lam}, evaluates the requested measure on the held-out data, and then
  averages the results across folds. For \code{measure = "auc"}, the selected
  value is the one with the largest score; for all other measures it is the
  one with the smallest score.
}
\examples{
# Linear regression
# Generate design matrix and response variable
n <- 100
p <- 40
x <- matrix(rnorm(n*p), n, p)
beta <- c(1,0,2,3,rep(0,p-4))
noise <- rnorm(n)
y <- x\%*\%beta+noise
lam <- c(0.1, 0.3, 0.5)
fit <- cv.l0ara(x, y, family="gaussian", lam, measure = "mse")
}
\seealso{
\code{\link{l0ara}}, \code{\link{coef.cv.l0ara}},
  \code{\link{plot.cv.l0ara}}.
}
\author{
Wenchuan Guo <wguo1017@gmail.com>, Shujie Ma <shujie.ma@ucr.edu>, Zhenqiu Liu <Zhenqiu.Liu@cshs.org>
}
