format model comparison metrics in APA style
Arguments
- ...
model fit objects, or a list of them. Models are labeled by the list's names (or the argument names), and "Model 1", "Model 2", ... for unnamed models.
- metrics
performance metrics. If
NULL(default), R2, deltaR2, F, and p for models with an estimated dispersion parameter (e.g.,lm, Gaussian or quasi-familyglm), and R2, deltaR2, Chi2, df, and p for GLMs with a fixed dispersion parameter (binomial, Poisson, negative binomial). Use "all" for all available metrics.- starred
columns to which significance stars are added (e.g.,
"Coefficient"or"p").NULLorNAfor none.- column_formats
column_formats object to format columns. If NULL, the default column_formats is used.
Details
Nested models are compared with F tests (performance::test_wald()) unless every model is a GLM with a fixed dispersion parameter, in which case likelihood ratio tests (performance::test_likelihoodratio()) are used. For GLMs, R2 is the pseudo-R^2^ that performance::r2() selects for the model family, and the header names it (e.g., R^2^~Tjur~).
Robust regression models fit with robustbase::lmrob are compared with robust Wald tests (robustbase::anova.lmrob()), and R2 is the robust R^2^; models fit with MASS::rlm are compared by the robust residual scale, without tests.
Cox proportional hazards models (survival::coxph) are compared with likelihood ratio tests, and R2 is Nagelkerke's pseudo-R^2^. So are beta regression models (betareg::betareg), with Ferrari and Cribari-Neto's pseudo-R^2^. Quantile regression models (quantreg::rq) are compared by the Koenker-Machado R^1^ and AIC, without tests.
Parametric survival models (survival::survreg) are compared like Cox models. Generalized estimating equations (geepack::geeglm) have no likelihood, so they are compared by QIC and Wald tests of the added terms (from geepack's anova()).
Mixed models (lme4::lmer, lme4::glmer, glmmTMB::glmmTMB, nlme::lme, and ordinal::clmm) are compared with likelihood ratio tests. R2 is the marginal R^2^ (variance explained by the fixed effects), and by default the conditional R^2^ (fixed and random effects) and its change (R2_conditional, deltaR2_conditional) are shown too, because adding random effects changes the conditional but not the marginal R^2^.
Nested lavaan models (e.g., the configural, metric, and scalar models of a measurement invariance analysis) are compared each with the one before it, so they should be listed from the least to the most constrained. Each row shows the fit of the model (any of the metrics of apa_performance.lavaan()), followed, under a "Change from previous model" spanner, by the chi-square difference test from lavaan::lavTestLRT() ("deltaChi2", "deltaChi2_df", "p_deltaChi2") and the changes in fit indices ("deltaCFI", "deltaTLI", "deltaRMSEA", "deltaSRMR"), shown with three decimals. The default metrics are "Chi2", "Chi2_df", "CFI", "RMSEA", "RMSEA_CI", "SRMR", "deltaChi2", "deltaChi2_df", "p_deltaChi2", "deltaCFI", and "deltaRMSEA". With a robust estimator (e.g., MLR or WLSMV), the difference test is scaled (e.g., the Satorra-Bentler scaled difference test), and the changes in fit indices are computed from their robust versions. apa_note() names the difference test. starred is ignored for lavaan models.
References
Satorra, A. (2000). Scaled and adjusted restricted tests in multi-sample analysis of moment structures. In R. D. H. Heijmans, D. S. G. Pollock, & A. Satorra (Eds.), Innovations in multivariate statistical analysis (pp. 233–247). Kluwer Academic Publishers. doi:10.1007/978-1-4615-4603-0_17
Satorra, A., & Bentler, P. M. (2001). A scaled difference chi-square test statistic for moment structure analysis. Psychometrika, 66(4), 507–514. doi:10.1007/BF02296192
Satorra, A., & Bentler, P. M. (2010). Ensuring positiveness of the scaled difference chi-square test statistic. Psychometrika, 75(2), 243–248. doi:10.1007/s11336-009-9135-y
Examples
m1 <- lm(mpg ~ cyl, data = mtcars)
m2 <- lm(mpg ~ cyl + wt, data = mtcars)
apa_performance_comparison(list(Cylinders = m1, `Cylinders and weight` = m2)) |>
apa_flextable()
Model
R2
ΔR2
F
p
Cylinders
.73
.73
Cylinders and weight
.83
.10
17.77
<.001
# Measurement invariance across schools
# \donttest{
if (requireNamespace("lavaan", quietly = TRUE)) {
model <- "visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9"
hs <- lavaan::HolzingerSwineford1939
apa_performance_comparison(
Configural = lavaan::cfa(model, data = hs, group = "school"),
Metric = lavaan::cfa(model, data = hs, group = "school",
group.equal = "loadings"),
Scalar = lavaan::cfa(model, data = hs, group = "school",
group.equal = c("loadings", "intercepts"))
)
}
#> # A tibble: 3 × 12
#> Model `*χ*^2^` `*df*` CFI RMSEA `90% CI` SRMR Change from previous…¹
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 Configu… 115.85 48 .92 .10 [.07, .… .07 ""
#> 2 Metric 124.04 54 .92 .09 [.07, .… .07 " 8.19"
#> 3 Scalar 164.10 60 .88 .11 [.09, .… .08 "40.06"
#> # ℹ abbreviated name: ¹`Change from previous model_Δ*χ*^2^`
#> # ℹ 4 more variables: `Change from previous model_Δ*df*` <chr>,
#> # `Change from previous model_*p*` <chr>,
#> # `Change from previous model_ΔCFI` <chr>,
#> # `Change from previous model_ΔRMSEA` <chr>
# }