Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mixture_starts gives unlikely starting values #76

Open
Gootjes opened this issue Jul 31, 2023 · 0 comments
Open

mixture_starts gives unlikely starting values #76

Gootjes opened this issue Jul 31, 2023 · 0 comments

Comments

@Gootjes
Copy link
Contributor

Gootjes commented Jul 31, 2023

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().

tidySEM/R/mx_mixture.R

Lines 567 to 590 in 7ab1d4c

strts_vals <- try(simple_starts(strts, type = "ULS"))
if(inherits(strts_vals, "try-error")){
strts_vals <- simple_starts(strts, type = "DWLS")
}
strts <- strts_vals
subnamz <- names(strts@submodels)
not_pd <- sapply(subnamz, function(n){ any(eigen(strts[[n]]$matrices$S$values)$values < 0)})
if(any(not_pd)){
for(n in names(not_pd)[not_pd]){
strts[[n]][["S"]]$values <- Matrix::nearPD(strts[[n]][["S"]]$values, keepDiag = TRUE, maxit = 10000)$mat
}
}
strts_vals <- try(mxRun(strts, silent = TRUE, suppressWarnings = TRUE), silent = TRUE)
if(inherits(strts_vals, "try-error")){
if(grepl("omxAssignFirstParameters", attr(strts_vals, "condition"), fixed = TRUE)){
strts <- omxAssignFirstParameters(strts)
strts_vals <- try(mxRun(strts, silent = TRUE, suppressWarnings = TRUE))
} else {
strts_vals <- try(mxTryHard(strts, extraTries = 100,
silent = TRUE,
verbose = FALSE,
bestInitsOutput = FALSE))
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant