I want to fit a CFA with one latent variable and three categorical indicators. This model is just-identified (DF=0). My indicators have 5 categories and are not normally distributed, so I should use DWLS estimator. My sample needs to be weighted, so I use the lavaan.survey package and include weights.
First of all, I tried fitting this model with lavaan command, like was done in the tutorial " package'lavaan.survey' ", but I got an error message, indicating that something might be going wrong.
Second, I tried fitting this model using sem command. Here I had to error message, but the model was estimated using MLM instead of DWLS.
Any suggestions of an alternative code that would work?
Here is my code and output.
> f <- "C:/.../mydata.csv"
> t <- read.csv(f,sep=";")
>
> u<-t[!
is.na(t$wreg),]
>
> is.numeric(u$q96_1)
[1] TRUE
> is.numeric(u$q96_2)
[1] TRUE
> is.numeric(u$q96_3)
[1] TRUE
> u <- subset(u, q96_1==1| q96_1==2| q96_1==3| q96_1==4| q96_1==5)
> u <- subset(u, q96_2==1| q96_2==2| q96_2==3| q96_2==4| q96_2==5)
> u <- subset(u, q96_3==1| q96_3==2| q96_3==3| q96_3==4| q96_3==5)
> fl <- subset(u, region==1)
> model <- 'ethic =~ q96_1 + q96_2 + q96_3'
# fit using lavaan # error message #
> fit <- lavaan(model, data=fl,ordered=c("q96_1","q96_2","q96_3"))
Erreur dans t(Delta[[g]]) %*% lavsamplestats@WLS.V[[g]] :
arguments inadéquats
De plus : Messages d'avis :
1: In WLS.obs - WLS.est :
la taille d'un objet plus long n'est pas multiple de la taille d'un objet plus court
2: In lavsamp...@WLS.obs[[g]] - WLS.est[[g]] :
la taille d'un objet plus long n'est pas multiple de la taille d'un objet plus court
> fit <- sem(model, data=fl,ordered=c("q96_1","q96_2","q96_3"))
> des <- svydesign(ids=~1, data=fl, weights=~wreg)
> fit.survey <- lavaan.survey(fit, des,)
# fit not taking into account the sampling design # here I get the right estimator #
> fit
lavaan (0.5-16) converged normally after 12 iterations
Number of observations 1036
Estimator DWLS Robust
Minimum Function Test Statistic 0.000 0.000
Degrees of freedom 0 0
P-value (Chi-square) 0.000 0.000
Scaling correction factor NA
Shift parameter
for simple second-order correction (Mplus variant)
# fit taking into account the sampling design # I don't have the right estimator anymore #
> fit.survey
lavaan (0.5-16) converged normally after 24 iterations
Number of observations 1036
Estimator ML Robust
Minimum Function Test Statistic 0.000 0.000
Degrees of freedom 0 0
P-value (Chi-square) 1.000 1.000
Scaling correction factor NA
for the Satorra-Bentler correction