Survival Curves - How to Add Number at Risk on X axis ?

3,129 views
Skip to first unread message

jafary

unread,
Jan 15, 2006, 9:37:29 PM1/15/06
to MedStats
Hi Folks

How can I add the number at risk along the x axis on the Kaplan-Meier
survival curve plots?

The statistical packages that I have at my disposal are SPSS and
MedCalc. Both don't seem to have this proviso and I'll be very
grateful if someone could prove me wrong or point me in the right
direction

Thanks.

Fahim Jafary, MD
Aga Khan University Hospital
Karachi, Pakistan

Peter Lane

unread,
Jan 16, 2006, 6:58:18 AM1/16/06
to MedStats
Fahim
General stats packages don't provide this easily, in my experience --
maybe the developers will wake up and improve things with the current
wave of interest in graphics in pharma. I've been involved in a
graphics team for a couple of years, and we are promoting some plots
for use in GSK, including numbers at risk, which we have drawn using
SAS, S-Plus and GenStat; however, all three require detailed
programming rather than just selecting options. I regret that I have no
experience of SPSS or MedCalc. Perhaps others on the list can provided
info on more specialized packages that may be accessible to you.
Peter Lane
Research Statistics Unit, GlaxoSmithKline

Martin P. Holt

unread,
Jan 16, 2006, 11:13:14 AM1/16/06
to MedS...@googlegroups.com
Hi Jafary,

SPSS can do a lot more than it seems if you program it with Syntax. There is
an SPSS list which busily addresses such questions using Syntax. You can
join it at
http://listserv.uga.edu/cgi-bin/wa?SUBED1=spssx-l&A=1

- beware though, it is a busy list !

I bet R addresses this - confirmation anyone ?

Best Wishes,
Martin

jafary

unread,
Jan 16, 2006, 12:16:27 PM1/16/06
to MedStats
Peter, Martin:

Thanks for your replies. Will check out the listserv you mentioned.
Hope someone else on this group can come up with some more suggestions.

Regards

Matt Sydes

unread,
Jan 17, 2006, 12:47:10 PM1/17/06
to MedStats
Hi,

It is possible to do this within Stata using the -stsatrisk- command.
It is an extension of the -sts- survival command and is one of the free
add-ins, I believe, though was kindly put together last year by Jean
Marie Linhart at Stata Corp after we nagged them. The layout it
provides requires some rejigging and the numbers at risk (and events)
appear within the graph area rather than under the axis, but it can
usually be made to look okay.

Alternatively, I sometimes use the package SCHARP which was written for
meta-analysis, primarily, and produces very nice forest plots. However,
the graphics for survival curves are very good. It can be tricky to
use sometimes and requires very precisely formatted data files. It
needs to be run in conjunction with SAS (it quietly opens SAS).

Finally, many people I now choose to do this manually - list out the
number of patients patients at risk at set timepoints, reshape the list
to be wide and present as a table under a picture of a KM plot from a
stats package of their choice. I find this a little cumbersome, but
many who haven't got used to either of the methods above have
semi-automated themselves this way.

Hope this is may be of some help.

Matt

Matt Sydes
Medical Statistician
MRC Clinical Trials Unit
London, UK

canada_pete

unread,
Feb 1, 2006, 9:46:18 AM2/1/06
to MedStats
Hi,

it is also very easy to do with S-plus/R. For example

fits1<-survfit(Surv(stime, primout),type="kaplan-meier")
nrisk1<-c(0,0,0,0,0)
nrisk1[1]<-fits1$n.risk[1]
for(i in 2:length(fits1$n.risk))
{
if(fits1$time[i]<=90) nrisk1[2]<-fits1$n.risk[i]
if(fits1$time[i]<=180) nrisk1[3]<-fits1$n.risk[i]
if(fits1$time[i]<=365) nrisk1[4]<-fits1$n.risk[i]
if(fits1$time[i]<=545) nrisk1[5]<-fits1$n.risk[i]
}

then use
text(0,.2,"# at Risk",cex=.8,adj=0)
text(90,.2,"Day 90",cex=.8,adj=0)
text(1,.19,nrisk1[1],cex=.8,adj=0)
text(90,.19,nrisk1[2],cex=.8,adj=0)

after your plot statement.

if u prefer, one of Dr. Harrell's libraries Hmisc/Design have a
function called survplot() that will do it as well.

Cheers
Peter

Reply all
Reply to author
Forward
0 new messages