How to run CFA or SEM in LAVAAN when Indicator Variables for measuring the Latent Variables are binary categorical

94 views
Skip to first unread message

Priya Chetri

unread,
Sep 26, 2020, 1:46:00 PM9/26/20
to lavaan
Dear LAVAAN community

I am struggling with the following issue. 
For the measurement of the latent variables, the indicators variables that I am using are all binary categorical variables having two levels (0 for no, and 1 for yes).
For instance, for measuring X =~ x1+ x2+ x3 (all the xi take either of the two values: 0/1). And as per my understanding, the default measure in LAVAAN is MLE which is for continuous indicator variables. So when I run the SEM command, I am getting different warning messages and the model is not running accurately.
I looked at various places and there are suggestions like keeping the value of categorical indicator variables in numeric terms (like 1,2,3) will work but apparently it is not. further I checked that the degrees of freedom are positive so there should not be a problem of identification which might be generating warning messages.

Can anyone please take out some time and help me out in this. I have been struggling and have spent a lot of time but could not find a solution. The examples and explanations given everywhere is either about continuous variables or about the ordered argument in the SEM function (which is also not working for me).

Regards
Priya

Patrick (Malone Quantitative)

unread,
Sep 26, 2020, 2:47:13 PM9/26/20
to lav...@googlegroups.com
Priya,

Positive degrees of freedom means you don't have a certain type of identification problem, but a model can also be locally unidentified. One of the places this often happens is a factor with rare categorical indicators.

It's hard to help more without more information. What is your model? If your model is large, please post a small version that still causes the problem. What is your sem() call? What is the exact language of the warnings you are getting? Are they warnings or errors? Warnings don't necessarily invalidate your results, though you should certainly consider them and why you're getting them.

Pat


--
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/075abece-643b-4065-b5b4-7bfea7c32baen%40googlegroups.com.


--
Patrick S. Malone, Ph.D., Malone Quantitative
NEW Service Models: http://malonequantitative.com

He/Him/His

Priya Chetri

unread,
Sep 27, 2020, 7:51:44 AM9/27/20
to lav...@googlegroups.com
Dear Dr. Patrick

Thank you so much for responding. I will try to explain the problem so that it may help in understanding the issue.
I am trying to look at Information and Communication Technology (ICT) like: (mobile phone, computer tv etc.) and its impact on some farming outcomes. 
Now considering that I run a SEM or say CFA
I have the following construct for the measurement model where i am say constructing two latent variables

ICT_access = ownership_tv + ownership_smartphone+  ownership_computer
ICT_capability = able_to_read_and_open_sms + use_mobile_banking+ use_online_phone_apps

Now each of these indicator/observed variables are binary in the form of yes(coded as 1) and no(coded as 0). So prior to running the SEM/CFA command, I directed R to consider each of the indicator variable as a factor using the following way

f_tv <- factor(tv, levels = c("0", "1"), ordered = TRUE)
levels(f_tv)
OR
f_tv1 <- tv
as.factor(f_tv1)


and then plugged in the factors into the CFA command
cfa1 <- 'ICT_access =~ 1*f_tv +  f_smartphone+  f_computer
ICT_capability =~ 1*f_ open _and_read_sms + f_mobile_banking+ f_online_phone_apps'

fit1 <- cfa(cfa1, data = eth)
summary(fit1, fit.measures=TRUE)  


now I am getting the following error

