Date: Wed, 8 Jan 2003 06:50:04 -0800
Reply-To: Sebastien Wasser <sebastien.wasser@AXYUS.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Sebastien Wasser <sebastien.wasser@AXYUS.COM>
Organization: http://groups.google.com/
Subject: Re: Critbinom
Content-Type: text/plain; charset=ISO-8859-1
Thank you for your help Dale.
Your program and Excel functionality apparently sometimes
didn't gave the same results.
Someone tried to reprogram it here. This macro (see below)
apparently gives the same results as the Excel critbinom
function.
Best regards,
Sebastien.
>>>>>>>>>>>>>
%macro critbinom(critval=critval,
trials=trials,
p_success=p_success,
alpha=alpha
);
/*********************************************************/
/* Macro variables name datastep variables: */
/* */
/* CRITVAL: Variable holding returned value */
/* TRIALS: Number of independent bernoulli trials */
/* P_SUCCESS: Success probability per bernoulli trial */
/* ALPHA: Criterion value with 0<alpha<1 */
/*********************************************************/
if nmiss(&trials, &p_success, &alpha)>0 then do;
put "Error: Invocation of CRITBINOM subroutine -";
put " Invalid specification of TRIALS, P_SUCCESS, or ALPHA";
end;
/*
sum = 0;
for (x=0; sum<alpha; x++)
sum += (combin(trials, x) * pow(p, x) * pow(1-p,
trials-x));
return value_int (x-1);
*/
else do;
&critval=0;
_it=0;
_sum=0;
do until (_sum>&alpha ! _it=&trials);
_sum = _sum + (comb(&trials, _it) * (&p_success ** _it) *
((1-&p_success) ** (&trials-_it)));
_it=_it+1;
end;
&critval=int(_it-1);
end;
drop _sum _it ;
%mend;
|