library(dynamic)
## Registered S3 method overwritten by 'future':
##   method               from      
##   all.equal.connection parallelly
## Beta version. Please report bugs: https://github.com/melissagwolf/dynamic/issues.
library(lavaan)
## This is lavaan 0.6-20.2330
## lavaan is FREE software! Please report any bugs.
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

Everything below is replicating the analyses from this page: https://rpubs.com/dmcneish/1025400

dat<-lavaan::HolzingerSwineford1939
dat1<-round(dat[,7:12])
lavmod <- "visual  =~ x1 + x2 + x3
           textual =~ x4 + x5 + x6"
fit <- lavaan::cfa(model=lavmod, data=dat1, ordered=T, estimator="WLSMV")
lavaan::fitmeasures(fit, c("srmr", "rmsea.scaled","cfi.scaled"))
##         srmr rmsea.scaled   cfi.scaled 
##        0.040        0.070        0.992
library(devtools)
## Loading required package: usethis
## Warning: package 'usethis' was built under R version 4.3.3
devtools::install_github("melissagwolf/dynamic")
## Skipping install of 'dynamic' from a github remote, the SHA1 (34091c4f) has not changed since last install.
##   Use `force = TRUE` to force installation
dynamic::catHB(fit, plot=T)
## Your DFI cutoffs: 
##             SRMR  RMSEA CFI   Magnitude
## Level-0     0.037 0.057 0.995 NONE     
## Specificity 95%   95%   95%            
##                                        
## Level-1     0.037 0.063 0.995 0.407    
## Sensitivity 91%   95%   95%            
## 
## Empirical fit indices: 
##  Chi-Square  df p-value   SRMR   RMSEA    CFI
##      11.546   8   0.173   0.04    0.07  0.992
## 
##  Notes:
##   -Number of levels is based on the number of factors in the model
##   -'Sensitivity' is % of hypothetically misspecified models correctly identified by cutoff in DFI simulation
##   -Cutoffs with 95% sensitivity are reported when possible
##   -If sensitivity is <50%, cutoffs will be supressed 
## 
##  The distributions for each level are in the Plots tab 
## [[1]]

dynamic::DDDFI(model=fit, data = dat1, estimator = "WLSMV", scale = "categorical")
## Warning in dynamic::DDDFI(model = fit, data = dat1, estimator = "WLSMV", : dynamic Warning:
## 
##             Computational times are longer for scale='categorical' due increased demand for categorical models.
## 
##             This may take a few minutes.
## Your DFI cutoffs: 
##             MAD   Sim. MAD CFI   RMSEA 90% CI
## Consistent  0.00  0.00     0.995 0.058 0.099 
## Specificity                95%   95%         
##                                              
## Close       0.038 0.033    NONE  NONE  NONE  
## Sensitivity                37%   34%         
##                                              
## Fair        0.05  0.044    0.995 0.059 0.1   
## Sensitivity                66%   65%         
##                                              
## Mediocre    0.06  0.051    0.995 0.059 0.1   
## Sensitivity                75%   75%         
## 
## Estimator: WLSMV 
## Sample Size: 301 
## 
## Empirical fit indices: 
##  Chi-Square  df p-value   SRMR    CFI   RMSEA RMSEA 90% CI
##      19.813   8   0.011   0.04  0.992    0.07         0.11
## 
##  Notes:
##   -'Sensitivity' is % of incorrect models identified by cutoff while rejecting <5% of correct models
##   - If sensitivity is <50%, cutoffs will be supressed
## 
##   -'90% CI' column is RMSEA cutoff, including sampling variability
##   - Only compare upper limit of 90% RMSEA confidence interval to '90% CI' column
##   - Do not compare RMSEA point estimate to '90% CI' column
## 
##   -'MAD' is the desired mean absolute discrepancy
##   -'Sim. MAD' is the MAD that was achieved in the simulations
##   - Values may diff when avoiding non-positive definite matrices
##