## Monday, June 14, 2010

### Example 7.41: hazard function plotting

As we continue with our series on survival analysis, we demonstrate how to plot estimated (smoothed) hazard functions.

R

We will utilize the routines available in the muhaz package. Background information on the methods can be found in K.R. Hess, D.M. Serachitopol and B.W. Brown Hazard Function Estimators: A Simulation Study, Statistics in Medicine, 1999: 18(22):3075-3088.
`ds = read.csv("http://www.math.smith.edu/sasr/datasets/help.csv")smallds = data.frame(dayslink=ds\$dayslink,    linkstatus=ds\$linkstatus, treat=ds\$treat)# drop subjects with missing datasmallds = na.omit(smallds)treatds = smallds[smallds\$treat==1,]controlds = smallds[smallds\$treat==0,]rm(ds, smallds)  # clean uplibrary(muhaz)haztreat = with(treatds, muhaz(dayslink, linkstatus))hazcontrol = with(controlds, muhaz(dayslink, linkstatus))plot(haztreat, lwd=2, xlab="Follow-up time (days)")lines(hazcontrol, lty=2, lwd=2)legend(200, 0.005, legend=c("Treatment", "Control"),    lty=1:2, lwd=2)`

The treatment group has dramatically higher hazard, but this drops appreciably after 6 months. The control group hazard is low, and decreases in a roughly linear fashion.

SAS

Paul Alison includes macros to display estimates from parametric and semiparametric models in Survival Analysis Using SAS (2nd edition). We'll use the smooth macro, which is built to accept output from proc lifetest.
`proc import file="c:\book\help.csv"  out=help dbms=dlm;  delimiter=',';  getnames=yes;run;data h2;set help;  if nmiss(dayslink, linkstatus, treat) eq 0;run;proc lifetest data=h2 outsurv=allison;  time dayslink*linkstatus(0);  strata treat;run;%include "c:/ken/sasmacros/smooth.sas";%smooth(data=allison, time=dayslink, width=25);`

The proc lifetest results (not shown) indicate that group 1 is the control and group 2 is the intervention. The macro uses a simpler smoothing method than that found in R, so that the curve is bumpier and estimates near the edges are not shown.

Anonymous said...

Not related to hazard function plotting, but related to your posted SAS code. May I ask if R has a function analogous to %include in SAS? Many thanks.

Ken Kleinman said...

I believe that source() is extremely similar. My sense is that R users tend to use source for running programs that do something, while SAS users tend to use %include to load macros into memory which they will then use to do something. (And SAS won't run the %include-ed material until it's submitted, while R runs it when it's source()-ed.) But either will grab a bunch of characters that live outside, usually in some external file.

Anonymous said...

Hi
With regard to SAS, is it possible to import the data directly from http://www.math.smith.edu/sasr/datasets/ as shown in the R code?
Thanks

Ken Kleinman said...

Sorry for the delay in responding, Anonymous-- Blogger had flagged your comment as spam, for some reason.

Yes, you can read from a URL in SAS. We cover this in our book, in section 1.1.6. You can also find a bunch of examples in this blog-- see example 8.31, for one.

John Lucas said...

Has anybody tried that sas macro with a dataset that has time-dependent covariates? (i.e. phreg has a start and a stop time)

joy said...

The real necklace of a woman is not her looks but her heart. Visit my site for more interesting offer. Thank you and God bless!

n8fan.net

www.n8fan.net

Silvia Jacinto said...

Things happened for a reason so be thankful for everything. Thank you for your wonderful article. I hope you could inspire more people. Please visit my site.

triciajoy.com

www.triciajoy.com