0

I'm trying to use a confirmatory factor analysis (CFA) in R studio. From what I have read online that CFA can be conducted in both categorical and continues variables. However the error message persists for all the continues variable. The code used is provided below

##CFA modelling
PSLmodel <- 'Geo =~ TR + PCI + EW
Traf =~ SRI + VPM
Colg =~ DELY + LUP'

##Model Fitting
fit <- cfa(PSLmodel, data=inputs_vehprop, std.lv=TRUE, estimator = "MLM")

I was expecting a CFA model with three latent variables. But stuck at this error.

Phil
  • 7,287
  • 3
  • 36
  • 66
  • The error is about the dataset. The function could not find some eof those variables in the data file supplied. You can use `head(inputs_vehprop)` to check whether all observed variables are in inputs_vehprop. – sfcheung Jul 08 '23 at 06:58
  • All observed variables are in the supplied data I have cross checked. The error is shown is for variables TR, EW, SRI, VPM, DELY which are continues in nature. While the two variable accepted the function are PCI and LUP are categorical variables. Some of the online reference shows that CFA can be performed on continues as well as discrete variables. Can you please guide me about the input type required for CFA and can i perform with continues ans well as categorical values. – Sujeet Sahoo Jul 09 '23 at 07:37
  • In that case, you do not need to specify the estimator manually ("MLM" cannot be used anyway). You can refer to the example on the official website (https://lavaan.ugent.be/tutorial/cat.html). Specify which variables are categorical and `cfa()` will do the rest (although you may override other options if necessary). – sfcheung Jul 09 '23 at 12:31
  • Nevertheless, the error may (or may not) be related to this issue. The easiest way to produce that error is using a variable not in the dataset. However, if you have confirmed that the variables are indeed in the data file, then it may be due to how lavaan "sees" the data file. If data security is a concern, may you run this, `str(inputs_vehprop[, c("TR", "PCI", "EW", "SRI", "VPM", "DELY", "LUP")], vec.len = 0)` and share the results? It should not display the raw data (though it will display factor labels, if any, and you will need to delete them). – sfcheung Jul 09 '23 at 12:32
  • Usually, we need script that can reproduce the error such that others can see what happened. However, I understand this is not easy if data security is a concern. Nevertheless, you can try to use a very small subset of your data (e.g., a few cases), or create a small artificial dataset with a structure identical (not similar, but identical) to your dataset, which can produce exactly the same error. Your problem can then be easier to solve this way. This post may be helpful: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example Hope this helps. – sfcheung Jul 09 '23 at 12:39
  • @sfcheung thanks removing the factor labels helped – Sujeet Sahoo Jul 14 '23 at 05:03

0 Answers0