tukey_hsd: Tukey Honest Significant Differences

View source: R/tukey_hsd.R

tukey_hsdR Documentation

Tukey Honest Significant Differences

Description

Provides a pipe-friendly framework to performs Tukey post-hoc tests. Wrapper around the function TukeyHSD(). It is essentially a t-test that corrects for multiple testing.

Can handle different inputs formats: aov, lm, formula.

Usage

tukey_hsd(x, ...)

## Default S3 method:
tukey_hsd(x, ...)

## S3 method for class 'lm'
tukey_hsd(x, ...)

## S3 method for class 'data.frame'
tukey_hsd(x, formula, ...)

Arguments

x

an object of class aov, lm or data.frame containing the variables used in the formula.

...

other arguments passed to the function TukeyHSD(). These include:

  • which: A character vector listing terms in the fitted model for which the intervals should be calculated. Defaults to all the terms.

  • ordered: A logical value indicating if the levels of the factor should be ordered according to increasing average in the sample before taking differences. If ordered is true then the calculated differences in the means will all be positive. The significant differences will be those for which the lwr end point is positive.

formula

a formula of the form x ~ group where x is a numeric variable giving the data values and group is a factor with one or multiple levels giving the corresponding groups. For example, formula = TP53 ~ cancer_group.

data

a data.frame containing the variables in the formula.

Value

a tibble data frame containing the results of the different comparisons.

Methods (by class)

  • tukey_hsd(default): performs tukey post-hoc test from aov() results.

  • tukey_hsd(lm): performs tukey post-hoc test from lm() model.

  • tukey_hsd(data.frame): performs tukey post-hoc tests using data and formula as inputs. ANOVA will be automatically performed using the function aov()

Examples

# Data preparation
df <- ToothGrowth
df$dose <- as.factor(df$dose)
# Tukey HSD from ANOVA results
aov(len ~ dose, data = df) %>% tukey_hsd()

# two-way anova with interaction
aov(len ~ dose*supp, data = df) %>% tukey_hsd()

# Tukey HSD from lm() results
lm(len ~ dose, data = df) %>% tukey_hsd()

# Tukey HSD from data frame and formula
tukey_hsd(df, len ~ dose)

# Tukey HSD using grouped data
df %>%
  group_by(supp) %>%
  tukey_hsd(len ~ dose)


kassambara/rstatix documentation built on Feb. 6, 2023, 3:36 a.m.