Error in lavaan::lavaan(model = cfa1, data = eth, model.type = "cfa",  :
  lavaan ERROR: missing observed variables in dataset: f_tv f_smart_phone f_computer f_open_read_sms  f_mobile_banking
 f_online_phone_apps  


(NOTE: there are no missing values in these indicator variables)

The similar error is happening with the ordered argument when I use the following command instead:
fit1 <- cfa(cfa1, data = eth, ordered = c(" ICT_access ", " ICT_capability "))
summary(fit1, fit.measures=TRUE)
  Error in lav_data_full(data = data, group = group, cluster = cluster,  :
  lavaan ERROR: missing observed variables in dataset: f_tv f_smart_phone f_computer 
f_open_read_sms  f_mobile_banking
 f_online_phone_apps  
In addition: Warning message:
In lavaan::lavaan(model = sem1, data = eth, ordered = c("ict_access",  :
  lavaan WARNING: ordered variable(s): ICT_access ICT_capability
  could not be found in the data and will be ignored  


Now if I do not to declare the indicator variable as factor and simply run the CFA considering the indicator variable as numeric

cfa1 <- 'ict_access =~ 1*tv + smart_phone + computer
+ ict_cap =~ 1*open_read_sms + online_app + mobile_banking'
>
> fit2 <- cfa(cfa1, data = eth)

I am getting the following warning message:

Warning message:
In lav_object_post_check(object) :
  lavaan WARNING: covariance matrix of latent variables
                is not positive definite;
                use lavInspect(fit, "cov.lv") to investigate.

but the model is running as followed:

> summary(fit2, fit.measures = TRUE)
lavaan 0.6-6 ended normally after 113 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of free parameters                         17
                                                     
  Number of observations                           463
                                                     
Model Test User Model:
                                                     
  Test statistic                               308.643
  Degrees of freedom                                19
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                               882.042
  Degrees of freedom                                28
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.661
  Tucker-Lewis Index (TLI)                       0.500

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -1210.913
  Loglikelihood unrestricted model (H1)      -1056.591
                                                     
  Akaike (AIC)                                2455.826
  Bayesian (BIC)                              2526.168
  Sample-size adjusted Bayesian (BIC)         2472.214

Root Mean Square Error of Approximation:

  RMSEA                                          0.181
  90 Percent confidence interval - lower         0.164
  90 Percent confidence interval - upper         0.200
  P-value RMSEA <= 0.05                          0.000

Standardized Root Mean Square Residual:

  SRMR                                           0.103

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)
  ICT_access =~                                      
    tv2017            1.000                          
    smart_phon2017    8.272    3.879    2.133    0.033
    cmptr_w___2017    2.198    1.105    1.988    0.047
  ICT_capability =~                                          
    opn_rd_sms2017    1.000                          
    online_app2017    3.655    0.616    5.931    0.000
    mobl_bnkng2017    0.967    0.194    4.973    0.000
    use_atm2017       2.352    0.439    5.354    0.000
    us_dbtc___2017    1.098    0.218    5.033    0.000

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)
  ICT_access ~~                                      
    ICT_capability           0.004    0.002    2.005    0.045

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .tv2017            0.147    0.010   15.185    0.000
   .smart_phon2017    0.079    0.019    4.177    0.000
   .cmptr_w___2017    0.119    0.008   14.992    0.000
   .opn_rd_sms2017    0.104    0.007   14.912    0.000
   .online_app2017    0.064    0.009    7.383    0.000
   .mobl_bnkng2017    0.051    0.003   14.633    0.000
   .use_atm2017       0.180    0.013   14.228    0.000
   .us_dbtc___2017    0.061    0.004   14.588    0.000
    ICT_access        0.002    0.002    1.068    0.286
    ICT_capability           0.010    0.003    3.013    0.003



I am not able to understand these error and warning messages. As I mentioned earlier, the data collected for the observed variable is in binary form (yes/no = 1/0) and therefore the ML method for CFA/SEM is not feasible neacuse data is not continuous. Now I am not able to figure out how to proceed further.
Any help in this direction will be much appreciated.

Kind regards

Priya Chetri
Doctoral Candidate
School of Public Policy
Indian Institute of Technology Delhi
Hauz Khas, New Delhi-110016



Patrick (Malone Quantitative)

unread,
Sep 27, 2020, 10:11:55 AM9/27/20
to lav...@googlegroups.com
Priya,

Thanks for the additional information.

Let's start with the first error:

missing observed variables in dataset: f_tv f_smart_phone f_computer f_open_read_sms  f_mobile_banking
 f_online_phone_apps 

It tells you what the problem is. These newly created variables aren't in the dataframe eth.

Instead of:

f_tv <- factor(tv, levels = c("0", "1"), ordered = TRUE)

try

eth$f_tv <- factor(eth$tv, levels = c("0", "1"), ordered = TRUE)

That will put the new variable into eth so it will be available to cfa().

Also, one of your attempts resulted in:

WARNING: ordered variable(s): ICT_access ICT_capability
  could not be found in the data and will be ignored 

ICT_access and ICT_capability aren't in the eth dataset because they're latent variables you're estimating from the observed variables. (Also, even with ordered indicators, the latents aren't ordered, butthat's a different issue.)

Hope that helps.

Pat

Reply all
Reply to author
Forward
0 new messages