R cannot open file with cfa()

2k views Asked by At

Trying to complete a confirmatory factor analysis right now. Have been reading the tutorial but am unable to overcome the following error that comes after the fit command:

Error in file(file, "r") : cannot open the connection
In addition: Warning message:
In file(file, "r") : cannot open file ' independence =~ x1 + x2 + x3 + x4
          therapies =~ x5': No such file or directory

Code I am using:

df <- data.frame(df.raw)
carl.model <- ' independence =~ x1 + x2 + x3 + x4
                therapies =~ x5 + x6'

fit <- cfa(carl.model, data=df)

summary(fit, fit.measures = TRUE)
2

There are 2 answers

0
Laura Melissa Cruz Castro On BEST ANSWER

This is because you have another library with the same function. Specify that you are talking about lavaan

lavaan::cfa(carl.model, data=df)

0
Jebediah15 On

Restarting and clearing workspace solved this problem. I did not change anything to the above code and now runs cleanly.