Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for dynamic interpretation of CFI/RMSEA/SRMR #392

Open
mattansb opened this issue Oct 28, 2021 · 1 comment
Open

Add support for dynamic interpretation of CFI/RMSEA/SRMR #392

mattansb opened this issue Oct 28, 2021 · 1 comment
Labels

Comments

@mattansb
Copy link
Member

melissagwolf/dynamic#3

get_dynamic <- function(model, type, level, rate = c(0.05, 0.10), verbose = TRUE) {
  type <- match.arg(type, c("CFA.one", "CFA.multi"))
  stopifnot(rate %in% c(0.05, 0.10))
  rate <- rate[1] * 100
  
  insight::check_if_installed("dynamic")
  
  if (verbose) message("Simulating...")
  
  foo <- switch (type,
                 CFA.one = dynamic::cfaOne,
                 CFA.multi = dynamic::cfaHB)
  
  dynamic_res <- foo(model)[[c(2,1)]]
  
  if (nrow(dynamic_res)/2 < level) {
    warning()
    level <- nrow(dynamic_res)/2
  }
  
  th <- dynamic_res[sprintf("Level %d: %d/%d", level, 100-rate, rate),]
  th <- lapply(th, as.numeric)
  th$CFI <- effectsize::rules(th$CFI, c("poor", "satisfactory"), right = FALSE)
  th$RMSEA <- effectsize::rules(th$RMSEA, c("satisfactory", "poor"))
  th$SRMR <- effectsize::rules(th$SRMR, c("satisfactory", "poor"))
  
  th
}


dat <- lavaan::HolzingerSwineford1939
lavmod <- "F1 =~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9"
fit <- lavaan::cfa(lavmod,dat)


rules <- get_dynamic(fit, type = "CFA.one", level = 3L)
#> Simulating...

effectsize::interpret(
  lavaan::fitMeasures(fit, "CFI"), rules = rules$CFI  
)
#>    cfi 
#> "poor" 
#> (Rules: Custom rules)

effectsize::interpret(
  lavaan::fitMeasures(fit, "RMSEA"), rules = rules$RMSEA  
)
#>  rmsea 
#> "poor" 
#> (Rules: Custom rules)

effectsize::interpret(
  lavaan::fitMeasures(fit, "SRMR"), rules = rules$SRMR  
)
#>   srmr 
#> "poor" 
#> (Rules: Custom rules)
@mattansb mattansb added the enhancement 🔥 New feature or request label Oct 28, 2021
@mattansb
Copy link
Member Author

@DominiqueMakowski Something to look forward to (in the long run)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant