write_lavaan {lavaanExtra}R Documentation

Vector-based lavaan syntax interpreter

Description

Vector-based lavaan syntax interpreter.

Usage

write_lavaan(
  mediation = NULL,
  regression = NULL,
  covariance = NULL,
  indirect = NULL,
  latent = NULL,
  intercept = NULL,
  threshold = NULL,
  constraint.equal = NULL,
  constraint.smaller = NULL,
  constraint.larger = NULL,
  custom = NULL,
  label = FALSE,
  use.letters = FALSE
)

Arguments

mediation

Mediation indicators (~ symbol: "is regressed on"). Differs from argument regression because path names can be optionally specified automatically with argument label.

regression

Regression indicators (~ symbol: "is regressed on").

covariance

(Residual) (co)variance indicators (⁠~~⁠ symbol: "is correlated with").

indirect

Indirect effect indicators (⁠:=⁠ symbol: "indirect effect defined as"). If a named list is provided, with names "IV" (independent variables), "M" (mediator), and "DV" (dependent variables), write_lavaan attempts to write indirect effects automatically. In this case, the mediation argument must be specified too.

latent

Latent variable indicators (⁠=~⁠ symbol: "is measured by").

intercept

Intercept indicators (~ 1 symbol: "intercept").

threshold

Threshold indicators (| symbol: "threshold").

constraint.equal

Equality indicators (== symbol).

constraint.smaller

Smaller than indicators (< symbol).

constraint.larger

Greater than indicators (> symbol).

custom

Custom specifications. Takes a single string just like regular lavaan syntax would. Always added at the end of the model.

label

Logical, whether to display path names for the mediation argument.

use.letters

Logical, for the labels, whether to use letters instead of the variable names.

Value

A character string, representing the specified lavaan model.

See Also

The corresponding vignette: https://lavaanextra.remi-theriault.com/articles/write_lavaan.html

Examples


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

HS.model <- write_lavaan(latent = latent)
cat(HS.model)

library(lavaan)
fit <- lavaan(HS.model,
  data = HolzingerSwineford1939,
  auto.var = TRUE, auto.fix.first = TRUE,
  auto.cov.lv.x = TRUE
)
summary(fit, fit.measures = TRUE)


[Package lavaanExtra version 0.2.1 Index]