apa_performance: format model performance metrics in APA style

View source: R/tables.R

apa_performanceR Documentation

format model performance metrics in APA style

Description

format model performance metrics in APA style

Fit indices of lavaan models

Usage

apa_performance(fit, metrics = c("R2", "Sigma"), column_formats = NULL)

## S3 method for class 'betareg'
apa_performance(fit, metrics = c("R2", "AIC"), column_formats = NULL)

## S3 method for class 'clmm'
apa_performance(
  fit,
  metrics = c("R2_marginal", "R2_conditional", "AIC"),
  column_formats = NULL
)

## S3 method for class 'gam'
apa_performance(
  fit,
  metrics = c("R2_adjusted", "Deviance_explained", "AIC"),
  column_formats = NULL
)

## S3 method for class 'bam'
apa_performance(
  fit,
  metrics = c("R2_adjusted", "Deviance_explained", "AIC"),
  column_formats = NULL
)

## S3 method for class 'geeglm'
apa_performance(fit, metrics = c("QIC", "QICu"), column_formats = NULL)

## S3 method for class 'lavaan'
apa_performance(
  fit,
  metrics = c("Chi2", "Chi2_df", "p_Chi2", "CFI", "TLI", "RMSEA", "RMSEA_CI", "SRMR"),
  column_formats = NULL
)

## S3 method for class 'rma'
apa_performance(fit, metrics = NULL, column_formats = NULL)

## S3 method for class 'mlm'
apa_performance(
  fit,
  metrics = c("R2", "R2_adjusted", "Sigma"),
  column_formats = NULL
)

## S3 method for class 'multinom'
apa_performance(fit, metrics = c("R2", "AIC"), column_formats = NULL)

## S3 method for class 'zeroinfl'
apa_performance(fit, metrics = c("R2", "AIC"), column_formats = NULL)

## S3 method for class 'hurdle'
apa_performance(fit, metrics = c("R2", "AIC"), column_formats = NULL)

## S3 method for class 'rq'
apa_performance(fit, metrics = c("R1", "AIC"), column_formats = NULL)

## S3 method for class 'rqs'
apa_performance(fit, metrics = c("R1", "AIC"), column_formats = NULL)

## S3 method for class 'lmrob'
apa_performance(fit, metrics = c("R2", "Sigma_robust"), column_formats = NULL)

## S3 method for class 'rlm'
apa_performance(fit, metrics = "Sigma_robust", column_formats = NULL)

## S3 method for class 'coxph'
apa_performance(
  fit,
  metrics = c("R2", "Concordance", "AIC"),
  column_formats = NULL
)

## S3 method for class 'survreg'
apa_performance(
  fit,
  metrics = c("R2", "Concordance", "AIC"),
  column_formats = NULL
)

## S3 method for class 'lm'
apa_performance(fit, metrics = c("R2", "Sigma"), column_formats = NULL)

## S3 method for class 'glm'
apa_performance(fit, metrics = c("R2", "AIC"), column_formats = NULL)

## S3 method for class 'polr'
apa_performance(fit, metrics = c("R2", "AIC"), column_formats = NULL)

## S3 method for class 'clm'
apa_performance(fit, metrics = c("R2", "AIC"), column_formats = NULL)

## S3 method for class 'merMod'
apa_performance(
  fit,
  metrics = c("R2_marginal", "R2_conditional", "ICC"),
  column_formats = NULL
)

## S3 method for class 'glmmTMB'
apa_performance(
  fit,
  metrics = c("R2_marginal", "R2_conditional", "ICC"),
  column_formats = NULL
)

## S3 method for class 'lme'
apa_performance(
  fit,
  metrics = c("R2_marginal", "R2_conditional", "ICC"),
  column_formats = NULL
)

## S3 method for class 'list'
apa_performance(fit, metrics = NULL, column_formats = NULL)

Arguments

fit

a fitted model of any class that apa_parameters() accepts (except aov, aovlist, and afex_aov), or a named list of models

metrics

