Skip to contents

Runs all k(k-1)/2 pairwise two-sample t-tests for a grouping variable with k levels and applies multiple-comparison p-value adjustment. Delegates pair-level computations to get_t_test().

Usage

get_pairwise(
  design,
  x,
  by,
  group = NULL,
  pval_adj = "holm",
  conf_level = 0.95,
  variance = "ci",
  na.rm = TRUE,
  min_cell_n = 30L,
  decimals = NULL,
  label_values = TRUE,
  label_vars = TRUE,
  name_style = "surveycore",
  ...,
  .id = NULL,
  .if_missing_var = NULL
)

Arguments

design

A survey design object: survey_taylor, survey_replicate, survey_twophase, or survey_nonprob.

x

<tidy-select> A single unquoted numeric variable name for the outcome variable.

by

<tidy-select> A single unquoted variable name for the grouping variable. Must have at least 2 active levels.

group

<tidy-select> Optional subgroup variable(s). When supplied, pairwise comparisons are run within each group stratum. P-value adjustment is applied separately per stratum. Default NULL.

pval_adj

Character(1). P-value adjustment method passed to stats::p.adjust(). Default "holm". Use "none" for unadjusted p-values. Error: surveycore_error_invalid_pval_adj.

conf_level

Numeric(1). Confidence level strictly in (0, 1). Default 0.95.

variance

Character. Which uncertainty columns to include. Valid values: "se", "ci". Default "ci".

na.rm

Logical(1). Accepted for API uniformity. Default TRUE.

min_cell_n

Integer(1). Warn for small cells. Default 30L.

decimals

Integer(1) or NULL. Round all double output columns. Default NULL.

label_values

Logical(1). Convert by/group codes to value labels. Default TRUE.

label_vars

Logical(1). Accepted for API uniformity; no visible effect. Default TRUE.

name_style

Character(1). "surveycore" (default) or "broom".

...

Unused. Reserved so that .id and .if_missing_var remain named-only when a survey_collection is passed as design.

.id

Character(1) or NULL. Column name used to identify each survey when design is a survey_collection. For collection inputs, NULL (the default) resolves to the collection's stored @id property. Pass a non-NULL value to override. Ignored when design is a single survey.

.if_missing_var

"error", "skip", or NULL. How to handle surveys in a collection that lack one of the requested NSE variables. For collection inputs, NULL (the default) resolves to the collection's stored @if_missing_var property. Pass a non-NULL value to override. Ignored when design is a single survey.

Value

A survey_pairwise tibble (also inheriting survey_result). Columns: group columns (when active), level_a, level_b, estimate, mean_a, mean_b, n_a, n_b, se (optional), ci_low (optional), ci_high (optional), t_stat, df, p_value (adjusted), stars. Use meta() to access the adjustment method and other metadata.

Examples

gss_sub <- gss_2024[gss_2024$sex %in% c(1L, 2L) & !is.na(gss_2024$age), ]
gss_sub$sex <- factor(gss_sub$sex, levels = c(1, 2), labels = c("Male", "Female"))
gss_design <- as_survey(gss_sub,
  ids = vpsu, weights = wtssps, strata = vstrat, nest = TRUE)
get_pairwise(gss_design, age, by = sex)
#> # A tibble: 1 × 13
#>   level_a level_b estimate mean_a mean_b   n_a   n_b ci_low ci_high t_stat    df
#>   <chr>   <chr>      <dbl>  <dbl>  <dbl> <int> <int>  <dbl>   <dbl>  <dbl> <dbl>
#> 1 Male    Female     0.260   47.8   48.1  1424  1773  -1.65    2.17  0.271    66
#> # ℹ 2 more variables: p_value <dbl>, stars <chr>