Hi Sorry for the rather long message. I am trying to use the cfa command in the lavaan package to run a CFA however I am unsure over a couple of issues. I have @25 dichotomous variables, 300 observations and an EFA on a training dataset suggests a 3 factor model. After defining the model I use the command fit.dat <- cfa(model.1, data=my.dat, std.lv = T, estimator="WLSMV", ordered=c("var1","var2" and so on for the other 23 variables)) Is it right that I define the variables as ordered (the output returns thresholds suggesting I should). Does the cfa command calculate tetrachoric correlations in the background? However, output for the command returns two variables with small negative variances (-0.002) which I think is due to the correlation matrix not being positive definite. Is it reasonable to force these to be zero when defining the model or is this more a sign of problems with the model? As an alternative is it possible to calculate the tetrachoric correlations using hetcor (which applies smoothing) and then use the smoothed sample correlation as the input to the model, such as fit.cor <- cfa(model.1, sample.cov=my.hetcor, sample.nobs=300, std.lv = T,estimator="ML", ordered=c("var1","var2" and so on for the other 23 variables)). This however does not produce thresholds suggesting what I have tried is nonsense but is there a way to do this? Final question is I have a lot of missing data - listwise deletion leaves 90 subjects. Is there a way to calculate estimates using pairwise deletion (this is another reason why I tried using the correlation matrix as the input). I have tried the analysis using John Fox's SEM package / command. I calculate the correlation matrix with smoothing my.cor<-hetcor(north.dat.sub,use="pairwise.complete.obs")$correlations This returns the warning indicating that the correlation matrix was adjusted to make it positive definite. However the following sem model does not run, with the error message that the matrix is non-invertible. mod1<-sem::sem(sem .model.1, S=my.cor, 300) Should the smoothing not allow it to be inverted? thanks for help, david ________________________________ The University of Glasgow, charity number SC004401 [[alternative HTML version deleted]]
Dear David, On Wed, 23 Jan 2013 11:19:09 +0000 David Purves <David.Purves at glasgow.ac.uk> wrote:> Hi > > Sorry for the rather long message. >. . .> > I have tried the analysis using John Fox's SEM package / command. > > I calculate the correlation matrix with smoothing > > my.cor<-hetcor(north.dat.sub,use="pairwise.complete.obs")$correlations > > This returns the warning indicating that the correlation matrix was adjusted to make it positive definite. However the following sem model does not run, with the error message that the matrix is non-invertible. > > mod1<-sem::sem(sem .model.1, S=my.cor, 300) > > Should the smoothing not allow it to be inverted? >If the input correlation matrix is really positive definite, then it has an inverse. You could check directly, e.g., by looking at the eignevalues of the tetrachoric correlation matrix. There's very little here to go on, not even the error message produced by sem(). By the way, I assume that you didn't really call sem in the sem package as sem::sem in a session in which lavann was loaded. I'm not sure what would happen if you did that. Best, John ------------------------------------------------ John Fox Sen. William McMaster Prof. of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/> > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
> I am trying to use the cfa command in the lavaan package to run a CFA > however I am unsure over a couple of issues. > > I have @25 dichotomous variables, 300 observations and an EFA on a > training dataset suggests a 3 factor model.That is a lot of variables, and a rather small sample size (for binary data).> After defining the model I use the command > > fit.dat <- cfa(model.1, data=my.dat, std.lv = T, estimator="WLSMV", > ordered=c("var1","var2" and so on for the other 23 variables))To avoid having to type "var?" 25 times, you can say ordered=paste("var",1:25,sep="")> Is it right that I define the variables as ordered (the output > returns thresholds suggesting I should).Yes! Does the cfa command> calculate tetrachoric correlations in the background?Yes, indeed. You can 'see' it by typing inspect(fit, "sampstat") lavaan also computes an asymptotic variance matrix of these correlations, so you should get correct standard errors and a correct test statistic. By default, lavaan will provide robust standard errors and a mean and variance adjusted test statistic (estimator="WLSMV").> However, output for the command returns two variables with small > negative variances (-0.002) which I think is due to the correlation > matrix not being positive definite. Is it reasonable to force these > to be zero when defining the model or is this more a sign of problems > with the model?You can NOT force these to be equal (at least not in the current version of lavaan - 0.5-11, where the residual variance is a function of other model parameters). I don't think this is caused by a non-pd correlation matrix (you should get a big warning if this was the case). Perhaps the sample size is too small. Could you remove some items, or regroup them?> As an alternative is it possible to calculate the tetrachoric > correlations using hetcor (which applies smoothing) and then use the > smoothed sample correlation as the input to the model, such as > > fit.cor <- cfa(model.1, sample.cov=my.hetcor, sample.nobs=300, std.lv > = T,estimator="ML", ordered=c("var1","var2" and so on for the other > 23 variables)).This will work only if you omit the 'ordered' argument. Perhaps in combination with estimator="ULS". But do not trust/report the standard errors in this case.> Final question is I have a lot of missing data - listwise deletion > leaves 90 subjects. Is there a way to calculate estimates using > pairwise deletion (this is another reason why I tried using the > correlation matrix as the input).You could do this, and use estimator="ULS". But again, you can not use the standard errors. Yves. -- http://lavaan.org