Error message in anova() when using MLR and FIML

2,054 views
Skip to first unread message

JB

unread,
Mar 25, 2013, 2:52:29 PM3/25/13
to lav...@googlegroups.com
Dear All,
I am using FIML and MLR in multi-group analysis. I get an error when I try to compare models with anova(). I do not get an error when I choose either MLR or FIML. I reproduced the error I get with the HS.model, see syntax below. The error is:

Error in if (scaling.factor < 0) scaling.factor <- as.numeric(NA) :
  missing value where TRUE / FALSE  is needed

Is it that I am not supposed to compare models when using both methods?

Thanks!

JB


HS.model <- 'visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9'

#create missing pattern
HSMiss <- HolzingerSwineford1939[,paste("x", 1:9, sep="")]
randomMiss <- rbinom(prod(dim(HSMiss)), 1, 0.1)
randomMiss <- matrix(as.logical(randomMiss), nrow=nrow(HSMiss))
HSMiss[randomMiss] <- NA
attach(HolzingerSwineford1939)
HSMiss=cbind(HSMiss,school)
detach(HolzingerSwineford1939)

 fit <- cfa(HS.model, data = HSMiss,group="school",missing="FIML",estimator="MLR")
fit1 <- cfa(HS.model, data = HSMiss,group="school",group.equal="loadings",missing="FIML",estimator="MLR")
anova(fit,fit1)
 

 

yrosseel

unread,
Mar 27, 2013, 3:58:13 PM3/27/13
to lav...@googlegroups.com
On 03/25/2013 07:52 PM, JB wrote:
> Dear All,
> I am using FIML and MLR in multi-group analysis. I get an error when I
> try to compare models with anova(). I do not get an error when I choose
> either MLR or FIML. I reproduced the error I get with the HS.model, see
> syntax below. The error is:
>
> Error in if (scaling.factor < 0) scaling.factor <- as.numeric(NA) :
> missing value where TRUE / FALSE is needed

That certainly looks like a bug. Will be fixed ASAP.

Yves.

Tobias Ludwig

unread,
Aug 26, 2013, 11:19:38 AM8/26/13
to lav...@googlegroups.com
I do have the same issue here!

JB

unread,
Dec 22, 2013, 10:01:14 AM12/22/13
to lav...@googlegroups.com
Hello,
I have come back to analyses with missing and non normal data, thus using Fiml and MLR in combination and I still get the same error with anova (see post above). I installed the latest release of lavaan but I get the same issue. Given the data I work on, I often need this configuration so it would be great if this was fixed...
Thanks a lot for lavaan and Happy Christmas 2013!
JB

yrosseel

unread,
Dec 29, 2013, 5:01:48 PM12/29/13
to lav...@googlegroups.com
On 12/22/2013 04:01 PM, JB wrote:
> Hello,
> I have come back to analyses with missing and non normal data, thus
> using Fiml and MLR in combination and I still get the same error with
> anova (see post above). I installed the latest release of lavaan but I
> get the same issue. Given the data I work on, I often need this
> configuration so it would be great if this was fixed...

I will fix this after the holidays (and certainly before 0.5-16) gets
released.

In the meantime, you can use the (hidden) SB.classic=TRUE option as in

anova(fit1, fit2, SB.classic = TRUE)

(In 0.5-16-dev, there is function lavTestLRT() which is a wrapper around
the anova() function; this one contains proper documentation).


Yves.

JB

unread,
Jan 7, 2014, 9:32:38 AM1/7/14
to lav...@googlegroups.com

Dear Yves,

Thanks for your answer! SB.classic works fine in the previous example (first post of this thread). Version .5-16-dev lavTestLRT(fit,fit1,SB.classic=T) also worked fine. Same thing with my data with one exception. I compared a series of nested models and the first one is a completely saturated model. When I run anova(saturated.model, constrained.model) I get a chi square diff equal to the model chi square I get in summary(constrained.model), as it should. However, when I use lavTestLRT(saturated.model, constrained.model,SB.classic=T) I get :

Error in if (any(cd1 < 0)) { : missing value where TRUE/FALSE needed

It is not very important as I can get the values anyway but it is still practical to extract results from a series of comparisons…

Many Thanks for your work!

JB

Yves Rosseel

unread,
Mar 5, 2014, 10:50:41 AM3/5/14
to lav...@googlegroups.com

It turns out this is much more difficult to fix (the original problem with FIML and MLR) than expected. Therefore, in 0.5-16, SB.classic=TRUE will be the default again (both in lavTestLRT() and anova()).

The good news is: it should work with saturated models.

Yves.

yleni...@gmail.com

unread,
Dec 23, 2015, 1:17:24 PM12/23/15
to lavaan
Hi Yves,

With version 0.5-20, whenever I use MLR and FIML, lavTestLRT() only uses the chi-square from ML, rather than MLR.

The output starts by stating the following: Scaled Chi Square Difference Test (method = "satorra.bentler.2001"). However, the chi-square is from ML estimation.

If I use anova or compareFit (from semTools) I get the same problem.

I can only do a scaled chi-square difference test with MLR and FIML, if I run measurementInvariance(). As useful as that function is, it would be great if lavTestLRT worked with MLR as well, as it would allow more control over the invariance testing process.

Thanks for all your work,
Ylenio

yrosseel

unread,
Jan 9, 2016, 1:47:50 PM1/9/16
to lav...@googlegroups.com
On 12/23/2015 07:17 PM, yleni...@gmail.com wrote:
> Hi Yves,
>
> With version 0.5-20, whenever I use MLR and FIML, lavTestLRT() only uses
> the chi-square from ML, rather than MLR.
>
> The output starts by stating the following: Scaled Chi Square Difference
> Test (method = "satorra.bentler.2001"). However, the chi-square is from
> ML estimation.

That is OK. The 'scaled' difference test scales the difference between
the non-scaled test statistics. See the references in ?lavTestLRT

Yves.

yleni...@gmail.com

unread,
Jan 11, 2016, 1:22:55 PM1/11/16
to lavaan

Thanks Yves. That’s great. I just wanted to make sure. 

Serena

unread,
Jun 13, 2024, 12:42:38 AM6/13/24
to lavaan

Hi there,

I also met a similar problem but with sem() when using MLR and FIML.

I have a standardized score of a variable that includes missing values. When I run a single-level model, it works well. 
However, when I run a multilevel model, it shows the error 'Error in if (scaling.factor < 0) scaling.factor <- as.numeric(NA) : missing value where TRUE/FALSE needed'.

If I remove either estimator = "MLR" or missing = "FIML", it works!

Does this mean I can not use both to run a multilevel model that includes missing values (might be just for standardized variables)?

Thanks in advance!
Serena

Terrence Jorgensen

unread,
Jun 20, 2024, 5:18:54 PM6/20/24
to lavaan
Please provide a reprex.  But first verify that this still occurs with the latest development version of lavaan.  You can install it using the remotes package:

remotes::install_github("yrosseel/lavaan")

Terrence D. Jorgensen    (he, him, his)
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam
http://www.uva.nl/profile/t.d.jorgensen


Mugo Muiruri

unread,
Jun 25, 2024, 7:39:42 AM6/25/24
to lav...@googlegroups.com
good

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/edcf4838-a2b5-4320-b030-a0399bdb9617n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages