melissagwolf / dynamic

Dynamic Fit Index Cutoffs For Latent Variable Models
GNU Affero General Public License v3.0
14 stars 2 forks source link

Make `dynamic` easier to use for developers #3

Closed mattansb closed 2 years ago

mattansb commented 2 years ago

Hey @melissagwolf !

Thanks for making open source tools!

We at easystats would like to try and incorporate the output from dynamic into our interpret functions for SEM/CFA fit indices.

To do that, it would be great if:

I think all information can be extracted from the model?

std_par <- lavaan::standardizedSolution(fit)
p_tab <- lavaan::parTable(fit)

if ("group" %in% colnames(std_par)) {
  std_par <- std_par[c("lhs", "op", "rhs", "group", "est.std")]
  std_par <- tidyr::pivot_wider(std_par, names_from = group, values_from = est.std, names_prefix = "G")
  grouo_V <- do.call(paste, c(std_par[-(1:3)], sep = ","))

  std_par <- std_par[1:3]
  std_par$est.std <- paste0("c(", grouo_V, ")")

  p_tab <- p_tab[p_tab$group == p_tab$group[1],]
}

model_spec <- with(std_par, paste0(lhs, op, est.std, "*", rhs, "\n"))
# filter only user parameters? Not sure if this is not correct here?
model_spec <- model_spec[as.logical(p_tab$user)]
model_spec <- paste(model_spec, collapse = "")

N <- fit@SampleStats@ntotal

Are any of these possible? Or something you wish to peruse?

mattansb commented 2 years ago

Sorry, I see now that the functions do all accept lavaan fits as inputs!

So only my second point is relevant 😊

melissagwolf commented 2 years ago

Do you mean that instead of cfaOne or cfaHB, there would only be one function, and it would perform the appropriate simulation given the number of factors? If so, that was how the package was originally set up - great minds think alike!

Short answer: Probably not

Long answer/explanation: cfaHB and cfaOne are slightly different, and that is partially why we separated them into different functions. cfaHB mimics Hu and Bentler's approach (e.g., f-1 levels of misspecification where f is the number of factors) while cfaOne has standardized levels of misspecification given the number of items. We plan to extend the standardized approach used in cfaOne to multi-factor cfa models soon, and would potentially put the two of those under the same function (perhaps renamed cfaFit).

We also hope to introduce multiple extensions to this approach (e.g., cutoffs for categorical models, cutoffs for measurement invariance, growth models, etc), so it would likely get to a point where the user would have to at least specify the model type in an argument. And then selfishly, it's a little easier to keep it separate on our end just because this package maps onto a shiny app with different applications.

It's something we'll think about (and thank you for requesting it and incorporating DFIs into your work!!) but for those reasons, we don't plan to combine the functions at this time.

mattansb commented 2 years ago

Thanks! Looking forward to more developments here (:

Will try to work with the given infrastructure in the meanwhile.