% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/inlavaan.R
\name{acfa}
\alias{acfa}
\title{Fit an Approximate Bayesian Confirmatory Factor Analysis Model}
\usage{
acfa(
  model,
  data,
  dp = priors_for(),
  test = "standard",
  vb_correction = TRUE,
  marginal_method = c("skewnorm", "asymgaus", "marggaus", "sampling"),
  marginal_correction = c("shortcut", "shortcut_fd", "hessian", "none"),
  nsamp = 1000,
  samp_copula = TRUE,
  sn_fit_ngrid = 21,
  sn_fit_logthresh = -6,
  sn_fit_temp = 1,
  sn_fit_sample = TRUE,
  control = list(),
  verbose = TRUE,
  debug = FALSE,
  add_priors = TRUE,
  optim_method = c("nlminb", "ucminf", "optim"),
  numerical_grad = FALSE,
  cores = NULL,
  ...
)
}
\arguments{
\item{model}{A description of the user-specified model. Typically, the model
    is described using the lavaan model syntax. See 
    \code{\link[lavaan]{model.syntax}} for more information. Alternatively, a
    parameter table (e.g., the output of the \code{lavParTable()} function) is also
    accepted.}

\item{data}{An optional data frame containing the observed variables used in
    the model. If some variables are declared as ordered factors, lavaan will
    treat them as ordinal variables.}

\item{dp}{Default prior distributions for the different types of model
parameters; a named character vector as returned by \code{\link[=priors_for]{priors_for()}}.}

\item{test}{Character indicating which post-estimation quantities to
compute. Defaults to "standard": posterior fit indices (PPP and DIC),
plus -- for models supported by the casewise machinery and fitted with
a mean structure -- the WAIC (reusing the fit's posterior draws, when
\code{nsamp >= 100}) and a full leave-one-out cross-validation whenever its
predicted serial cost is within a 10-second budget; both are stored
with the fit (see \code{\link[=loo]{loo()}} and \code{\link[=waic]{waic()}}). "none" skips all of these.
Include "loo" (e.g. \code{test = c("standard", "loo")}, or \code{test = "loo"}
alone) to force the full LOO regardless of the budget.}

\item{vb_correction}{Logical indicating whether to apply a variational Bayes
correction for the posterior mean vector of estimates. Defaults to \code{TRUE}.}

\item{marginal_method}{The method for approximating the marginal posterior
distributions. Options include \code{"skewnorm"} (skew-normal), \code{"asymgaus"}
(two-piece asymmetric Gaussian), \code{"marggaus"} (marginalising the Laplace
approximation), and \code{"sampling"} (sampling from the joint Laplace
approximation).}

\item{marginal_correction}{Which type of correction to use when fitting the
skew-normal or two-piece Gaussian marginals. \code{"hessian"} computes the full
\code{"shortcut"} (default) computes only diagonals via central differences
(full z-trace plus Schur complement correction), \code{"shortcut_fd"} is the
same formula using forward differences (roughly half the cost, less
accurate), \code{"hessian"} computes the full Hessian-based correction (slow),
and \code{"none"} (or \code{FALSE}) applies no correction.}

\item{nsamp}{The number of samples to draw for all sampling-based approaches
(including posterior sampling for model fit indices).}

\item{samp_copula}{Logical. When \code{TRUE} (default), posterior samples are
drawn using the copula method with the fitted marginals (e.g. skew-normal
or asymmetric Gaussian), with NORTA correlation adjustment. When \code{FALSE},
samples are drawn from the Gaussian (Laplace) approximation. Only re}

\item{sn_fit_ngrid}{Number of grid points to lay out per dimension when
fitting the skew-normal marginals. A finer grid gives a better fit at the
cost of more joint-log-posterior evaluations. Defaults to \code{21}.}

\item{sn_fit_logthresh}{The log-threshold for fitting the skew-normal. Points
with log-posterior drop below this threshold (relative to the maximum) will
be excluded from the fit. Defaults to \code{-6}.}

\item{sn_fit_temp}{Temperature parameter for fitting the skew-normal.
Defaults to \code{1} (weights are the density values themselves). If \code{NA}, the
temperature is included as an additional optimisation parameter.}

\item{sn_fit_sample}{Logical. When \code{TRUE} (default), a parametric skew-normal
is fitted to the posterior samples for covariance and defined parameters.
When \code{FALSE}, these are summarised using kernel density estimation instead.}

\item{control}{A list of control parameters for the optimiser.}

\item{verbose}{Logical indicating whether to print progress messages.}

\item{debug}{Logical indicating whether to return debug information.}

\item{add_priors}{Logical indicating whether to include prior densities in
the posterior computation.}

\item{optim_method}{The optimisation method to use for finding the posterior
mode. Options include \code{"nlminb"} (default), \code{"ucminf"}, and \code{"optim"}
(BFGS).}

\item{numerical_grad}{Logical indicating whether to use numerical gradients
for the optimisation. Defaults to \code{FALSE} to use analytical gradients.}

\item{cores}{Integer or \code{NULL}. Number of cores for parallel marginal
fitting. When \code{NULL} (default), serial execution is used unless the number
of free parameters exceeds 120, in which case parallelisation is enabled
automatically using all available physical cores. Set to \code{1L} to force
serial execution. If \code{cores > 1}, marginal fits are distributed across
cores using \code{\link[parallel:mclapply]{parallel::mclapply()}} (fork-based; no parallelism on Windows).}

\item{...}{Additional arguments to be passed to the \link[lavaan:lavaan]{lavaan} model fitting
function.}
}
\value{
An S4 object of class \code{INLAvaan} which is a subclass of the
\link[lavaan:lavaan-class]{lavaan} class.
}
\description{
Fit an Approximate Bayesian Confirmatory Factor Analysis Model
}
\details{
The \code{\link[=acfa]{acfa()}} function is a wrapper for the more general \code{\link[=inlavaan]{inlavaan()}}
function, using the following default arguments:
\itemize{
\item \code{int.ov.free = TRUE}
\item \code{int.lv.free = FALSE}
\item \code{auto.fix.first = TRUE} (unless \code{std.lv = TRUE})
\item \code{auto.fix.single = TRUE}
\item \code{auto.var = TRUE}
\item \code{auto.cov.lv.x = TRUE}
\item \code{auto.efa = TRUE}
\item \code{auto.th = TRUE}
\item \code{auto.delta = TRUE}
\item \code{auto.cov.y = TRUE}
}

For further information regarding these arguments, please refer to the
\code{\link[lavaan:lavOptions]{lavaan::lavOptions()}} documentation.
}
\examples{
# The famous Holzinger and Swineford (1939) example
HS.model <- "
  visual  =~ x1 + x2 + x3
  textual =~ x4 + x5 + x6
  speed   =~ x7 + x8 + x9
"
utils::data("HolzingerSwineford1939", package = "lavaan")

# Fit a CFA model with standardised latent variables
fit <- acfa(HS.model, data = HolzingerSwineford1939, std.lv = TRUE, nsamp = 100)
summary(fit)
}
\seealso{
Typically, users will interact with the specific latent variable
model functions instead, including \code{\link[=acfa]{acfa()}}, \code{\link[=asem]{asem()}}, and \code{\link[=agrowth]{agrowth()}}.
}
