Learn R Programming

rstatix (version 1.1.0)

adjust_pvalue: Adjust P-values for Multiple Comparisons

Description

A pipe-friendly function to add an adjusted p-value column into a data frame. Supports grouped data.

Usage

adjust_pvalue(data, p.col = NULL, output.col = NULL, method = "holm")

Value

a data frame

Arguments

data

a data frame containing a p-value column

p.col

column name containing p-values

output.col

the output column name to hold the adjusted p-values

method

method for adjusting p values (see p.adjust). Allowed values include "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". If you don't want to adjust the p value (not recommended), use p.adjust.method = "none".

Details

For grouped data (and, equivalently, when a test is run on data grouped with dplyr::group_by() using an in-test p.adjust.method), the p-value adjustment is computed within each group separately, not across all groups. If you instead want a single family of comparisons adjusted across all groups, run the test without adjustment (p.adjust.method = "none") and then call adjust_pvalue() on the combined result (see the grouped example below).

Examples

Run this code
# Perform pairwise comparisons and adjust p-values
ToothGrowth %>%
 t_test(len ~ dose) %>%
 adjust_pvalue()

# Grouped data: adjustment within vs across groups
# Per-group adjustment (within each supp level):
ToothGrowth %>%
  group_by(supp) %>%
  t_test(len ~ dose)                    # in-test holm, adjusted within each group

# One family across ALL comparisons (all groups together):
ToothGrowth %>%
  group_by(supp) %>%
  t_test(len ~ dose, p.adjust.method = "none") %>%
  adjust_pvalue(method = "holm")

Run the code above in your browser using DataLab