Attachment | Size |
---|---|
R codes | 2.9 KB |
data | 31.9 KB |
Screenshot 2024-04-12 at 01.04.31.png | 360.02 KB |
Dear community,
I trust you are doing well. Thank you very much for your immense work in structural equation modelling. I'm contacting you because I'm currently working on a research project that involves implementing a two-step structural equation model.
I got an error when I implemented the command to run the first-stage model (I've attached the document). From here, I do not particularly understand how to proceed. I have attached the codes and the data to aid you. I would be grateful if you could help me identify the error and, if convenient, with the right codes.
Once again, thank you very much, and I look forward to your response.
Kindest Regards,
There are errors in the data, such as correlation coefficients with minimum and maximum values of -550 and 1.188, respectively (see the end of the outputs), which are clearly invalid.
Dear Mike,
Thank you for the prompt response. Your answer helped helped. I have one more concern: Is it problematic if the TSSEM estimation returns a CFI of 0.265?
Thank you once again.
Regards
Regards
It is very strange that the CFI is so bad, especially for a mediation model. There is probably something wrong in your model or data.
Hi Mike,
Thank you for your response. Can you please give me any pointers as to where I can look to rectify this?
It is hard to tell. One common issue is that you forget to allow the predictors correlated. This will make the model fit terribly bad.
Hi Mike,
Thank you. How can I allow my predictors to correlate? Is there a code to incorporate into what I have at the moment, please?
Regards
If you use the lavaan syntax to specify the models, you may check https://lavaan.ugent.be/tutorial/syntax1.html, especially the "~~" operator. You may also refer to some SEM books about model specifications.
Mike,
Thank you. I will have a look and revert. A quick scan of the codes file, which I have attached, showed that the "~~" was used to specify the covariance between a variable and itself (i.e., variance). Do I need to use the same operator to specify the covariance between different variables?
Yes, if you have read the example in https://lavaan.ugent.be/tutorial/syntax1.html. You may also try it and see if it works.
Hi Mike,
Thanks for the link. I have checked the mediation model section. It appears all the codes I have are in order regarding the "tilde" sign. If convenient, can you cross-check the codes I have already uploaded to see if they are indeed in order? Maybe I am missing something that is not obvious to me.
Thank you.
The predictors are independent in your model. You need to include the correlations among ALL predictors, e.g., 'X1 ~~ X2'.
Dear Mike,
Thanks for your response so far. I did what you suggested in the earlier conversation. See the updated code sheet that I have attached. However, I get this error when I try to estimate the model:
Warning message:
In .solve(x = object$mx.fit@output$calculatedHessian, parameters = my.name) :
Error in solving the Hessian matrix. Generalized inverse is used. The standard errors may not be trustworthy.
> summary(tssem.fit)
Error in if (pchisq(chi.squared, df = df, ncp = 0) >= upper) { :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In pchisq(tT, df = dfT, lower.tail = FALSE) : NaNs produced
2: In sqrt(max((tT - dfT)/(n - 1), 0)/dfT) : NaNs produced
3: In pchisq(chi.squared, df = df, ncp = 0) : NaNs produced
What could actually be an issue now? Thank you in advance.
Since the previous dataset contains error, could you attached the corrected dataset? Moreover, please ensure that the errors are reproducible by attaching the complete R code to read the CSV file and run the analysis.
Hi Mike,
I have attached the corrected dataset and the complete R code. Thank you very much.
Regards
Hi Mike,
I have attached the corrected dataset and the complete R code. Thank you very much.
Regards
Please see my first reply and ensure the data are valid. Your correlations vary from -1.216 to 1.050. You can check your data with the following syntax.
Dear Mike,
Apologies, I uploaded the wrong file. Kindly find the corrected file attached.
Many thanks.
Regards
I noticed a few peculiarities in the data. First, the range of correlations varies from -0.887 to 0.990. This (0.8 or 0.9) could indicate a problem with multicollinearity. Secondly, many correlations seem identical, such as X1_X2 and X1_X3 on rows 1 to 6. Overall, the dataset looks unusual to me.
Dear Prof Cheung,
Thank you for your answer. I have removed all the duplicated intercorrelations and correlations greater than 0.8, hoping the model will fit. However, a new problem arises (see below). Do you think the problem results from the model specification, specifically with the outlined covariance and variances? As you might remember when the covariance and variances are not specified, the model can fit but with a low CFI.
name="Dir_AGE"),Dir_LIQ=mxAlgebra(x, name="Dir_LIQ")))
Warning messages:
1: In .solve(x = object$mx.fit@output$calculatedHessian, parameters = my.name) :
Error in solving the Hessian matrix. Generalized inverse is used. The standard errors may not be trustworthy.
2: In checkRAM(Amatrix = Amatrix, Smatrix = Smatrix, cor.analysis = cor.analysis) :
The variances of the dependent variables in 'Smatrix' should be free.
summary(tssem.fit)
> summary(tssem.fit)
Error in if (pchisq(chi.squared, df = df, ncp = 0) >= upper) { :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In pchisq(tT, df = dfT, lower.tail = FALSE) : NaNs produced
2: In sqrt(max((tT - dfT)/(n - 1), 0)/dfT) : NaNs produced
3: In pchisq(chi.squared, df = df, ncp = 0) : NaNs produced
Regards
Please provide the data and R code to reproduce the errors.
Dear Prof. Cheung,
I have attached the files. In the quest to push the CFI up (the initial problem that furthered this thread), I have specified the covariances and variances as part of the model (for e.g, X1 ~~ X2, X1 ~~ XX1). Unexpectedly, this leads to the error. I can not locate where this error comes from. So, I would appreciate your guidance from here.
One more question: do I need to include the covariance between the mediator variable (X9) and the other variables, as well as its variance (X9 ~~ X9) in the model specification?
Thank you
The following changes may help.
1) Rerun the model with the
autofixtau2=TRUE
argument.2) Remove the covariance between the residues of X5 and other variables and free the residues of X5.
Dear Mike,
Thank you. This was helpful. My CFI improved to 1. The TLI is -inf. Is that normal?
Regards.