Skip to content

A collection of functions to insert stats inline in Rmd and qmd documents

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

KyleOfCanada/statsreportr

Repository files navigation

statsreportr statsreportr hexsticker

Codecov test coverage R-CMD-check

The goal of statsreportr is to make it easy to report the results of statistical analyses in inline code of a R Markdown or Quarto document.

Installation

You can install the development version of statsreportr from GitHub with:

# install.packages("pak")
pak::pak("KyleOfCanada/statsreportr")

Example

Some basic examples which shows you how to generate reports for ANOVAs and t-tests:

library(statsreportr)

# ANOVAs
results <- mtcars |>
  rstatix::anova_test(mpg ~ cyl)

format_p(results$p)
#> [1] "< 0.0001"

results2 <- mtcars |>
  rstatix::anova_test(mpg ~ cyl * carb)

results3 <- aov(mpg ~ cyl * carb, data = mtcars)

report_anova(results2)
#> [1] "*F*~(1,28)~ = 47.2, *p* < 0.0001, $\\eta^2_G$ = 0.628"
report_anova(results2, "carb")
#> [1] "*F*~(1,28)~ = 1.55, *p* = 0.223, $\\eta^2_G$ = 0.052"
report_anova(results2, 2)
#> [1] "*F*~(1,28)~ = 1.55, *p* = 0.223, $\\eta^2_G$ = 0.052"
report_anova(results3, 2)
#> [1] "*F*~(1,28)~ = 1.55, *p* = 0.223, $\\eta^2_G$ = 0.052"

# t-tests
results3 <- mtcars |>
  rstatix::t_test(mpg ~ am)

report_t(results3)
#> [1] "*t*~(18.3)~ = -3.77, *p* = 0.00137"

results4 <- mtcars |>
  rstatix::t_test(mpg ~ cyl)

cohensd4 <- mtcars |>
  rstatix::cohens_d(mpg ~ cyl)

report_t(results4,
  effect = c("6", "8"),
  cohensd = cohensd4, cohens_magnitude = TRUE
)
#> [1] "*t*~(18.5)~ = 5.29, adjusted *p* < 0.0001, *d* = 2.23, indicating a large effect"

# Descriptive stats

mtcars |> report_mean_sd(mpg, cyl, effect = "6")
#> [1] "19.7 ± 1.45"

mtcars |> report_mean_sem(mpg, cyl, effect = "6")
#> [1] "19.7 ± 0.549"

The intent of this package is to be used inline in a R Markdown or Quarto document. For example, the following inline code:

The results of the t test showed a significant difference in the mpg of 6 (`r mtcars |> report_mean_sd(mpg, cyl, effect = "6")`) vs 8 (`r mtcars |> report_mean_sd(mpg, cyl, effect = "8")`) cylinder cars (`r report_t(results4, effect = c("6", "8"), cohensd = cohensd4, cohens_magnitude = TRUE)`).

Will render as:

The results of the t test showed a significant difference in the mpg of 6 (19.7 ± 1.45) vs 8 (15.1 ± 2.56) cylinder cars (t(18.5) = 5.29, adjusted p < 0.0001, d = 2.23, indicating a large effect).

About

A collection of functions to insert stats inline in Rmd and qmd documents

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages