
Export CFA Boosting Results to Structured Data Frames
Source:R/print_cfa_boosting.R
export_cfa_boosting.RdExport CFA Boosting results to structured data frames suitable for saving as CSV, embedding in a manuscript table, or further analysis.
Arguments
- result
Output from
cfa_boosting.
Value
A named list of data frames (fit_indices,
standardized_loadings, factor_correlations,
reliability, steps_log).
Examples
# \donttest{
data(Data_Personality, package = "OptimalFactor")
model <- '
F1 =~ PPTQ1 + PPTQ2 + PPTQ3 + PPTQ4 + PPTQ5
F2 =~ PPTQ6 + PPTQ7 + PPTQ8 + PPTQ9 + PPTQ10
F3 =~ PPTQ11 + PPTQ12 + PPTQ13 + PPTQ14 + PPTQ15
'
res <- cfa_boosting(Data_Personality, model,
model_config = list(estimator = "MLR", ordered = FALSE),
verbose = FALSE)
#> Warning: lavaan->lavaan():
#> the first indicator of the following latent variable(s) is a poor item;
#> switching to another marker item (to set the metric) to avoid convergence
#> problems; use bad.marker.crit = 0 to switch off this behavior: F2 (PPTQ6
#> -> PPTQ10)
#> Warning: lavaan->lav_object_post_check():
#> covariance matrix of latent variables is not positive definite ; use
#> lavInspect(fit, "cov.lv") to investigate.
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F2
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F2 F3
#> Warning: lavaan->lavaan():
#> the first indicator of the following latent variable(s) is a poor item;
#> switching to another marker item (to set the metric) to avoid convergence
#> problems; use bad.marker.crit = 0 to switch off this behavior: F2 (PPTQ6
#> -> PPTQ10)
#> Warning: lavaan->lav_object_post_check():
#> covariance matrix of latent variables is not positive definite ; use
#> lavInspect(fit, "cov.lv") to investigate.
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F2
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F2 F3
#> Warning: lavaan->lavaan():
#> the first indicator of the following latent variable(s) is a poor item;
#> switching to another marker item (to set the metric) to avoid convergence
#> problems; use bad.marker.crit = 0 to switch off this behavior: F2 (PPTQ6
#> -> PPTQ10)
#> Warning: lavaan->lav_object_post_check():
#> covariance matrix of latent variables is not positive definite ; use
#> lavInspect(fit, "cov.lv") to investigate.
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F2
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F2 F3
#> Warning: lavaan->lav_object_post_check():
#> covariance matrix of latent variables is not positive definite ; use
#> lavInspect(fit, "cov.lv") to investigate.
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F2
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F2 F3
#> Warning: lavaan->lav_object_post_check():
#> covariance matrix of latent variables is not positive definite ; use
#> lavInspect(fit, "cov.lv") to investigate.
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F2
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F2 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F2
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F2 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F2
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F2 F3
#> Warning: lavaan->lav_object_post_check():
#> covariance matrix of latent variables is not positive definite ; use
#> lavInspect(fit, "cov.lv") to investigate.
#> Warning: lavaan->lav_object_post_check():
#> covariance matrix of latent variables is not positive definite ; use
#> lavInspect(fit, "cov.lv") to investigate.
#> Warning: lavaan->lav_object_post_check():
#> covariance matrix of latent variables is not positive definite ; use
#> lavInspect(fit, "cov.lv") to investigate.
#> Warning: lavaan->lavaan():
#> the first indicator of the following latent variable(s) is a poor item;
#> switching to another marker item (to set the metric) to avoid convergence
#> problems; use bad.marker.crit = 0 to switch off this behavior: F1 (PPTQ1
#> -> PPTQ5)
#> Warning: lavaan->lav_object_post_check():
#> covariance matrix of latent variables is not positive definite ; use
#> lavInspect(fit, "cov.lv") to investigate.
#> Warning: lavaan->lav_object_post_check():
#> covariance matrix of latent variables is not positive definite ; use
#> lavInspect(fit, "cov.lv") to investigate.
#> Warning: lavaan->lav_object_post_check():
#> covariance matrix of latent variables is not positive definite ; use
#> lavInspect(fit, "cov.lv") to investigate.
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F2
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F2 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F2
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F2 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F2
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F2 F3
#> Warning: lavaan->lavaan():
#> the first indicator of the following latent variable(s) is a poor item;
#> switching to another marker item (to set the metric) to avoid convergence
#> problems; use bad.marker.crit = 0 to switch off this behavior: F1 (PPTQ1
#> -> PPTQ5)
#> Warning: lavaan->lav_object_post_check():
#> covariance matrix of latent variables is not positive definite ; use
#> lavInspect(fit, "cov.lv") to investigate.
#> Warning: lavaan->lavaan():
#> the first indicator of the following latent variable(s) is a poor item;
#> switching to another marker item (to set the metric) to avoid convergence
#> problems; use bad.marker.crit = 0 to switch off this behavior: F1 (PPTQ1
#> -> PPTQ5)
#> Warning: lavaan->lav_object_post_check():
#> covariance matrix of latent variables is not positive definite ; use
#> lavInspect(fit, "cov.lv") to investigate.
#> Warning: lavaan->lavaan():
#> the first indicator of the following latent variable(s) is a poor item;
#> switching to another marker item (to set the metric) to avoid convergence
#> problems; use bad.marker.crit = 0 to switch off this behavior: F1 (PPTQ1
#> -> PPTQ5)
#> Warning: lavaan->lav_object_post_check():
#> covariance matrix of latent variables is not positive definite ; use
#> lavInspect(fit, "cov.lv") to investigate.
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F2
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F2 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F2
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F2 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F2
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F2 F3
#> Warning: lavaan->lavaan():
#> the first indicator of the following latent variable(s) is a poor item;
#> switching to another marker item (to set the metric) to avoid convergence
#> problems; use bad.marker.crit = 0 to switch off this behavior: F1 (PPTQ1
#> -> PPTQ5)
#> Warning: lavaan->lav_object_post_check():
#> covariance matrix of latent variables is not positive definite ; use
#> lavInspect(fit, "cov.lv") to investigate.
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F2
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F2 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F2
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F2 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F2
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F1 F3
#> Warning: lavaan->lav_start_check_cov():
#> starting values imply a correlation larger than 1; variables involved are:
#> F2 F3
out <- export_cfa_boosting(res)
names(out)
#> [1] "fit_indices" "loadings" "correlations"
#> [4] "reliability" "steps" "removed_items"
#> [7] "added_covariances" "model_syntax"
# Each component is a data.frame ready for write.csv()
head(out$fit_indices)
#> Index Value Criterion Met
#> 1 RMSEA 0.06686829 <= 0.08 TRUE
#> 2 CFI 0.89374995 >= 0.95 FALSE
#> 3 TLI 0.84062492 >= 0.95 FALSE
#> 4 SRMR 0.08239618 <= 0.08 FALSE
#> 5 Chi-square 43.41410542 NA
#> 6 df 30.00000000 NA
head(out$loadings)
#> Factor Item Loading SE p_value
#> 1 F1 PPTQ1 0.502 0.084 0.000
#> 2 F1 PPTQ2 -0.316 0.120 0.008
#> 3 F1 PPTQ3 0.337 0.115 0.003
#> 4 F1 PPTQ5 0.725 0.099 0.000
#> 5 F2 PPTQ6 0.387 0.113 0.001
#> 6 F2 PPTQ9 0.202 0.107 0.059
head(out$steps)
#> step action
#> 1 0 Initial
#> 2 1 Remove Item (below loading floor)
#> 3 2 Remove Item (below loading floor)
#> 4 3 Remove Item (below loading floor)
#> 5 4 Remove Item (below loading floor)
#> 6 5 Remove Item (instead of cov)
#> detail rmsea cfi
#> 1 Modelo base 0.08323645 0.6873575
#> 2 Eliminar PPTQ13 (F3, λ=0.103) 0.09279513 0.6743279
#> 3 Eliminar PPTQ8 (F2, λ=0.111) 0.10023001 0.6768687
#> 4 Eliminar PPTQ7 (F2, λ=-0.180) 0.09611073 0.7316030
#> 5 Eliminar PPTQ14 (F3, λ=-0.218) 0.09276684 0.7769166
#> 6 Eliminar PPTQ4 (F1) en lugar de cov PPTQ1 ~~ PPTQ4 0.08159420 0.8312530
#> srmr loss
#> 1 0.09819991 2.801699
#> 2 0.10120468 3.111338
#> 3 0.10377506 3.226980
#> 4 0.09857549 2.576318
#> 5 0.09410667 2.037659
#> 6 0.08937294 1.276526
# Save the data frames to a temporary directory.
for (nm in c("fit_indices", "loadings", "reliability"))
if (!is.null(out[[nm]]))
utils::write.csv(out[[nm]],
file.path(tempdir(), paste0("cfa_boost_", nm, ".csv")),
row.names = FALSE)
# }