Error messages when using the HTMT and reliability functions in SEMTools

491 views
Skip to first unread message

Theuns

unread,
Sep 2, 2019, 4:51:06 AM9/2/19
to lavaan
Dear Lavaan experts,

I have tried to fit the model below using the WLSMV estimator in lavaan 0.6-5:

> CFAmodel <- '
+ 
+     Staffing =~ Q4_1_1 + Q4_2_1 + Q4_3_1 + Q4_4_1 + Q4_5_1
+     Training =~ Q5_1_1 + Q5_3_1 + Q5_4_1 + Q5_5_1
+     Compensation =~ Q6_1_1 + Q6_2_1 + Q6_3_1 + Q6_4_1
+     Rewards =~ Q7_1_1 + Q7_2_1 + Q7_3_1 + Q7_4_1 + Q7_5_1
+     Partici =~ Q9_1_1 + Q9_2_1 + Q9_3_1 + Q9_4_1
+     Empower =~ Q10_1_1 + Q10_2_1 + Q10_5_1
+     UWES =~ Q13_1_1 + Q13_2_1 + Q13_3_1 + Q13_4_1 + Q13_5_1 + Q13_6_1 + Q13_7_1 + Q13_8_1 + Q13_9_1
+     ServiceClimate =~ Q2_1_1 + Q2_3_1 + Q2_4_1 + Q2_5_1 + Q2_6_1 + Q2_7_1
+ '
> fit <- cfa(CFAmodel, data=my_data, estimator="WLSMV", ordered = c("Q4_1_1", "Q4_2_1", "Q4_3_1", "Q4_4_1", "Q4_5_1", 
+                                                                   "Q5_1_1", "Q5_3_1", "Q5_4_1", "Q5_5_1",
+                                                                   "Q6_1_1", "Q6_2_1", "Q6_3_1", "Q6_4_1",
+                                                                   "Q7_1_1", "Q7_2_1", "Q7_3_1", "Q7_4_1", "Q7_5_1", 
+                                                                   "Q9_1_1", "Q9_2_1", "Q9_3_1", "Q9_4_1",
+                                                                   "Q10_1_1", "Q10_2_1", "Q10_5_1",
+                                                                   "Q13_1_1", "Q13_2_1", "Q13_3_1", "Q13_4_1", "Q13_5_1", "Q13_6_1", "Q13_7_1", "Q13_8_1", "Q13_9_1",
+                                                                   "Q2_1_1", "Q2_3_1", "Q2_4_1", "Q2_5_1", "Q2_6_1", "Q2_7_1"), mimic="Mplus")

When I run the model, lavaan issues a warning message:

