Skip to contents

Fit an Approximate Bayesian Confirmatory Factor Analysis Model

Usage

acfa(
  model,
  data,
  dp = blavaan::dpriors(),
  estimator = "ML",
  marginal_method = c("skewnorm", "asymgaus", "marggaus", "sampling"),
  nsamp = 3000,
  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.syntax for more information. Alternatively, a parameter table (eg. the output of the lavParTable() 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 the dpriors() help file for more information.

estimator

The estimator to be used. Currently only "ML" (maximum likelihood) is supported.

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" 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 = TRUE

  • int.lv.free = FALSE

  • auto.fix.first = TRUE (unless std.lv = TRUE)

  • auto.fix.single = TRUE

  • auto.var = TRUE

  • auto.cov.lv.x = TRUE

  • auto.efa = TRUE

  • auto.th = TRUE

  • auto.delta = TRUE

  • auto.cov.y = TRUE

For further information regarding these arguments, please refer to the lavaan::lavOptions() documentation.

See also

Typically, users will interact with the specific latent variable model functions instead, including acfa(), asem(), and agrowth().

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)
#>  Using MVN log-likelihood.
#>  Finding posterior mode.
#>  Finding posterior mode. [140ms]
#> 
#>  Computing the Hessian.
#>  Computing the Hessian. [337ms]
#> 
#>  Performing VB correction.
#>  Performing VB correction. [293ms]
#> 
#>  Using skew normal approximation.
#> ⠙ Fitting skew normal to 0/21 marginals.
#>  Fitting skew normal to 21/21 marginals. [1.6s]
#> 
#> ⠙ Computing ppp and DIC.
#> ⠹ Computing ppp and DIC.
#>  Computing ppp and DIC. [2s]
#> 
summary(fit)
#> INLAvaan 0.2.0.9005 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.969 
#>    PPP (Chi-square)                              0.000 
#> 
#> Information Criteria:
#> 
#>    Deviance (DIC)                             7518.571 
#>    Effective parameters (pD)                    21.411 
#> 
#> Parameter Estimates:
#> 
#>    Marginalisation method                     SKEWNORM
#>    VB correction                                  TRUE
#> 
#> Latent Variables:
#>                    Estimate       SD     2.5%    97.5%      KLD    Prior       
#>   visual =~                                                                    
#>     x1                0.907    0.083    0.746    1.071    0.003    normal(0,10)
#>     x2                0.501    0.081    0.343    0.663    0.003    normal(0,10)
#>     x3                0.663    0.078    0.511    0.818    0.006    normal(0,10)
#>   textual =~                                                                   
#>     x4                0.999    0.058    0.888    1.116    0.021    normal(0,10)
#>     x5                1.112    0.063    0.990    1.238    0.023    normal(0,10)
#>     x6                0.926    0.054    0.820    1.032    0.019    normal(0,10)
#>   speed =~                                                                     
#>     x7                0.617    0.077    0.463    0.766    0.012    normal(0,10)
#>     x8                0.734    0.077    0.587    0.887    0.010    normal(0,10)
#>     x9                0.681    0.079    0.530    0.838    0.058    normal(0,10)
#> 
#> Covariances:
#>                    Estimate       SD     2.5%    97.5%      KLD    Prior       
#>   visual ~~                                                                    
#>     textual           0.449    0.064    0.317    0.568    0.000       beta(1,1)
#>     speed             0.474    0.085    0.298    0.630    0.024       beta(1,1)
#>   textual ~~                                                                   
#>     speed             0.284    0.071    0.141    0.420    0.004       beta(1,1)
#> 
#> Variances:
#>                    Estimate       SD     2.5%    97.5%      KLD    Prior       
#>    .x1                0.558    0.121    0.351    0.825    0.000 gamma(1,.5)[sd]
#>    .x2                1.144    0.107    0.952    1.370    0.002 gamma(1,.5)[sd]
#>    .x3                0.849    0.097    0.676    1.056    0.000 gamma(1,.5)[sd]
#>    .x4                0.378    0.049    0.289    0.481    0.001 gamma(1,.5)[sd]
#>    .x5                0.453    0.059    0.347    0.579    0.000 gamma(1,.5)[sd]
#>    .x6                0.363    0.044    0.283    0.457    0.002 gamma(1,.5)[sd]
#>    .x7                0.825    0.090    0.664    1.017    0.039 gamma(1,.5)[sd]
#>    .x8                0.508    0.093    0.349    0.711    0.033 gamma(1,.5)[sd]
#>    .x9                0.553    0.090    0.398    0.751    0.053 gamma(1,.5)[sd]
#>     visual            1.000                                                    
#>     textual           1.000                                                    
#>     speed             1.000                                                    
#>