simsem / semTools

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

partialInvariance "Error in out[free != 0] <- est[free[free != 0]]: replacement has length zero" #111

Closed SarBearSchwartz closed 2 years ago

SarBearSchwartz commented 2 years ago

I have been using this package a great deal recently. Today I had to update my software to get my Rmd file to knit to pdf. Once I updated R to version 4.2.0 (64-bit Windows 10), the function "partialInvariance" started returning: "Error in out[free != 0] <- est[free[free != 0]]: replacement has length zero". This error is returned when running the code below (from the function "help" documentation).

library(lavaan)

conf <- "
f1 =~ NA*x1 + x2 + x3
f2 =~ NA*x4 + x5 + x6
f1 ~~ c(1, 1)*f1
f2 ~~ c(1, 1)*f2
"

weak <- "
f1 =~ NA*x1 + x2 + x3
f2 =~ NA*x4 + x5 + x6
f1 ~~ c(1, NA)*f1
f2 ~~ c(1, NA)*f2
"

configural <- cfa(conf, data = HolzingerSwineford1939, std.lv = TRUE, group="school")
weak <- cfa(weak, data = HolzingerSwineford1939, group="school", group.equal="loadings")
models <- list(fit.configural = configural, fit.loadings = weak)
partialInvariance(models, "metric")
TDJorgensen commented 2 years ago

I added 3 backticks before and after your code, so that the code appears as desired (i.e., so the Markdown interpreter does not treat text between asterisks as italics).

I have no problem running this syntax in R 4.2.0 using semTools 0.5-6. Have you (re)installed semTools after re-installing R? That could help.

SarBearSchwartz commented 2 years ago

Thank you for responding. I also use the backticks to run in Rmd. Additionally, I copy-pasted the code into the console and received the same error. In the help page for partialInvariance() (viewed inR Studio), clicking the "Run examples" link at the bottom yields the same error, too.

Info: (updated R, R Studio, and all pacakges yesterday) R version 4.2.0 (2022-04-22 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18363)

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

other attached packages: [1] semTable_1.8 semTools_0.5-6.904 tidySEM_0.2.3 OpenMx_2.20.6 lavaan_0.6-11 pander_0.6.5 furniture_1.9.12
[8] readxl_1.4.0 forcats_0.5.1 stringr_1.4.0 dplyr_1.0.9 purrr_0.3.4 readr_2.1.2 tidyr_1.2.0
[15] tibble_3.1.7 ggplot2_3.3.6 tidyverse_1.3.1 magrittr_2.0.3

TDJorgensen commented 2 years ago

I was using the CRAN version, but I confirmed that development version 0.5-6.904 threw that error on my Mac, too. Couldn't exactly figure out the cause, but I at least narrowed down the origin to a change I had no problem reversing. Development version 0.5-6.905 no longer throws that error.

SarBearSchwartz commented 2 years ago

Thank you! I installed the latest developmental version and no longer receive an error message.