My data is as attached.
prob is get by the following formula
prob=exp(theta-bpar)/(1+exp(theta-bpar))
I need to update theta (then update prob) using the following condition
If TCC - cut > delta then theta=theta-ABS(theta-low)/2
if TCC - cut < (-1*delta) then theta=theta+ABS(hi-theta)/2
iteration will stop
if ABS(TCC-cut)<=delta
Please help on how to write code to incorporate the above conditions to do the iteration. Any help would be much appreciated. Thanks!
I guess you mean:
do dummy = 1 to 1000 while(ABS(TCC-cut) > delta);
If TCC - cut > delta then theta = theta-ABS(theta-low)/2;
if TCC - cut < -delta then theta = theta+ABS(hi-theta)/2;
end;
prob=exp(theta-bpar)/(1+exp(theta-bpar));
The dummy count was added to prevent infinite looping.
(untested)
Thanks much for your reply!
I need to write SAS code based on the following code. From the code below, does that mean Newton Raphson iteration is needed? If yes, could you please direct me how to do that? FIY, "try" in the code below is the "try.csv" as in the attachment. Thanks a bunch!
LOOP K = 1 TO 150.
COMPUTE theta_lo={-20}.
COMPUTE theta_hi={20}.
COMPUTE delta={.000001}.
COMPUTE cut={K}.
COMPUTE theta={0}.
COMPUTE low={theta_lo}.
COMPUTE hi={theta_hi}.
COMPUTE IPROB=MAKE(NITEM,1,0).
COMPUTE IINFO=MAKE(NITEM,1,0).
LOOP.
LOOP J=1 TO NITEM.
COMPUTE IPROB(J)=(exp(theta-try(J,2))/(1+exp(theta-try(J,2))))).
COMPUTE IINFO(J)=IPROB(J)*(1-IPROB(J)).
END LOOP.
COMPUTE TCC=CSUM(IPROB).
DO IF (tcc-cut>delta).
COMPUTE hi = theta.
COMPUTE theta=theta-ABS((theta-low))/2.
END IF.
DO IF (tcc-cut< (-1*delta)).
COMPUTE low=theta.
COMPUTE theta=theta+ABS((hi-theta))/2.
END IF.
END LOOP IF (abs(tcc-cut)<=delta).
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.