2

I am running a CFA with the lavaan package in R, but get this error message, saying that some observed variables are missing:

Error in lav_data_full(data = data, group = group, cluster = cluster,  : 
  lavaan ERROR: missing observed variables in dataset: Q2 Q4 Q5 Q6 Q12 Q15 Q17 Q18 Q20 Q21 Q25 Q3 Q9 Q10 Q11 Q13 Q14 Q16 Q24 Q26 Q1 Q7 Q8 Q19 Q22 Q23

Here is my code:

dat <- read.csv(file="C:/.../CFA_R.csv",header=TRUE, sep=",")

Factor3.model<-'
 Reward=~ Q2+Q4+Q5+Q6+Q12+Q15+Q17+Q18+Q20+Q21+Q25
 Profession=~ Q3+Q9+Q10+Q11+Q13+Q14+Q16+Q24+Q26
 Mentor=~ Q1+Q7+Q8+Q19+Q22+Q23'

fit<- cfa(model =Factor3.model, data = dat, mimic = "Mplus",
          estimator = "WLSMV", missing = "listwise")

I did other descriptive analysis on my data which means the data was read in successfully.

I don't know what's wrong.

Any help is appreciated. Thanks.

stefan
  • 90,330
  • 6
  • 25
  • 51
shuying
  • 21
  • 1
  • 2
  • 1
    Can you run summary(dat) with a desirable outcome? Haven't you renamed the dat to data or something similar? It's difficult to tell where's the mistake without reproducible example. – Lstat Apr 05 '20 at 12:25
  • 1
    ï..Q1 Q2 Min. :1.000 Min. :1.00 1st Qu.:4.000 1st Qu.:3.00 Median :4.000 Median :4.00 Mean :4.198 Mean :3.81 3rd Qu.:5.000 3rd Qu.:5.00 Max. :5.000 Max. :5.00 Yes. I ran summary and didn't see anything abnormal – shuying Apr 05 '20 at 13:06
  • 1
    Can you edit your question and add `dput(head(dat))`? – Lstat Apr 06 '20 at 06:23
  • 1
    Q1-Q26 is my variable name when I used dput(head(dat)) I got the following outpout structure(list(ï..Q1 = c(1L, 1L, 1L, 1L, 1L, 1L), Q2 = c(1L, 2L, 3L, 1L, 2L, 1L), Q3 = c(2L, 3L, 2L, 1L, 4L, 1L), Q4 = c(1L, 3L, 1L, 1L, 4L, 1L), Q5 = c(1L, 3L, 4L, 1L, 5L, 1L), Q6 = c(1L, 5L, 5L, 1L, 2L, 1L), Q7 = c(1L, 5L, 5L, 1L, 1L, 1L), Q8 = c(3L, 1L, 2L, 3L, 4L, 3L), Q9 = c(5L, 4L, 5L, 1L, 5L, 5L), Q10 = c(3L, 5L, 2L, 3L, 2L, 5L), Q11 = c(2L, 5L, 2L, 4L, 4L, 4L), Q12 = c(3L, 4L, 2L, 4L, 5L, 3L).....), row.names = c(NA, 6L), class = "data.frame") > – shuying Apr 07 '20 at 18:02
  • 1
    I can run the model on your dput data (after removing missing variables). It only fails at the estimation phase due to the insufficient number of observations. Try to create a simplified example on a new data.frame. – Lstat Apr 08 '20 at 06:40

1 Answers1

0

The error message is because lavaan is looking for data but you have defined it as dat

This has been fixed in the code block and so the question has inconsistencies.

MilleCodex
  • 315
  • 2
  • 6