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, orsurvey_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. DefaultNULL.- 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. DefaultNULL.- label_values
Logical(1). Convert
by/groupcodes to value labels. DefaultTRUE.- 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
.idand.if_missing_varremain named-only when asurvey_collectionis passed asdesign.- .id
Character(1) or
NULL. Column name used to identify each survey whendesignis asurvey_collection. For collection inputs,NULL(the default) resolves to the collection's stored@idproperty. Pass a non-NULLvalue to override. Ignored whendesignis a single survey.- .if_missing_var
"error","skip", orNULL. 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_varproperty. Pass a non-NULLvalue to override. Ignored whendesignis 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.
See also
Other analysis:
clean(),
get_anova(),
get_corr(),
get_covariance(),
get_diffs(),
get_freqs(),
get_means(),
get_quantiles(),
get_ratios(),
get_t_test(),
get_totals(),
get_variance(),
meta()
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>
