Skip to contents

Fits a structural equation model to the genetic covariance structure estimated by ldsc.

Usage

usermodel(
  covstruc,
  estimation = "DWLS",
  model = "",
  CFIcalc = TRUE,
  std.lv = FALSE,
  imp_cov = FALSE,
  fix_resid = TRUE,
  toler = NULL,
  Q_Factor = FALSE
)

Arguments

covstruc

Output from ldsc

estimation

Estimation method: "DWLS" (default) or "ML"

model

lavaan-style model syntax string

CFIcalc

Compute CFI (default TRUE; FALSE skips null model fitting)

std.lv

Standardize latent variables (default FALSE)

imp_cov

Return model-implied covariance matrix (default FALSE)

fix_resid

Fix residual variances to be positive (default TRUE)

toler

Gradient norm tolerance for L-BFGS optimizer (default NULL = 1e-6)

Q_Factor

Compute Q factor heterogeneity statistic (default FALSE)

Value

A list with components:

results

Data frame of parameter estimates

modelfit

Data frame of fit indices (chisq, df, p_chisq, AIC, CFI, SRMR)

converged

Logical indicating convergence

implied_cov

Model-implied covariance matrix (if imp_cov=TRUE)

Q_Factor

Q factor results (if Q_Factor=TRUE)

Examples

# Synthetic 3-trait covariance structure (normally from `ldsc()`).
covstruc <- list(
  S = matrix(c(0.60, 0.42, 0.35,
               0.42, 0.50, 0.30,
               0.35, 0.30, 0.40), 3, 3,
             dimnames = list(c("V1", "V2", "V3"), c("V1", "V2", "V3"))),
  V = diag(6) * 0.001,
  I = diag(3),
  N = c(1e5, 1e5, 1e5),
  m = 1e6
)
um <- usermodel(
  covstruc,
  model = "F1 =~ NA*V1 + V2 + V3\nF1 ~~ 1*F1\nV1 ~~ V1\nV2 ~~ V2\nV3 ~~ V3"
)
um$results
#>   lhs op rhs  est
#> 1  F1 =~  V1 0.70
#> 2  F1 =~  V2 0.60
#> 3  F1 =~  V3 0.50
#> 4  V1 ~~  V1 0.11
#> 5  V2 ~~  V2 0.14
#> 6  V3 ~~  V3 0.15
um$modelfit
#>          chisq chisq_df p_chisq AIC         SRMR CFI
#> 1 3.068317e-16        0       1  12 4.759581e-10   1