Warning running fitMeasures on imputed SEM model: "In Th_mean - Implied$th : longer object length...

81 views
Skip to first unread message

Tim Cadman

unread,
May 22, 2019, 6:40:31 AM5/22/19
to lavaan
Hi there,

I'm running a structural equation model across imputed datasets using runMI and Lavaan. The model contains both ordinal and continuous data and uses the DWLS estimator.  The model converges fine on each imputed dataset and the summary output looks sensible (and comparable to running the model on the original dataset). However, when I use the fitMeasures function, I get the following warning message:

fitMeasures(mfq_imp_fit_1, 
            test = "D2",
            pool.robust = TRUE,
            baseline.model = NULL)

"In Th_mean - Implied$th :
  longer object length is not a multiple of shorter object length"

Some of the reported values are negative (e.g. TLI, CFI).

                 chisq                     df                 pvalue
              2493.948                993.000                  0.000
                  npar                 ntotal           chisq.scaled
               202.000               6409.000               2406.791
             df.scaled          pvalue.scaled         baseline.chisq
               993.000                  0.000               2078.517
           baseline.df        baseline.pvalue  baseline.chisq.scaled
              1081.000                  0.000               3913.828
    baseline.df.scaled baseline.pvalue.scaled                    cfi
              1081.000                  0.000                  0.000
            cfi.scaled                    rni             rni.scaled
                 0.501                 -0.505                  0.501
                  nnfi                    tli            nnfi.scaled
                -0.638                 -0.638                  0.457
            tli.scaled                    rfi             rfi.scaled
                 0.457                  1.000                  0.331
                   nfi             nfi.scaled                   pnfi
                -0.200                  0.385                 -0.184
           pnfi.scaled                    ifi             ifi.scaled
                 0.354                 -0.383                  0.516
                   mfi                  rmsea         rmsea.ci.lower
                 0.889                  0.015                  0.015
        rmsea.ci.upper           rmsea.pvalue           rmsea.scaled
                 0.016                  1.000                  0.015
 rmsea.ci.lower.scaled  rmsea.ci.upper.scaled    rmsea.pvalue.scaled
                 0.014                  0.016                  1.000
              gammaHat            adjGammaHat        gammaHat.scaled
                 0.990                  0.989                  0.991
    adjGammaHat.scaled                    rmr                   crmr
                 0.989                  0.706                  0.043
                  srmr
                 0.043

Do you have any ideas what is going on here? If you need more details of the model or other output to diagnose this just let me know.

Many thanks,

Tim

Terrence Jorgensen

unread,
May 23, 2019, 4:20:25 AM5/23/19
to lavaan
Do you have any ideas what is going on here? 

This is something lavaan does that I did not expect.  When there is a mix of continuous and categorical endogenous variables, the vector of model-implied thresholds returned by lav_model_implied() will include any continuous variable's mean instead of leaving that threshold NULL (i.e., excluding it from the vector).  I asked Yves whether that was intentional, before I program a fix.  I'll post here when it is resolved.

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

Tim Cadman

unread,
May 23, 2019, 5:28:20 AM5/23/19
to lavaan
Great - thanks for your quick response and support with this.

bw

Tim

Terrence Jorgensen

unread,
May 26, 2019, 4:03:48 PM5/26/19
to lavaan
This is resolved in the development version.

install.packages("lavaan", repos = "http://www.da.ugent.be", type = "source")
devtools
::install_github("simsem/semTools/semTools")

Tim Cadman

unread,
Jun 6, 2019, 6:15:14 AM6/6/19
to lavaan
Hi Terrence,

Apologies for the delay, I've been away at a conference.

I've tried to install the latest development version but I still get the same warning message and negative fit statistics. However I'm not completely sure the dev version installed correctly - I received the following warnings on install:

"Rd warning: C:/Users/tc18889/AppData/Local/Temp/RtmpWysgSG/R.INSTALL399875ff7e51/lavaan/man/getCov.Rd:39: file link 'cov2cor' in package 'stats' does not exist and so has been treated as a topic"
"Rd warning: C:/Users/tc18889/AppData/Local/Temp/RtmpWysgSG/R.INSTALL399875ff7e51/lavaan/man/lavaan-class.Rd:127: file link 'BIC' in package 'stats' does not exist and so has been treated as a topic"

Here are the versions I am running:

other attached packages:
[1] semTools_0.5-1.922 lavaan_0.6-4.1402

best wishes

Tim

Terrence Jorgensen

unread,
Jun 6, 2019, 7:41:05 AM6/6/19
to lavaan
[1] semTools_0.5-1.922 lavaan_0.6-4.1402

That's not the latest semTools.  Try installing it again in a fresh R session, then restart R again before loading semTools (it should be at least 0.5-1.926 now).

Tim Cadman

unread,
Jun 7, 2019, 6:44:09 AM6/7/19
to lavaan
Hi Terrence,

I've correctly installed the latest version; however I'm now getting the following error message:

fitMeasures(sdq_imp_fit_1, c("chisq", "srmr", "rmsea"), test = "D2", pool.robust = TRUE)

Error in object@h1List[[useImps[1]]] : subscript out of bounds

These are the package version I have loaded:

semTools_0.5-1.928 lavaan_0.6-4.1412

