Error in requesting modification indices for a fitted lavaan.mi model

164 views
Skip to first unread message

Timothy Wong

unread,
Apr 4, 2023, 1:32:33 AM4/4/23
to lavaan
Hello lavaan community,

I am wanting to request modification indices for a lavaan model conducted on multiply imputed datasets. Specifically, it is a threshold invariance model with a significant chi-square change versus the baseline model (suggesting non-invariance, hence why I want to inspect the mod indices).

My code is

mi1 <- modificationIndices.mi(thresh.fit)

Which produces the error and warning

Error in `$<.data.frame `(`*tmp*`, "mi", value = c(1.46131364303112, 0.458487752314134,  :
    replacement has 1560 rows, data has 1559
In addition: warning message:
In (function (..., deparse.level = 1)  :
    number of rows of result is not a multiple of vector length (arg1)

At the moment, I am running the command with test = "D1", but it is taking a long time to execute (as suggested by the documentation).

Has anyone encountered this issue as well?

Terrence Jorgensen

unread,
Apr 5, 2023, 5:29:02 PM4/5/23
to lavaan
Not sure why the number of rows in the parameter table differs from the number of score tests calculated for those rows, but modindices.mi() only provides score tests for fixed parameters.  If you want score tests for equality constraints on estimated parameters, you need to use lavTestScore.mi() and explicitly choose which constraints at the bottom of the parTable() you want to consider whether to release=

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

Elena O.

unread,
May 15, 2023, 3:03:31 PM5/15/23
to lavaan
Hi! Have you solved this? I am getting exactly the same warning!

Timothy Wong

unread,
May 15, 2023, 10:30:53 PM5/15/23
to lavaan
Hi Elena,

I tried Terrence's solution of lavTestScore.mi() on the model fitted to the multiple imputations, and this worked.

Elena O.

unread,
May 16, 2023, 7:02:10 AM5/16/23
to lavaan
For me, it all boils down to a problem with the loadedNamespaces(). Before I start running code, I have to check that no extra Namespaces have been loaded (even after restarting the session).

Timothy Wong

unread,
May 16, 2023, 10:12:20 PM5/16/23
to lavaan
Hi Elena,

I used to have this problem as well (R objects and other packages conflicting with semTools). If you go into Tools > General, make sure "Restore .RData into workspace at startup" is not selected, and (optionally) "Save workspace to .RData on exit" is set to Never.

This means you have to manually save and load any objects you want to keep (using the saveRDS and readRDS functions). But it should fix your issues with namespaces.

Elena O.

unread,
May 17, 2023, 8:02:51 PM5/17/23
to lav...@googlegroups.com
Hi Timothy,

I did this already, but it is still not solving the issue...

El mié, 17 may 2023, 4:12, Timothy Wong <thetimw...@gmail.com> escribió:
Hi Elena,

I used to have this problem as well (R objects and other packages conflicting with semTools). If you go into Tools > General, make sure "Restore .RData into workspace at startup" is not selected, and (optionally) "Save workspace to .RData on exit" is set to Never.

This means you have to manually save and load any objects you want to keep (using the saveRDS and readRDS functions). But it should fix your issues with namespaces.

On Tuesday, May 16, 2023 at 9:02:10 PM UTC+10 elenaort...@gmail.com wrote:
For me, it all boils down to a problem with the loadedNamespaces(). Before I start running code, I have to check that no extra Namespaces have been loaded (even after restarting the session).

El martes, 16 de mayo de 2023 a las 4:30:53 UTC+2, thetimw...@gmail.com escribió:
Hi Elena,

I tried Terrence's solution of lavTestScore.mi() on the model fitted to the multiple imputations, and this worked.
On Tuesday, May 16, 2023 at 5:03:31 AM UTC+10 elenaort...@gmail.com wrote:
Hi! Have you solved this? I am getting exactly the same warning!

El miércoles, 5 de abril de 2023 a las 23:29:02 UTC+2, Terrence Jorgensen escribió:
Not sure why the number of rows in the parameter table differs from the number of score tests calculated for those rows, but modindices.mi() only provides score tests for fixed parameters.  If you want score tests for equality constraints on estimated parameters, you need to use lavTestScore.mi() and explicitly choose which constraints at the bottom of the parTable() you want to consider whether to release=

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

--
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/49a927d9-c757-4c7a-9d18-b09b95aad107n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages