You are here

Expected covariance matrix is not positive-definite in data row ... at iteration ...

5 posts / 0 new
Last post
JoopDirksen's picture
Joined: 06/28/2011 - 10:40
Expected covariance matrix is not positive-definite in data row ... at iteration ...


I'm developing a model, but I run into a couple of problems. Since the OpenMx documentation did not give the answer I was looking for, I want to try it here. I'm having a hard time getting started with SEM and with OpenMx because there is no real good overview of SEM methodology in my opinion.

I'm trying to run the following code:


model <- mxModel(
manifestVars = c("A", "B", "C", "D", "E","F"),
latentVars = c("var1", "var2", "var3", "var4"),
mxPath(from="var1",to=c("A", "B", "C")),
mxPath(from="var2",to=c("B", "D", "E")),
mxPath(from="var3",to=c("F", "E")),
mxPath(from="var4",to=c("C", "D")),
mxPath(from="one",to=c("A", "B", "C", "D", "E","F", "var1", "var2", "var3", "var4")),

fit <- mxRun(model)

I'm getting the error message "Expected covariance matrix is not positive-definite in data row 126 at iteration 0"

Can anybody tell me what this error message means? I read on the errors page that it means that you should change your "starting values", but where should I do that? And besides that, what are "starting values" anyway? Somewhere it also mentions "free variables", but I cannot find a clear explanation what a "free variable" is exactly.

Who can give me the exact code I need to add to modify these starting values? I also read somewhere that it has to do with matrices for which no inverse can be calculated and that a Cholesky decomposition could help. Is anybody familiar with this method? And if so, what exactly do I need to change in the code above to make this work?



kkelley's picture
Joined: 08/04/2009 - 16:01
In short, starting values are

In short, starting values are how the maximum likelihood estimation procedures gets started. You can add starting values for each parameter estimate or you can add a single value to each mxPath statement and OpenMX will use that starting value for the set of starting values referenced in the statement. Or, you can specify a different starting value for each parameter references in the mxPath statement. For some models not specifying any starting values leads to a model implied matrix that is ill formed (specifically filled with zeros because no starting values have been specified). But, specifying starting values will allow the model implied matrix to start off being invertible. You can add "values=1" to each of your mxPath statements so that OpenMx has something other than a null matrix to start with. I suggest trying that and seeing what happens.

JoopDirksen's picture
Joined: 06/28/2011 - 10:40
I tried to add "values=1" to

I tried to add "values=1" to each of the mxPath statements but it doesn't work, still the same error message. Should I try it with other values, or values for each connection separately? Or should I maybe use the Cholesky decomposition?

I'm reading the book "Principles and Practices of Structural Equation Modeling" by Rex Kline, but the book goes into detail much too soon so I get lost pretty early. Are there any introductory texts available on this topic?



Ryne's picture
Joined: 07/31/2009 - 15:12
Just setting 'values=1' for

Just setting 'values=1' for all of your factor loadings and means isn't enough, as you still don't have any variance terms in your model.

I think John Loehlin's 'Latent Variable Modeling' book is a fantastic introduction to the range of confirmatory and exploratory methods. If you're looking for something free, take a look at Steve Boker's course, posted here on the forums ( and the other materials available on our resources page (

Ryne's picture
Joined: 07/31/2009 - 15:12
Hi Steven, I'm going to have

Hi Steven,

I'm going to have to answer your questions out of order.

OpenMx fits models by comparing an expected or model implied mean and covariance structure to the mean and covariance structure in your data. This expected covariance matrix is defined by the various free and fixed parameters in your model. Fixed parameters are numbers you assign as features of the model that don't change (i.e. you didn't assign a covariance between "var1" and "var2", so they have a fixed covariance of zero), while free parameters are variables that you change or estimate to make the model fit the data better (i.e., you're trying to find values for your factor loadings that best fit the data in your example). The process for finding these estimates is as follows:

-take the current values for all parameters and evaluate model fit by -2 log likelihood (a major iteration)
-vary all of the free parameters a little bit in either direction and get their -2LLs (minor iterations)
-use the results of the minor iteration to vary the free parameters and improve fit.
-take the new parameter estimates from step 3 and go back to step 1. when you can't make the fit any better (i.e., the parameter estimates from step 3 are about the same as what you started with in step 1), you're done!

To kick this process off, you have to provide values for the first iteration. Because it's all done in the OpenMx backend code that's written in C, and C counts up from zero, you have to supply the values for all parameters for iteration zero. Your error is caused by the fact that you didn't specify any starting values at all, so everything was zero. This means that your expected covariance matrix can't be inverted (inversion is the matrix algebra analog to division. A covariance matrix with a zero variance or a perfect correlation can't be inverted), and thus can't be used as a set of starting values. You'll have to add "values=???" to your mxPath statements to assign numeric values to each path you want to create. Other programs guess at what your starting values should be, but OpenMx does exactly what you tell it to and nothing more. This keeps the program from making false assumptions about your model, but means you have to be explicit about every part of your model.

I also notice that none of your variables have variances. You'll have to add variances for all of your variables, as well as any covariances (say, between your latent variables) that you want. You'll also have to identify the scale of the latent variables by fixing either the variance or a single loading for each factor to a non-zero constant (usually to the number 1).

Hope this helps, and let us know what other questions we can answer,

Log in or register to post comments