Details
This function performs one of several Frequentist hypothesis tests on a single Binomial proportion.
‘me_t_h_o_d = “ex_a_c_t”’:
Rsbinom.test()` implements the exact test described in Section 1.4 of Agresti (2012). Once the data have been transformed into the number of events and the total number of non-missing values, the code using default argument values is
binom.test(num_events, num_total, alternative = “two.sided”, p = 0.5)
There is no corresponding Proc Freq code; there are several methodological differences between the exact test produced by SAS and binom.test(). Using the terminology of Fay (2010):
- One-sided p-values. Both use the same tail sums, P(X <= x) and P(X >= x).
• binom.test() returns whichever tail you ask for.
• Proc Freq keeps only the smaller tail, in variables XPL_BIN or XPR_BIN, and leaves the other variable missing.
- Two-sided p-values.
• binom.test() uses the “minlike” method (short for “minimum likelihood”): it adds the probabilities of every outcome no more likely than the observed one.
• SAS uses the “central” method: twice the smaller tail, capped at 1. The two agree only when p_0 = 0.5, where the null distribution is symmetric.
- Numerical calculation (not a definition difference).
• SAS`s right tail behaves as if it were computed as 1 - P(X <= x - 1). That subtraction leaves an absolute error of about 1e-14.
• R computes the upper tail directly.
‘me_t_h_o_d = “ex_a_c_t_sa_s”’:
This method mimics the results produced by:
proc freq data={data set}; tables {analysis column} / binomial; exact binomial; run;
In the terms of Fay (2010), Proc Freq uses the “central” method: twice the smaller tail, capped at 1. This is also called “doubling” or “TST” by Hirji (2006).
• One-sided p-values: only the smaller of the two tails is reported. If the requested tail is the larger one, the p-value is NA, as it is missing in SAS.
• Two-sided p-value: twice the smaller tail, capped at 1 (the “central” method).
• The right tail is computed as 1 - P(X <= x - 1), as SAS does, so very small right tails lose precision and can be exactly 0.
The results agree with Proc Freq to about 1e-13 but are not identical to the last bit, because R and SAS use different algorithms for the binomial distribution function.
The underlying R function for this method is [binom_test_sas()], which gives more details for the comparison to SAS.
‘me_t_h_o_d = “sc_o_r_e”’:
The score test produces a Z statistic that uses the null value to compute the variance in the denominator. To compute a two-sided p-value, compare the square of the Z statistic to a chi-squared distribution with a single degree of freedom. For a one-sided test, use the Z statistic and compare it to the appropriate standard normal tail.
This method`s defaults does not use a continuity correction (for SAS compatibility) and is is equivalent to
prop.test(num_events, num_total, alternative = “two.sided”, p = 0.5, correct = FALSE)
The equivalent SAS code is
proc freq data={data set}; tables {analysis column} / binomial(cl=score); run;
The SAS output data set has Z_BIN (the statistic), P2_BIN (two-sided p-value), PL_BIN (left-sided p-value) and PR_BIN (right-sided p-value). 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.
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
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:
events total null p z alternative p_value 1 2 0.01 6.96 greater 1.6e-12 1 2 0.01 6.96 less missing 1 2 0.01 6.96 two.sided 3.3e-12 1 50 0.25 -3.76 greater missing 1 50 0.25 -3.76 less 8.6e-05 1 50 0.25 -3.76 two.sided 1.73e-04
To assess the level of equivalence, each was tested at three 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 no missing p-values.
The two methods showed good concordance, with absolute differences ranging from -1.2e-15 to 8.3e-16.