Skip to contents

Conducts pairwise two-sample independence tests across groups.

Usage

pairwisePermutationMatrix(
  formula = NULL,
  data = NULL,
  x = NULL,
  g = NULL,
  method = "fdr",
  ...
)

Arguments

formula

A formula indicating the measurement variable and the grouping variable. e.g. y ~ group.

data

The data frame to use.

x

The response variable as a vector.

g

The grouping variable as a vector.

method

The p-value adjustment method to use for multiple tests. See stats::p.adjust.

...

Additional arguments passed to coin::independence_test.

Value

A list consisting of: A matrix of p-values; the p-value adjustment method; a matrix of adjusted p-values.

Details

The input should include either formula and data; or x, and g.

This function is a wrapper for coin::independence_test, passing pairwise groups to the function. It's critical to read and understand the documentation for this function to understand its use and options.

For some options for common tests, see Horthorn et al., 2008.

Note

The parsing of the formula is simplistic. The first variable on the left side is used as the measurement variable. The first variable on the right side is used for the grouping variable.

References

https://rcompanion.org/handbook/K_02.html

Hothorn, T., K. Hornik, M.A. van de Wiel, and A. Zeileis. 2008. Implementing a Class of Permutation Tests: The coin Package. Journal of Statistical Software, 28(8), 1–23.

Author

Salvatore Mangiafico, mangiafico@njaes.rutgers.edu

Examples

### Fisher-Pitman test

data(BrendonSmall)

library(coin)
                                 
independence_test(Sodium ~ Instructor, data = BrendonSmall, 
                  teststat = "quadratic") 
#> 
#> 	Asymptotic General Independence Test
#> 
#> data:  Sodium by
#> 	 Instructor (Brendon Small, Jason Penopolis, Melissa Robins, Paula Small, Coach McGuirk)
#> chi-squared = 30.34, df = 4, p-value = 4.174e-06
#> 
                                      
PT = pairwisePermutationMatrix(Sodium ~ Instructor,
                               data     = BrendonSmall,
                               teststat = "quadratic",
                               method   = "fdr")
PT
#> $Unadjusted
#>                 Brendon Small Jason Penopolis Melissa Robins Paula Small
#> Brendon Small              NA          0.2245       0.002135   0.0004433
#> Jason Penopolis            NA              NA       0.004881   0.0004822
#> Melissa Robins             NA              NA             NA   0.0812900
#> Paula Small                NA              NA             NA          NA
#> Coach McGuirk              NA              NA             NA          NA
#>                 Coach McGuirk
#> Brendon Small       0.0004439
#> Jason Penopolis     0.0004830
#> Melissa Robins      0.0820900
#> Paula Small         0.9877000
#> Coach McGuirk              NA
#> 
#> $Method
#> [1] "fdr"
#> 
#> $Adjusted
#>                 Brendon Small Jason Penopolis Melissa Robins Paula Small
#> Brendon Small        1.000000        0.249400       0.004270    0.001208
#> Jason Penopolis      0.249400        1.000000       0.008135    0.001208
#> Melissa Robins       0.004270        0.008135       1.000000    0.102600
#> Paula Small          0.001208        0.001208       0.102600    1.000000
#> Coach McGuirk        0.001208        0.001208       0.102600    0.987700
#>                 Coach McGuirk
#> Brendon Small        0.001208
#> Jason Penopolis      0.001208
#> Melissa Robins       0.102600
#> Paula Small          0.987700
#> Coach McGuirk        1.000000
#> 

PA = PT$Adjusted
library(multcompView)
multcompLetters(PA,
                compare="<",
                threshold=0.05,
                Letters=letters)   
#>   Brendon Small Jason Penopolis  Melissa Robins     Paula Small   Coach McGuirk 
#>             "a"             "a"             "b"             "b"             "b"