BookmarkSubscribeRSS Feed
superbug
Quartz | Level 8

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!

 

 

2 REPLIES 2
PGStats
Opal | Level 21

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)

PG
superbug
Quartz | Level 8

@PGStats 

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).

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 992 views
  • 0 likes
  • 2 in conversation