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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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