cjvanlissa / tidySEM

54 stars 7 forks source link

mixture_starts gives unlikely starting values #76

Open Gootjes opened 11 months ago

Gootjes commented 11 months ago

Hi, I am running into an issue while running a latent growth mixture model (2 classes, and four slopes: linear, quadratic, ...). Using mx_growth_mixture, with run = FALSE, and then later run_mx.

Proposed solution

Either of these solve the problem (I like B best): A. Would it be an option to specify DWLS as an argument to mixture_starts (and therefore, to mx_growth_mixture) so I can use DWLS? B. Line 580 should not only check for errors, but also check for status code ( != 0) of strts_vals at line 579 of mx_mixture.R and run mxTryHard() if necessary.

Problem description

OpenMx returns this error:

Running mix2 with 29 parameters
Error: The job for model 'mix2' exited abnormally with the error message: fit is not finite (The continuous part of the model implied covariance (loc2) is not positive definite in data 'mix2.data' row 12001. Detail:
covariance =  matrix(c(    # 9x9
 0.247388230845111,   0,   0,   0,   0,   0,   0,   0,   0
,   0, 0.0679163079200978,   0,   0,   0,   0,   0,   0,   0
,   0,   0, 0.185108791846561,   0,   0,   0,   0,   0,   0
,   0,   0,   0, 0.278227182808709,   0,   0,   0,   0,   0
,   0,   0,   0,   0, 0.0886282635083546,   0,   0,   0,   0
,   0,   0,   0,   0,   0, 0.197910968005967,   0,   0,   0
,   0,   0,   0,   0,   0,   0, 0.245595354137519,   0,   0
,   0,   0,   0,   0,   0,   0,   0, 0.151912385785354,   0
,   0,   0,   0,   0,   0,   0,   0,   0, -0.0727230601402252), byrow=TRUE, nrow=9, ncol=9)
)
In addition: Warning messages:
1: In model 'mix2' Optimizer returned a non-zero status code 10. Starting values are not feasible. Consider mxTryHard()
2: In model 'mix2' Optimizer returned a non-zero status code 10. Starting values are not feasible. Consider mxTryHard()
Execution halted

I wondered what the starting values were of this model so I did a little debugging of mixture_starts. Line 567 (see end of message for the snippet) returns a model with crazy intercept and slope values for the two classes. The intercept value for class 1 is -25.21408 while my data is on the 1 to 5 scale. For class 2, the linear slope has value -73.41519. I think these values lead to issues down the line.

After line 579, the model gives a warning (which is silenced by the code):

The model does not satisfy the first-order optimality conditions to the required accuracy, and no improved point for the merit function could be found during the final linesearch (Mx status RED)
** Information matrix is not positive definite (not at a candidate optimum).
  Be suspicious of these results. At minimum, do not trust the standard errors.

I guess this result that does not satisfy optimality contraints (stuck in a local optimum I guess) Comparing those results with the simple_starts values, they don't differ a lot (I subtracted the M matrices for the intercept and slopes) 0.0001419474 0.0004197741 0.001446449 0.004306184 0.002721691

So, the final starting values are improbable values. Leading to the error message I got.

I tried line 569 strts_vals <- simple_starts(strts, type = "DWLS") and that does lead to sensible starting values at line 579.

Would it be an option to specify DWLS as an argument to mixture_starts (and therefore, to mx_growth_mixture) so I can use DWLS?

Line 585, the mxTryHard, also leads to sensible starting values. Perhaps Line 580 should not only check for errors, but also check for status code ( != 0) of strts_vals at line 579 and run mxTryHard().

https://github.com/cjvanlissa/tidySEM/blob/7ab1d4c4f610da140cd25c72b98fc465b2100a5b/R/mx_mixture.R#L567-L590