lavaan_extract {lavaanExtra}R Documentation

Extract relevant indices from lavaan model based on specified operator

Description

Extract relevant indices from lavaan model through lavaan::parameterEstimates and lavaan::standardizedsolution.

Usage

lavaan_extract(
  fit,
  operator = NULL,
  lhs_name = "Left-Hand Side",
  rhs_name = "Right-Hand Side",
  underscores_to_symbol = "→",
  diag = NULL,
  nice_table = FALSE,
  ...
)

Arguments

fit

lavaan fit object to extract fit indices from

operator

Which operator to subselect with.

lhs_name

Name of first column, referring to the left-hand side expression (lhs).

rhs_name

Name of first column, referring to the right-hand side expression (rhs).

underscores_to_symbol

Character to convert underscores to arrows in the first column, like for indirect effects. Default to the right arrow symbol, but can be set to NULL or "_", or to any other desired symbol. It is also possible to provide a vector of replacements if they they are not all the same.

diag

When extracting covariances (⁠~~⁠), whether to include or exclude diagonal values (one of "exclude" or "include").

nice_table

Logical, whether to print the table as a rempsyc::nice_table as well as print the reference values at the bottom of the table.

...

Arguments to be passed to rempsyc::nice_table

Value

A dataframe, including the indirect effect ("lhs"), corresponding paths ("rhs"), standardized regression coefficient ("std.all"), corresponding p-value, as well as the unstandardized regression coefficient ("est") and its confidence interval ("ci.lower", "ci.upper").

Examples


x <- paste0("x", 1:9)
(latent <- list(
  visual = x[1:3],
  textual = x[4:6],
  speed = x[7:9]
))

(mediation <- list(
  speed = "visual",
  textual = "visual",
  visual = c("ageyr", "grade")
))

(indirect <- list(
  IV = c("ageyr", "grade"),
  M = "visual",
  DV = c("speed", "textual")
))

HS.model <- write_lavaan(mediation,
  indirect = indirect,
  latent = latent, label = TRUE
)
cat(HS.model)

library(lavaan)
fit <- sem(HS.model, data = HolzingerSwineford1939)
lavaan_extract(fit, lhs_name = "Indirect Effect", operator = ":=")


[Package lavaanExtra version 0.2.1 Index]