residuals: Model Residuals for INLAvaan Models

residualsR Documentation

Model Residuals for INLAvaan Models

Description

Extract the difference between the observed and model-implied (fitted) sample statistics from a fitted INLAvaan model. As in lavaan and blavaan, residuals are computed at the parameter estimates – here the posterior means – not as a posterior distribution over residuals.

Usage

## S4 method for signature 'INLAvaan'
residuals(object, type = "raw", labels = TRUE, ...)

## S4 method for signature 'INLAvaan'
resid(object, type = "raw", ...)

Arguments

object

An object of class INLAvaan.

type

Character. "raw" (default) returns the unscaled difference between the observed and model-implied covariance matrix (and mean vector, when a mean structure is present). "cor" (or "cor.bollen") first rescales both matrices to a correlation matrix. "cor.bentler" rescales both by the observed variances (the basis of the SRMR). "normalized" and "standardized" divide the raw residuals by their asymptotic standard errors. "casewise" (aliases "case", "obs", "observations", "ov") returns observed-minus-fitted values for each observation.

labels

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

...

Currently unused.

Details

This delegates to lavaan's own residuals() machinery, so the return structure matches lavaan exactly. Because INLAvaan stores the posterior means as the point estimates of the fitted object, the residuals are the observed statistics minus the posterior-mean model-implied statistics (mirroring blavaan, which likewise inherits lavaan's residuals() without overriding it).

Value

For moment-based types, a list with elements type, cov, and (when relevant) mean. For type = "casewise", a numeric matrix of observed-minus-fitted values.

See Also

fitted(), predict(), 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)

# Raw residual covariance matrix (posterior means)
residuals(fit)

# SRMR-basis residuals
residuals(fit, type = "cor.bentler")

# Casewise observed-minus-fitted values
head(residuals(fit, type = "casewise"))



INLAvaan documentation built on Oct. 2, 2026, 1:07 a.m.