effectsize icon indicating copy to clipboard operation
effectsize copied to clipboard

Add support for dynamic interpretation of CFI/RMSEA/SRMR

Open mattansb opened this issue 3 years ago • 1 comments

https://github.com/melissagwolf/dynamic/issues/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 avatar Oct 28 '21 11:10 mattansb

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

mattansb avatar Oct 28 '21 11:10 mattansb