Laura Bonnett
2010-May-25 12:28 UTC
[R] Relative Risk/Hazard Ratio plots for continuous variables
Dear all, I am using Windows and R 2.9.2 for my analyses. I have a large dataset and I am particularly interested in looking at time to an event for a continuous variable. I would like to produce a plot of log(relative risk) or relative risk (also known as hazard ratio) against the continuous variable. I have spent a long time looking for advice on how to do this but my search has proved fruitless - sorry if I've missed something obvious. It seems that there are options such as muhaz, survfit, coxph and cph that may enable some plots to be produced but none that specifically look at the relative risk one. In addition to the survival analysis, I have incorporated the mfp function (from package mfp). I currently use code such as, library(mfp) library(Design) coxfit1 <- coxph(Surv(rtime,rcens)~cts,data=data1) or coxfit2 <- mfp(Surv(rtime,rcens)~fp(cts),family=cox,data=data1,select=0.05,verbose=TRUE) plot(coxfit1) nor plot(coxfit2) produce the relevant relative risk vs. continuous variable that I need. Can anyone help? Thank you, Laura [[alternative HTML version deleted]]
Frank E Harrell Jr
2010-May-25 12:41 UTC
[R] Relative Risk/Hazard Ratio plots for continuous variables
On 05/25/2010 07:28 AM, Laura Bonnett wrote:> Dear all, > > I am using Windows and R 2.9.2 for my analyses. I have a large dataset and > I am particularly interested in looking at time to an event for a continuous > variable. I would like to produce a plot of log(relative risk) or relative > risk (also known as hazard ratio) against the continuous variable.Please use correct terminology. A risk is a probability (except perhaps in finance) whereas a hazard is a rate (instantaneous conditional risk). What you want is relative hazard.> > I have spent a long time looking for advice on how to do this but my search > has proved fruitless - sorry if I've missed something obvious. It seems > that there are options such as muhaz, survfit, coxph and cph that may enable > some plots to be produced but none that specifically look at the relative > risk one. > > In addition to the survival analysis, I have incorporated the mfp function > (from package mfp). > > I currently use code such as, > > library(mfp) > library(Design) > > coxfit1<- coxph(Surv(rtime,rcens)~cts,data=data1) > or > coxfit2<- > mfp(Surv(rtime,rcens)~fp(cts),family=cox,data=data1,select=0.05,verbose=TRUE) > > plot(coxfit1) nor plot(coxfit2) produce the relevant relative risk vs. > continuous variable that I need.Replace Design with the new rms package and see http://biostat.mc.vanderbilt.edu/Rrms The plot you need is a basic one provided by rms (or its ancestor Design). Frank> > Can anyone help? > > Thank you, > Laura > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University
Terry Therneau
2010-May-26 13:29 UTC
[R] Relative Risk/Hazard Ratio plots for continuous variables
I prefer smoothing splines, Frank prefers regression splines. The former is built into the survival package: options(na.action=na.exclude) # This should be the default IMHO coxfit1<- coxph(Surv(rtime,rcens) ~ pspline(cts), data=data1) summary(coxfit1) #shows the linear and nonlinear tests plot(data1$cts, predict(coxfit1)) or if you want confidence intervals, this gives the data to plot pr1 <- predict(coxfit1, type='terms', se=T) Terry Therneau