fitted: Model-Implied Moments for INLAvaan Models

fittedR Documentation

Model-Implied Moments for INLAvaan Models

Description

Extract the model-implied (fitted) sample statistics from a fitted INLAvaan model. As in lavaan and blavaan, the moments are the model-implied covariance matrix (and mean vector, when a mean structure is present) evaluated at the parameter estimates – here the posterior means.

Usage

## S4 method for signature 'INLAvaan'
fitted(object, type = "moments", labels = TRUE, ..., per_cluster = FALSE)

## S4 method for signature 'INLAvaan'
fitted.values(
  object,
  type = "moments",
  labels = TRUE,
  ...,
  per_cluster = FALSE
)

Arguments

object

An object of class INLAvaan.

type

Character. "moments" (default) returns the model-implied variance-covariance matrix and, when relevant, the mean vector (plus thresholds for ordinal data). "casewise" (aliases "obs", "ov") returns the model-predicted values for each observation.

labels

Logical. Attach variable names to the output. Default TRUE.

...

Currently unused.

per_cluster

Logical. For a random-slope model, return the moments of each cluster instead of their average. Default FALSE.

Details

This delegates to lavaan's own fitted() machinery, so the return structure matches lavaan exactly. Because INLAvaan stores the posterior means as the point estimates of the fitted object, the implied moments are the posterior-mean model-implied moments (mirroring blavaan).

For a model with random slopes (lavaan's rv()), the moments are averaged over the covariates and include the mean and the variance of each slope. With per_cluster = TRUE, each cluster gets the expected cluster mean and within-cluster covariance (divisor n_j) of its outcomes and covariates at its own covariate values, and the mean also holds the expected values of any between-only outcomes. This is not available for a slope on a latent or split covariate. type = "casewise" gives the outcomes' means given the covariates (closed-form route only).

Value

For type = "moments", a list (or list of lists, for multiple groups) with elements such as cov, mean, and th. For type = "casewise", a numeric matrix of predicted observed-variable values. With per_cluster = TRUE, a list with one element per cluster, each holding cov and mean.

See Also

predict(), coef(), fitMeasures()

Examples


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)

# Model-implied covariance matrix (posterior means)
fitted(fit)

# Casewise model-predicted observed values
head(fitted(fit, type = "ov"))



INLAvaan documentation built on Nov. 13, 2026, 5:08 p.m.