Function Overview

library(tadaatoolbox)
knitr::opts_chunk$set(message = FALSE, warning = FALSE)

This toolbox has been compiled to make the intro to R and statistics with R a little easier.
Besides that, it also contains some neat helper functions for tasks or problems one might run in frequently in our field.

A neat overview of functions and stuff can be found on tadaatoolbox.tadaa-data.de

High Level Functions

There are several high level functions aimed at quick output generation:

cat(paste0("- **", apropos("tadaa_"), "**", collapse = "\n"))

The point of these function is to combine routine steps into one function, so let's showcase them.

t-Tests: tadaa_t.test

The effect size $d$ is calculated with pooled/weighted variances to ensure accuracy. It then formats the output according to broom::tidy, sprinkles it with pixiedust and prints either to console, markdown or whatever printing method is passed via the print argument to pixiedust::sprinkle_print_method.

tadaa_t.test(ngo, stunzahl, geschl, print = "markdown")

Or, if you're having a non-parametric day, try this:

tadaa_wilcoxon(ngo, stunzahl, geschl, print = "markdown")

ANOVA: tadaa_aov

The function knows 3 types of sums of squares, adjustable via the type argument and defaulting to type 3 sums of squares. Additionally for type 3, the function also automatically checks the contrasts associated with the factor variables (only for unordered factors), and if check_names = TRUE, the contrasts are set to contr.sum.

tadaa_aov(stunzahl ~ jahrgang * geschl, data = ngo, print = "markdown")

Or, if you're still unsure about the parametricity of your day:

tadaa_kruskal(stunzahl ~ jahrgang, data = ngo, print = "markdown")

Pairwise tests

Pairwise t-tests

Since we found stats::pairwise.t.test insufficient in cases of two-way ANOVAs, we wrapped the function to also enable the testing of interactions. The adjusted p-values are only adjusted within each term, so it is like performing stats::pairwise.t.test 3 times with each factor and additionally the interaction of the two factors (which is what the function does internally).

As a bonus, this functions knows the two additional p-adjustment methods sidak and sidakSD for the Sidak adjustement and the Sidak-like step-down procedure respectively.

tadaa_pairwise_t(ngo, response = deutsch, group1 = jahrgang, p.adjust = "bonf", print = "markdown")

tadaa_pairwise_t(ngo, response = deutsch, group1 = jahrgang, group2 = geschl, p.adjust = "sidakSD", print = "markdown")

Statistics Wrappers

These are pretty self-explanatory. The goal is to provide simple functions for commonly used statistics that look and behave the same, and also only return a single numerical value to play nice with dplyr::summarize.

Summaries

General Helper Functions

Intervals and recoding

Plotting helpers

library(ggplot2)

ggplot(data = ngo, aes(x = jahrgang, y = deutsch)) +
  stat_summary(fun.data = "mean_ci_t", geom = "errorbar") +
  theme_tadaa()

As a convenience, we added tadaa_mean_ci to quickly plot means with errorbars to get a quick glance at your data.

tadaa_mean_ci(data = ngo, response = deutsch, group = jahrgang) +
  theme_tadaa()

Prebuilt plotting functions

library(ggplot2)
if (!("cowplot" %in% installed.packages())) install.packages("cowplot")

tadaa_int(data = ngo, response = stunzahl, group1 = jahrgang, group2 = geschl, grid = T, brewer_palette = "Set1")

Data

The infamous ngo dataset is included for teaching purposes as well. It differs from ryouready's provided version with regards to classes and labels. The code below was used to generate the provided version of the dataset:

(Note that \u00e4 is a unicode encoded Umlaut for compatibility reasons)

ngo <- ryouready::d.ngo

## sjPlot value labels
ngo$geschl   <- sjmisc::set_labels(ngo$geschl,   c("M\u00e4nnlich", "Weiblich"))
ngo$abschalt <- sjmisc::set_labels(ngo$abschalt, c("Ja", "Nein"))
ngo$jahrgang <- sjmisc::set_labels(ngo$jahrgang, c("11", "12", "13"))
ngo$hausauf  <- sjmisc::set_labels(ngo$hausauf,  c("gar nicht", "weniger als halbe Stunde",
                                                   "halbe Stunde bis Stunde", "1 bis 2 Stunden",
                                                   "2 bis 3 Stunden", "3 bis 4 Stunden",
                                                   "mehr als 4 Stunden"))

## factors
ngo$geschl   <- factor(ngo$geschl,   labels = c("M\u00e4nnlich", "Weiblich"))
ngo$jahrgang <- factor(ngo$jahrgang, labels = c("11", "12", "13"), ordered = TRUE)
ngo$hausauf  <- car::recode(ngo$hausauf,  "0 = NA")
ngo$abschalt <- car::recode(ngo$abschalt, "0 = NA")
ngo$abschalt <- factor(ngo$abschalt, labels = c("Ja", "Nein"))

## Variable labels
ngo$geschl   <- sjmisc::set_label(ngo$geschl, "Geschlecht")
ngo$abschalt <- sjmisc::set_label(ngo$abschalt, "Abschalten")
ngo$jahrgang <- sjmisc::set_label(ngo$jahrgang, "Jahrgang")
ngo$hausauf  <- sjmisc::set_label(ngo$hausauf, "Hausaufgaben")

## Saving
ngo <- dplyr::tbl_df(ngo)


Try the tadaatoolbox package in your browser

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

tadaatoolbox documentation built on July 2, 2020, 2:30 a.m.