Skip to contents

This function compares pairs of variables using matched-pairs t-tests, and also provides "homogeneous subsets" (similar to SPSS) following a Bonferroni correction.

Usage

compare_pairs_of_vars(df, vars, order_output = TRUE)

Arguments

df

data.frame

vars

Vector of variable names

order_output

(logical) Whether to rank-order row and columns of subsets matrix by mean size (recommended)

Value

List with two matrices:

p_uncorrected

Matrix of (unadjusted) p-values

subsets

Matrix indicating whether each pair of variables are part of the same subset (indicated by "SAMESET") or are instead significantly different (blank entry) following a Bonferroni correction

Details

p-values come from matched-pairs t-tests assuming equal variances and are uncorrected for the number of tests. Subsets are generated following a Bonferroni correction, and the rows and columns of the resulting matrix can be ordered by variable mean: This is recommended to simplify examination of the homogeneous subsets.

Examples

df |> compare_pairs_of_vars(c("x1", "x2", "x3"))
#> [1] "Bonferroni correction for 3 tests"
#> $p_uncorrected
#>           x1        x2        x3
#> x1 1.0000000 0.7311431 0.6870606
#> x2 0.7311431 1.0000000 0.8192890
#> x3 0.6870606 0.8192890 1.0000000
#> 
#> $subsets
#>         x3      x2      x1
#> x3 SAMESET SAMESET SAMESET
#> x2 SAMESET SAMESET SAMESET
#> x1 SAMESET SAMESET SAMESET
#>