Skip to main content

Testing Single Binomial Proportions

bin_prop_test() is an interface to a set of statistial methods to test that \(H_0: \pi = \pi_0\) where \(\pi_0\) is the null value. There is a section below that descibes the results for each method.

Experimental Setup

Since this function takes qualitative data as the input, we can look at the results over a range of both the number of events and the total number of trials. For each method value, the number of total events ranged from 2 to 50 data points. For segue and SAS, a compaison was made for

  • Each possible value for the number of events within these ranges.
  • The three possible alternatives: \(H_a: \pi \ne \pi_0\), \(H_a: \pi > \pi_0\), and \(H_a: \pi < \pi_0\)
  • \(\pi_0 \in \{0.01, 0.25, 0.50\}\)

To measure the difference, we consider the absolute difference in the resulting p-values.

Resources:

Exact Test (R-based): method = "exact"

There are no comparisons to make for this method; SAS does not compute the same type of test as the R equivalent.

Exact Test (SAS-based): method = "exact_sas"

For one-sided p-values, Proc Freq computes both tails but reports only the smaller one:

  • When \(p_L \le p_R\), the left tail is reported (XPL_BIN) and the right tail (XPR_BIN) is missing.
  • Otherwise, the right tail is reported and the left tail is missing.

Proc Freq computes the right tail as one minus the left tail at \(x - 1\):

\[ p_R = 1 - \Pr(X \le x - 1) \]

When \(p_R\) is small, \(\Pr(X \le x - 1)\) is close to 1 and the subtraction loses relative precision. For example, with \(n = 6\), \(x = 6\), and \(p_0 = 0.01\), \(p_R = 10^{-12}\), and SAS’s value is correct to only about four significant digits instead of the usual 15 or 16. Right tails below about \(10^{-16}\) come out as exactly 0.

The results are not identical to Proc Freq’s to the last bit. R’s stats::pbinom() and Proc Freq use different algorithms for the binomial distribution function, and their results usually differ by a few dozen units in the last place (at most a few hundred). This is random rounding error in both, not a bias in either. Over 11,466 combinations of \(1 \le x \le n\), \(2 \le n \le 50\), \(p_0 \in \{0.01, 0.25, 0.5\}\), and the three alternatives, the p-values from exact_binom_test_sas() are within \(5.5 \times 10^{-14}\) (absolute) of Proc Freq’s. Because of the cancellation, the agreement for small right tails is only absolute: a right tail that is 0 in one can be about \(10^{-16}\) in the other.

Ties

When \(p_0 = 0.5\) and \(x = n / 2\), the two tails are exactly equal, and which tail is reported depends on rounding error. Proc Freq reported the right tail for some even \(n\) and the left tail for others, and segue can choose differently. For the 25 ties with \(n \le 50\), Proc Freq reported the right tail in 14, so the NA is on the other alternative in those cases. The reported values differ from Proc Freq’s by at most \(1.2 \times 10^{-14}\), as in the cases without ties. When the computed tails are equal, the left tail is reported. The two-sided p-value is 1 either way.

Absolute differences in code that test p-values using SAS’s approach to exact tests.

Score Test: method = "score"

Proc Freq only reports one of the two one-sided p-values for each test: the one in the direction of the observed deviation. The other is missing.

Which Proc Freq p-values are reported, by the sign of the score statistic.
Sign of z PL_BIN (less) PR_BIN (greater) P2_BIN (two.sided)
z > 0 missing reported reported
z < 0 reported missing reported
z = 0 reported (0.5) missing reported (1)

The reported one-sided p-value is always the smaller tail, so it is never above 0.5. The larger tail is never produced. In the results, 3,822 of 11,466 rows are missing a p-value. Each of them is a one-sided test that points away from the data. No two-sided test’s p-value is missing. Some examples:

Example SAS score test results.
events total null p z alternative p-value
1 2 0.01 6.96 greater 1.65 × 10−12
1 2 0.01 6.96 less missing
1 2 0.01 6.96 two.sided 3.29 × 10−12
1 50 0.25 −3.76 greater missing
1 50 0.25 −3.76 less 8.64 × 10−5
1 50 0.25 −3.76 two.sided 1.73 × 10−4

To assess the level of equivalence, each was tested at 3 null values (0.01, 0.25, 0.5) and three alternatives, which gives 11,466 tests per language. SAS has no value for 3,822 one-sided tests. The comparison drops those, leaving 7,644 tests: 3,822 two-sided, 2,897 greater and 925 lesser. R has 0 missing p-values.

The two methods showed good concordance, with absolute differences ranging from −1.22 × 10−15 to 8.33 × 10−16.

Absolute differences in score test p-values.