Warning message:
In lav_model_vcov(lavmodel = lavmodel2, lavsamplestats = lavsamplestats,  :
  lavaan WARNING:
    The variance-covariance matrix of the estimated parameters (vcov)
    does not appear to be positive definite! The smallest eigenvalue
    (= -2.167349e-17) is smaller than zero. This may be a symptom that
    the model is not identified.

Despite this, the model produces what seems like a sensible solution:


lavaan 0.6-5 ended normally after 79 iterations Estimator DWLS Optimization method NLMINB Number of free parameters 244 Number of observations 781 Model Test User Model: Standard Robust Test Statistic 974.79105 1322.25029 Degrees of freedom 712 712 P-value (Chi-square) 0.00000 0.00000 Scaling correction factor 1.02761 Shift parameter 373.64875 for the simple second-order correction (WLSMV) Model Test Baseline Model: Test statistic 208943.71190 40071.56631 Degrees of freedom 780 780 P-value 0.00000 0.00000 Scaling correction factor 5.29795 User Model versus Baseline Model: Comparative Fit Index (CFI) 0.99874 0.98447 Tucker-Lewis Index (TLI) 0.99862 0.98299 Robust Comparative Fit Index (CFI) NA Robust Tucker-Lewis Index (TLI) NA Root Mean Square Error of Approximation: RMSEA 0.02175 0.03315 90 Percent confidence interval - lower 0.01825 0.03036 90 Percent confidence interval - upper 0.02506 0.03592 P-value RMSEA <= 0.05 1.00000 1.00000 Robust RMSEA NA 90 Percent confidence interval - lower NA 90 Percent confidence interval - upper NA Standardized Root Mean Square Residual: SRMR 0.03634 0.03634 Weighted Root Mean Square Residual: WRMR 1.00978 1.00978

However, when I now try to use the HTMT and reliability functions in semTools (0.5-2), I receive the warning / error messages shown below. No output is generated for the reliability function.

> dat <- my_data[,6:70] > htmt(CFAmodel, dat) Stffng Tranng Cmpnst Rewrds Partic Empowr UWES SrvcCl Staffing 1.000 Training 0.618 1.000 Compensation 0.520 0.458 1.000 Rewards 0.739 0.631 0.593 1.000 Partici 0.673 0.681 0.459 0.766 1.000 Empower 0.654 0.593 0.458 0.656 0.699 1.000 UWES 0.355 0.365 0.254 0.367 0.347 0.318 1.000 ServiceClimate 0.610 0.641 0.451 0.647 0.692 0.536 0.371 1.000 Warning message: In lavaan(slotParTable = PT.un, slotData = lav.data, model.type = "unrestricted", : lavaan WARNING: estimation of the baseline model failed. > reliability(fit) Error: $ operator not defined for this S4 class

Could you please assist me by indicating what these warning / error messages mean and how the problem can be resolved.

Kind regards,

Theuns



Terrence Jorgensen

unread,
Sep 3, 2019, 8:50:28 AM9/3/19
to lavaan
lavaan WARNING:
    The variance-covariance matrix of the estimated parameters (vcov)
    does not appear to be positive definite! The smallest eigenvalue
    (= -2.167349e-17) is smaller than zero. This may be a symptom that
    the model is not identified.

Despite this, the model produces what seems like a sensible solution:
 
That's why it is a warning, not an error.  The smallest eigenvalue is essentially zero, not substantially negative, so this is probably ignorable.  Given you have 3+ items uniquely defining each factor, I don't see an obvious identification problem.
 
  lavaan WARNING: estimation of the baseline model failed.

This means what it says.  A new feature of lavaan is that it tries fitting the default baseline model after fitting your model, so it can store the result in "fit".  That way, the baseline model doesn't have to be fit each time you call summary(fit, fit.measures = TRUE) or fitMeasures(fit) to calculate CFI etc.  This has nothing to do with your hypothesized model, so you can ignore it.

> reliability(fit)
Error: $ operator not defined for this S4 class

Ugh, this stupid error only occurs for categorical data, when a hidden function calls fitted(fit).  For whatever reason, within the scope of the function, the correct fitted() method is not selected for lavaan objects.  I addressed this error in the reliability() function itself, but did not correct it in the hidden function for retrieving thresholds.  Corrected now in the development version:

devtools::install_github("simsem/semTools/semTools")

Thanks for catching it.

Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Theuns Kotze

unread,
Sep 3, 2019, 9:24:07 AM9/3/19
to lav...@googlegroups.com
Dear Terrence,

Thank you for your speedy and detailed response.

For a day, it almost felt like my PhD was hanging on a thread ... but now I am back on track again!!

Kind regards,

Theuns

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/042285c9-e910-49e7-afa3-9b4ab57aa5b4%40googlegroups.com.


--
Theuns Kotzé
E-mail: tgk...@gmail.com

Theuns

unread,
Sep 4, 2019, 3:16:58 AM9/4/19
to lavaan
Dear Terrence,

I upgraded semTools to the development version (0.5-2.901) as you sugggested and next tested a slightly different version of the model shown in my previous post (https://groups.google.com/d/msg/lavaan/rPVEHUQjqVQ/0UE4EWWiAQAJ).

The new model provides a good fit and HTMT values, but I get the following error when I use the reliability function:

> reliability(fit)
Error in pnorm(t2) : Non-numeric argument to mathematical function

Do you have any suggestions on how this can be resolved?

Kind regards,

Theuns


Theuns

unread,
Sep 4, 2019, 4:24:22 AM9/4/19
to lavaan
Hello Terrence,

Please ignore my previous post. I have found the cause of the error. It was a typo in the model specification on my part.

Kind regards,

Theuns


Reply all
Reply to author
Forward
0 new messages