Dear Lavaan users,
I attached the Lavaan.csv data file for this model with 200 samples. This is my code:
library(lavaan)
Table <- read.csv("Lavaan.csv",header = TRUE,sep = ",",dec = ".")
M<-as.matrix(Table)
#Run model with continuous variables
model <- '
y1 =~ x1
y2 =~ x2
y3 =~ x3 + x4 + x5
y4 =~ x6 + x7 + x8
y5 =~ x9
y6 =~ x10 + x11
# regressions
y1 ~ y3 + y5
y3 ~ y2 + y4 + y5 + y6
y2 ~ y6
y4 ~ y6
#Correlation
y2 ~~ y4
y2 ~~ y5
y4 ~~ y5
'
fit <- sem(model,sample.nobs = 200,estimator = "DWLS",data=M,std.lv=TRUE)
fitMeasures(fit,c("CFI","TLI","RMSEA","GFI","NFI","SRMR"))
> fit <- sem(model,sample.nobs = 200,estimator = "DWLS",data=M,std.lv=TRUE)
> fitMeasures(fit,c("CFI","TLI","RMSEA","GFI","NFI","SRMR"))
cfi tli rmsea gfi nfi srmr
1.000 1.011 0.000 0.990 0.978 0.056
#Run model with categorical variables
#Define ordered variables
M<- data.frame(M)
M$x1 <- ordered(M$x1,levels = c("1","2","3","4","5"))
M$x2 <- ordered(M$x2,levels = c("1","2","3","4","5"))
M$x3 <- ordered(M$x3,levels = c("1","2","3","4","5"))
M$x4 <- ordered(M$x4,levels = c("1","2","3","4","5"))
M$x5 <- ordered(M$x5,levels = c("1","2","3","4","5"))
M$x6 <- ordered(M$x6,levels = c("1","2","3","4","5"))
M$x7 <- ordered(M$x7,levels = c("1","2","3","4","5"))
M$x8 <- ordered(M$x8,levels = c("1","2","3","4","5"))
M$x9 <- ordered(M$x9,levels = c("1","2","3","4","5"))
M$x10 <- ordered(M$x10,levels = c("1","2","3","4","5"))
M$x11 <- ordered(M$x11,levels = c("1","2","3","4","5"))
fit <- sem(model,sample.nobs = 200,estimator = "DWLS",data=M,std.lv=TRUE)
> fit <- sem(model,sample.nobs = 200,estimator = "DWLS",data=M,std.lv=TRUE)
Warning messages:
1: In lav_samplestats_from_data(lavdata = lavdata, missing = lavoptions$missing, :
lavaan WARNING: 54 bivariate tables have empty cells; to see them, use:
lavInspect(fit, "zero.cell.tables")
2: In lav_model_vcov(lavmodel = lavmodel, lavsamplestats = lavsamplestats, :
lavaan WARNING: could not compute standard errors!
lavaan NOTE: this may be a symptom that the model is not identified.
3: In lav_object_post_check(object) :
lavaan WARNING: covariance matrix of latent variables
is not positive definite;
use inspect(fit,"cov.lv") to investigate.
> fit <- sem(model,sample.nobs = 200,estimator = "WLS",data=M,std.lv=TRUE)
> fitMeasures(fit,c("CFI","TLI","RMSEA","GFI","NFI","SRMR"))
cfi tli rmsea gfi nfi srmr
0.670 0.481 0.107 0.904 0.613 0.215