Many thanks,

Tim

Terrence Jorgensen

unread,
Jun 7, 2019, 7:27:46 AM6/7/19
to lavaan
I'm now getting the following error message:

It can't be the mix of continuous and categorical indicators, because that problem is fixed:

data(datCat)
datCat$u2
<- as.integer(datCat$u2) # mixture of ordered/continuous indicators
datCat$u3
<- as.integer(datCat$u3)
## impose missing values
set.seed(123)
for (i in 1:8) datCat[sample(1:nrow(datCat), size = .1*nrow(datCat)), i] <- NA
catout
<- cfa.mi(' f =~ 1*u1 + 1*u2 + 1*u3 + 1*u4 ', data = datCat,
                 m
= 3, seed = 456,
                 miArgs
= list(ords = paste0("u", c(1, 4:8)), noms = "g"))
fitMeasures
(catout, fit.measures = c("chisq","rmsea","srmr","cfi"),

           test
= "D2", pool.robust = TRUE)


fitMeasures(sdq_imp_fit_1, c("chisq", "srmr", "rmsea"), test = "D2", pool.robust = TRUE)

Error in object@h1List[[useImps[1]]] : subscript out of bounds

Not sure how that is possible.  It is trying to extract the first imputation's saturated-model information.  What do you see when you run this?

sdq_imp_fit_1@h1List[[1]]
str
(sdq_imp_fit_1@h1List)


If the first returns an error, and the second returns an empty list(), then try running your model again with the explicit argument runMI(..., h1 = TRUE).  The default is TRUE

lavOptions("h1")

so I'm not sure why it wouldn't save that slot.  Otherwise, please post your str(sdq_imp_fit_1@h1List) output so I can see what it looks like.

Tim Cadman

unread,
Jun 7, 2019, 8:00:49 AM6/7/19
to lavaan
Thanks Terrance. I've added the argument "hi = TRUE" and the fitMeasures function now runs without any warning messages.

However it is still returning a number of negative values:

fitMeasures(sdq_imp_fit_1, test = "D2", pool.robust = TRUE)
                 chisq                     df                 pvalue
              2470.728                741.000                  0.000
                  ariv                    fmi                   npar
                 4.503                  0.818                181.000
                ntotal           chisq.scaled              df.scaled
              6409.000               2907.092                741.000
         pvalue.scaled            ariv.scaled             fmi.scaled
                 0.000                  3.032                  0.752
        baseline.chisq            baseline.df        baseline.pvalue
              1128.886                820.000                  0.000
 baseline.chisq.scaled     baseline.df.scaled baseline.pvalue.scaled
              2034.922                820.000                  0.000
                   cfi             cfi.scaled                    rni
                 0.000                  0.000                 -4.600
            rni.scaled                   nnfi                    tli
                -0.783                 -5.197                 -5.197
           nnfi.scaled             tli.scaled                    rfi
                -0.973                 -0.973                  1.000
            rfi.scaled                    nfi             nfi.scaled
                 1.000                 -1.189                 -0.429
                  pnfi            pnfi.scaled                    ifi
                -1.074                 -0.387                 -3.459
            ifi.scaled                    mfi                  rmsea
                -0.674                  0.874                  0.019
        rmsea.ci.lower         rmsea.ci.upper           rmsea.pvalue
                 0.018                  0.020                  1.000
          rmsea.scaled  rmsea.ci.lower.scaled  rmsea.ci.upper.scaled
                 0.021                  0.021                  0.022
   rmsea.pvalue.scaled               gammaHat            adjGammaHat
                 1.000                  0.987                  0.985
       gammaHat.scaled     adjGammaHat.scaled                    rmr
                 0.984                  0.981                  0.757
            rmr_nomean                   srmr           srmr_bentler
                 0.757                  0.065                  0.065
   srmr_bentler_nomean                   crmr            crmr_nomean
                 0.065                  0.065                  0.065
            srmr_mplus      srmr_mplus_nomean
                 0.065                  0.065

Thanks for your ongoing help with this

bw

Tim

Terrence Jorgensen

unread,
Jun 7, 2019, 10:24:51 AM6/7/19
to lavaan
 it is still returning a number of negative values:

Notice the pattern?  It is only the incremental fit indices that are negative, and you can see the cause looking at the baseline.chisq, which is smaller than the hypothesized model's.  Strange things like that can happen when using conditional.x=TRUE because the default baseline.model syntax will estimate all possible effects of exogenous covariates on all other observed variables in the model, whereas your hypothesized model might only estimate a subset of possible covariate effects.  

?lav_partable_baseline

You could fit a custom baseline.model to pass via the baseline.model= argument, if you can think of a reasonable one to judge your hypothesized model(s) in reference to.  Note that the baseline model should be nested within all hypothesized models.

The other fit indices all look reasonable, but (s/c)rmr can also act weird when conditional.x=TRUE, because (again) the saturated model partials that covariates out of all observed variables, not just the ones implied by the effects you estimate in your hypothesized model.

Tim Cadman

unread,
Jun 7, 2019, 10:43:17 AM6/7/19
to lavaan
Ah ok - thanks for the explanation.

bw

Tim
Reply all
Reply to author
Forward
0 new messages