%inc ' tmp1, sdf - tmp1, 0); ucl= sdf + tmp1; ucl= choose( ucl > 1., 1., ucl); /* PRINTOUT #3*/ left= {0} // p; right= q // p[nparm]; sdf= {1} // sdf // {0}; lcl= {.} // lcl //{.}; ucl= {.} // ucl //{.}; /* PRINTOUT */ %if &print = 1 %then %do; if (&nby > 0) then print "-----" %do jj= 1 %to &nby; " &&by&jj = &&byval&jj " %end; "-----",; print "Nonparametric Survival Curve for Interval Censoring",,; reset noname nocenter spaces=0; print "Number of Observations: " (trim(left(char(nobs)))); print "Number of Parameters: " (trim(left(char(nparm)))); if method = 1 then print "Optimization Technique: Newton Raphson Ridge"; else if method = 2 then print "Optimization Technique: Quasi-Newton"; else if method = 3 then print "Optimization Technique: Conjugate Gradient"; else if method = 4 then print "Optimization Technique: Self-Consistency Algorithm"; reset center; print ,"Parameter Estimates", ,q[colname={q}] p[colname={p}] theta[colname={theta} format=12.7],; tmp1= 100. * (1. - &alpha); print , "Survival Curve Estimates and "(trim(left(char(tmp1)))) "% Confidence Intervals", , left[colname={left}] right[colname={right}] sdf[colname={estimate} format=12.4] lcl[colname={lower} format=12.4] ucl[colname={upper} format=12.4]; %end; %if (%bquote(&outs) ^=) %then %do; %if (&ii = 1) %then %do; create &outs var{&by left right sdf lcl ucl}; append; %end; %else %do; edit &outs var{&by left right sdf lcl ucl}; append; %end; %end; /* PLOTTING THE SURVIVAL FUNCTION */ %if &plot = 1 %then %do; xy1= left || sdf; xy2= right || sdf; pmax= left[nparm+1];; c= log10(pmax / 10); b= int(c); d= 10 ** (c-b); if d <= 2 then a=2; else if d <=5 then a=5; else a=10; width= a * 10 ** b; c= pmax / width; b= int(c); if (b < c) then do; b= b+1; pmax= b * width; end; *print b pmax; world= {0 0, 1 1}; world[2,1]= pmax; leng= world[2,]; window= world + 0.2 * {-1 , 1} * leng; call gstart; call gwindow (window); *call gpoint (rowvec(time),rowvec(prob)) color="red"; *call gdraw( rowvec(time),rowvec(prob),1,"cyan"); call gdrawl(xy1,xy2) color="cyan"; call gxaxis ({0 0}, pmax, b); call gyaxis ({0 0}, 1, 10) format="3.1"; call gtext( .5 # pmax, -.15, "Time"); call gvtext( -width # 1.5, 1, "SDF" ); call gset("font","swiss"); call gset("height",1.3); call gscenter(.5 # pmax, 1.1, "Survival Curve Estimate"); call gshow; %end; finish interval; %* loglikelihood function *; start LL(theta) global(_x,nparm,_zfreq,_freq); if _zfreq then xlt= _freq # (log(_x * theta`)); else xlt= log(_x * theta`); f= xlt[+]; return(f); print f; finish LL; %* gradient vector *; start GRAD(theta) global(_x,nparm,_zfreq,_freq); g= j(1,nparm,0); if _zfreq then do; tmp= _x # (_freq / (_x * theta`)); end; else do; tmp= _x # (1 / (_x * theta`) ); end; g= tmp[+,]; return(g); finish GRAD; %* hessian matrix *; start HESS(theta) global(_x,nparm,nobs,_zfreq,_freq); h= j(nparm, nparm, 0); tmp= _x # (1/ (_x * theta`)); if _zfreq then do; do i= 1 to nobs; rowtmp= tmp[i,]; h= h + (_freq[i] # (rowtmp` * rowtmp)); end; end; else do; do i= 1 to nobs; rowtmp= tmp[i,]; h= h + (rowtmp` * rowtmp); end; end; h= -1 # h; return(h); finish HESS; %****** CONSTRUCT THE NON-OVERLAPPING TIME ******; %****** INTERVALS FOR THE TURNBULL METHOD *******; start nolap(nq, p,q,l,r); pp= unique(r); npp= ncol(pp); qq= unique(l); nqq= ncol(qq); q= j(1,npp, .); do i= 1 to npp; do j= 1 to nqq; if ( qq[j] < pp[i] ) then q[i]= qq[j]; end; if q[i] = qq[nqq] then goto lab1; end; lab1: if i > npp then nq= npp; else nq= i; q= unique(q[1:nq]); nq= ncol(q); p= j(1,nq, .); do i= 1 to nq; do j= npp to 1 by -1; if ( pp[j] > q[i] ) then p[i]= pp[j]; end; end; *print nq p q; finish nolap; %****** Self-Consistency Algorithm *******; start em(theta0, conv) global(_x,nobs,_zfreq,_freq); iter=0; u= _x # theta0; xt= u[,+]; lxt= log(xt); if _zfreq then do; lxt= lxt # _freq; u= u # (_freq / xt); ntot= _freq[+]; end; else do; u= u # (1 / xt); ntot= nobs; end; ll0= lxt[+]; print ll0; theta0= u[+,] / ntot; difcrit= 1; do while ( difcrit > conv ); iter= iter + 1; u= _x # theta0; xt= u[,+]; lxt= log(xt); if _zfreq then do; lxt= lxt # _freq; u= u # (_freq / xt); end; else u= u # (1 / xt); ll= lxt[+]; theta0= u[+,] / ntot; difcrit= ll - ll0; print iter ll[format=20.10] difcrit[format=20.10]; ll0= ll; end; *print theta0; return(theta0); finish; %*-- CENTER TEXT STRING IN IML GRAPHICS --*; start gscenter(x,y,str); call gstrlen(len,str); call gscript(x-len/2,y,str); finish gscenter; %*---------- Main IML Program -----------*; use &data; read all var{<ime &rtime &freq}; %if %bquote(&freq)= %then %do; _zfreq= 0; _freq= 1; %end; %else %do; _zfreq= 1; _freq= &freq; %end; call interval(<ime,&rtime); quit; %mend xice; %************************** xchkdefv **********************; %* If argument value is blank, set it to default value. Otherwise, put it in the form of an IML rowvector, ie, enclose the numbers with braces and eliminate any parentheses or brackets; %* _arg name of argument to check; %* def (optional) default value; %macro xchkdefv(_arg,def); %* put %upcase(&_arg)=&&&_arg; %* set default for &_arg; %xchkech(&_arg); %if %bquote(&&&_arg)= %then %let &_arg=&def; %else %do; %let tmp1=; %let n=1; %let token=%scan(&&&_arg,&n,%bquote( ()[]{})); %do %while(%bquote(&token)^=); %if %verify(&token,&_digits_)= 0 %then %let tmp1=&tmp1 &token; %else %do; %let _xrc_=Error: Incorrect %upcase(&_arg)= specification; %if &_xrc_^=OK %then %put &_xrc_..; %goto skip1; %end; %let n=%eval(&n+1); %let token=%scan(&&&_arg,&n,%bquote( ()[]{})); %end; %let &_arg={&tmp1}; %skip1: %end; %* put %upcase(&_arg)=&&&_arg; %mend xchkdefv;