Skip to content

Commit

Permalink
Revised p-value computation for greater numerical stability
Browse files Browse the repository at this point in the history
With the use of the logarithm of the gamma function, Hodges' exact formula for the p-value may be used reliably for sample sizes up to at least 10^7, if not greater. For n < 50, where the exact formula was previously implemented using nchoosek, the implementation using gammaln to compute the binomial coefficients agrees with that using nchoosek.

Co-Authored-By: Jacob Zavatone-Veth <[email protected]>
  • Loading branch information
adehad and jzavatoneveth committed May 21, 2019
1 parent c16dcc4 commit c52050f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion circ_otest.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
pval = sqrt(2*pi) / A * exp(-pi^2/8/A^2);
else
% exact formula by Hodges (1955)
pval = 2^(1-n) * (n-2*m) * nchoosek(n,m);
% pval = 2^(1-n) * (n-2*m) * nchoosek(n,m); % revised below for numerical stability
pval = exp((1-n)*log(2) + log(n-2*m) + gammaln(n+1) - gammaln(m+1) - gammaln(n-m+1));
end
end

0 comments on commit c52050f

Please sign in to comment.