Skip to content

Commit

Permalink
refactor: Further clean-up of column names and add class "model_fit"
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmsm committed Aug 17, 2024
1 parent 9cc807e commit 41a043c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion R/model_fit.lavaan.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,27 @@ extract_fit_lavaan <- function(fit, type, metrics, verbose) {
fit_measure_df <- data.frame(
NOBS = sum(lavaan::lavInspect(fit, "nobs")),
ESTIMATOR = lavaan_estimator(fit),
NGROUPS = lavaan::lavInspect(fit, "ngroups"),
fit_measure_df,
row.names = NULL # Remove row names
)

# Clean up the column names to remove ".scaled" and ".robust"
colnames(fit_measure_df) <- gsub("\\.(SCALED|ROBUST)$", "", colnames(fit_measure_df))

# Further clean-up of column names
colnames(fit_measure_df) <- gsub("^RMSEA\\.CI\\.LOWER$", "RMSEA_CI_low", colnames(fit_measure_df))
colnames(fit_measure_df) <- gsub("^RMSEA\\.CI\\.UPPER$", "RMSEA_CI_high", colnames(fit_measure_df))
colnames(fit_measure_df) <- gsub("^CHISQ$", "Chi2", colnames(fit_measure_df))
colnames(fit_measure_df) <- gsub("^DF$", "Chi2_df", colnames(fit_measure_df))
colnames(fit_measure_df) <- gsub("^PVALUE$", "p_Chi2", colnames(fit_measure_df))

# Add a "converged" column only if the model did not converge
if (!lavaan::lavInspect(fit, "converged")) {
fit_measure_df$converged <- FALSE
}

class(fit_measure_df) <- c("model_fit", class(fit_measure_df))

return(fit_measure_df)
}

Expand Down

0 comments on commit 41a043c

Please sign in to comment.