simsem / semTools

Useful tools for structural equation modeling
74 stars 35 forks source link

permuteMeasEq() bug on covariance-built models #132

Closed JarGottfried closed 8 months ago

JarGottfried commented 8 months ago

Hello. I find it impossible to run permuteMeasEq() on lavaan models built using variance-covariance matrices. It always results in the error:

Error in `colnames<-`(`*tmp*`, value = object@Data@ov.names[[g]]) : 
  attempt to set 'colnames' on an object with less than two dimensions

Example:

HS <- lavaan::HolzingerSwineford1939
HS$ageGroup <- ifelse(HS$ageyr < 13, "preteen",
                      ifelse(HS$ageyr > 13, "teen", "thirteen"))
cov_matrix_preteen <- cov(dplyr::select(subset(HS, ageGroup == "preteen"), x1:x9))
nobs_preteen <- nrow(subset(HS, ageGroup == "preteen"))
cov_matrix_thirteen <- cov(dplyr::select(subset(HS, ageGroup == "thirteen"), x1:x9))
nobs_thirteen <- nrow(subset(HS, ageGroup == "thirteen"))
cov_matrix_teen <- cov(dplyr::select(subset(HS, ageGroup == "teen"), x1:x9))
nobs_teen <- nrow(subset(HS, ageGroup == "teen"))
mod.config <- '
visual  =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed   =~ x7 + x8 + x9
'
fit.config <- lavaan::cfa(mod.config, sample.cov = list(cov_matrix_preteen, cov_matrix_thirteen, cov_matrix_teen),
                  sample.nobs = c(nobs_preteen, nobs_thirteen, nobs_teen))
semTools::permuteMeasEq(10, con = fit.config)
TDJorgensen commented 8 months ago

If you read the paper cited in the help-page references, you will understand why. You cannot permute rows of raw data if you do not have raw data.

JarGottfried commented 8 months ago

If you read the paper cited in the help-page references, you will understand why. You cannot permute rows of raw data if you do not have raw data.

My bad, thank you for explanation.

TDJorgensen commented 8 months ago

No worries, a more informative error message would also be helpful, so I added a check for raw data.