Fit an Approximate Bayesian Confirmatory Factor Analysis Model
Usage
acfa(
model,
data,
dp = priors_for(),
marginal_method = c("skewnorm", "asymgaus", "marggaus", "sampling"),
nsamp = 500,
test = "standard",
marginal_correction = c("shortcut", "hessian", "none"),
sn_fit_logthresh = -6,
sn_fit_temp = NA,
control = list(),
verbose = TRUE,
debug = FALSE,
add_priors = TRUE,
optim_method = c("nlminb", "ucminf", "optim"),
numerical_grad = FALSE,
...
)Arguments
- model
A description of the user-specified model. Typically, the model is described using the lavaan model syntax. See
model.syntaxfor more information. Alternatively, a parameter table (eg. the output of thelavParTable()function) is also accepted.- 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.
- dp
Default prior distributions on different types of parameters, typically the result of a call to
dpriors(). See thedpriors()help file for more information.- marginal_method
The method for approximating the marginal posterior distributions. Options include
"skewnorm"(skew normal),"asymgaus"(two-piece asymmetric Gaussian),"marggaus"(marginalising the Laplace approximation), and"sampling"(sampling from the joint Laplace approximation).- nsamp
The number of samples to draw for all sampling-based approaches (including posterior sampling for model fit indices).
- test
Character indicating whether to compute posterior fit indices. Defaults to "standard". Change to "none" to skip these computations.
- marginal_correction
Which type of correction to use when fitting the skew normal or two-piece Gaussian marginals.
"hessian"computes the full Hessian-based correction (slow),"shortcut"(default) computes only diagonals, and"none"(orFALSE) applies no correction.- 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
-6.- sn_fit_temp
Temperature parameter for fitting the skew normal. If
NA, the temperature will be included in the optimisation during the skew normal fit.- control
A list of control parameters for the optimiser.
- verbose
Logical indicating whether to print progress messages.
- debug
Logical indicating whether to return debug information.
- add_priors
Logical indicating whether to include prior densities in the posterior computation.
- optim_method
The optimisation method to use for finding the posterior mode. Options include
"nlminb"(default),"ucminf", and"optim"(BFGS).- numerical_grad
Logical indicating whether to use numerical gradients for the optimisation.
- ...
Additional arguments to be passed to the lavaan::lavaan model fitting function.
Value
An S4 object of class INLAvaan which is a subclass of the
lavaan::lavaan class.
Details
The acfa() function is a wrapper for the more general inlavaan()
function, using the following default arguments:
int.ov.free = TRUEint.lv.free = FALSEauto.fix.first = TRUE(unlessstd.lv = TRUE)auto.fix.single = TRUEauto.var = TRUEauto.cov.lv.x = TRUEauto.efa = TRUEauto.th = TRUEauto.delta = TRUEauto.cov.y = TRUE
For further information regarding these arguments, please refer to the
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)
#> ℹ Finding posterior mode.
#> ✔ Finding posterior mode. [56ms]
#>
#> ℹ Computing the Hessian.
#> ✔ Computing the Hessian. [144ms]
#>
#> ℹ Performing VB correction.
#> ✔ VB correction; mean |δ| = 0.008σ. [120ms]
#>
#> ⠙ Fitting skew normal to 0/21 marginals.
#> ✔ Fitting skew normal to 21/21 marginals. [649ms]
#>
#> ⠙ Computing ppp and DIC.
#> ✔ Computing ppp and DIC. [92ms]
#>
summary(fit)
#> INLAvaan 0.2.3.9004 ended normally after 56 iterations
#>
#> Estimator BAYES
#> Optimization method NLMINB
#> Number of model parameters 21
#>
#> Number of observations 301
#>
#> Model Test (User Model):
#>
#> Marginal log-likelihood -3830.975
#> PPP (Chi-square) 0.000
#>
#> Information Criteria:
#>
#> Deviance (DIC) 7584.377
#> Effective parameters (pD) 54.358
#>
#> Parameter Estimates:
#>
#> Marginalisation method SKEWNORM
#> VB correction TRUE
#>
#> Latent Variables:
#> Estimate SD 2.5% 97.5% NMAD Prior
#> visual =~
#> x1 0.906 0.083 0.744 1.071 0.011 normal(0,10)
#> x2 0.500 0.081 0.343 0.660 0.001 normal(0,10)
#> x3 0.662 0.078 0.511 0.818 0.005 normal(0,10)
#> textual =~
#> x4 0.999 0.058 0.889 1.116 0.004 normal(0,10)
#> x5 1.114 0.064 0.993 1.244 0.004 normal(0,10)
#> x6 0.927 0.055 0.823 1.038 0.004 normal(0,10)
#> speed =~
#> x7 0.615 0.074 0.758 0.466 0.004 normal(0,10)
#> x8 0.725 0.076 0.987 0.569 0.027 normal(0,10)
#> x9 0.686 0.079 0.538 0.848 0.034 normal(0,10)
#>
#> Covariances:
#> Estimate SD 2.5% 97.5% NMAD Prior
#> visual ~~
#> textual 0.449 0.064 0.319 0.568 0.001 beta(1,1)
#> speed 0.474 0.086 0.302 0.639 0.021 beta(1,1)
#> textual ~~
#> speed 0.280 0.071 0.138 0.415 0.003 beta(1,1)
#>
#> Variances:
#> Estimate SD 2.5% 97.5% NMAD Prior
#> .x1 0.544 0.119 1.395 0.306 0.021 gamma(1,.5)[sd]
#> .x2 1.144 0.106 0.952 1.366 0.001 gamma(1,.5)[sd]
#> .x3 0.846 0.097 1.253 0.665 0.002 gamma(1,.5)[sd]
#> .x4 0.376 0.049 0.477 0.286 0.002 gamma(1,.5)[sd]
#> .x5 0.451 0.059 0.574 0.342 0.002 gamma(1,.5)[sd]
#> .x6 0.361 0.044 0.453 0.279 0.002 gamma(1,.5)[sd]
#> .x7 0.823 0.091 0.661 1.016 0.004 gamma(1,.5)[sd]
#> .x8 0.495 0.092 1.046 0.318 0.050 gamma(1,.5)[sd]
#> .x9 0.542 0.093 1.146 0.344 0.016 gamma(1,.5)[sd]
#> visual 1.000
#> textual 1.000
#> speed 1.000
#>
