% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fit.R
\name{et_fit}
\alias{et_fit}
\title{Fit a Bayesian regression model with informed priors}
\usage{
et_fit(
  formula,
  data,
  priors = NULL,
  chains = 4L,
  iter = 2000L,
  warmup = floor(iter/2),
  cores = min(chains, parallel::detectCores()),
  seed = 42L,
  adapt_delta = 0.95,
  max_treedepth = 12L,
  grouping = NULL,
  eiv = NULL,
  silent = 2L,
  ...
)
}
\arguments{
\item{formula}{An R formula, e.g.\ \code{response ~ .} or
\code{y ~ x1 + x2}.}

\item{data}{A \code{data.frame} with all predictors and the response.}

\item{priors}{An \code{et_prior_spec} object from
\code{\link{extract_priors}}, or a \code{brmsprior} object, or
\code{NULL} for brms defaults.}

\item{chains}{Integer.  Number of MCMC chains (default 4).}

\item{iter}{Integer.  Total iterations per chain, including warmup
(default 2000).}

\item{warmup}{Integer.  Warmup iterations per chain (default
\code{floor(iter / 2)}).}

\item{cores}{Integer.  Parallel cores (default
\code{min(chains, parallel::detectCores())}).}

\item{seed}{Integer.  Random seed for reproducibility (default 42).}

\item{adapt_delta}{Numeric.  Target acceptance probability for HMC
(default 0.95).}

\item{max_treedepth}{Integer.  Maximum tree depth (default 12).}

\item{grouping}{Character.  Name of a column in \code{data} to use for
grouping.  If non-\code{NULL}, one model is fitted per unique group
value and an \code{et_model_list} is returned.}

\item{eiv}{Optional errors-in-variables specification.  A named list /
vector mapping predictor names to either a scalar SD or a vector of
per-row SDs (length \code{nrow(data)}).  For each entry, the formula
term for that predictor is rewritten as \code{brms::me(pred, se_pred)}
(an auxiliary \code{se_<pred>} column is appended to \code{data}), so
the posterior reflects measurement error in the predictor as well as
coefficient uncertainty.  The beta posteriors widen accordingly, which
partially absorbs what ErrorTracer's downstream \code{env_var}
component would otherwise report.  When \code{eiv} is supplied together
with an \code{et_prior_spec} from \code{\link{extract_priors}}, the
informed priors are \emph{dropped} because they target \code{class = "b"}
terms and \code{me()} terms live under \code{class = "bsp"}; brms
defaults are used instead (and a warning is logged).}

\item{silent}{Integer passed to \code{brms::brm()} (default 2, no Stan
output).}

\item{...}{Additional arguments passed to \code{brms::brm()}.}
}
\value{
An \code{et_model} object (or an \code{et_model_list} if
  \code{grouping} is specified).
}
\description{
Wraps \code{brms::brm()} and attaches the prior specification,
training data reference, and configuration for downstream uncertainty
decomposition.  Pass \code{priors} from \code{\link{extract_priors}} to
use regularized-model coefficients as prior means; omit it for
default (weakly informative) priors.
}
\examples{
\donttest{
set.seed(1)
df  <- data.frame(y = rnorm(20), x1 = rnorm(20), x2 = rnorm(20))
ps  <- extract_priors(lm(y ~ x1 + x2, data = df))
fit <- et_fit(y ~ x1 + x2, data = df, priors = ps,
              chains = 1, iter = 500, warmup = 250,
              cores = 1, refresh = 0)
print(fit)
}
}
