Talk:Welch's t-test: Difference between revisions

m
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 Fortran 77FORTRAN77 version by KL Majumder, GP Bhattacharjee.
C version by John Burkardt.
Stata version by Jean-Claude Arbaut
*/
function betain(x,p,q,beta) {
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)-betalnbeta)/pp
return(indx?1-value:value)
}
1,336

edits