fit statistics to display, named as in performance::model_performance() (e.g., "R2", "R2_adjusted", "AIC", "BIC", "RMSE", "Sigma"). The defaults depend on the model: R2 and Sigma for lm; R2 (a pseudo-R^2^) and AIC for glm, ordinal, multinomial, zero-inflated, and hurdle models; R2_marginal, R2_conditional, and ICC for mixed models; R2_adjusted, Deviance_explained, and AIC for generalized additive models; and the fit indices listed under apa_performance.lavaan() for lavaan models. For meta-analyses and lists, NULL (default) chooses them.

column_formats

column_formats object to format columns. If NULL, the default column_formats is used.

Details

For beta regression models (betareg::betareg), R2 is the pseudo-R^2^ of Ferrari and Cribari-Neto (2004): the squared correlation of the linear predictor and the link-transformed outcome. The default metrics are R2 and AIC. Nested models are compared with likelihood ratio tests in apa_performance_comparison().

For ordinal mixed models (ordinal::clmm), the default metrics are the marginal and conditional R^2^ (R2_marginal and R2_conditional) and AIC. Nested models are compared with likelihood ratio tests in apa_performance_comparison().

For generalized additive models (mgcv::gam and mgcv::bam), the metrics are the adjusted R^2^ ("R2_adjusted"), the percentage of the deviance explained ("Deviance_explained"), the number of observations ("n"), "AIC", and "BIC", as reported by summary(). The defaults are "R2_adjusted", "Deviance_explained", and "AIC".

For generalized estimating equations (geepack::geeglm), the default metrics are QIC and QICu (Pan, 2001), from geepack::QIC(); "all" adds CIC. GEE models have no likelihood, so there is no AIC or likelihood-based R^2^.

For structural equation models and confirmatory factor analyses fit with lavaan (e.g., lavaan::cfa() or lavaan::sem()), the default metrics are the model \chi^2 test ("Chi2", "Chi2_df", "p_Chi2"), the comparative fit index ("CFI"), the Tucker-Lewis index ("TLI"), the root mean square error of approximation with its confidence interval ("RMSEA", "RMSEA_CI"), and the standardized root mean square residual ("SRMR"). "AIC" and "BIC" are also available, and "all" selects every metric. Values come from lavaan::fitMeasures(). When the model was fit with a robust estimator (e.g., estimator = "MLR" or "WLSMV"), the scaled \chi^2 test and the robust (or, if unavailable, scaled) CFI, TLI, and RMSEA are displayed. apa_note() gives the sample size, the estimator, and how missing data were handled, and defines the abbreviations.

For meta-analyses (metafor::rma()), the metrics are the number of studies ("k"), the test of residual heterogeneity ("QE" and "p_QE", with its df in the header), \tau^2 ("tau2") and \tau ("tau"), I^2 ("I2"), H^2 ("H2"), confidence intervals of \tau^2 and I^2 ("tau2_CI" and "I2_CI", from stats::confint()), and, for meta-regressions, the omnibus test of the moderators ("QM" and "p_QM") and the proportion of heterogeneity they explain ("R2"). The defaults are "k", "QE", "p_QE", "tau2", and "I2", plus "QM", "p_QM", and "R2" for meta-regressions. Equal-effects models have no \tau^2.

For multilevel meta-analyses (metafor::rma.mv()), "k" is the number of effect sizes, and the variance components are reported for each level: \sigma^2 ("sigma2"), \sigma ("sigma"), and their confidence intervals ("sigma2_CI"), with the level as a subscript. "I2" is the multilevel I^2 for all levels together, and "I2_levels" gives it for each level (Cheung, 2014). The defaults are "k", "QE", "p_QE", "sigma2", and "I2", plus "QM" and "p_QM" for meta-regressions.

For multivariate linear models (class mlm), each outcome gets a row (labeled in an Outcome column) with its R^2^, adjusted R^2^, and residual SD (Sigma), computed from stats::summary.lm() for each outcome. "all" adds the overall F test of each outcome's regression.

For multinomial logistic regression models (nnet::multinom), R2 is McFadden's pseudo-R^2^, and the default metrics are R2 and AIC.

For zero-inflated and hurdle models (pscl::zeroinfl and pscl::hurdle), R2 is computed by performance::r2_zeroinflated(), and the default metrics are R2 and AIC.

