I will be thankful if anyone could diagnose the problem in my code and the reason I'm getting error and how to solve the problem. Many thanks :)
note: many of these variables are highly-correlated (e.g., .8 or above), some variables have outliers and became non-normal; scales of these variables are different, but Rex Kline in his book said not to used z-score standardized data as input to CFA or SEM models, so I just used covariance matrix which is already a form of standardization??
library(lavaan)
data<- read.csv("mydata.csv", header=TRUE) #original data with all 22 variables;
cov.data<- cov(data)
#model with 22 variables, noted as V:
my.model<- 'group2=~ v1 + v2 + v3 +v4 + v5 + v6 + v7
group3=~ v8 + v9 + v10 + v11
group4=~ v12 + v13 + v14 + v15 + v16 + v17 +v18
group5=~ v19 + v20 + v21 + v22'
fit <- sem(my.model,
sample.cov = cov.data,
sample.nobs = 210)
summary(fit, standardized = TRUE)
Results:
Warning messages:
1: In lav_model_vcov(lavmodel = lavmodel, lavsamplestats = lavsamplestats, :
lavaan WARNING:
Could not compute standard errors! The information matrix could
not be inverted. This may be a symptom that the model is not
identified.
2: In lav_object_post_check(object) :
lavaan WARNING: some estimated ov variances are negative
3: In lavaan::lavaan(model = lex.model, sample.cov = cov.lex, sample.nobs = 210, :
lavaan WARNING: not all elements of the gradient are (near) zero;
the optimizer may not have found a local solution;
use lavInspect(fit, "optim.gradient") to investigate
****************************************************************************************
#change sem() to cfa():
fit1 <- cfa(model= my.model, sample.cov= cov.data, sample.nobs= 210)
results: the exact same warning messages as above