Skip to contents

Inference for One Proportion

It will automatically choose between Wilson’s CI and the “exact” CI. No null hypothesis is tested by default.

one_proportion_inference(vs ~ 1, data = mtcars2)
response x n proportion SE conf.low conf.high
vs = straight 14 32 0.438 0.088 0.282 0.607
Wilson's proportion test (two.sided), with 95% confidence intervals.

Separately by another categorical variable

one_proportion_inference(vs ~ am, data = mtcars2)
response variable x n proportion SE conf.low conf.high
vs = straight am = automatic 7 19 0.37 0.11 0.19 0.59
vs = straight am = manual 7 13 0.54 0.14 0.29 0.77
Wilson's proportion test (two.sided), with 95% confidence intervals.

Inference for Two Proportions

It will automatically choose between the asymptotic test (with or without continuity correction) and Fisher’s test.

two_proportion_inference(vs ~ am, data = mtcars2)
response variable difference SE conf.low conf.high chisq.value p.value
vs = straight am: automatic - manual −0.17 0.18 −0.58 0.24 0.348   0.56
2-sample test for equality of proportions with continuity correction (two.sided), with 95% confidence intervals.

together in one table

combine_tests(
  one_proportion_inference(vs ~ am, data = mtcars2),
  two_proportion_inference(vs ~ am, data = mtcars2))
response variable x n proportion difference SE conf.low conf.high chisq.value p.value footnote
vs = straight am = automatic 7 19 0.37
0.11  0.19 0.59

1 
vs = straight am = manual 7 13 0.54
0.14  0.29 0.77

1 
vs = straight am: automatic - manual


−0.17 0.18 −0.58 0.24 0.348   0.56 2 
1 Wilson's proportion test (two.sided), with 95% confidence intervals.
2 2-sample test for equality of proportions with continuity correction (two.sided), with 95% confidence intervals.

Pairwise Proportion Tests

combine_tests(
  one_proportion_inference(vs ~ cyl, data = mtcars2),
  pairwise_proportion_inference(vs ~ cyl, data = mtcars2))
response variable x n proportion difference SE conf.low conf.high p.value p.adjust footnote
vs = straight cyl = 4 10 11 0.909
0.087 0.587 0.998

1,2 
vs = straight cyl = 6 4 7 0.57 
0.19  0.18  0.90 

1,3 
vs = straight cyl = 8 0 14 0.00 

0.00  0.23 

1,2 
vs = straight cyl: 4 - 6


0.34  0.21 

  0.25   0.74 4,5,6 
vs = straight cyl: 4 - 8


0.909 0.087

< 0.0001 < 0.0001 4,5,6 
vs = straight cyl: 6 - 8


0.57  0.19 

  0.0058   0.018 4,5,6 
1 Exact binomial test (two.sided), with 95% confidence intervals.
2 Method chosen because observed proportion < 0.10.
3 Method chosen because n < 10.
4 Fisher's Exact Test for Count Data (two.sided)
5 Method chosen due to expected counts < 5.
6 p-values adjusted for 3 multiple comparisons using the Bonferroni method.

Paired Proportion Test (McNemar’s)

combine_tests(
  one_proportion_inference(pass1 + pass2 ~ 1, data = passfail),
  one_proportion_inference(pass2 ~ pass1, data = passfail, all_success = TRUE),
  paired_proportion_inference(pass2 - pass1 ~ 1, data = passfail))
response variable x n proportion SE conf.low conf.high null chisq.value p.value footnote
pass1 = pass
30 50 0.600 0.069 0.462 0.724


1 
pass2 = pass
37 50 0.740 0.062 0.604 0.841


1 
pass2 = fail pass1 = fail 5 20 0.250 0.097 0.112 0.469


1 
pass2 = pass pass1 = fail 15 20 0.750 0.097 0.531 0.888


1 
pass2 = fail pass1 = pass 8 30 0.267 0.081 0.142 0.444


1 
pass2 = pass pass1 = pass 22 30 0.733 0.081 0.556 0.858


1 
pass: pass2 - pass1
15 23 0.652 0.099 0.449 0.812 0.500 2.13   0.14 2 
1 Wilson's proportion test (two.sided), with 95% confidence intervals.
2 McNemar's test, using Wilson's proportion test (two.sided), with 95% confidence intervals.

Independence Test

It will automatically choose between the chi-squared test and Fisher’s test.

combine_tests(
  one_proportion_inference(cyl ~ vs, data = mtcars2, all_success = TRUE),
  independence_test(cyl ~ vs, data = mtcars2))
response variable x n proportion SE conf.low conf.high p.value footnote
cyl = 4 vs = V-shaped 1 18 0.056 0.054 0.001 0.273
1,2 
cyl = 6 vs = V-shaped 3 18 0.167 0.088 0.058 0.392
3 
cyl = 8 vs = V-shaped 14 18 0.778 0.098 0.548 0.910
3 
cyl = 4 vs = straight 10 14 0.71  0.12  0.45  0.88 
3 
cyl = 6 vs = straight 4 14 0.29  0.12  0.12  0.55 
3 
cyl = 8 vs = straight 0 14 0.00 
0.00  0.23 
1,2 
cyl vs





< 0.0001 4,5 
1 Exact binomial test (two.sided), with 95% confidence intervals.
2 Method chosen because observed proportion < 0.10.
3 Wilson's proportion test (two.sided), with 95% confidence intervals.
4 Fisher's Exact Test for Count Data
5 Method chosen due to expected counts < 5.