For quantile regression models (quantreg::rq), R1 is the Koenker-Machado goodness of fit, R^1^: the proportional reduction in the sum of weighted absolute residuals from the model with only an intercept at the same quantile. It is the quantile regression counterpart of R^2^, and it is usually smaller. The default metrics are R1 and AIC. Models with several quantiles get a row for each quantile. Lists of models are compared in apa_performance_comparison() by R^1^ and AIC, without tests.

For robust regression models fit with robustbase::lmrob, R2 is the robust R^2^ of Renaud and Victoria-Feser (2010), and Sigma_robust is the robust residual scale. For models fit with MASS::rlm, which have no R^2^, the default metric is the robust residual scale. Nested lmrob models are compared with robust Wald tests in apa_performance_comparison(), and rlm models without tests.

For Cox proportional hazards models (survival::coxph), R2 is Nagelkerke's pseudo-R^2^ and Concordance is the concordance index (Harrell's C): the proportion of pairs of cases in which the case with the higher predicted risk had the event sooner. The default metrics are R2, Concordance, and AIC. Nested models are compared with likelihood ratio tests in apa_performance_comparison().

For parametric survival models (survival::survreg), R2 is Nagelkerke's pseudo-R^2^ and Concordance is the concordance index (Harrell's C), as for Cox models. The default metrics are R2, Concordance, and AIC, and nested models are compared with likelihood ratio tests in apa_performance_comparison().

For glm objects, R2 is the pseudo-R^2^ that performance::r2() selects for the model family (e.g., Tjur's R^2^ for logistic regression and Nagelkerke's R^2^ for count models). The header names the pseudo-R^2^ that was used. Because the residual standard deviation is not meaningful for most GLMs, the default metrics are R2 and AIC.

For mixed models (lme4::lmer, lme4::glmer, glmmTMB::glmmTMB, and nlme::lme), the default metrics are the marginal R^2^ (variance explained by the fixed effects), the conditional R^2^ (fixed and random effects), and the intraclass correlation (ICC), as computed by performance::model_performance().

For a list of models, each model's metrics are displayed in a row, labeled in a Model column by the list's names (or "Model 1", "Model 2", ... for unnamed elements). If metrics is NULL (default), each model's default metrics are used.

Value

apa7_tbl (tibble)

References

McFadden, D. (1974). Conditional logit analysis of qualitative choice behavior. In P. Zarembka (Ed.), Frontiers in econometrics (pp. 105–142). Academic Press.

Nagelkerke, N. J. D. (1991). A note on a general definition of the coefficient of determination. Biometrika, 78(3), 691–692. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1093/biomet/78.3.691")}

Nakagawa, S., & Schielzeth, H. (2013). A general and simple method for obtaining R^2 from generalized linear mixed-effects models. Methods in Ecology and Evolution, 4(2), 133–142. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1111/j.2041-210x.2012.00261.x")}

Satorra, A., & Bentler, P. M. (1994). Corrections to test statistics and standard errors in covariance structure analysis. In A. von Eye & C. C. Clogg (Eds.), Latent variables analysis: Applications for developmental research (pp. 399–419). Sage.

Tjur, T. (2009). Coefficients of determination in logistic regression models—A new proposal: The coefficient of discrimination. The American Statistician, 63(4), 366–372. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1198/tast.2009.08210")}

Yuan, K.-H., & Bentler, P. M. (2000). Three likelihood-based methods for mean and covariance structure analysis with nonnormal missing data. Sociological Methodology, 30(1), 165–200. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1111/0081-1750.00078")}

Examples

lm(mpg ~ cyl + wt, data = mtcars) |>
   apa_performance() |>
   apa_flextable()

if (requireNamespace("lavaan", quietly = TRUE)) {
  model <- "visual =~ x1 + x2 + x3
            textual =~ x4 + x5 + x6
            speed =~ x7 + x8 + x9"
  fit_cfa <- lavaan::cfa(model, data = lavaan::HolzingerSwineford1939)
  apa_performance(fit_cfa)
}

list(
  `Cylinders` = lm(mpg ~ cyl, data = mtcars),
  `Cylinders and weight` = lm(mpg ~ cyl + wt, data = mtcars)
) |>
  apa_performance()

apa7 documentation built on Dec. 1, 2026, 5:06 p.m.