test statistics unavailable (tli, cfi, rmsea) and Error in TEST[[2]] : subscript out of bounds

60 views
Skip to first unread message

marieelyse.l...@gmail.com

unread,
Feb 15, 2021, 11:39:53 AM2/15/21
to lavaan
Hi ran the following script:

subsample_one_item_present2 <- NEW[which((rowMeans(is.na(NEW[c("a","b")]))) <= 1/2),]
dim(subsample_one_item_present2)

data2 <- subsample_one_item_present2[c("a","b")]

sink('model_teacher.txt')
model2 <- '
A =~ a + b'

fit2 <- cfa(model2, data = data2, estimator = "MLR", missing = "FIML", std.ov = TRUE, std.lv = TRUE, orthogonal = T, verbose = T)
sink()

o <- lavInspect(fit2, what ='fit')
capture.output(o, file = "fit_indices_model_fiml_onefactor_teacher.txt")
s <- summary(fit2, standardized = T, fit.measures = T)
capture.output(s, file = "model_output_model_fiml_onefactor_teacher.txt")
sink()

The model ran fine wihout any error messages, however when I run the lavInspect or summary, I get:
Error in TEST[[2]] : subscript out of bounds

what can I do to fix this and get the cfi, tli, rmsea?

Thank you very much


Edward Rigdon

unread,
Feb 15, 2021, 12:13:46 PM2/15/21
to lav...@googlegroups.com
A factor model with only 2 indicators is not statistically identified. I am surprised that lavaan did not turn up that diagnosis but instead produced a "subscript out of bounds" error. Perhaps, per your call to the cfa() function, the function both standardized the common factor AND fixed the first loading to 1, thus reducing the number of estimated parameters to 3, the same as the number of unique elements in the covariance matrix of the two observed variables. You could make the model identified by imposing an equality constraint on the two loadings.


--
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/99fa9981-deaa-4157-9b97-086187c7929dn%40googlegroups.com.

marieelyse.l...@gmail.com

unread,
Feb 15, 2021, 12:36:52 PM2/15/21
to lavaan
Hi Edward,

Thank you for your suggestion. I just constrained the model like so 
model2 <- '
c==0.5
A =~ c*a + c*a'

This was my output :
lavaan 0.6-7 ended normally after 10 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of free parameters                          6
  Number of equality constraints                     2
                                                      
  Number of observations                           151
  Number of missing patterns                         3
                                                      
Model Test User Model:
                                               Standard      Robust
  Test Statistic                                 99.330          NA
  Degrees of freedom                                  1           1
  P-value (Chi-square)                            0.000          NA
  Scaling correction factor                                      NA
       Yuan-Bentler correction (Mplus variant)                     

Model Test Baseline Model:

  Test statistic                               159.268     116.971
  Degrees of freedom                                 1           1
  P-value                                        0.000       0.000
  Scaling correction factor                                  1.362

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.379          NA
  Tucker-Lewis Index (TLI)                       0.379          NA
                                                                  
  Robust Comparative Fit Index (CFI)                            NA
  Robust Tucker-Lewis Index (TLI)                               NA

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)               -306.734    -306.734
  Scaling correction factor                                  0.935
      for the MLR correction                                      
  Loglikelihood unrestricted model (H1)       -257.069    -257.069
  Scaling correction factor                                  1.116
      for the MLR correction                                      
                                                                  
  Akaike (AIC)                                 621.469     621.469
  Bayesian (BIC)                               633.538     633.538
  Sample-size adjusted Bayesian (BIC)          620.878     620.878

Root Mean Square Error of Approximation:

  RMSEA                                          0.807       0.000
  90 Percent confidence interval - lower         0.677       0.000
  90 Percent confidence interval - upper         0.945       0.000
  P-value RMSEA <= 0.05                          0.000         NaN
                                                                  
  Robust RMSEA                                                  NA
  90 Percent confidence interval - lower                     0.000
  90 Percent confidence interval - upper                     0.000

Standardized Root Mean Square Residual:

  SRMR                                           0.385       0.385

Parameter Estimates:

  Standard errors                             Sandwich
  Information bread                           Observed
  Observed information based on                Hessian

and I had the following error message for lavInspect:

Warning message:
In pchisq(XX2, df = df2, ncp = ncp) : NaNs produced

What would be the reason for not obtaining the robust fit measures?

Thank you very much again

Edward Rigdon

unread,
Feb 15, 2021, 2:03:05 PM2/15/21
to lav...@googlegroups.com
     I would remove the line where you constrain c to be 0.5. Given that both observed variables and factor are standardized, that 0.5 has a specific meaning, and may not be appropriate for your data.
     It might be that the NaN's happen because the fit of the model is so poor, but that is just a guess.
--Ed R.

marieelyse.l...@gmail.com

unread,
Feb 15, 2021, 2:38:22 PM2/15/21
to lavaan

ok, thanks I thought that is how I would apply the equality constrain that you suggested.
thanks
Reply all
Reply to author
Forward
0 new messages