% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/l0ara.R
\name{l0ara}
\alias{l0ara}
\title{Fit a generalized linear model with an L0 penalty}
\usage{
l0ara(x, y, family, lam, standardize, maxit, eps)
}
\arguments{
\item{x}{Design matrix. A numeric matrix is used as-is; other inputs must be
coercible to a model matrix. Rows correspond to observations and columns to
predictors.}

\item{y}{Response vector. For accurate use, supply numeric outcomes for
\code{family = "gaussian"}, positive numeric outcomes for
\code{family = "gamma"} and \code{family = "inv.gaussian"}, binary outcomes
coded as 0/1 for \code{family = "logit"}, and non-negative counts for
\code{family = "poisson"}.}

\item{family}{Model family.}

\item{lam}{A single user-supplied penalty value. If you have a candidate
sequence of values, use \code{cv.l0ara()} to choose \code{lam.min} and then
refit with \code{l0ara()}. Setting \code{lam = 2} mimics AIC-style model
selection, and \code{lam = log(n)} mimics BIC-style model selection.}

\item{standardize}{Logical flag indicating whether to standardize the columns
of \code{x} before fitting. The original \code{x} is stored in the returned
object.}

\item{maxit}{Maximum number of iterations passed to the fitting routine.}

\item{eps}{Convergence threshold. Default value is \code{1e-4}.}
}
\value{
An object with S3 class "l0ara" containing:
 \item{beta}{A vector of fitted coefficients.}
 \item{df}{Number of non-zero coefficients.}
 \item{iter}{Number of iterations used by the fitting routine.}
 \item{lam}{The supplied penalty value.}
 \item{lambda}{A copy of \code{lam} for compatibility with downstream
   methods.}
 \item{family}{The fitted model family.}
 \item{x}{The original design matrix supplied to the function.}
 \item{y}{The response vector supplied to the function.}
}
\description{
Fit a sparse generalized linear model by approximating the
  L0-penalized objective with an adaptive ridge algorithm.
}
\details{
The objective function is
  \deqn{-(\log\mbox{-}\mathrm{likelihood}) + (\lambda / 2)|\beta|_0,}
  where \eqn{|\beta|_0} is the number of non-zero elements of \eqn{\beta}.
  The adaptive ridge algorithm provides an efficient approximation to the
  corresponding L0-penalized generalized linear model.
}
\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
# fit sparse linear regression using BIC
res.gaussian <- l0ara(x, y, family="gaussian", log(n))

# predict for new observations
print(res.gaussian)
predict(res.gaussian, newx=matrix(rnorm(3,p),3,p))
coef(res.gaussian)

# Logistic 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))
prob <- exp(x\%*\%beta)/(1+exp(x\%*\%beta))
y <- rbinom(n, rep(1, n), prob)
# fit sparse logistic regression
res.logit <- l0ara(x, y, family="logit", 0.7)

# predict for new observations
print(res.logit)
predict(res.logit, newx=matrix(rnorm(3,p),3,p))
coef(res.logit)

# Poisson regression
# Generate design matrix and response variable
n <- 100
p <- 40
x <- matrix(rnorm(n*p), n, p)
beta <- c(1,0,0.5,0.3,rep(0,p-4))
mu <- exp(x\%*\%beta)
y <- rpois(n, mu)
# fit sparse Poisson regression using AIC
res.pois <- l0ara(x, y, family="poisson", 2)

# predict for new observations
print(res.pois)
predict(res.pois, newx=matrix(rnorm(3,p),3,p))
coef(res.pois)
}
\seealso{
\code{\link{cv.l0ara}}, \code{\link{predict.l0ara}},
  \code{\link{coef.l0ara}}, \code{\link{plot.l0ara}}.
}
\author{
Wenchuan Guo <wguo1017@gmail.com>, Shujie Ma <shujie.ma@ucr.edu>, Zhenqiu Liu <Zhenqiu.Liu@cshs.org>
}
