Nader Mehri
Nader Mehri

Reputation: 556

How to include a nominal factor variable in Confirmatory Factor Analysis using lavaan package

Using the code below, I am trying to fit a CFA model using laavan package. One of my observed variables is nominal with 5 categories (HOUSEHOLD_I), two of them are ordinal, and the remaining are dichotomic. My questions:

Is MLR an appropriate estimator for my variables? and

Is the specification of the variable types correct in my code? i.e., do I need to specify the dichotomic variables? How to specify the nominal variable?

# Specify the model for the Health_Status
    Health_Status <- '
      # Define latent factor
      Health_Status =~ IMMUNO_I + AUTOIMMUNE_I + HYPTENSE_I + DIABETES_I + CKD_I + CANCER_I +
                      CVD_I + ASTHMA_I + COPD_I + CLUNG_I + SICKLE_I + DEPRESSION_I + SUBSUSE_I +
                      INTRAVUSE_I + OTHERMH_I + OTHERCC_I + ordered(BMIC_I) + ordered(HLTHSTATUS_I) + factor(HOUSEHOLD_I)'
    # Fit the CFA model
    Health_Status <- sem(Health_Status, data=RADx0030_Imputed_imp1, estimator="MLR")
    summary(Health_Status, fit.measures=TRUE)
    

The code above returned the error below:

Error in lav_data_full(data = data, group = group, cluster = cluster, : lavaan ERROR: unordered factor(s) detected; make them numeric or ordered: HOUSEHOLD_I

Upvotes: 0

Views: 98

Answers (1)

Terrence
Terrence

Reputation: 1250

The lavaan model syntax is a character string, not a formula object, so you cannot use functions to transform variables that way. You have to make whatever dummy/contrast codes you want to use, so those variables can appear in your model syntax.

https://lavaan.ugent.be/tutorial/cat.html

Upvotes: 1

Related Questions