categorial variariable in sem no standard error

607 views
Skip to first unread message

Mango Dada

unread,
Apr 8, 2014, 5:14:33 AM4/8/14
to lav...@googlegroups.com
Dear all,

I am trying to compute a structural equation model with the sem-function in lavaan.
There are two categorial variables (one latent exogenous and one latent endogenous) I wish to include in the final version of the model.
As soon as I include one of the categorial variables in the model, however, R produces the following warning:

1: In estimateVCOV(lavaanModel, samplestats = lavaanSampleStats, options = lavaanOptions,  :
  lavaan WARNING: could not compute standard errors!

2: In computeTestStatistic(lavaanModel, partable = lavaanParTable,  :
  lavaan WARNING: could not compute scaled test statistic

Here is the code and the output:
(This is a very small version of the final model and here I introduce only one categorial variable. The warning is the same for the complex and any simple version of the model).

model1 <- '
# measurement models
#uv
Wertschaetzung_Essen =~ abwechslungsreiche_M + schnell_zubereitbar + koche_sehr_gerne + koche_sehr_haeufig

#av
Fleischverzicht =~ Ern_Index1

#structural part
Fleischverzicht ~ Wertschaetzung_Essen
'

fit_model1 <- sem(model1, data=survey2_subset, ordered = c("Ern_Index1"))
summary(fit_model1, fit.measures = TRUE, standardized=TRUE)

lavaan (0.5-15) converged normally after  31 iterations

                                                  Used       Total
  Number of observations                          3469        3676

  Estimator                                       DWLS      Robust
  Minimum Function Test Statistic               13.716          NA
  Degrees of freedom                                 4           4
  P-value (Chi-square)                           0.008          NA
  Scaling correction factor                                     NA
  Shift parameter                                    
    for simple second-order correction (Mplus variant)

Model test baseline model:

  Minimum Function Test Statistic             2176.159    1582.139
  Degrees of freedom                                10          10
  P-value                                        0.000       0.000

User model versus baseline model:

  Comparative Fit Index (CFI)                    0.996          NA
  Tucker-Lewis Index (TLI)                       0.989          NA

Root Mean Square Error of Approximation:

  RMSEA                                          0.026          NA
  90 Percent Confidence Interval          0.012  0.042          NA     NA
  P-value RMSEA <= 0.05                          0.994          NA

Parameter estimates:

  Information                                 Expected
  Standard Errors                           Robust.sem

                   Estimate  Std.err  Z-value  P(>|z|)   Std.lv  Std.all
Latent variables:
  Wertschaetzung_Essen =~
    abwchslngsr_M     1.000                               0.363    0.436
    schnll_zbrtbr     1.179                               0.428    0.438
    koche_shr_grn     2.549                               0.925    0.846
    koche_shr_hfg     2.530                               0.918    0.775
  Fleischverzicht =~
    Ern_Index1        1.000                               0.249    0.249

Regressions:
  Fleischverzicht ~
    Wrtschtzng_Es     0.302                               0.440    0.440

Intercepts:
    abwchslngsr_M     3.133                               3.133    3.760
    schnll_zbrtbr     1.701                               1.701    1.741
    koche_shr_grn     2.978                               2.978    2.725
    koche_shr_hfg     2.543                               2.543    2.148
    Wrtschtzng_Es     0.000                               0.000    0.000
    Fleischvrzcht     0.000                               0.000    0.000

Thresholds:
    Ern_Index1|t1     0.197                               0.197    0.197

Variances:
    abwchslngsr_M     0.562                               0.562    0.810
    schnll_zbrtbr     0.771                               0.771    0.808
    koche_shr_grn     0.339                               0.339    0.284
    koche_shr_hfg     0.559                               0.559    0.399
    Ern_Index1        0.938                               0.938    0.938
    Wrtschtzng_Es     0.132                               1.000    1.000
    Fleischvrzcht     0.050                               0.806    0.806

I suppose that the model is not identified, but there should be enough degrees of freedom and the loadings of the first manifest items are set to one as well.
What to do and try next?
I would be very grateful, if someone could help me or give me a hint what to do to make the model estimable with standard errors and a scaled test statistic.

Thanks very much in advance

Sandra

Alex Schoemann

unread,
Apr 14, 2014, 10:52:36 AM4/14/14
to lav...@googlegroups.com
Hi Sandra,

Your model is globally identified (positive df) but the latent variable Fleischvrzcht is not locally identified. For a latent variable with a single indicator, you must fix two parameters associated with the latent variable. Currently the factor loading is fixed to 1 to set the scale but you're estimating the residual variance and the latent variance. Fixing one of these parameters (e.g. fixing the residual variance of Ern_Index1 to 0) should help.

Alex

yrosseel

unread,
Apr 14, 2014, 11:04:50 AM4/14/14
to lav...@googlegroups.com
On 04/08/2014 11:14 AM, Mango Dada wrote:
> Fleischverzicht =~ Ern_Index1

This is the problem. This would work out-of-the-box if Ern_Index1 was a
continuous variable (because lavaan would set the residual variance of
Ern_Index1 to zero behind the scenes). But if fails if Ern_Index1 is a
categorical variable.

Simply remove this line, and replace all occurrences of
'Fleischverzicht' by 'Ern_Index1' in the other equations.

Yves.

Message has been deleted

Amanda Pollitt

unread,
Jun 18, 2014, 6:07:14 PM6/18/14
to lav...@googlegroups.com
How would using a categorical single indicator in the cfa function work? 

yrosseel

unread,
Jun 21, 2014, 8:50:45 AM6/21/14
to lav...@googlegroups.com
On 06/19/2014 12:06 AM, Amanda Pollitt wrote:
> How would using a categorical single indicator in the cfa function work?

I don't think that is possible. With a continuous indicator, we could
fix the residual error variance to a constant (perhaps zero), but with a
categorical indicator, the residual variance is not a free parameter. It
is a function of other parameters.

Yves.

ni wi

unread,
Jun 23, 2014, 7:08:02 AM6/23/14
to lav...@googlegroups.com
Hello! 
I'm new to R (and to SEM in general), and currently I'm trying to run a few CFAs.
I've came across similar warnings when I tried to fit a bifactor model to my data. I was able to fit more simple models, in which I've separated the factors for the bifactor model. 

here is the syntax and part of the output:

datar.model<- '
general =~ Q2 + Q3 + Q5 + Q8 + Q10 + Q11 + Q12 + Q15 + Q16 + Q18 + Q21 + Q22 + Q25 + Q28 + Q29 + Q30 + Q33 + Q35 + Q36 + Q37 + Q39 + Q40 + Q41 + Q43 + Q48 + Q49 + Q4 + Q7 + Q9 + Q13 + Q17 + Q20 + Q23 + Q26 + Q27 + Q31 + Q34 + Q38 + Q42 + Q44 + Q45 + Q46 + Q47
at =~ Q2 + Q3 + Q5 + Q8 + Q10 + Q11 + Q12 + Q15 + Q16 + Q18 + Q21 + Q22 + Q25 + Q28 + Q29 + Q30 + Q33 + Q35 + Q36 + Q37 + Q39 + Q40 + Q41 + Q43 + Q48 + Q49 
hy =~ Q4 + Q7 + Q9 + Q13 + Q17 + Q20 + Q23 + Q26 + Q27 + Q31 + Q34 + Q38 + Q42 + Q44 + Q45 + Q46 + Q47 
'
fit<- cfa (datar.model, data=datar, estimator="WLSMV", ordered=c("Q2", "Q3", "Q5", "Q8", "Q10", "Q11", "Q12", "Q15", "Q16", "Q18", "Q21", "Q22", "Q25", "Q28", "Q29", "Q30", "Q33", "Q35", "Q36", "Q37", "Q39", "Q40", "Q41", "Q43", "Q48", "Q49", "Q4", "Q7", "Q9", "Q13", "Q17", "Q20", "Q23", "Q26", "Q27", "Q31", "Q34", "Q38", "Q42", "Q44", "Q45", "Q46", "Q47"))
summary(fit, fit.measures=TRUE, standardized=TRUE)

Warning messages:
1: In lav_model_vcov(lavmodel = lavmodel, lavsamplestats = lavsamplestats,  :
  lavaan WARNING: could not compute standard errors!

2: In lav_model_test(lavmodel = lavmodel, lavpartable = lavpartable,  :
  lavaan WARNING: could not compute scaled test statistic

> summary(fit, fit.measures=TRUE, standardized=TRUE)
lavaan (0.5-16) converged normally after 113 iterations

  Number of observations                          2414

  Estimator                                       DWLS      Robust
  Minimum Function Test Statistic             8561.327          NA
  Degrees of freedom                               814         814
  P-value (Chi-square)                           0.000          NA
  Scaling correction factor                                     NA
  Shift parameter                                     
    for simple second-order correction (Mplus variant)

Model test baseline model:

  Minimum Function Test Statistic           314818.047   79538.667
  Degrees of freedom                               903         903
  P-value                                        0.000       0.000

User model versus baseline model:

  Comparative Fit Index (CFI)                    0.975          NA
  Tucker-Lewis Index (TLI)                       0.973          NA

Root Mean Square Error of Approximation:

  RMSEA                                          0.063          NA
  90 Percent Confidence Interval          0.062  0.064          NA     NA
  P-value RMSEA <= 0.05                          0.000          NA

Weighted Root Mean Square Residual:

  WRMR                                           2.882       2.882

Parameter estimates:

  Information                                 Expected
  Standard Errors                           Robust.sem

                   Estimate  Std.err  Z-value  P(>|z|)   Std.lv  Std.all
Latent variables:
  general =~
    Q2            1.000                               0.629    0.629
    Q3            1.189                               0.748    0.748
    Q5            1.439                               0.906    0.906
    Q8            0.996                               0.627    0.627
    Q10           1.299                               0.817    0.817
    Q11          1.162                               0.732    0.732
    Q12           1.354                               0.852    0.852
    Q15           1.272                               0.800    0.800
    Q16           1.053                               0.663    0.663
    Q18           1.154                               0.726    0.726


Is it possible I've missed something in the syntax? 
Any thought would be much a appreciated!

בתאריך יום שבת, 21 ביוני 2014 15:50:45 UTC+3, מאת Yves Rosseel:
Message has been deleted

ni wi

unread,
Jun 30, 2014, 7:56:43 AM6/30/14
to lav...@googlegroups.com
.

Edward Rigdon

unread,
Jun 30, 2014, 8:10:57 AM6/30/14
to lav...@googlegroups.com
Diana--
     If a common factor has 2 indicators, you do not need to constrain the Loadings to equality in order to achieve identification, as long as the factor covaries significantly with something else, like another common factor.  Unless those loading equality constraints for the factors with two indicators are based on prior knowledge, I would remove them.  Understand otherwise that the CFA function is imposing constraints of its own to achieve identification.  It is quite likely that those defaults along would achieve identification for you, without the steps you have taken in this syntax.  On the other hand, I am entirely in favor of specifying your own model, rather than relying on automatic constraints that may not be entirely clear.
--Ed Rigdon

Sent from my iPad

On Jun 25, 2014, at 4:18 PM, Diana Meter <djm...@gmail.com> wrote:

Hello,

I've been trying to fit a model with a number of single indicator and 2-indicator constructs. I also have a categorical single indicator, but I pulled it out just to see if I could get this to run. I previously fit this model in another program and had fair model fit. I am new to lavaan and have tried different ways of setting the scale and providing values for the variances and residual variances in order for each construct to be locally identified. After running the model below the following error message came up:

lavaan WARNING: covariance matrix of latent variables is not positive definite; use inspect(fit,"cov.lv") to investigate.

If anyone has ideas about how to fix this syntax or a better (or best) way model with single and 2-indicator constructs, I'd very much appreciate your response.
Thank you!

mod1 <- '
cvict =~ cvict1 + cvict2 + cvict3
cbul =~ v2*cbul1 + v2*cbul2
clim =~ clim1 + clim2 + clim3 + clim4
teachdo=~NA*teachdo1
peerdo=~NA*peerdo1
agg =~ v3*agg1 + v3*agg2
assert =~ v6*assert1 + v6*assert2
talk=~NA*talk1
telladult =~ v4*telladult1 + v4*telladult2
donothing =~ v5*donothing1 + v5*donothing2
cvict~~1*cvict
clim~~1*clim
teachdo~~1*teachdo
peerdo~~1*peerdo
agg~~1*agg
assert~~1*assert
talk~~1*talk
telladult~~1*telladult
cbul~~1*cbul
donothing~~1*donothing'

fit1 <- cfa(mod1, data=data, meanstructure=T, control=list(iter.max=1000), verbose=TRUE, std.lv=TRUE)
summary(fit1, standardized=T, fit.measures=T)


Warning message:

In lavaan::lavaan(model = mod1, data = data, meanstructure = T,  :
 
> summary(fit1, standardized=T, fit.measures=T)
lavaan (0.5-16) converged normally after  45 iterations

  Number of observations                           480

  Estimator                                         ML
  Minimum Function Test Statistic              527.746
  Degrees of freedom                               133
  P-value (Chi-square)                           0.000

Model test baseline model:

  Minimum Function Test Statistic             2369.511
  Degrees of freedom                               190
  P-value                                        0.000

User model versus baseline model:

  Comparative Fit Index (CFI)                    0.819
  Tucker-Lewis Index (TLI)                       0.741

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)             -13373.637
  Loglikelihood unrestricted model (H1)     -13109.764

  Number of free parameters                         97
  Akaike (AIC)                               26941.274
  Bayesian (BIC)                             27346.131
  Sample-size adjusted Bayesian (BIC)        27038.263

Root Mean Square Error of Approximation:

  RMSEA                                          0.079
  90 Percent Confidence Interval          0.072  0.086
  P-value RMSEA <= 0.05                          0.000

Standardized Root Mean Square Residual:

  SRMR                                           0.067

Parameter estimates:

  Information                                 Expected
  Standard Errors                             Standard

                   Estimate  Std.err  Z-value  P(>|z|)   Std.lv  Std.all
Latent variables:
  cvict =~
    cvict1            0.246    0.037    6.684    0.000    0.246    0.399
    cvict2            0.427    0.046    9.321    0.000    0.427    0.653
    cvict3            0.151    0.026    5.716    0.000    0.151    0.339
  cbul =~
    cbul1    (v2)     0.236    0.018   13.435    0.000    0.236    0.511
    cbul2    (v2)     0.236    0.018   13.435    0.000    0.236    0.626
  clim =~
    clim1             0.727    0.070   10.350    0.000    0.727    0.498
    clim2             0.522    0.076    6.895    0.000    0.522    0.336
    clim3             0.863    0.082   10.486    0.000    0.863    0.504
    clim4             0.777    0.073   10.667    0.000    0.777    0.513
  teachdo =~
    teachdo1          1.819    0.059   30.984    0.000    1.819    1.000
  peerdo =~
    peerdo1           1.612    0.052   30.984    0.000    1.612    1.000
  agg =~
    agg1     (v3)     0.770    0.040   19.092    0.000    0.770    0.726
    agg2     (v3)     0.770    0.040   19.092    0.000    0.770    0.667
  assert =~
    assert1  (v6)     0.817    0.053   15.543    0.000    0.817    0.657
    assert2  (v6)     0.817    0.053   15.543    0.000    0.817    0.575
  talk =~
    talk1             1.267    0.041   30.984    0.000    1.267    1.000
  telladult =~
    telldlt1 (v4)     1.285    0.044   28.938    0.000    1.285    0.958
    telldlt2 (v4)     1.285    0.044   28.938    0.000    1.285    0.914
  donothing =~
    donthng1 (v5)     0.565    0.060    9.465    0.000    0.565    0.437
    donthng2 (v5)     0.565    0.060    9.465    0.000    0.565    0.506

Covariances:
  cvict ~~
    cbul              0.634    0.086    7.392    0.000    0.634    0.634
    clim             -0.302    0.085   -3.555    0.000   -0.302   -0.302
    teachdo          -0.239    0.062   -3.840    0.000   -0.239   -0.239
    peerdo           -0.045    0.064   -0.709    0.479   -0.045   -0.045
    agg               0.000    0.078    0.003    0.997    0.000    0.000
    assert            0.094    0.085    1.101    0.271    0.094    0.094
    talk              0.120    0.063    1.891    0.059    0.120    0.120
    telladult         0.036    0.065    0.552    0.581    0.036    0.036
    donothing        -0.011    0.105   -0.109    0.913   -0.011   -0.011
  cbul ~~
    clim             -0.152    0.088   -1.734    0.083   -0.152   -0.152
    teachdo          -0.166    0.064   -2.610    0.009   -0.166   -0.166
    peerdo           -0.119    0.064   -1.862    0.063   -0.119   -0.119
    agg               0.276    0.078    3.553    0.000    0.276    0.276
    assert           -0.102    0.086   -1.183    0.237   -0.102   -0.102
    talk              0.088    0.064    1.362    0.173    0.088    0.088
    telladult        -0.110    0.066   -1.659    0.097   -0.110   -0.110
    donothing        -0.062    0.107   -0.585    0.559   -0.062   -0.062
  clim ~~
    teachdo           0.765    0.042   18.327    0.000    0.765    0.765
    peerdo            0.582    0.050   11.720    0.000    0.582    0.582
    agg               0.067    0.077    0.868    0.386    0.067    0.067
    assert            0.220    0.082    2.673    0.008    0.220    0.220
    talk              0.010    0.062    0.167    0.867    0.010    0.010
    telladult         0.461    0.056    8.200    0.000    0.461    0.461
    donothing         0.301    0.102    2.952    0.003    0.301    0.301
  teachdo ~~
    peerdo            0.354    0.040    8.875    0.000    0.354    0.354
    agg               0.071    0.056    1.260    0.208    0.071    0.071
    assert            0.001    0.061    0.015    0.988    0.001    0.001
    talk              0.041    0.046    0.902    0.367    0.041    0.041
    telladult         0.137    0.046    2.974    0.003    0.137    0.137
    donothing         0.101    0.075    1.336    0.181    0.101    0.101
  peerdo ~~
    agg               0.114    0.056    2.050    0.040    0.114    0.114
    assert            0.085    0.061    1.399    0.162    0.085    0.085
    talk              0.046    0.046    1.018    0.308    0.046    0.046
    telladult         0.381    0.040    9.423    0.000    0.381    0.381
    donothing         0.120    0.075    1.595    0.111    0.120    0.120
  agg ~~
    assert            0.194    0.074    2.614    0.009    0.194    0.194
    talk              0.093    0.056    1.653    0.098    0.093    0.093
    telladult        -0.062    0.058   -1.066    0.286   -0.062   -0.062
    donothing        -0.045    0.093   -0.479    0.632   -0.045   -0.045
  assert ~~
    talk              0.553    0.051   10.840    0.000    0.553    0.553
    telladult         0.292    0.060    4.868    0.000    0.292    0.292
    donothing        -0.295    0.100   -2.936    0.003   -0.295   -0.295
  talk ~~
    telladult         0.304    0.043    7.110    0.000    0.304    0.304
    donothing        -0.001    0.075   -0.010    0.992   -0.001   -0.001
  telladult ~~
    donothing         0.142    0.077    1.827    0.068    0.142    0.142

Intercepts:
    cvict1            1.264    0.028   44.845    0.000    1.264    2.047
    cvict2            1.354    0.030   45.396    0.000    1.354    2.072
    cvict3            1.096    0.020   53.921    0.000    1.096    2.461
    cbul1             1.168    0.021   55.325    0.000    1.168    2.525
    cbul2             1.128    0.017   65.422    0.000    1.128    2.986
    clim1             2.901    0.067   43.537    0.000    2.901    1.987
    clim2             2.851    0.071   40.167    0.000    2.851    1.833
    clim3             2.148    0.078   27.486    0.000    2.148    1.255
    clim4             2.021    0.069   29.227    0.000    2.021    1.334
    teachdo1          2.079    0.083   25.043    0.000    2.079    1.143
    peerdo1           1.766    0.074   24.001    0.000    1.766    1.095
    agg1              1.619    0.048   33.429    0.000    1.619    1.526
    agg2              1.783    0.053   33.831    0.000    1.783    1.544
    assert1           3.416    0.057   60.139    0.000    3.416    2.745
    assert2           3.138    0.065   48.346    0.000    3.138    2.207
    talk1             2.879    0.058   49.791    0.000    2.879    2.273
    telladult1        2.436    0.061   39.774    0.000    2.436    1.815
    telladult2        2.497    0.064   38.905    0.000    2.497    1.776
    donothing1        2.791    0.059   47.312    0.000    2.791    2.159
    donothing2        2.243    0.051   43.982    0.000    2.243    2.008
    cvict             0.000                               0.000    0.000
    cbul              0.000                               0.000    0.000
    clim              0.000                               0.000    0.000
    teachdo           0.000                               0.000    0.000
    peerdo            0.000                               0.000    0.000
    agg               0.000                               0.000    0.000
    assert            0.000                               0.000    0.000
    talk              0.000                               0.000    0.000
    telladult         0.000                               0.000    0.000
    donothing         0.000                               0.000    0.000

Variances:
    cvict             1.000                               1.000    1.000
    clim              1.000                               1.000    1.000
    teachdo           1.000                               1.000    1.000
    peerdo            1.000                               1.000    1.000
    agg               1.000                               1.000    1.000
    assert            1.000                               1.000    1.000
    talk              1.000                               1.000    1.000
    telladult         1.000                               1.000    1.000
    cbul              1.000                               1.000    1.000
    donothing         1.000                               1.000    1.000
    cvict1            0.321    0.024                      0.321    0.841
    cvict2            0.245    0.036                      0.245    0.573
    cvict3            0.176    0.013                      0.176    0.885
    cbul1             0.158    0.012                      0.158    0.739
    cbul2             0.087    0.009                      0.087    0.608
    clim1             1.603    0.114                      1.603    0.752
    clim2             2.145    0.142                      2.145    0.887
    clim3             2.186    0.156                      2.186    0.746
    clim4             1.692    0.121                      1.692    0.737
    teachdo1          0.000                               0.000    0.000
    peerdo1           0.000                               0.000    0.000
    agg1              0.533    0.058                      0.533    0.474
    agg2              0.740    0.067                      0.740    0.555
    assert1           0.880    0.086                      0.880    0.568
    assert2           1.354    0.109                      1.354    0.670
    talk1             0.000                               0.000    0.000
    telladult1        0.149    0.037                      0.149    0.083
    telladult2        0.325    0.041                      0.325    0.165
    donothing1        1.351    0.107                      1.351    0.809
    donothing2        0.929    0.087                      0.929    0.744

--
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 post to this group, send email to lav...@googlegroups.com.
Visit this group at http://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.

yrosseel

unread,
Jul 1, 2014, 4:13:03 AM7/1/14
to lav...@googlegroups.com
On 06/23/2014 01:08 PM, ni wi wrote:
> Hello!
> I'm new to R (and to SEM in general), and currently I'm trying to run a
> few CFAs.
> I've came across similar warnings when I tried to fit a bifactor model
> to my data. I was able to fit more simple models, in which I've
> separated the factors for the bifactor model.
>
> here is the syntax and part of the output:
>
> datar.model<- '
> general =~ Q2 + Q3 + Q5 + Q8 + Q10 + Q11 + Q12 + Q15 + Q16 + Q18 + Q21 +
> Q22 + Q25 + Q28 + Q29 + Q30 + Q33 + Q35 + Q36 + Q37 + Q39 + Q40 + Q41 +
> Q43 + Q48 + Q49 + Q4 + Q7 + Q9 + Q13 + Q17 + Q20 + Q23 + Q26 + Q27 + Q31
> + Q34 + Q38 + Q42 + Q44 + Q45 + Q46 + Q47
> at =~ Q2 + Q3 + Q5 + Q8 + Q10 + Q11 + Q12 + Q15 + Q16 + Q18 + Q21 + Q22
> + Q25 + Q28 + Q29 + Q30 + Q33 + Q35 + Q36 + Q37 + Q39 + Q40 + Q41 + Q43
> + Q48 + Q49
> hy =~ Q4 + Q7 + Q9 + Q13 + Q17 + Q20 + Q23 + Q26 + Q27 + Q31 + Q34 + Q38
> + Q42 + Q44 + Q45 + Q46 + Q47
> '

In a bifactor model, the 'general' factor should be orthogonal
(uncorrelated) to the other factors. So, add this:

general ~~ 0*at
general ~~ 0*hy

to your model syntax.

Yves.

Reply all
Reply to author
Forward
0 new messages