Talk:Welch's t-test: Difference between revisions
Content added Content deleted
Line 847: | Line 847: | ||
: |
: |
||
:There is another problem: you damaged the original function, by replacing <code>*ifault = 0;</code> with <code>ifault = 0;</code>, replacing ifault with a null pointer. This will crash the program with a null pointer dereference whenever the arguments passed to betain are incorrect (hence ifault is assigned a value). I didn't check if you introduced another problem in the code. |
:There is another problem: you damaged the original function, by replacing <code>*ifault = 0;</code> with <code>ifault = 0;</code>, replacing ifault with a null pointer. This will crash the program with a null pointer dereference whenever the arguments passed to betain are incorrect (hence ifault is assigned a value). I didn't check if you introduced another problem in the code. |
||
:Your statement that ''existing libraries don't calculate correct numbers'' is wrong. |
|||
:About '''"existing libraries don't calculate correct numbers"''': you should make sure you master the basics of the C language, and debug your own program (and the bugs you introduced in the "existing library", before making such a bold claim. Unless you really believe you are a C expert, you should always start with '''"my program don't calculate correct numbers"'''. While it's not necessarily always true, it's a best bet. |
|||
:[[User:Eoraptor|Eoraptor]] ([[User talk:Eoraptor|talk]]) 19:31, 28 December 2017 (UTC) |
:[[User:Eoraptor|Eoraptor]] ([[User talk:Eoraptor|talk]]) 19:31, 28 December 2017 (UTC) |
||
::For the record, here is a quick Stata translation of this betain implementation. |
|||
::<lang stata>mata |
|||
function betain(x,p,q,beta) { |
|||
acu = 1e-15 |
|||
value = x |
|||
/* Check the input arguments. */ |
|||
if (p<=0 | q<=0 | x<0 | x>1) return(.) |
|||
/* Special cases. */ |
|||
if (x==0 | x==1) { |
|||
return(value) |
|||
} |
|||
/* Change tail if necessary and determine S. */ |
|||
psq = p+q |
|||
if (p<psq*x) { |
|||
xx = 1-x |
|||
cx = x |
|||
pp = q |
|||
qq = p |
|||
indx = 1 |
|||
} |
|||
else { |
|||
xx = x |
|||
cx = 1-x |
|||
pp = p |
|||
qq = q |
|||
indx = 0 |
|||
} |
|||
term = ai = value = 1 |
|||
ns = floor(qq+cx*psq) |
|||
/* Use the Soper reduction formula. */ |
|||
rx = xx/cx |
|||
temp = qq-ai |
|||
if (ns==0) rx = xx |
|||
while(1) { |
|||
term = term*temp*rx/(pp+ai) |
|||
value = value+term |
|||
temp = abs(term) |
|||
if (temp<=acu & temp<=acu*value) { |
|||
value = value*exp(pp*log(xx)+(qq-1)*log(cx)-beta)/pp |
|||
return(indx?1-value:value) |
|||
} |
|||
ai++ |
|||
if (--ns>=0) { |
|||
temp = qq-ai |
|||
if (ns==0) rx=xx |
|||
} |
|||
else { |
|||
temp = psq++ |
|||
} |
|||
} |
|||
} |
|||
end</lang> |
|||
::[[User:Eoraptor|Eoraptor]] ([[User talk:Eoraptor|talk]]) 21:31, 28 December 2017 (UTC) |