psych::fa vs. lavaan::lavCor for mixed polychoric/linear exploratory factor analysis

Skip to first unread message

Lawrence Hunsicker

Dec 1, 2019, 3:03:38 PM12/1/19
to lavaan
I am trying to develope a reliable efa model for a 17 variable (14 0-3 valued Likert scales and 3 linear variables), and I am running into various issues and warnings that I don't know how to deal with.  I went first to psych::fa, including cor = mixed, but I can't figure out how to tell fa which variables are ordered factors vs. continuous, and the program keeps telling me that my data have problems.  I then found psych:mixedCor, which permits me to tell it which variables are polychoric and which continuous,  to generate a correlation matrix that I could feed to fa, but I got a lot of less than helpful warnings.  E.g:
stuff <- mixedCor(csbx[1:17], p = 1:13, c=14:17)
Warning messages:
1: In matpLower(x, nvar, gminx, gmaxx, gminy, gmaxy) :
  46 cells were adjusted for 0 values using the correction for continuity. Examine your data carefully.
2: In cor.smooth(mat) :
  Matrix was not positive definite, smoothing was done
What am I supposed to examing my data for?  They seem to be correct.  Should I just barge on ahead?  (I'm OK with the matrix smoothing, I think.)
When I submitted that matrix to fa, I got a result that seems to make sense.  But again, loads of warnings.  E.g., 
Warning messages:
1: In cor.smooth(R) : Matrix was not positive definite, smoothing was done
2: In cor.smooth(R) : Matrix was not positive definite, smoothing was done
3: In cor.smooth(R) : Matrix was not positive definite, smoothing was done
4: In cor.smooth(r) : Matrix was not positive definite, smoothing was done
5: In fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs,  :
  The estimated weights for the factor scores are probably incorrect.  Try a different factor extraction method.
I thought that the smoothing had already been done!
And what "different factor extraction method" should I consider?

So then I turned to lavaan.  I declared my ordered factors in R and used lavCor, which tells me that it knows how to handle ordinal data variables.  This gave me:
cor2 <- lavCor(csbx1[-18], missing = 'pairwise', output = 'cor')
Warning message:
In lavaan(slotParTable = PT.un, slotData =, model.type = "unrestricted",  :
  lavaan WARNING: estimation of the baseline model failed. 
I can't find any documentation about what this warning means.  But it was only a warning, so I barged on ahead.
efa1 <- efaUnrotate(csbx1, nf=4, missing = 'pairwise')
efa1 <- efaUnrotate(csbx1, nf=4, missing = 'pairwise')
Warning message:
In lav_object_post_check(object) :
  lavaan WARNING: some estimated ov variances are negative  [I know that this is impossible, and probably results from some missing data and "pairwise deletion."
efa2 <- oblqRotate(efa1, method = 'quartimin')
> efa2 <- oblqRotate(efa1, method = 'quartimin')
> efa2 ...  Sensible result output followed by:
The standard errors are close but do not match with other packages. Be mindful when using it.
Warning message:
In testLoadings(object) :
  The standard error is currently invalid because it does not account for the variance of the rotation function. It is simply based on the delta method.
Hardly reassuring.

I know that this is a lavaan support site.  I can't find a similar psych support site to ask about the psych issues.  Is there one?  Are the folks here open to try to help a relative newbie on psych package issues?   And lavaan seems to assume that I will know what its warnings mean.  Is there some good documentation about the meaning of the lavaan warnings?  Can I trust the results I have gotten from either of the psych or lavaan approaches?
I would really appreciate some help with all of the above.
Larry Hunsicker

Mauricio Garnier-Villarreal

Dec 1, 2019, 8:17:27 PM12/1/19
to lavaan
lavaan WARNING: some estimated ov variances are negative

This indicates that the explained variance for 1 or more items is higher than 100%, this is a type of "impossible" solution that are also called Heywood cases. Given that in EFA you are stating that all the factors explained every item, this oculd happen. This is saying that to have the "best" solution you need some negative variances, Savalei & Kolenikov (2008) stated that is this negative variance want too far from 0, you could do a test if it is relevant enough to worry, if not its a better idea to keep the negative variance. Because if you constraint the model to not have the negative variance, the added constraint will bias other parameters

Savalei, V., & Kolenikov, S. (2008). Constrained versus unconstrained estimation in structural equation modeling. Psychological Methods, 13(2), 150–170.

efa1 <- efaUnrotate(csbx1, nf=4, missing = 'pairwise')

The efaUnrotate function calls lavaan arguments, so, you can add any other relevant arguments, like ordered= ..., estimator=..., and so on

If you use this function, it will estimate the appropriate covariance matrix, no need to use a middle function to estimate the covariance matrix that account for ordered and continuous items

Lawrence Hunsicker

Dec 1, 2019, 9:11:41 PM12/1/19
to lavaan
Got it.  Thanks!  Incidentally, the warnings and the variance < 0 all went away when I dropped the ct variable (very strongly correlated to ci) as suggested by Gavin.  I finally realized that I was feeding the program a close to absolutely singular matrix.  Now everything is working nicely.  Larry
Reply all
Reply to author
0 new messages