simsem / semTools

Useful tools for structural equation modeling
75 stars 36 forks source link

Error in reliability calculation: subscript out of bounds #45

Closed brianmsm closed 4 years ago

brianmsm commented 6 years ago

218/5000 I have the following problem when I try to calculate the reliability of an estimated model with wash, using the reliability function. When I enter the function with the "fit" as an argument, I get the following error: Error in r[cbind(1L:p, 1L:p)] <- 1 : subscript out of bounds. As it is a second order model, I also try to use reliabilityL2, where I get the following error: Error in ps[[i]][indexl2, indexl2, drop = FALSE] : subscript out of bounds. I am using the following code to perform the calculation:

model_01 <- "Autoritarismo  =~  CPP2 + CPP17 + CPP39
             Logro          =~  CPP4 + CPP13 + CPP24 + CPP32
             Auto_Engrand   =~  1*Autoritarismo + 1*Logro"

fit_01 <-   cfa(model_01, data = CPV, estimator = "WLSMV", 
                ordered = names(CPV),
                mimic = "Mplus")

summary(fit_01, fit.measures = TRUE, standardized = TRUE, rsquare = T)

Output:

lavaan 0.6-3 ended normally after 24 iterations

  Optimization method                           NLMINB
  Number of free parameters                         43

  Number of observations                           364

  Estimator                                       DWLS      Robust
  Model Fit Test Statistic                      22.279      31.908
  Degrees of freedom                                13          13
  P-value (Chi-square)                           0.051       0.002
  Scaling correction factor                                  0.717
  Shift parameter                                            0.832
    for simple second-order correction (WLSMV)

Model test baseline model:

  Minimum Function Test Statistic              450.376     371.883
  Degrees of freedom                                21          21
  P-value                                        0.000       0.000

User model versus baseline model:

  Comparative Fit Index (CFI)                    0.978       0.946
  Tucker-Lewis Index (TLI)                       0.965       0.913

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

Root Mean Square Error of Approximation:

  RMSEA                                          0.044       0.063
  90 Percent Confidence Interval          0.000  0.075       0.036  0.091
  P-value RMSEA <= 0.05                          0.578       0.193

  Robust RMSEA                                                  NA
  90 Percent Confidence Interval                                NA     NA

Standardized Root Mean Square Residual:

  SRMR                                           0.043       0.043

Weighted Root Mean Square Residual:

  WRMR                                           0.631       0.631

Parameter Estimates:

  Information                                 Expected
  Information saturated (h1) model        Unstructured
  Standard Errors                           Robust.sem

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  Autoritarismo =~                                                      
    CPP2              1.000                               0.475    0.475
    CPP17             1.192    0.225    5.300    0.000    0.566    0.566
    CPP39             1.256    0.208    6.047    0.000    0.596    0.596
  Logro =~                                                              
    CPP4              1.000                               0.568    0.568
    CPP13             1.125    0.153    7.337    0.000    0.639    0.639
    CPP24             0.788    0.125    6.305    0.000    0.448    0.448
    CPP32             0.628    0.114    5.488    0.000    0.357    0.357
  Auto_Engrand =~                                                       
    Autoritarismo     1.000                               0.893    0.893
    Logro             1.000                               0.746    0.746

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .CPP2              0.000                               0.000    0.000
   .CPP17             0.000                               0.000    0.000
   .CPP39             0.000                               0.000    0.000
   .CPP4              0.000                               0.000    0.000
   .CPP13             0.000                               0.000    0.000
   .CPP24             0.000                               0.000    0.000
   .CPP32             0.000                               0.000    0.000
    Autoritarismo     0.000                               0.000    0.000
    Logro             0.000                               0.000    0.000
    Auto_Engrand      0.000                               0.000    0.000

