Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Error when running sem model for ordinal endogenous variable

712 views
Skip to first unread message

Amanda Hoffman

unread,
May 8, 2019, 9:54:13 PM5/8/19
to lavaan
Below is the code that I am trying to run along with the error message I get. It was running previously, so I'm not sure what little change I made that would affect this.

Thanks in advance for your help!

expcomp is an ordinal variable from 1 to 11

> m4 <- '#measurement component
+        sint =~ NA * senjoy + swaste + sboring + senjoys + fav + least
+        mint =~ NA * menjoy + mwaste + mboring + menjoys + fav + least
+        sint ~~ 1 * sint
+        mint ~~ 1 * mint
+        muti =~ musec + musej + musel
+        suti =~ susec + susej + susel
+        belong =~ NA * safe + proud + talk + schwaste + goodgrades
+        belong ~~ 1 * belong
+        engage =~ hw + paper + books + late
+        musec ~~ susec
+        safe ~~ proud
+        musel ~~ susel
+        swaste ~~ mwaste
+        senjoys ~~ menjoys
+        proud ~~ talk
+        safe ~~ talk
+        musej ~~ susej
+        ##structural component
+        expcomp ~ h * belong + i * engage + c * suti + e * muti
+        engage ~ d * suti + f * muti + g * belong
+        suti ~ a * sint + j * muti
+        muti ~ b * mint
+        #indirect effects
+        ac := a * c
+        adi := a * d * i
+        be := b * e
+        bfi := b * f * i
+        bjc := b * j * c
+        bjdi := b * j * d * i
+        di := d * i 
+        fi := f * i
+        gi := g * i
+        sint ~~ mint'
> m4.fit <- sem(m4, data = dat2)
Error in eigen(VarCov, symmetric = TRUE, only.values = TRUE) : 
  infinite or missing values in 'x'
In addition: Warning message:
In sqrt(A1[[g]]) : NaNs produced

Yves Rosseel

unread,
May 10, 2019, 5:04:50 AM5/10/19
to lav...@googlegroups.com
> > m4.fit <- sem(m4, data = dat2)
> Error in eigen(VarCov, symmetric = TRUE, only.values = TRUE) :
>   infinite or missing values in 'x'
> In addition: Warning message:
> In sqrt(A1[[g]]) : NaNs produced

It looks like this was caused by the 'vcov' check (which was added
relatively recently, hence it may have worked before). You can shut it
off like this:

fit <- sem(...., check.vcov = FALSE)

If this works, then some other problems should be visible in the output
(or in the warning messages).

If you can send me a reproducible example, I can investigate the exact
cause of this error message.

Yves.

Shujun Liu

unread,
Nov 3, 2023, 11:20:58 AM11/3/23
to lavaan
Hi Yves,

I encountered the same errors when trying to run SEM model with ordinal exogenous variable (i.e., one item), and I used your advised methodology, then I got another error:

Error in if (scaling.factor < 0) scaling.factor <- as.numeric(NA) : missing value where TRUE/FALSE needed
I just wonder do you know the reason and how to solve this.

Thanks

Shujun

Terrence Jorgensen

unread,
Nov 5, 2023, 3:02:33 AM11/5/23
to lavaan
Please provide a reproducible example (just enough syntax and data to reproduce the problem).

Yves Rosseel

unread,
Nov 6, 2023, 2:26:15 AM11/6/23
to lav...@googlegroups.com
On 11/3/23 16:20, Shujun Liu wrote:
> I just wonder do you know the reason and how to solve this.

Hard to tell without a reprex. But I think the issue may be the ordinal
exogenous variable (which produces a warning). Declare that variable as
numeric in the data.frame. Something like

myData$item <- as.numeric(myData$item)

Does it work then?

Yves.

Tara P

unread,
Nov 14, 2023, 10:19:18 AM11/14/23
to lavaan
Dear all,

I seem to have the same problem as Shujun Liu.
I have a SEM model that runs fine normally, but when I want to correlate a binary exogenous variable ('psychopath') to a latent variable ('ER'), I get the errors above, and changing to numeric does not help. Weirdly enough, when regressing it, it is fine.  I've attached a csv with minimal data, and here is my code:

Model_PHQ<-'
 
  # PHQ bifactor contruction part
  pain =~ PQ01_02 + PQ01_03+ PQ01_06
  cardio =~ PQ01_07 + PQ01_08 + PQ01_10 + PQ01_11
  gastro =~ PQ01_01 + PQ01_05 + PQ01_12 + PQ01_13
  fatigue =~PQ02_01 + PQ02_02
  gsoma =~ NA*PQ01_02 + PQ01_03+ PQ01_06 + PQ01_07 + PQ01_08 + PQ01_10 + PQ01_11 + PQ01_01 + PQ01_05 + PQ01_12 + PQ01_13+PQ02_01 + PQ02_02
 
  #PHQ covariances
  gsoma ~~ 0*pain
  gsoma ~~0*cardio
  gsoma ~~ 0 * gastro
  gsoma ~~ 0 * fatigue
  pain ~~ 0*cardio + 0*fatigue + 0*gastro
  cardio ~~ 0*fatigue + 0*gastro
  fatigue ~~ 0*gastro
 
  #PHQ variances
  gsoma ~~ 1*gsoma
  fatigue~~1*fatigue
  cardio ~~1*cardio
  pain ~~ 1*pain
  gastro ~~1*gastro
 
  #Emotion regulation construction
  ER =~ NA*s_prepost_valence + s_prepost_arousal + r_prepost_arousal + r_prepost_valence
  gvalenz =~  NA*o_prepost_valence +s_prepost_valence + r_prepost_valence
  garousal =~ NA*o_prepost_arousal + r_prepost_arousal + s_prepost_arousal
 
  #Emotion regulation covariances
  o_prepost_valence ~~ o_prepost_arousal
  s_prepost_valence ~~ s_prepost_arousal
  r_prepost_valence ~~ r_prepost_arousal
  ER~~0*gvalenz + 0*garousal
  ER ~~ psychopath
 
  #Emotion regulation variances
  gvalenz ~~1*gvalenz
  garousal ~~ 1* garousal
  ER~~1*ER  
 
  #Bringing the 2 parts together
  ER ~~ gsoma+pain+cardio+gastro+fatigue
  gvalenz~~ pain + cardio + fatigue + gastro+ gsoma
  garousal ~~  pain + cardio + fatigue + gastro+ gsoma
'

fit_PHQ <- sem(model=Model_PHQ, na.omit(vars), estimator = "WLSMV", parameterization ="theta")
summary(fit_PHQ, standardized=TRUE, fit.measures=TRUE)



Thank you in advance!
minimalcodeTara.csv

Terrence Jorgensen

unread,
Nov 15, 2023, 10:01:03 AM11/15/23
to lavaan
By default with categorical outcomes, lavaan will set fixed.x = TRUE and conditional.x=TRUE.  It might help to set both FALSE if you want to correlate the residuals of an exogenous and endogenous variable.

Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Reply all
Reply to author
Forward
0 new messages