ggstatsplot (version 0.0.11)

pairwise_p: Pairwise comparison tests

Description

Calculate pairwise comparisons between group levels with corrections for multiple testing.

Usage

pairwise_p(data, x, y, type = "parametric", tr = 0.1, paired = FALSE,
  var.equal = FALSE, p.adjust.method = "holm", k = 2,
  messages = TRUE, ...)

Arguments

data

A dataframe (or a tibble) from which variables specified are to be taken. A matrix or tables will not be accepted.

x

The grouping variable from the dataframe data.

y

The response (a.k.a. outcome or dependent) variable from the dataframe data.

type

Type of statistic expected ("parametric" or "nonparametric" or "robust" or "bayes").Corresponding abbreviations are also accepted: "p" (for parametric), "np" (nonparametric), "r" (robust), or "bf"resp.

tr

Trim level for the mean when carrying out robust tests. If you get error stating "Standard error cannot be computed because of Winsorized variance of 0 (e.g., due to ties). Try to decrease the trimming level.", try to play around with the value of tr, which is by default set to 0.1. Lowering the value might help.

paired

a logical indicating whether you want a paired t-test.

var.equal

a logical variable indicating whether to treat the variances in the samples as equal. If TRUE, then a simple F test for the equality of means in a one-way analysis of variance is performed. If FALSE, an approximate method of Welch (1951) is used, which generalizes the commonly known 2-sample Welch test to the case of arbitrarily many samples.

p.adjust.method

Adjustment method for p-values for multiple comparisons. Possible methods are: "holm" (default), "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none".

k

Number of digits after decimal point (should be an integer) (Default: k = 2).

messages

Decides whether messages references, notes, and warnings are to be displayed (Default: TRUE).

...

Additional arguments.

See Also

ggbetweenstats, grouped_ggbetweenstats

Other helper_messages: bartlett_message, effsize_ci_message, ggcorrmat_matrix_message, grouped_message, normality_message, palette_message

Examples

Run this code
# NOT RUN {
# time consuming, so not run on `CRAN` machines
# }
# NOT RUN {
# show all columns in a tibble
options(tibble.width = Inf)

# for reproducibility
set.seed(123)

#------------------- between-subjects design ----------------------------

# parametric
# if `var.equal = TRUE`, then Student's *t*-test will be run
ggstatsplot::pairwise_p(
  data = ggplot2::msleep,
  x = vore,
  y = brainwt,
  type = "p",
  var.equal = TRUE,
  paired = FALSE,
  p.adjust.method = "bonferroni"
)

# if `var.equal = FALSE`, then Games-Howell test will be run
ggstatsplot::pairwise_p(
  data = ggplot2::msleep,
  x = vore,
  y = brainwt,
  type = "p",
  var.equal = FALSE,
  paired = FALSE,
  p.adjust.method = "bonferroni"
)

# non-parametric
ggstatsplot::pairwise_p(
  data = ggplot2::msleep,
  x = vore,
  y = brainwt,
  type = "np",
  paired = FALSE,
  p.adjust.method = "none"
)

# robust
ggstatsplot::pairwise_p(
  data = ggplot2::msleep,
  x = vore,
  y = brainwt,
  type = "r",
  paired = FALSE,
  p.adjust.method = "fdr"
)
# }
# NOT RUN {
#------------------- within-subjects design ----------------------------

set.seed(123)
library(jmv)
data("bugs", package = "jmv")

# converting to long format
bugs_long <- bugs %>%
  tibble::as_tibble(.) %>%
  tidyr::gather(., key, value, LDLF:HDHF)

# parametric
ggstatsplot::pairwise_p(
  data = bugs_long,
  x = key,
  y = value,
  type = "p",
  paired = TRUE,
  p.adjust.method = "BH"
)

# non-parametric
ggstatsplot::pairwise_p(
  data = bugs_long,
  x = key,
  y = value,
  type = "np",
  paired = TRUE,
  p.adjust.method = "BY"
)

# robust
ggstatsplot::pairwise_p(
  data = bugs_long,
  x = key,
  y = value,
  type = "r",
  paired = TRUE,
  p.adjust.method = "hommel"
)
# }

Run the code above in your browser using DataCamp Workspace