pairPropTest

pairPropTest is a function for comparing a set of proportion pairs for statistically significant differences.

Sample data

pairPropTest applied to the iris dataset, after glancing at the first few rows of data.

head(iris_wtd) %>% 
    knitr::kable()
Sepal.Length Sepal.Width Petal.Length Petal.Width Species rand_bin weight index
5.1 3.5 1.4 0.2 setosa 2 1 36
4.9 3.0 1.4 0.2 setosa 2 3 19
4.7 3.2 1.3 0.2 setosa 1 2 10
4.6 3.1 1.5 0.2 setosa 3 3 6
5.0 3.6 1.4 0.2 setosa 1 1 32
5.4 3.9 1.7 0.4 setosa 1 1 52

pairPropTest(iris_wtd, "index", "rand_bin", "Species") %>%
  head(8) %>% 
  knitr::kable(digits = 2)
rand_bin grp1_lbl grp2_lbl p.value sig
1 versicolor setosa 1 FALSE
1 virginica setosa 1 FALSE
1 virginica versicolor 1 FALSE
2 versicolor setosa 1 FALSE
2 virginica setosa 1 FALSE
2 virginica versicolor 1 FALSE
3 versicolor setosa 1 FALSE
3 virginica setosa 1 FALSE

## Get underlying counts
pairPropTest(iris_wtd, "index", "rand_bin", "Species",
             counts = TRUE) %>%
  head(8) %>% 
  knitr::kable(digits = 2)
Species rand_bin grp_val_count grp_count
setosa 1 14 50
setosa 2 21 50
setosa 3 15 50
versicolor 1 15 50
versicolor 2 19 50
versicolor 3 16 50
virginica 1 14 50
virginica 2 17 50

Weighted tests

The package also supports weighted testing, using the wtd.chi.sq() function from the weights package.

wtdPairPropTest(iris_wtd, "index", "rand_bin", "Species", "weight") %>%
  head(8) %>% 
  knitr::kable(digits = 2)
rand_bin grp1_lbl grp2_lbl Chisq df p.value sig
2 setosa versicolor 0.08 1 1 FALSE
2 setosa virginica 0.54 1 1 FALSE
2 versicolor virginica 0.21 1 1 FALSE
1 setosa versicolor 0.02 1 1 FALSE
1 setosa virginica 0.17 1 1 FALSE
1 versicolor virginica 0.29 1 1 FALSE
3 setosa versicolor 0.03 1 1 FALSE
3 setosa virginica 1.28 1 1 FALSE

## Get underlying counts
wtdPairPropTest(iris_wtd, "index", "rand_bin", "Species", "weight",
                counts = TRUE) %>%
  head(8) %>% 
  knitr::kable(digits = 2)
Species rand_bin grp_val_count grp_count
setosa 1 29 106
setosa 2 46 106
setosa 3 31 106
versicolor 1 26 91
versicolor 2 37 91
versicolor 3 28 91
setosa 1 29 106
setosa 2 46 106

## Use unadjusted p-values
wtdPairPropTest(iris_wtd, "index", "rand_bin", "Species", "weight",
                p.adjust.method = "none") %>%
  head(8) %>% 
  knitr::kable(digits = 2)
rand_bin grp1_lbl grp2_lbl Chisq df p.value sig
2 setosa versicolor 0.08 1 0.78 FALSE
2 setosa virginica 0.54 1 0.46 FALSE
2 versicolor virginica 0.21 1 0.65 FALSE
1 setosa versicolor 0.02 1 0.89 FALSE
1 setosa virginica 0.17 1 0.68 FALSE
1 versicolor virginica 0.29 1 0.59 FALSE
3 setosa versicolor 0.03 1 0.87 FALSE
3 setosa virginica 1.28 1 0.26 FALSE