CFA in lavaan package throwing 'unused arguments' error

I’m trying to do a confirmatory factor analysis using the lavaan package, but I’m running into issues. Here’s what I’ve done:

I’ve set up my factor structure like this:

model_spec <- '
Factor1: Item1, Item2, Item3
Factor2: Item4, Item5, Item6
Factor3: Item7, Item8, Item9
'

When I try to run the CFA with this code:

model_fit <- cfa(model_spec, reference.indicators = FALSE)

I get an error saying ‘unused arguments’. I’ve already installed the lavaan package, but it’s still not working.

Has anyone else run into this problem? Any ideas on what I might be doing wrong or how to fix it? I’m pretty new to CFA, so I might be missing something obvious. Thanks for any help!

hey luke, i’ve had similar issues. did u remember to load ur data into the cfa function? it should look like cfa(model_spec, data=your_dataset, reference.indicators=FALSE). Also, make sure ur variable names in the model match exactly with ur dataset columns. hope this helps!

I’ve encountered this error before, and it usually stems from issues with data or variable names. First, ensure that the data is properly loaded into the environment and that the variable names in the model specification exactly match the columns in your dataset. Also, check that you’re including all required arguments in the cfa() function. If the problem persists, try running summary() on your dataset to verify that all variables are present and have the proper data types. Additionally, consider setting extra parameters using lavOptions() and confirm you are using the latest version of lavaan.

Hey Luke87! :thinking: I’m curious about your CFA journey. Have you double-checked that you’re passing the data to the cfa() function? It’s a common hiccup!

Something like this might do the trick:

model_fit <- cfa(model_spec, data = your_data_frame, reference.indicators = FALSE)

Also, I wonder if all your items (Item1, Item2, etc.) match exactly with your dataset column names? R can be pretty picky about that stuff.

What version of lavaan are you using? Sometimes updating to the latest can solve mysterious errors.

Have you tried running a simpler model first to see if it works? Maybe start with just one factor and build up from there?

Let us know how it goes! CFA can be tricky, but we’re all learning together here. :blush: