
This function can be used to easily generate input matrices for lvnet based on a lavaan model.
lav2lvnet(model, data, std.lv = TRUE, lavaanifyOps = list(auto = TRUE, std.lv = std.lv))
Lavaan model syntax
The dataset. Only used to extract order of variables names from the columnnames.
Should the model be identified by constraining latent variable variance to 1. Defaults to TRUE
unlike lavaan! This is because the starting values work better for this identification.
A list with other options sent to lavaanify
A list with the model matrices for lambda
, psi
, theta
and beta
# NOT RUN {
library("lavaan")
# Load dataset:
data(HolzingerSwineford1939)
Data <- HolzingerSwineford1939[,7:15]
# lavaan model
HS.model <- '
visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
# fit via lavaan:
lavFit <- cfa(HS.model, HolzingerSwineford1939[7:15],std.lv=TRUE)
# Fit via lvnet:
mod <- lav2lvnet(HS.model, HolzingerSwineford1939[7:15])
lvnetFit <- lvnet(Data, lambda = mod$lambda, psi = mod$psi)
# Compare:
Compare <- data.frame(
lvnet = round(unlist(lvnetFit$fitMeasures)[c("npar","df","chisq","fmin","aic","bic",
"rmsea","cfi","tli","nfi","logl")],3),
lavaan = round(fitMeasures(lavFit)[c("npar","df","chisq","fmin","aic","bic","rmsea",
"cfi","tli","nfi","logl")],3))
Compare
# }
Run the code above in your browser using DataLab