% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/coef.R, R/coef.autotune_lasso.R,
%   R/coef.autotune_lasso_path.R
\name{coef.autotune_lasso}
\alias{coef.autotune_lasso}
\alias{coef.autotune_lasso_path}
\title{Extract coefficients for autotune_lasso objects}
\usage{
\method{coef}{autotune_lasso}(object, intercept = TRUE, path = FALSE, sparse = TRUE, ...)

\method{coef}{autotune_lasso_path}(object, intercept = TRUE, a0 = NULL, ...)
}
\arguments{
\item{object}{An \code{"autotune_lasso"} object (for \code{coef.autotune_lasso})
or \code{"autotune_lasso_path"} object (for \code{coef.autotune_lasso_path}).}

\item{intercept}{Logical; include the intercept term? If \code{FALSE}, the intercept
row is omitted.}

\item{path}{Logical; if \code{TRUE}, return the entire coefficient path across
different lambdas.}

\item{sparse}{Logical; controls the output format of \code{coef.autotune_lasso()} when
\code{path = FALSE}. If \code{TRUE}, returns a sparse \code{dgCMatrix} (glmnet-style);
if \code{FALSE}, returns a base numeric vector.}

\item{...}{Other arguments to coef.}

\item{a0}{Intercept of the fitted autotune regression. Used only when \code{intercept = TRUE}.}
}
\value{
\itemize{
  \item \code{coef.autotune_lasso(path = FALSE, sparse = TRUE)} returns a sparse \code{dgCMatrix}
    of dimension (\code{nvars} + 1) \eqn{\times 1} (or \code{nvars}  \eqn{\times 1} if \code{intercept = FALSE}).
  \item \code{coef.autotune_lasso(path = FALSE, sparse = FALSE)} returns a named numeric vector.
  \item \code{coef.autotune_lasso(path = TRUE)} calls \code{coef.autotune_lasso_path()}, which returns a sparse
    \code{dgCMatrix} of dimension (\code{nvars}  + 1) \eqn{\times} (k + 1) (or \code{nvars}  \eqn{\times} (k + 1) if
    \code{intercept = FALSE}), with columns named \code{lambda_1, ..., lambda_k, final_lambda}.
}
}
\description{
This function extracts the regression coefficients estimated by an autotune
lasso model, using the stored \code{"autotune_lasso"} object
}
\examples{
set.seed(10)
n = 300
p = 500
s = 10
beta = c(rep(1, s), rep(0, p - s))
x = matrix(rnorm(n * p), ncol = p)
# Maunal sigma allocation
# y = x \%*\% beta + rnorm(n, sd = 1)
# Dynamic sigma allocation with snr specified
snr = 2
y = x \%*\% beta + rnorm(n, sd = sqrt(var(x\%*\%beta)/snr))
fit <- autotune_lasso(x, y)
coef(fit)                    # final solution
coef(fit, path = TRUE)        # coefficient path (sparse)

}
