# statAPA

<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/statAPA)](https://CRAN.R-project.org/package=statAPA)
[![R-CMD-check](https://github.com/causalfragility-lab/statAPA/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/causalfragility-lab/statAPA/actions)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
<!-- badges: end -->

**statAPA** produces publication-ready statistical tables and figures formatted
according to the 7th edition of the American Psychological Association (APA)
style guidelines. Output can be directed to the R console, Microsoft Word
(via `officer` + `flextable`), or LaTeX.

---

## Installation

Install the released version from CRAN:

```r
install.packages("statAPA")
```

Or the development version from GitHub:

```r
# install.packages("remotes")
remotes::install_github("causalfragility-lab/statAPA")
```

---

## Functions at a glance

| Function | What it does |
|---|---|
| `apa_descriptives()` | Descriptive statistics table (optionally by group) |
| `apa_t_test()` | One-sample, two-sample (Welch/pooled), and paired t-tests |
| `apa_z_test_mean()` | z-test with known population standard deviation(s) |
| `apa_chisq()` | Chi-square test (goodness-of-fit or independence) |
| `apa_prop_test()` | Proportion test with risk difference, risk ratio, odds ratio |
| `apa_anova()` | One-way ANOVA/ANCOVA (Type II/III) with effect sizes |
| `apa_ancova()` | ANCOVA with covariate validation and adjusted means |
| `apa_twoway_anova()` | Two-way ANOVA with interaction and simple effects |
| `apa_manova()` | MANOVA (Pillai, Wilks, Hotelling-Lawley, Roy) |
| `apa_posthoc()` | Post-hoc pairwise comparisons (emmeans) |
| `apa_table()` | Regression / multilevel coefficient table |
| `apa_robust()` | Robust regression (HC or cluster-robust SEs) |
| `apa_hetero()` | Heteroscedasticity diagnostics |
| `apa_homoskedasticity()` | Homoskedasticity check (Breusch-Pagan, White, Levene) |
| `apa_multilevel()` | Multilevel models: fixed/random effects, ICC, R², model comparison |
| `apa_plot_descriptives()` | Mean ± 95% CI plot by group |
| `apa_plot_regression()` | Fitted-line plot with confidence ribbon |
| `apa_plot_anova()` | Estimated marginal means plot |
| `apa_plot_residuals()` | Residual diagnostic plots |
| `apa_to_flextable()` | Convert any result to an APA-styled flextable |
| `save_apa()` | Save a ggplot figure at 300 dpi with APA dimensions |
| `theme_apa()` | APA-style ggplot2 theme |

---

## Quick example

```r
library(statAPA)

# Descriptive statistics
apa_descriptives(mtcars, vars = c("mpg", "wt", "hp"), group = "cyl")

# t-test
apa_t_test(mtcars$mpg[mtcars$am == 0],
           mtcars$mpg[mtcars$am == 1],
           output = "console")

# Two-way ANOVA with simple effects
mtcars2 <- transform(mtcars, cyl = factor(cyl), gear = factor(gear))
apa_twoway_anova(mpg ~ cyl * gear, data = mtcars2,
                 factorA = "cyl", factorB = "gear")

# MANOVA
apa_manova(cbind(Sepal.Length, Petal.Length) ~ Species, data = iris)

# Multilevel model
library(lme4)
data(ECLS_demo)
m0 <- lmer(math ~ 1 + (1 | schid), data = ECLS_demo, REML = FALSE)
m1 <- lmer(math ~ SES + (1 | schid), data = ECLS_demo, REML = FALSE)
apa_multilevel(m0, m1, model_names = c("Null", "+ SES"))

# Export to Word
fit <- lm(mpg ~ wt + hp, data = mtcars)
apa_table(fit, output = "word", file = "regression_table.docx")
```

---

## Citation

If you use statAPA in published research, please cite:
Hait, S. (2026). statAPA: APA 7th Edition Statistical Tables, Plots,
and Multilevel Model Reports. R package version 0.1.0.
https://CRAN.R-project.org/package=statAPA
---

## License

MIT © 2026 Subir Hait
