Talk:Welch's t-test: Difference between revisions
m
→Stata translation of Burkardt's C translation of AS 63
Line 853:
For the record, here is a quick Stata translation of this betain implementation.
The original C code can be simplified in several places using shortcuts (it could be simplified even more in C). Also, ifault is not used here: instead, the function returns a missing value if the arguments are invalid. And log(beta(p,q)) is computed inside betain, rather than passed as an argument.
<lang stata>mata
Line 860:
Modified 28dec2017
Author:
Original
C version by John Burkardt.
Stata version by Jean-Claude Arbaut
*/
function betain(x,p,q
acu = 1e-15▼
/* Check the input arguments. */
if (p<=0 | q<=0 | x<0 | x>1) return(.)
/* Special cases. */
if (x==0 | x==1) {
Line 875 ⟶ 873:
}
▲ acu = 1e-15
lnbeta = lngamma(p)+lngamma(q)-lngamma(p+q)
/* Change tail if necessary and determine S. */
psq = p+q
Line 906 ⟶ 907:
if (temp<=acu & temp<=acu*value) {
value = value*exp(pp*log(xx)+(qq-1)*log(cx)-
return(indx?1-value:value)
}
|