Accessing defined parameters vcov in runMI

87 views
Skip to first unread message

Petr Palíšek

unread,
Jun 9, 2024, 4:05:34 PMJun 9
to lavaan
Hi,
is there a way to access the variance-covariance matrix of the defined parameters of the lavaan.mi model list generated by the runMI function? In other words, is it possible to get the pooled estimates of what lavaan would output via lavInspect(fit, "vcov.def.std.all")?

Thank you!

Terrence Jorgensen

unread,
Jun 24, 2024, 11:10:28 AMJun 24
to lavaan
is there a way to access the variance-covariance matrix of the defined parameters of the lavaan.mi model list generated by the runMI function? In other words, is it possible to get the pooled estimates of what lavaan would output via lavInspect(fit, "vcov.def.std.all")?

Can I ask why?  What you want to accomplish might already be available in the new lavaan.mi package, which you can install from GitHub (along with the latest development versions of semTools and lavaan):

remotes::install_github("yrosseel/lavaan") 
remotes::install_github("TDJorgensen/lavaan.mi") 
remotes::install_github("simsem/semTools/semTools")

For example, there is now a standardizedSolution.mi() function.

If you need it for something specific I don't already implement, I can either implement it or think of a hack for you to obtain this.

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

Petr Palíšek

unread,
Jun 24, 2024, 6:00:35 PMJun 24
to lavaan
Dear Terrence,
thank you for your response.

Now I am indeed able to get the standardized estimate from the lavaan.mi object. I just need to find the function analogous to lavInspect(fit, "vcov.def.std.all").

I need to do this to run informative hypothesis testing using GORICA in the package restriktor on the pooled estimates. I can circumvent this by pooling the goricas from the imputed datasets but it would be useful to be able to do this on the pooled estimates as well. See: https://www.rdocumentation.org/packages/restriktor/versions/0.3-100/topics/goric

Thank you.
Petr

Dne pondělí 24. června 2024 v 17:10:28 UTC+2 uživatel Terrence Jorgensen napsal:

Terrence Jorgensen

unread,
Jun 24, 2024, 6:52:45 PMJun 24
to lavaan
I just need to find the function analogous to lavInspect(fit, "vcov.def.std.all").
I need to do this to run informative hypothesis testing using GORICA in the package restriktor on the pooled estimates

Ah, that is a good motivation indeed!  :-)
OK, here's the (undocumented) hack:  You can access that (or any) vcov via the standardizedSolution(type=) argument, ONLY when you also set a hidden argument return.vcov = TRUE.  The trick is to leave out the initial "vcov." from any lavInspect(what=) option, because I already paste() that in front of any type= string.

standardizedSolution.mi(fit, return.vcov = TRUE,
                        type = "def.std.all") # or "def.joint.std.all"

I implemented this hack for the semTools::monteCarloCI() function to work on lavaan.mi-class objects when standardized=TRUE.  Ultimately, it will return ANY lavInspect(what="vcov.*") output, which I had not foreseen being useful for anything else.  So I do not "support" this as a public feature, but it is a hack that will accomplish this particular goal.

Here is a reprex, in case anyone else finds this useful:

library(lavaan.mi)
data(HS20imps) # import a list of 20 imputed data sets

## specify CFA model from lavaan's ?cfa help page
HS.model <- '
  visual  =~ x1 + a*x2 + x3
  textual =~ x4 + b*x5 + x6
  speed   =~ x7 + c*x8 + x9
'
## fit model to 20 imputed data sets
fit <- cfa.mi(HS.model, data = HS20imps, constraints = 'abc := a*b*c')

standardizedSolution.mi(fit, return.vcov = TRUE, type = "def.std.all")
standardizedSolution.mi(fit, return.vcov = TRUE, type = "def.joint.std.all")

I would appreciate if you respond with your own reprex, to demonstrate how this can be useful for the restriktor or gorica packages.

Petr Palíšek

unread,
Jun 25, 2024, 9:47:29 AMJun 25
to lavaan
Wow, thank you, Terrence, that's very helpful! I will indeed like to send you my own reprex once I get this running.

The only issue I have now is that the function you sent does not return the VCOV for the defined parameters. This is an example of what I need in bare lavaan based on your code:

data(HS20imps) # import a list of 20 imputed data sets

## specify CFA model from lavaan's ?cfa help page
HS.model <- '
  visual  =~ x1 + a*x2 + x3
  textual =~ x4 + b*x5 + x6
  speed   =~ x7 + c*x8 + x9
 
  abc := a*b*c

'
## fit model to 20 imputed data sets
fit <- lavaan::cfa(HS.model, data = HS20imps$imp1)

VCOV <- lavaan::lavInspect(fit, what = "vcov.def.std.all")

With VCOV returning:       
         abc
abc 0.002

Thank you!
P.

Dne úterý 25. června 2024 v 0:52:45 UTC+2 uživatel Terrence Jorgensen napsal:

Terrence Jorgensen

unread,
Jun 26, 2024, 3:20:08 AMJun 26
to lavaan
the function you sent does not return the VCOV for the defined parameters

Yes, this function does:

standardizedSolution.mi(fit, return.vcov = TRUE, type = "def.std.all")

The pooled value is even the same (to the 3rd decimal place) as the one you showed for the first imputation.  If it is not working, please try installing lavaan.mi again.

The lavInspect() function will not provide this kind of output for a lavaan.mi-class object.  You can only reliably use lavInspect() for what= options listed on the ?lavListInspect help page. 

Petr Palíšek

unread,
Sep 5, 2024, 10:31:39 AMSep 5
to lavaan
Thanks for all your help, Terrence. I was able to get everything running. 

As per your request earlier in this thread, Rebecca Kuiper and I prepared a reproducible example of using GORICA with a lavaan.mi object. Hope this helps people with a similar issue!

Best,
Petr

Dne středa 26. června 2024 v 9:20:08 UTC+2 uživatel Terrence Jorgensen napsal:
gorica runmi reprex.R

Terrence Jorgensen

unread,
Sep 12, 2024, 5:19:17 AMSep 12
to lavaan
As per your request earlier in this thread, Rebecca Kuiper and I prepared a reproducible example of using GORICA with a lavaan.mi object

This works great, thanks for posting!
Reply all
Reply to author
Forward
0 new messages