Skip to contents

Conducts pairwise McNemar, exact, and permutation tests as a post-hoc to Cochran Q test.

Usage

pairwiseMcnemar(
  formula = NULL,
  data = NULL,
  x = NULL,
  g = NULL,
  block = NULL,
  test = "exact",
  method = "fdr",
  digits = 3,
  correct = FALSE
)

Arguments

formula

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

data

The data frame to use.

x

The response variable.

g

The grouping variable.

block

The blocking variable.

test

If "exact", conducts an exact test of symmetry analogous to a McNemar test. If "mcnemar", conducts a McNemar test of symmetry. If "permutation", conducts a permutation test analogous to a McNemar test.

method

The method for adjusting multiple p-values. See p.adjust.

digits

The number of significant digits in the output.

correct

If TRUE, applies a continuity correction for the McNemar test.

Value

A list containing: a data frame of results of the global test; a data frame of results of the pairwise results; and a data frame mentioning the p-value adjustment method.

Details

The component tables for the pairwise tests must be of size 2 x 2.

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

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. The second variable on the right side is used for the blocking variable.

Author

Salvatore Mangiafico, mangiafico@njaes.rutgers.edu

Examples

### Cochran Q post-hoc example
data(HayleySmith)
library(DescTools)
CochranQTest(Response ~ Practice | Student,
             data = HayleySmith)
#> 
#> 	Cochran's Q test
#> 
#> data:  Response and Practice and Student
#> Q = 16.953, df = 3, p-value = 0.0007225
#> 
HayleySmith$Practice = factor(HayleySmith$Practice,
                          levels = c("MowHeight", "SoilTest",
                                     "Clippings", "Irrigation"))
PT = pairwiseMcnemar(Response ~ Practice | Student,
                     data    = HayleySmith,
                     test    = "exact",
                     method  = "fdr",
                     digits  = 3)
PT
#> $Test.method
#>    Test
#> 1 exact
#> 
#> $Adustment.method
#>   Method
#> 1    fdr
#> 
#> $Pairwise
#>                   Comparison Successes Trials p.value p.adjust
#> 1   MowHeight - SoilTest = 0         0      1       1   1.0000
#> 2  MowHeight - Clippings = 0         1      6   0.219   0.3280
#> 3 MowHeight - Irrigation = 0         1     12 0.00635   0.0351
#> 4   SoilTest - Clippings = 0         2      7   0.453   0.5440
#> 5  SoilTest - Irrigation = 0         1     11  0.0117   0.0351
#> 6 Clippings - Irrigation = 0         0      6  0.0313   0.0626
#> 
PT = PT$Pairwise
cldList(comparison = PT$Comparison,
        p.value    = PT$p.adjust,
        threshold  = 0.05)
#>        Group Letter MonoLetter
#> 1  MowHeight      a         a 
#> 2   SoilTest      a         a 
#> 3  Clippings     ab         ab
#> 4 Irrigation      b          b