% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/priors.R
\name{extract_priors}
\alias{extract_priors}
\alias{extract_priors.lm}
\alias{extract_priors.glm}
\alias{extract_priors.cv.glmnet}
\alias{extract_priors.glmnet}
\alias{extract_priors.ranger}
\title{Extract brms prior specification from a regularized or standard regression model}
\usage{
extract_priors(
  model,
  multiplier = 2,
  min_sd = 0.1,
  intercept_prior_sd = NULL,
  sigma_prior_scale = 1,
  ...
)

\method{extract_priors}{lm}(
  model,
  multiplier = 2,
  min_sd = 0.1,
  intercept_prior_sd = NULL,
  sigma_prior_scale = 1,
  ...
)

\method{extract_priors}{glm}(
  model,
  multiplier = 2,
  min_sd = 0.1,
  intercept_prior_sd = NULL,
  sigma_prior_scale = 1,
  ...
)

\method{extract_priors}{cv.glmnet}(
  model,
  multiplier = 2,
  min_sd = 0.1,
  intercept_prior_sd = NULL,
  sigma_prior_scale = 1,
  lambda = "lambda.min",
  ...
)

\method{extract_priors}{glmnet}(
  model,
  multiplier = 2,
  min_sd = 0.1,
  intercept_prior_sd = NULL,
  sigma_prior_scale = 1,
  s = 1L,
  ...
)

\method{extract_priors}{ranger}(
  model,
  multiplier = 2,
  min_sd = 0.1,
  intercept_prior_sd = NULL,
  sigma_prior_scale = 1,
  ...
)
}
\arguments{
\item{model}{A fitted model.  Supported classes:
\itemize{
  \item \code{cv.glmnet} / \code{glmnet} — elastic net / lasso
  \item \code{lm} — ordinary least squares
  \item \code{glm} — generalized linear model
  \item \code{ranger} — random forest (importance-scaled flat priors)
}}

\item{multiplier}{Numeric scalar.  Prior SD is set to
\code{multiplier * |coef|} (for signed-coefficient methods) or
\code{multiplier * importance_normalised} (for ranger).  Default 2.0.}

\item{min_sd}{Numeric scalar.  Minimum prior SD to avoid degenerate
(spike) priors on near-zero coefficients.  Default 0.1.}

\item{intercept_prior_sd}{Optional prior SD for the intercept term.  The
default \code{NULL} emits \emph{no} explicit intercept prior and lets
\code{brms} pick its data-aware default
(\code{student_t(3, median(y), mad(y))}).  If you supply a numeric value,
the prior becomes \code{normal(0, intercept_prior_sd)} --- this is only
appropriate when the response has been centred (or nearly so) before
fitting, since \code{brms}'s \code{class = "Intercept"} refers to the
intercept at the centre of the predictors, whose posterior mean equals
\code{E[y]} there.  Supplying a small \code{intercept_prior_sd} for an
uncentred response will pull the intercept toward zero and cripple the
fit.}

\item{sigma_prior_scale}{Scale parameter for the half-Cauchy prior on the
residual SD sigma.  Default 1.0.}

\item{...}{Additional arguments passed to methods.}

\item{lambda}{Which lambda to extract coefficients from when the model is a
\code{cv.glmnet} object.  Either \code{"lambda.min"} (default) or
\code{"lambda.1se"}.}

\item{s}{Index (integer) or value of lambda to extract coefficients at when
the model is a plain \code{glmnet} object.  Defaults to the first lambda
(smallest regularisation).}
}
\value{
An \code{et_prior_spec} list containing:
  \describe{
    \item{\code{prior}}{A \code{brmsprior} object for use in \code{brms::brm()}.}
    \item{\code{pred_names}}{Character vector of included predictor names.}
    \item{\code{coefs}}{Named numeric vector of regularized coefficients
      (NULL for ranger, which uses importance instead).}
    \item{\code{method}}{Character: the dispatch method used.}
    \item{\code{multiplier}, \code{min_sd}}{Settings echo.}
  }
}
\description{
Converts a fitted model object into a \code{brms} prior specification
suitable for \code{\link{et_fit}}.  The coefficient estimates (or
importance weights for \pkg{ranger}) from the regularized or standard fit are used as
informative prior means, so the Bayesian model starts close to the
regularized or standard solution while remaining open to data-driven revision.
}
\details{
For \code{ranger} models, signed coefficients are not available.  Priors
are centred at zero (direction unknown) and the prior SD for each predictor
is set to \code{multiplier * importance_normalised}, where importance is
normalised to the \code{[min_sd, 1]} interval.  Only variables with
positive permutation importance are included.
}
\examples{
fit_lm <- lm(mpg ~ wt + hp + cyl, data = mtcars)
ps <- extract_priors(fit_lm, multiplier = 2, min_sd = 0.1)
print(ps)
}
