% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/method-predict.R
\name{predict}
\alias{predict}
\alias{predict,INLAvaan-method}
\title{Posterior Predictions for INLAvaan Models}
\usage{
\S4method{predict}{INLAvaan}(
  object,
  type = c("lv", "yhat", "ov", "ypred", "ydist", "ymis", "ovmis"),
  newdata = NULL,
  level = 1L,
  nsamp = 1000,
  ymis_only = FALSE,
  summary = FALSE,
  ...
)
}
\arguments{
\item{object}{An object of class \link{INLAvaan}.}

\item{type}{Character string specifying the type of prediction:
\describe{
\item{\code{"lv"}}{(default) Posterior draws of latent variable scores
\eqn{\eta | y, \theta}.}
\item{\code{"yhat"}, \code{"ov"}}{Predicted means for observed variables
\eqn{E(y | \eta, \theta) = \nu + \Lambda \eta}; no residual noise.}
\item{\code{"ypred"}, \code{"ydist"}}{Predicted observed values including
residual noise \eqn{y = \nu + \Lambda \eta + \varepsilon},
\eqn{\varepsilon \sim N(0, \Theta)}.}
\item{\code{"ymis"}, \code{"ovmis"}}{Imputed values for missing
observations, drawn from the conditional distribution
\eqn{y_{mis} | y_{obs}, \theta}.}
}}

\item{newdata}{An optional data frame of new observations. If supplied,
predictions are computed for \code{newdata} rather than the original
training data. Not supported for \code{type = "ymis"}.}

\item{level}{Integer; for \code{type = "lv"} in multilevel models, specifies
whether level 1 or level 2 latent variables are desired (default \code{1L}).}

\item{nsamp}{Integer; number of posterior samples to use for prediction.
Defaults to \code{1000}.}

\item{ymis_only}{Logical; only applies when \code{type = "ymis"}. When
\code{TRUE}, returns only the imputed values as a named numeric vector per
sample (names of the form \code{"varname[rowindex]"}, matching the blavaan
convention). When \code{FALSE} (default), returns the full data matrix with
missing values filled in.}

\item{summary}{Logical. When \code{TRUE}, collapse the posterior draws with
\code{summary()} and return summary statistics (mean, SD, quantiles, mode)
instead of the raw draws -- equivalent to calling
\code{summary(predict(object, ...))} but without materialising the
intermediate draws object. Default \code{FALSE}.}

\item{...}{Currently unused.}
}
\value{
A list of \code{nsamp} posterior draws, each a matrix (or data
frame, for multiple groups) with rows corresponding to cases and columns
to variables or latent factors. When \code{summary = TRUE}, instead
returns a \code{summary.predict.inlavaan_internal} object with the
posterior mean, SD, quantiles, and mode for each case/variable.
}
\description{
Compute posterior predictions from a fitted \code{INLAvaan} model,
including latent variable scores, predicted observed values, and imputed
missing data.
}
\examples{
\donttest{
HS.model <- "
  visual  =~ x1 + x2 + x3
  textual =~ x4 + x5 + x6
  speed   =~ x7 + x8 + x9
"
utils::data("HolzingerSwineford1939", package = "lavaan")
fit <- acfa(HS.model, HolzingerSwineford1939, std.lv = TRUE, nsamp = 100,
            test = "none", verbose = FALSE)

# Posterior latent variable scores
lv_scores <- predict(fit)
head(lv_scores)

# Predicted observed variable means
yhat <- predict(fit, type = "yhat")
head(yhat)

# Point estimates only, skipping the manual summary() step
predict(fit, type = "yhat", summary = TRUE)
}

}
\seealso{
\code{\link[=sampling]{sampling()}}, \code{\link[=simulate]{simulate()}}, \code{\link[=summary]{summary()}}
}
