SEM categorical item issue

2,034 views
Skip to first unread message

Taman Powell

unread,
Dec 1, 2015, 4:59:24 PM12/1/15
to lavaan
Hello, I'm a bit of a novice at lavaan and SEM and was hoping for some assistance with this problem. Basically I have a SEM that was working fine, now I’ve added 4 binary items to the model (each one coded as 1 or 0) and the model dies with the following error:

Error in lavsamplestats@cov[[g]][cbind(row.idx, col.idx)] :
  subscript
out of bounds
In addition: Warning messages:
1: In lav_data_full(data = data, group = group, group.label = group.label,  :
  lavaan WARNING
: exogenous variable(s) declared as ordered in data: locSZ locGD locMA locOT
2: In lav_partable_check(lavpartable, categorical = categorical, warn = TRUE) :
  lavaan WARNING
: parameter table does not contain thresholds

The actual SEM model is:

modelDef <- '
Control =~ contr4 + contr6 + contr3 + contr9      # latent variable definitions
TranSuc =~ prac10 + prac7 + prac11
HCAvail =~ resoua12 + resoua11
HCDevl =~ perfor8 + perfor9
HCStr =~ confid4 + confid1 + confid3
Perform =~ perfor20 + perfor18 + perfor19


TranSuc ~ Control                                 # Model
HCStr ~ HCAvail + HCDevl
Perform ~ TranSuc + HCStr + Age + Sector + staffchil + staffhkl + locSZ + locGD + locMA + locOT
‘

With the locSZ,  locGD,  locMA, locOT fields being the categorical items. I’ve identified these in the SEM as follows as I think I need to do, but not having any joy.

modelFit <- sem(modelDef, data = dataset, ordered=c("locSZ","locGD", "locMA","locOT")
               
, sample.cov = true, estimator = "WLS")


Prior to adding these 4 items it was all working fine!

Any tips would be greatly appreciated.

yrosseel

unread,
Dec 2, 2015, 10:55:24 AM12/2/15
to lav...@googlegroups.com
On 12/01/2015 10:59 PM, Taman Powell wrote:

> Perform ~ TranSuc + HCStr + Age + Sector + staffchil + staffhkl + locSZ
> + locGD + locMA + locOT
>
> With the locSZ, locGD, locMA, locOT fields being the categorical
> items. I’ve identified these in the SEM as follows as I think I need to
> do, but not having any joy.
>
> |
> modelFit <-sem(modelDef,data
> =dataset,ordered=c("locSZ","locGD","locMA","locOT")
> ,sample.cov =true,estimator ="WLS")

Only endogenous (dependent) variables need to be declared as 'ordered'.
Not exogenous predictors. If they are binary (coded 0/1), you can just
leave them as they are.

See: http://lavaan.ugent.be/tutorial/cat.html

Yves.

Taman Powell

unread,
Dec 2, 2015, 11:54:38 AM12/2/15
to lav...@googlegroups.com
Hi Yves,

Thanks for your response. I’ve tried just leaving them binary coded. The model works when I just use 1 of the 4 items, but when I add a second I get an error:

Error in lav_samplestats_from_data(lavdata = lavdata, missing = lavoptions$missing,  : 
  lavaan ERROR: Gamma (NACOV) matrix is not positive-definite

I’ve tried this will all different combinations but still seem to get the same error.

Sorry if this is a really basic question. But it’s killing me!

Best, Taman 
--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/QxnaM5eyNv8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.
To post to this group, send email to lav...@googlegroups.com.
Visit this group at http://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.

yrosseel

unread,
Dec 2, 2015, 12:59:17 PM12/2/15
to lav...@googlegroups.com
On 12/02/2015 05:54 PM, Taman Powell wrote:
> Thanks for your response. I’ve tried just leaving them binary coded. The
> model works when I just use 1 of the 4 items, but when I add a second I
> get an error:
>
> Error in lav_samplestats_from_data(lavdata = lavdata, missing =
> lavoptions$missing, :
> lavaan ERROR: Gamma (NACOV) matrix is not positive-definite

Are the binary variables perfectly correlated?

Could you post a snippet of the data (just enough to show this error)?
Only then can we investigate.

Yves.

Taman Powell

unread,
Dec 2, 2015, 1:09:25 PM12/2/15
to lav...@googlegroups.com
Hi Yves,

I’m actually just trying to control for geographic area in the data. So I’ve setup four items where only one will be true relating to the area that the company is in. I’m attaching a csv with the first 40 lines of data. The fields are E, F, G, H. Only one in each row will be positive relating to the geographic area that the company is in. Maybe there is a better way to do this, but this seemed to make sense.

Thanks again for your help with this. In final revision (well should be) of quite a big paper for me and this is the key outstanding question.

Best, Taman
for Yves.csv

yrosseel

unread,
Dec 2, 2015, 1:24:46 PM12/2/15
to lav...@googlegroups.com
On 12/02/2015 07:09 PM, Taman Powell wrote:
> I’m actually just trying to control for geographic area in the data. So
> I’ve setup four items where only one will be true relating to the area
> that the company is in.

It would seem three columns are enough (and use 0 0 0 for the 4th area).

Yves.

Taman Powell

unread,
Dec 2, 2015, 1:51:08 PM12/2/15
to lav...@googlegroups.com
Three would be enough, but even when I just use 2 of the items it returns a:

Error in lav_samplestats_from_data(lavdata = lavdata, missing = lavoptions$missing,  : 
  lavaan ERROR: Gamma (NACOV) matrix is not positive-definite

I’m just trying to see whether geographic area has an impact on the model - like the attached figure (geographic areas being the four items to the right).

Best, Taman


Figures 4.pdf

yrosseel

unread,
Dec 2, 2015, 1:53:48 PM12/2/15
to lav...@googlegroups.com
On 12/02/2015 07:51 PM, Taman Powell wrote:
> Three would be enough, but even when I just use 2 of the items it returns a:
>
> Error in lav_samplestats_from_data(lavdata = lavdata, missing =
> lavoptions$missing, :
> lavaan ERROR: Gamma (NACOV) matrix is not positive-definite
>
> I’m just trying to see whether geographic area has an impact on the
> model - like the attached figure (geographic areas being the four items
> to the right).

Is it possible that the information contained in the two location
variables somehow overlaps with information contained in other parts of
the model?

If you wish, you can email me the full data + script directly, and I can
have a look at it.

Yves.

Message has been deleted

yrosseel

unread,
Dec 2, 2015, 3:45:52 PM12/2/15
to lav...@googlegroups.com
On 12/02/2015 07:56 PM, Taman Powell wrote:
> Hi Yves,
>
> I don’t think there is any overlap with other parts of the model.
> Basically model was looking at completely different things and then had
> a query regarding whether geographic area had an impact, so setup the 4
> items to look at this. Anyway, I’m attaching the complete dataset and
> code. I really appreciate your help with this.

Ok. The estimator is the problem: "WLS". Your sample is not large enough
for this estimator. You really should use ML, or even better MLR (robust
ML). It works, I tried.

WLS (in the continuous case!) will treat all variables (including the
exogenous 0/1 variables) as stochastic and Gaussian. That will almost
certainly give problems if you include 0/1 variables...

Yves.

Taman Powell

unread,
Dec 2, 2015, 3:58:55 PM12/2/15
to lav...@googlegroups.com
Thank you! OMG, it works. I didn’t think about trying to change this. Changed almost everything else!! Thanks again!!!! If you’re in London sometime let me buy you several beers :-)

Mandy

unread,
Jan 12, 2016, 1:49:19 PM1/12/16
to lavaan
Dear Yves, 

My question is out of topic but I was wondering whether you could tell me the equations of how to manually calculate 
(i) the Satorra-Bentler scaling correction factor by which to divide the original ML chi-square test statistic
and 
(i) robust standard errors (the ones that show in lavaan package under MLM)

Thanking you in advance

Reply all
Reply to author
Forward
0 new messages