TDJorgensen / lavaan.mi

Use R package lavaan to fit SEM to multiple imputations of missing data
3 stars 1 forks source link

'version' is not a slot in class "lavaan.mi" #3

Closed Suppanut closed 3 months ago

Suppanut commented 4 months ago

My code terminated with an error after I updated lavaan.mi to 0.1-0.0012.

library(lavaan.mi)
data(HS20imps)
impSubset1 <- lapply(HS20imps, "[", i = paste0("x", 1:9)) # only modeled variables
HS3cat <- lapply(impSubset1, function(x) {
  as.data.frame( lapply(x, cut, breaks = 3, labels = FALSE) )
})
## pool polychoric correlations and thresholds
(prePooledData3 <- poolSat(HS3cat, ordered = paste0("x", 1:9)))

Output

Error in (function (cl, name, valueClass)  : 
  ‘version’ is not a slot in class “lavaan.mi”

I fixed this by adding the 'version' slot:

 setClass("lavaan.mi", contains = "lavaanList",
         slots = c(version = "character", # lavaan version
                   coefList = "list",     # coefficients in matrix format
                   phiList = "list",      # list of model-implied latent covariance matrices
                   miList = "list",       # modification indices
                   lavListCall = "list",  # store actual call to lavaanList
                   convergence = "list")) # also check SEs and Heywood cases

https://github.com/TDJorgensen/lavaan.mi/blob/3245af77789375af7fd25065b776994d45719fb2/R/class-methods.R#L188

TDJorgensen commented 4 months ago

First try updating lavaan. I had to add that slot to lavaanList, which lavaan inherits from. So it doesn't need defining in the lavaan.mi class.

Suppanut commented 4 months ago

I think I'm using the most recent version of lavaan

> library(lavaan.mi)
Loading required package: lavaan
This is lavaan 0.6-18.2102
lavaan is FREE software! Please report any bugs.

###################################################################
This is lavaan.mi 0.1-0.0012
See the README file on github.com/TDJorgensen/lavaan.mi
for a table comparing it with deprecated semTools features.
###################################################################
> data(HS20imps)
> impSubset1 <- lapply(HS20imps, "[", i = paste0("x", 1:9)) # only modeled variables
> HS3cat <- lapply(impSubset1, function(x) {
+   as.data.frame( lapply(x, cut, breaks = 3, labels = FALSE) )
+ })
> ## pool polychoric correlations and thresholds
> (prePooledData3 <- poolSat(HS3cat, ordered = paste0("x", 1:9)))
Error in (function (cl, name, valueClass)  : 
  ‘version’ is not a slot in class “lavaan.mi”
TDJorgensen commented 3 months ago

I don't know what to tell you. I just ran your reprex fine with the same versions.

> library(lavaan.mi)
Loading required package: lavaan
This is lavaan 0.6-18.2102
lavaan is FREE software! Please report any bugs.

###################################################################
This is lavaan.mi 0.1-0.0012
See the README file on github.com/TDJorgensen/lavaan.mi
for a table comparing it with deprecated semTools features.
###################################################################
> data(HS20imps)
> impSubset1 <- lapply(HS20imps, "[", i = paste0("x", 1:9))
> HS3cat <- lapply(impSubset1, function(x) {
+     as.data.frame( lapply(x, cut, breaks = 3, labels = FALSE) )
+ })
> ## pool polychoric correlations and thresholds
> (prePooledData3 <- poolSat(HS3cat, ordered = paste0("x", 1:9)))
This lavMoments-class object contains summary statistics in a list consisting of the following elements:
  sample.cov, sample.nobs, NACOV, WLS.V, sample.mean, sample.th, ov.order, lavOptions
You can view list elements with str(x) or standard extraction methods (e.g., x$sample.cov).

This object can be passed to lavaan() as the data= argument, in which case each element in this object (e.g., $sample.cov) will be internally passed to the corresponding lavaan() argument.
The following recommended lavOptions() will also be passed to lavaan():
  sample.cov.rescale = FALSE,
  fixed.x = FALSE,
  conditional.x = FALSE,
  estimator = "DWLS",
  se = "robust.sem",
  test = "Browne.residual.adf"

You can override these settings in your lavaan() call, but you should NOT set fixed.x=TRUE, which would yield incorrect standard errors and test statistics.

In case your sessionInfo() shows something different, here is mine:

R version 4.3.3 (2024-02-29)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.4.1

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/Amsterdam
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] lavaan.mi_0.1-0.0012 lavaan_0.6-18.2102  

loaded via a namespace (and not attached):
[1] compiler_4.3.3 parallel_4.3.3 tools_4.3.3    mnormt_2.1.1   pbivnorm_0.6.0 stats4_4.3.3  
[7] quadprog_1.5-8
Suppanut commented 3 months ago

I did a clean install of lavaan and lavaan.mi. Now everything works. Thank you so much!