Skip to contents

Generates lavaan-style model syntax from a factor loading matrix.

Usage

write.model(
  Loadings,
  S_LD,
  cutoff,
  fix_resid = TRUE,
  bifactor = FALSE,
  mustload = FALSE,
  common = FALSE
)

Arguments

Loadings

Matrix of factor loadings (rows=phenotypes, cols=factors)

S_LD

Not used (kept for R GenomicSEM compatibility)

cutoff

Minimum absolute loading to include (default 0.3)

fix_resid

Add positivity constraints on residual variances (default TRUE)

bifactor

Generate bifactor model (default FALSE)

mustload

Require all variables to load on at least one factor (default FALSE)

common

Include a common factor (default FALSE)

Value

Character string of lavaan model syntax

Examples

# Build a 1-factor loadings matrix and generate lavaan syntax.
loadings <- matrix(c(0.80, 0.70, 0.60), nrow = 3, ncol = 1,
                   dimnames = list(c("V1", "V2", "V3"), "F1"))
cat(write.model(loadings, S_LD = NULL, cutoff = 0.3))
#> F1 =~ NA*V1 + V2 + V3
#> F1 ~~ 1*F1
#> V1 ~~ aaaa*V1
#> aaaa > 0.0001
#> V2 ~~ aaab*V2
#> aaab > 0.0001
#> V3 ~~ aaac*V3
#> aaac > 0.0001