Automated Reporting: Getting Started"

knitr::opts_chunk$set(
  collapse = TRUE,
  warning = FALSE,
  message = FALSE,
  out.width = "100%",
  comment = "#"
)

options(
  knitr.kable.NA = "",
  width = 60
)

pkgs <- c("dplyr", "lme4")
successfully_loaded <- vapply(pkgs, requireNamespace, FUN.VALUE = logical(1L), quietly = TRUE)
can_evaluate <- all(successfully_loaded)

if (can_evaluate) {
  knitr::opts_chunk$set(eval = TRUE)
  vapply(pkgs, require, FUN.VALUE = logical(1L), quietly = TRUE, character.only = TRUE)
} else {
  knitr::opts_chunk$set(eval = FALSE)
}

library(report)

Installation

First, install R and R studio. Then, copy and paste the following lines in the console:

install.packages("remotes")
remotes::install_github("easystats/report") # You only need to do that once
library("report") # Load the package every time you start R

Great! The report package is now installed and loaded in your session.

Supported Objects

The report package works in a two step fashion: - First, you create a report object with the report() function. - Second, this report object can be displayed either textually (the default output) or as a table, using as.data.frame(). Moreover, you can also access a more compact version of the report using summary() on the report object.

Dataframes

If an entire dataframe is supplied, report will provide descriptive statistics for all columns:

report(iris)

Grouped Dataframes

The dataframe can also be a grouped dataframe (from {dplyr} package), in which case report would return a separate report for each level of the grouping variable. Additionally, instead of textual summary, report also allows one to return a tabular summary using the report_table() function:

iris %>%
  group_by(Species) %>%
  report_table()

Correlations, t-test, and Wilcox test

report can also be used to provide automated summaries for statistical model objects from correlation, t-tests, Wilcoxon tests, etc.

report(t.test(formula = mtcars$wt ~ mtcars$am))
report(cor.test(mtcars$mpg, mtcars$wt))

Regression models

Linear regression (lm)

We will start out simple: a simple linear regression

model <- lm(wt ~ am + mpg, data = mtcars)

report(model)

anova (aov)

And its close cousin ANOVA is also covered by report:

model <- aov(wt ~ am + mpg, data = mtcars)

report(model)

General Linear Models (GLMs) (glm)

model <- glm(vs ~ mpg + cyl, data = mtcars, family = "binomial")

report(model)

Linear Mixed-Effects Models (merMod)

library(lme4)

model <- lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy)

report(model)


Try the report package in your browser

Any scripts or data that you put into this service are public.

report documentation built on Sept. 11, 2024, 8:47 p.m.