All intercepts are 0 except one? Possible recoding problem

61 views
Skip to first unread message

Karen Boyd

unread,
Jul 27, 2018, 5:04:09 PM7/27/18
to lav...@googlegroups.com
Hi! 

I've encountered some weird behavior and haven't been able to straighten out what's going on. 

This is a sample of the output of summary(fit1,fit.measures=TRUE, standardized=TRUE)

Intercepts: Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
.item1         0.000                               0.000    0.000
.item2         0.000                               0.000    0.000
.item3         0.000                               0.000    0.000
.item4         0.000                               0.000    0.000
.item5         0.000                               0.000    0.000
.item6         0.000                               0.000    0.000
.item7         1.170    0.004  298.045   0.000    1.170    3.116
.item8         0.000                               0.000    0.000


Item 7 is a variable I attempted to recode. 

When solving a different issue, I stumbled across a readout that indicates that lavaan believes this variable has the number of levels it had before recoding, not after. (This is a table that returns after a cfa fails due to items with no variance. It has the following column names: "name idx nobs type exo user mean var nlev  lnam"). The nlev and lnam values for item 7 reflect the number of levels and "names" before the recode. I don't know, but I assume this is the cause of the anomaly in the "intercepts" readout, because the only difference between item7 and the other items is that i recoded it. 

I have tried to put in some recoded some binary variables as well (hoping that 0,1 instead of 1, NA is the solution to "no variance") and lavaan reports their old number of levels as well.

I have inspected each, and the recoding was successful-- the nlev and lnam values should be different. However, levels() of any item returns NULL, because of their data types, so I can't directly change the levels or names. 

Does anyone know what I've done wrong, or how I can fix this? 

Thanks, 
Karen 



--

Jeremy Miles

unread,
Jul 27, 2018, 5:07:35 PM7/27/18
to lav...@googlegroups.com
I think we need to see your code, and perhaps something like the result of summary(mydataframe).

Jeremy

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To post to this group, send email to lav...@googlegroups.com.
Visit this group at https://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.
--
--
My employer has nothing to do with this email. 

Karen Boyd

unread,
Jul 27, 2018, 6:50:35 PM7/27/18
to lav...@googlegroups.com
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: 
item3<- data$item3
item3[is.na(item3)] <- 0 

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: 

Intercepts: Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
.item1         0.000                               0.000    0.000
.item2         0.000                               0.000    0.000
.item3         0.000                               0.000    0.000
.item4         0.000                               0.000    0.000
.item5         0.000                               0.000    0.000
.item6         0.000                               0.000    0.000
.item7         1.170    0.004  298.045   0.000    1.170    3.116
.item8         0.000                               0.000    0.000

Other features are a "used" value lower than the "total" (I believe this is due to NA values) 

the variances table looks similar to the Intercepts table, in that item 7 is anomalous: 
            Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
.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 


To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+unsubscribe@googlegroups.com.

To post to this group, send email to lav...@googlegroups.com.
Visit this group at https://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.
--
--
My employer has nothing to do with this email. 

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+unsubscribe@googlegroups.com.

To post to this group, send email to lav...@googlegroups.com.
Visit this group at https://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.

Jeremy Miles

unread,
Jul 28, 2018, 1:19:02 AM7/28/18
to lav...@googlegroups.com
On Sat, 28 Jul 2018 at 00:50 Karen Boyd <karen...@gmail.com> wrote:
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: 
item3<- data$item3
item3[is.na(item3)] <- 0 

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

[snip]
 
ms. 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. .. )


If that's what you wrote, then it looks like you have pulled the variables out of the data  frame, and changed them. But then you ask Lavaan to read the data from the data frame. The data in the data frame are not changed.

What happens if you do:
 
data$item7[data$item7 == 3] <- 2 
data$item7[data$item7 == 2] <- 0

?

Karen Boyd

unread,
Jul 31, 2018, 4:42:47 PM7/31/18
to lav...@googlegroups.com
Oh goodness. Thank you. That explains it and seems obvious now. 

I am hesitant to change the data itself in case those "I don't knows" are theoretically valuable and I missed it, but I will create a new column in the data frame and recode there. 

Thank you very much!
Cheers, 
Karen 

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+unsubscribe@googlegroups.com.
To post to this group, send email to lav...@googlegroups.com.
Visit this group at https://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages