Get a parameter estimate table from a lavaan.mi object?

167 views
Skip to first unread message

Shu Fai Cheung

unread,
Apr 16, 2023, 10:27:10 AM4/16/23
to lav...@googlegroups.com
Dear All,

I would like to ask a quick question on runMI() and lavaan.mi class objects.

parameterEstimates() can be used to get the parameter estimates of the output of lavaan() and its wrappers in the form of a lavaan.data.frame object.

I found that parameterEstimates() does not work on a lavaan.mi object. Only lhs, op, and rhs is returned, as shown in the example below.

However, if I call summary() but output is not set to "text", the default, then, the output is a lavaan.data.frame, as shown below. I also compared the results with those from summary() with output = "text" and confirmed that results are the same.

Is this an intended behavior of the summary-method of lavaan.mi? Can I trust this way to use summary() as the lavaan.mi version of parameterEstimates()?

Regards,
Shu Fai Cheung (張樹輝)

The long example appended below:
# Adapted from the example of runMI()

library(semTools)
#> Loading required package: lavaan
#> This is lavaan 0.6-15
#> lavaan is FREE software! Please report any bugs.
#> 
#> ###############################################################################
#> This is semTools 0.5-6
#> All users of R (or SEM) are invited to submit functions or ideas for functions.
#> ###############################################################################
HSMiss <- HolzingerSwineford1939[ , c(paste("x", 1:9, sep = ""),
                                      "ageyr","agemo","school")]
set.seed(12345)
HSMiss$x5 <- ifelse(HSMiss$x5 <= quantile(HSMiss$x5, .3), NA, HSMiss$x5)
age <- HSMiss$ageyr + HSMiss$agemo/12
HSMiss$x9 <- ifelse(age <= quantile(age, .3), NA, HSMiss$x9)
HS.model <- '
  visual  =~ x1 + x2 + x3
  textual =~ x4 + x5 + x6
  speed   =~ x7 + x8 + x9
'
out1 <- cfa.mi(HS.model, data = HSMiss, m = 20, seed = 12345,
               miArgs = list(noms = "school"))
#> Loading required namespace: Amelia
#> ## 
#> ## Amelia II: Multiple Imputation
#> ## (Version 1.8.1, built: 2022-11-18)
#> ## Copyright (C) 2005-2023 James Honaker, Gary King and Matthew Blackwell
#> ## Refer to http://gking.harvard.edu/amelia/ for more information
#> ##

# `parameterEstimates()` does not work
parameterEstimates(out1)
#>        lhs op     rhs
#> 1   visual =~      x1
#> 2   visual =~      x2
#> 3   visual =~      x3
#> 4  textual =~      x4
#> 5  textual =~      x5
#> 6  textual =~      x6
#> 7    speed =~      x7
#> 8    speed =~      x8
#> 9    speed =~      x9
#> 10      x1 ~~      x1
#> 11      x2 ~~      x2
#> 12      x3 ~~      x3
#> 13      x4 ~~      x4
#> 14      x5 ~~      x5
#> 15      x6 ~~      x6
#> 16      x7 ~~      x7
#> 17      x8 ~~      x8
#> 18      x9 ~~      x9
#> 19  visual ~~  visual
#> 20 textual ~~ textual
#> 21   speed ~~   speed
#> 22  visual ~~ textual
#> 23  visual ~~   speed
#> 24 textual ~~   speed
# Set output = "" to get a lavaan.data.frame
summary(out1, output = "")
#>        lhs op     rhs   est    se      t       df pvalue
#> 1   visual =~      x1 1.000 0.000     NA       NA     NA
#> 2   visual =~      x2 0.556 0.108  5.153      Inf  0.000
#> 3   visual =~      x3 0.728 0.118  6.180      Inf  0.000
#> 4  textual =~      x4 1.000 0.000     NA       NA     NA
#> 5  textual =~      x5 0.661 0.052 12.792  116.901  0.000
#> 6  textual =~      x6 0.993 0.072 13.760  463.762  0.000
#> 7    speed =~      x7 1.000 0.000     NA       NA     NA
#> 8    speed =~      x8 1.176 0.185  6.348 1374.016  0.000
#> 9    speed =~      x9 0.901 0.142  6.366  321.076  0.000
#> 10      x1 ~~      x1 0.549 0.123  4.475      Inf  0.000
#> 11      x2 ~~      x2 1.132 0.110 10.297      Inf  0.000
#> 12      x3 ~~      x3 0.846 0.098  8.634      Inf  0.000
#> 13      x4 ~~      x4 0.450 0.061  7.374  491.475  0.000
#> 14      x5 ~~      x5 0.272 0.032  8.588  150.445  0.000
#> 15      x6 ~~      x6 0.309 0.053  5.844  201.536  0.000
#> 16      x7 ~~      x7 0.768 0.090  8.525 5997.168  0.000
#> 17      x8 ~~      x8 0.449 0.088  5.104  675.850  0.000
#> 18      x9 ~~      x9 0.634 0.074  8.569  264.311  0.000
#> 19  visual ~~  visual 0.809 0.157  5.147      Inf  0.000
#> 20 textual ~~ textual 0.901 0.121  7.422 5617.667  0.000
#> 21   speed ~~   speed 0.415 0.099  4.189 8611.644  0.000
#> 22  visual ~~ textual 0.428 0.079  5.406 6361.340  0.000
#> 23  visual ~~   speed 0.242 0.061  3.951      Inf  0.000
#> 24 textual ~~   speed 0.177 0.054  3.264 3695.871  0.001
# Compare the estimates with default options
summary(out1)
#> lavaan.mi object based on 20 imputed data sets. 
#> See class?lavaan.mi help page for available methods. 
#> 
#> Convergence information:
#> The model converged on 20 imputed data sets 
#> 
#> Rubin's (1987) rules were used to pool point and SE estimates across 20 imputed data sets, and to calculate degrees of freedom for each parameter's t test and CI.
#> 
#> Parameter Estimates:
#> 
#>   Standard errors                             Standard
#>   Information                                 Expected
#>   Information saturated (h1) model          Structured
#> 
#> Latent Variables:
#>                    Estimate  Std.Err  t-value       df  P(>|t|)
#>   visual =~                                                    
#>     x1                1.000                                    
#>     x2                0.556    0.108    5.153      Inf    0.000
#>     x3                0.728    0.118    6.180      Inf    0.000
#>   textual =~                                                   
#>     x4                1.000                                    
#>     x5                0.661    0.052   12.792  116.901    0.000
#>     x6                0.993    0.072   13.760  463.762    0.000
#>   speed =~                                                     
#>     x7                1.000                                    
#>     x8                1.176    0.185    6.348 1374.016    0.000
#>     x9                0.901    0.142    6.366  321.076    0.000
#> 
#> Covariances:
#>                    Estimate  Std.Err  t-value       df  P(>|t|)
#>   visual ~~                                                    
#>     textual           0.428    0.079    5.406 6361.340    0.000
#>     speed             0.242    0.061    3.951      Inf    0.000
#>   textual ~~                                                   
#>     speed             0.177    0.054    3.264 3695.871    0.001
#> 
#> Variances:
#>                    Estimate  Std.Err  t-value       df  P(>|t|)
#>    .x1                0.549    0.123    4.475      Inf    0.000
#>    .x2                1.132    0.110   10.297      Inf    0.000
#>    .x3                0.846    0.098    8.634      Inf    0.000
#>    .x4                0.450    0.061    7.374  491.475    0.000
#>    .x5                0.272    0.032    8.588  150.445    0.000
#>    .x6                0.309    0.053    5.844  201.536    0.000
#>    .x7                0.768    0.090    8.525 5997.168    0.000
#>    .x8                0.449    0.088    5.104  675.850    0.000
#>    .x9                0.634    0.074    8.569  264.311    0.000
#>     visual            0.809    0.157    5.147      Inf    0.000
#>     textual           0.901    0.121    7.422 5617.667    0.000
#>     speed             0.415    0.099    4.189 8611.644    0.000

Terrence Jorgensen

unread,
Apr 18, 2023, 8:45:50 AM4/18/23
to lavaan
parameterEstimates() can be used to get the parameter estimates of the output of lavaan() and its wrappers in the form of a lavaan.data.frame object.

The latter is its class (inherits from data.frame), not a wrapper function.  The special class is just so lavaan can define a nicer print method than the default one for data.frame objects.

 parameterEstimates() does not work on a lavaan.mi object.

No, that is not a generic function, so I can't write a method for it to operate on lavaan.mi objects.  lavaan will allow parameterEstimates() to be applied to a class?lavaanList object, which is what lavaan.mi inherits from, but it is not informative.
 
Is this an intended behavior of the summary-method of lavaan.mi? Can I trust this way to use summary() as the lavaan.mi version of parameterEstimates()?

Yes, the lavaan.mi analog is just the summary() method (which is a generic function).  To make it return a familiar data.frame like parameterEstimates() does, just set the argument output = "data.frame" (see class?lavaan.mi).  
lavaan's summary() method also just calls parameterEstimates(..., output = "text"), but will return it in a list with anything else you request (e.g., fitMeasures() or modindices(), by setting the corresponding arguments TRUE).

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

Shu Fai Cheung

unread,
Apr 18, 2023, 9:39:36 AM4/18/23
to lav...@googlegroups.com
Thanks a lot for the detailed explanation and sorry for my oversight. I was studying the help page of lavaan.mi class when I received your post. I should have read it first before posting.

It would be nice if commonly used lavaan functions can be used directly on lavaan.mi objects, or raise an error when a function should not be used on lavaan.mi objects, but I understand this may not be desirable. Changes may need to be made in lavaan, as in the case of parameterEstimates(). For personal use, I am compiling a list of functions that I usually use on lavaan objects (I do not use lavaanList objects) and see whether and/or how these functions work on lavaan.mi objects.

Regards,
Shu Fai Cheung (張樹輝)

--
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/3467162e-a8d7-403c-999d-9d47a0f6ea85n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages