I'm afraid it's quite a large model and there are a ton of variables (i.e demographics) in the df that are necessary for other tests, but aren't used in this model. I'll try to pull out what I think is important, but feel free to ask for more.
First, I stored each of the columns into a variable:
i.e.
item1 <- data$item1
item2 <- data$item2
these are all likert style items with, for example, responses of 1, 2, 3, 4, 5 or NA. Some are smaller (ie. 1, 2, 3 or NA).
there are a couple binary ones, too, which I stored in this way:
I did this because if all the responses are 1 or NA, there's no variance and the model will not run. (I can't confirm that this works, because lavaan doesn't recognize the new level. Therefore I have yet to run the model successfully with these binary variables in it.)
For the anomalous variable described in my initial question, I recoded the variable in order to collapse categories 2 and 3 ("no" and "i don't know")
item7 <- data$item7
item7[item7 == 3] <- 2
item7[item7 == 2] <- 0
Then, I created a model, i.e:
CModel <-
' LV1 =~ item1 + item2 +item3 + item 4
LV2 =~ item5 + item6 + item7
LV3 =~ item8 + item9
LV4=~ item10 + item11 +item12
LV2~ LV3
LV1 ~ LV3
LV4 ~ LV1 + LV2'
(The above mimics the exact structure of the model, but does not include all the items. There are a lot).
Then I fit the model using CFA,
fit1 <- cfa(CModel1, data = data, meanstructure = TRUE,
ordered =c(item1, item2, item4, item5, item6, item7. .. )
When I try to included the binary variables in the model and in ordered(), it fails. If I include the binary variables in the model, but exclude them from ordered(), that at least allows the model to run, but the binary variables are not included in the summary report and the output looks the same as if they were not included in the model.
I have tried including item7 in ordered() and excluding it. When it is included, I get this error:
Error in lav_samplestats_step1(Y = Data, ov.names = ov.names, ov.types = ov.types, :
lavaan ERROR: some categories of variable `CAppHasPolicy' are empty in group 1; frequencies are [181 37 0]
If I keep it excluded, the model converges with the following warning :
Warning message:
In muthen1984(Data = X[[g]], ov.names = ov.names[[g]], ov.types = ov.types, :
lavaan WARNING: trouble constructing W matrix; used generalized inverse for A11 submatrix
I can still get a summary of the model:
summary(fit1,fit.measures=TRUE, standardized=TRUE)
The summary has the problem in the original email, quoted here:
.item5 0.773 0.773 0.773
.item6 0.938 0.938 0.938
.item7 0.112 0.010 11.097 0.000 0.112 0.792
.item8 0.477 0.477 0.477
.item9 0.643 0.643 0.643
For the dataframe summary you requested, here's an idea of what the normal, problem, and binary variables look like. Item 7 is the problem variable, item 8 is a very similar variable for which there is no problem and item 3 is a binary variable (which, as you can see, is not recognized as recoded, even though printing item3
item7 item8
Min. :1.000 Min. :1.000
1st Qu.:1.000 1st Qu.:1.000
Median :1.000 Median :1.000
Mean :1.335 Mean :1.377
3rd Qu.:1.000 3rd Qu.:2.000
item3
Min. :1
1st Qu.: 1
Median :1
Mean :1
3rd Qu.:1
item3 looks like this:
[1] 0 0 1 1 0 1 0 0 0 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 0 0 1 0 1 0 1 1 0 0 0 0 0 0 1 1 1 0 0 1 1 1 . . .
item7
[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 . . . NA. . .
item8
[1] 1 1 1 3 1 1 1 1 1 1 1 1 3 1 1 3 1 3 1 1 1 1 2 1 1 2 1 1 2 1 2 1 1 1 . . . NA. . .
(Item 8 did not require recoding to collapse categories 2 and 3)
Let me know if I can provide any more info-- I tried to be concise as I could because I know this is long.
Thanks!
Karen