TDJorgensen / lavaan.mi

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

Calling fitMeasures( ) function gives error #8

Closed MarkHuisman-jme closed 2 weeks ago

MarkHuisman-jme commented 3 weeks ago

Hello,

I am estimating a latent change model (one latent variable on two time points, with five indicators) on an imputed data set (for testing purposes only m=10 imputations). The model fits on each imputed data set separately, and the sem.mi() function also works. It give parameters estimates:

parameterEstimates.mi(mod1_imp_fit, fmi = T)

Using fitMeasures(mod1_imp_fit) gives and error, however:

fitMeasures(mod1_imp_fit) Error in vec_cast.haven_labelled.haven_labelled(): ! Can't convert from value <labelled> to <labelled> due to loss of precision. • Locations: 21, 28, 42, 56, 60, 162, 163, 164, 165, 166

Any idea how to solve this?

TDJorgensen commented 2 weeks ago

Error in vec_cast.haven_labelled.haven_labelled():

The tidyverse strikes again. This error has nothing to do with lavaan.mi. It involves the "labelled" class, which for some reason does not inherit from class "factor" (probably because the former does not necessitate all values to belong to one of the labeled categories?). If you open its help page in the haven documentation, Hadley's description says "I expect you’ll coerce to a standard R class (e.g. as_factor()) soon after importing".

Any idea how to solve this?

You can convert tidyverse to normal R objects when you go anywhere outside the tidyverse, as Hadley's philosophy only prioritizes internal consistency. For example, turn a tbl into a data.frame, a labelled vector into a factor vector, etc.