Learn R Programming

rstatix (version 0.1.1)

tukey_hsd: Tukey Honest Significant Differences

Description

Provides a pipe-friendly framework to performs Tukey post-hoc tests. Wrapper around the function TukeyHSD().

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

Usage

tukey_hsd(x, ...)

# S3 method for default tukey_hsd(x, ...)

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

# S3 method for 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)

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

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

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

Examples

Run this code
# NOT RUN {
# 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)

# }

Run the code above in your browser using DataLab