Format CFA/SEM objects from the lavaan package (Rosseel, 2012; Merkle and Rosseel 2018).

# S3 method for lavaan
model_parameters(
  model,
  ci = 0.95,
  standardize = FALSE,
  component = c("regression", "correlation", "loading", "defined"),
  keep = NULL,
  drop = NULL,
  parameters = keep,
  verbose = TRUE,
  ...
)

Arguments

model

CFA or SEM created by the lavaan::cfa or lavaan::sem functions.

ci

Confidence Interval (CI) level. Default to 0.95 (95%).

standardize

Return standardized parameters (standardized coefficients). Can be TRUE (or "all" or "std.all") for standardized estimates based on both the variances of observed and latent variables; "latent" (or "std.lv") for standardized estimates based on the variances of the latent variables only; or "no_exogenous" (or "std.nox") for standardized estimates based on both the variances of observed and latent variables, but not the variances of exogenous covariates. See lavaan::standardizedsolution for details.

component

What type of links to return. Can be "all" or some of c("regression", "correlation", "loading", "variance", "mean").

keep

Character containing a regular expression pattern that describes the parameters that should be included in the returned data frame (for keep), resp. parameters to exclude (drop). keep may also be a named list of regular expressions. All non-matching parameters will be removed from the output. If keep is a character vector, every parameter name in the "Parameter" column that matches the regular expression in parameters will be selected from the returned data frame (and vice versa, all parameter names matching drop will be excluded). Furthermore, if keep has more than one element, these will be merged with an OR operator into a regular expression pattern like this: "(one|two|three)". If keep is a named list of regular expression patterns, the names of the list-element should equal the column name where selection should be applied. This is useful for model objects where model_parameters() returns multiple columns with parameter components, like in model_parameters.lavaan. Note that the regular expression pattern should match the parameter names as they are stored in the returned data frame, which can be different from how they are printed. Inspect the $Parameter column of the parameters table to get the exact parameter names.

drop

Character containing a regular expression pattern that describes the parameters that should be included in the returned data frame (for keep), resp. parameters to exclude (drop). keep may also be a named list of regular expressions. All non-matching parameters will be removed from the output. If keep is a character vector, every parameter name in the "Parameter" column that matches the regular expression in parameters will be selected from the returned data frame (and vice versa, all parameter names matching drop will be excluded). Furthermore, if keep has more than one element, these will be merged with an OR operator into a regular expression pattern like this: "(one|two|three)". If keep is a named list of regular expression patterns, the names of the list-element should equal the column name where selection should be applied. This is useful for model objects where model_parameters() returns multiple columns with parameter components, like in model_parameters.lavaan. Note that the regular expression pattern should match the parameter names as they are stored in the returned data frame, which can be different from how they are printed. Inspect the $Parameter column of the parameters table to get the exact parameter names.

parameters

Deprecated, alias for keep.

verbose

Toggle warnings and messages.

...

Arguments passed to or from other methods.

Value

A data frame of indices related to the model's parameters.

Note

There is also a plot()-method implemented in the see-package.

References

  • Rosseel Y (2012). lavaan: An R Package for Structural Equation Modeling. Journal of Statistical Software, 48(2), 1-36.

  • Merkle EC , Rosseel Y (2018). blavaan: Bayesian Structural Equation Models via Parameter Expansion. Journal of Statistical Software, 85(4), 1-30. http://www.jstatsoft.org/v85/i04/

Examples

library(parameters)

# lavaan -------------------------------------
if (require("lavaan", quietly = TRUE)) {

  # Confirmatory Factor Analysis (CFA) ---------

  structure <- " visual  =~ x1 + x2 + x3
                 textual =~ x4 + x5 + x6
                 speed   =~ x7 + x8 + x9 "
  model <- lavaan::cfa(structure, data = HolzingerSwineford1939)
  model_parameters(model)
  model_parameters(model, standardize = TRUE)

  # filter parameters
  model_parameters(
    model,
    parameters = list(
      To = "^(?!visual)",
      From = "^(?!(x7|x8))"
    )
  )

  # Structural Equation Model (SEM) ------------

  structure <- "
    # latent variable definitions
      ind60 =~ x1 + x2 + x3
      dem60 =~ y1 + a*y2 + b*y3 + c*y4
      dem65 =~ y5 + a*y6 + b*y7 + c*y8
    # regressions
      dem60 ~ ind60
      dem65 ~ ind60 + dem60
    # residual correlations
      y1 ~~ y5
      y2 ~~ y4 + y6
      y3 ~~ y7
      y4 ~~ y8
      y6 ~~ y8
  "
  model <- lavaan::sem(structure, data = PoliticalDemocracy)
  model_parameters(model)
  model_parameters(model, standardize = TRUE)
}
#> # Loading 
#> 
#> Link            | Coefficient |   SE |       95% CI |     z |      p
#> --------------------------------------------------------------------
#> ind60 =~ x1     |        0.92 | 0.02 | [0.88, 0.97] | 40.08 | < .001
#> ind60 =~ x2     |        0.97 | 0.02 | [0.94, 1.01] | 59.14 | < .001
#> ind60 =~ x3     |        0.87 | 0.03 | [0.81, 0.93] | 28.09 | < .001
#> dem60 =~ y1     |        0.85 | 0.04 | [0.77, 0.93] | 20.92 | < .001
#> dem60 =~ y2 (a) |        0.69 | 0.06 | [0.57, 0.81] | 11.58 | < .001
#> dem60 =~ y3 (b) |        0.76 | 0.05 | [0.66, 0.86] | 14.70 | < .001
#> dem60 =~ y4 (c) |        0.84 | 0.04 | [0.76, 0.92] | 20.11 | < .001
#> dem65 =~ y5     |        0.82 | 0.04 | [0.73, 0.90] | 18.52 | < .001
#> dem65 =~ y6 (a) |        0.75 | 0.05 | [0.65, 0.86] | 14.01 | < .001
#> dem65 =~ y7 (b) |        0.80 | 0.05 | [0.71, 0.89] | 17.40 | < .001
#> dem65 =~ y8 (c) |        0.83 | 0.04 | [0.75, 0.91] | 19.79 | < .001
#> 
#> # Regression 
#> 
#> Link          | Coefficient |   SE |       95% CI |     z |      p
#> ------------------------------------------------------------------
#> dem60 ~ ind60 |        0.45 | 0.10 | [0.25, 0.65] |  4.33 | < .001
#> dem65 ~ ind60 |        0.19 | 0.07 | [0.05, 0.33] |  2.64 | 0.008 
#> dem65 ~ dem60 |        0.88 | 0.05 | [0.78, 0.98] | 17.24 | < .001
#> 
#> # Correlation 
#> 
#> Link     | Coefficient |   SE |        95% CI |    z |      p
#> -------------------------------------------------------------
#> y1 ~~ y5 |        0.28 | 0.14 | [ 0.00, 0.56] | 1.97 | 0.049 
#> y2 ~~ y4 |        0.29 | 0.11 | [ 0.07, 0.52] | 2.55 | 0.011 
#> y2 ~~ y6 |        0.36 | 0.10 | [ 0.17, 0.54] | 3.71 | < .001
#> y3 ~~ y7 |        0.17 | 0.13 | [-0.09, 0.43] | 1.26 | 0.208 
#> y4 ~~ y8 |        0.11 | 0.13 | [-0.14, 0.36] | 0.86 | 0.388 
#> y6 ~~ y8 |        0.34 | 0.11 | [ 0.12, 0.55] | 3.08 | 0.002