Thresholds:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
    CPP2|t1          -0.208    0.066   -3.134    0.002   -0.208   -0.208
    CPP2|t2           0.518    0.069    7.488    0.000    0.518    0.518
    CPP2|t3           1.055    0.081   13.013    0.000    1.055    1.055
    CPP2|t4           1.599    0.108   14.837    0.000    1.599    1.599
    CPP2|t5           2.132    0.163   13.085    0.000    2.132    2.132
    CPP17|t1         -0.159    0.066   -2.403    0.016   -0.159   -0.159
    CPP17|t2          0.558    0.070    8.000    0.000    0.558    0.558
    CPP17|t3          1.144    0.084   13.585    0.000    1.144    1.144
    CPP17|t4          1.551    0.105   14.837    0.000    1.551    1.551
    CPP17|t5          1.839    0.128   14.414    0.000    1.839    1.839
    CPP39|t1         -0.859    0.076  -11.380    0.000   -0.859   -0.859
    CPP39|t2         -0.166    0.066   -2.508    0.012   -0.166   -0.166
    CPP39|t3          0.359    0.067    5.320    0.000    0.359    0.359
    CPP39|t4          0.849    0.075   11.284    0.000    0.849    0.849
    CPP39|t5          1.304    0.091   14.349    0.000    1.304    1.304
    CPP4|t1          -1.486    0.100  -14.788    0.000   -1.486   -1.486
    CPP4|t2          -0.830    0.075  -11.092    0.000   -0.830   -0.830
    CPP4|t3          -0.187    0.066   -2.821    0.005   -0.187   -0.187
    CPP4|t4           0.308    0.067    4.593    0.000    0.308    0.308
    CPP4|t5           0.890    0.076   11.663    0.000    0.890    0.890
    CPP13|t1         -1.288    0.090  -14.289    0.000   -1.288   -1.288
    CPP13|t2         -0.727    0.073  -10.016    0.000   -0.727   -0.727
    CPP13|t3         -0.166    0.066   -2.508    0.012   -0.166   -0.166
    CPP13|t4          0.330    0.067    4.904    0.000    0.330    0.330
    CPP13|t5          0.910    0.077   11.851    0.000    0.910    0.910
    CPP24|t1         -0.456    0.068   -6.665    0.000   -0.456   -0.456
    CPP24|t2          0.229    0.067    3.447    0.001    0.229    0.229
    CPP24|t3          0.649    0.071    9.116    0.000    0.649    0.649
    CPP24|t4          1.171    0.085   13.738    0.000    1.171    1.171
    CPP24|t5          1.599    0.108   14.837    0.000    1.599    1.599
    CPP32|t1         -1.737    0.118  -14.677    0.000   -1.737   -1.737
    CPP32|t2         -1.272    0.089  -14.226    0.000   -1.272   -1.272
    CPP32|t3         -0.615    0.071   -8.712    0.000   -0.615   -0.615
    CPP32|t4         -0.131    0.066   -1.986    0.047   -0.131   -0.131
    CPP32|t5          0.666    0.071    9.317    0.000    0.666    0.666

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .CPP2              0.775                               0.775    0.775
   .CPP17             0.680                               0.680    0.680
   .CPP39             0.645                               0.645    0.645
   .CPP4              0.677                               0.677    0.677
   .CPP13             0.591                               0.591    0.591
   .CPP24             0.799                               0.799    0.799
   .CPP32             0.873                               0.873    0.873
    Autoritarismo     0.046    0.045    1.007    0.314    0.203    0.203
    Logro             0.143    0.055    2.603    0.009    0.444    0.444
    Auto_Engrand      0.180    0.037    4.797    0.000    1.000    1.000

Scales y*:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
    CPP2              1.000                               1.000    1.000
    CPP17             1.000                               1.000    1.000
    CPP39             1.000                               1.000    1.000
    CPP4              1.000                               1.000    1.000
    CPP13             1.000                               1.000    1.000
    CPP24             1.000                               1.000    1.000
    CPP32             1.000                               1.000    1.000
reliability(fit_01)
Error in r[cbind(1L:p, 1L:p)] <- 1 : subscript out of bounds

CPP.xlsx

TDJorgensen commented 6 years ago

Without data, I might not be able to track down the source of the error. Does this error occur when you fit a single-level model?

model_01 <- "Autoritarismo  =~  CPP2 + CPP17 + CPP39
             Logro          =~  CPP4 + CPP13 + CPP24 + CPP32"

You'll notice that the estimated factor covariance from the first-order model will exactly equal the variance of your second-order factor, because the second-order model is just a reparameterized equivalent of a first-order model (no information added).

TDJorgensen commented 4 years ago

Someone else provided a reproducible example in issue #65, and I tracked it down a fixed it in the development version.