Gengrui-Zhang / R2spa

An R Package for Two-Stage Path Analysis (2S-PA)
https://gengrui-zhang.github.io/R2spa/
Other
0 stars 0 forks source link

Add an error when the names of `vc` does not match that of the input data frame #53

Closed marklhc closed 1 year ago

marklhc commented 1 year ago
library(R2spa)
data("PoliticalDemocracy", package = "lavaan")
mod2 <- "
  # latent variables
    ind60 =~ x1 + x2 + x3
    dem60 =~ y1 + y2 + y3 + y4
    dem65 =~ y5 + y6 + y7 + y8
"
fs_dat2 <- get_fs(PoliticalDemocracy, model = mod2, std.lv = TRUE)
ecov_fs <- attr(fs_dat2, "av_efs")
dimnames(ecov_fs) <- lapply(dimnames(ecov_fs),
                            FUN = \(x) paste0("bs_", x))
tspa(model = "dem60 ~ ind60
              dem65 ~ ind60 + dem60",
     data = fs_dat2,
     vc = ecov_fs)
#> Warning in split.default(loadings, factor(rep(var, each = len), levels = var)):
#> data length is not a multiple of split variable
#> Error in str2lang(x): <text>:1:3: unexpected '*'
#> 1: ~ *
#>       ^

Created on 2023-05-01 with reprex v2.0.2

marklhc commented 1 year ago

A few other suggestions:

marklhc commented 1 year ago

TODO: add a unit test to check for not using fs_ for indicators.

winniewytse commented 1 year ago

@marklhc I added the suggested error controls as well as one for missing group argument when trying to fit a multigroup model. I momentarily changed the argument names vc to fsT and cross_loadings to fsL for consistency. I also changed these names in other files correspondingly. Please let me know if you want to keep the original ones or want to use other names (e.g., mat_ld and mat_vc).

I would like to create a pull request after resolving the above question.

marklhc commented 1 year ago

Thanks @winniewytse. Ya I think using fsT and fsL throughout may be more consistent. We could make the changes for the tspa_mx() function later as well. Thanks.