Kaplan Meier curve

Kaplan Meier curve

by Margaret -
Number of replies: 5

For the figure in my final project, I'd like to make a Kaplan Meier survival curve. I am using the Graphics tab to try to make it- I made the X-variable my overallsurvival variable which is # of months of survival. I thought the Y-axis was just proportion of patients who survive, which I think the program already counted for me through the command: "stset overallsurvival, failure(deathevent==1)". However, when I create the plot it asks for a Y-variable- what should I enter here?

 

Thank you!

-Margaret

In reply to Margaret

Re: Kaplan Meier curve

by Anjana Sharma -

Hi Margaret,  Might be an issue with spaces. Here is a guide you will get when you take Epidemiologic Methods this Fall.  I hope Dr Martin doesn't mind that I am stealing it!
see below,

Anjana

=================

 

The three commands you need to understand are:

 

1.  stset -- Declare data to be survival-time data

 

      This command tells STATA that you have a dataset that you want to analyze using survival analysis.  In other words, you want to set the data to survival time.  The syntax (for multiple-record-per-subject survival data) is as follows: 

stset timevar, failure(failvar)

      In the STATA documentation, timevar means "type the name of the survival time variable here," and failvar means "type the name of the variable that defines your failure (outcome) here."  

The syntax has to be exactly as specified.  There has to be a space between stset and the time variable, then a comma, then a space, then failure (or abreviated as f), then an open parenthesis without a space between the failure and it, then the failure variable name, and then a close parenthesis.  The spacing matters in STATA. You can at any time type help followed by the command name into the command line in STATA for official STATA documentation

By setting the data to have a survival data structure, STATA then specifies that any survival analysis commands you enter will be based on whatever timevar you specified to be the survival-time variable and whatever failvar you gave for the outcome.

STATA specifies its syntax for stset in the following way:

   stset timevar [if] [weight] [, id(idvar) failure(failvar[==numlist])

                multiple_options]


This documentation can be interpreted as follows:

     

      The command's name is the first thing you see.  Variable names (such as timevar or failvar) are in italics.  Anything optional is in square brackets--so in other words, the only absolutely mandatory thing with this command is the timevar.  However, not specifying a failure variable leads STATA to believe that every subject fails at the end of its survival time, which is certainly not valid in most cases, so we do need to specify the failure option.  As with most STATA commands, there are options that are expressed before the comma, and others that are expressed after the comma.  In the manual or in command help, you can see that if something is underlined, then you can abbreviate it by including at least the letters that are underlined.  Note that the f in failure is underlined, which means that you can abbreviate failure(failvar) to f(failvar).  For more information on options and abreviations, you can read the first few pages in the User's Manual [U], and read Getting Started with STATA for Windows.

In case you start looking up other commands, other things to know:
If you see varlist, it means "enter a list of one or more variables here."
If you see depvar, it means "enter the name of the dependent (outcome) variable here."

 

2.   sts list -- List the survivor or cumulative hazard function

      This command lists the Kaplan-Meier survival estimates at the time of each failure, assuming that you have already set your data to survival time by using the stset command.  The syntax is as follows:

     sts list [if] [in] [, options]

Notice that you can type just sts list, and it requires no additional information.  This will give you the cumulative probability of survival [S(t)] with standard errors (and 95% confidence intervals), in addition to the time of the failure, the number of subjects in the analysis, the number failing and the number censored in that interval. 

There are options after the comma, including one called "failure".  If you scroll down either in the command help or look on the next page of the manual, you'll see that if you specify "failure", STATA will give you the cumulative probability of failure [1-S(t)] at each failure time.  You'd ask for this by typing:


sts list, failure

If, hypothetically, you were interested in calculating the "cumulative probability of survival at year 3," for example, you would look for the cumulative probability of survival at the failure time that is at or immediately before year 3. 

3.  sts graph -- Graph the survivor and cumulative hazard functions

      This command graphs the estimated Kaplan-Meier survivor function (again, assuming you have already set your data to survival time with the stset command).  It has the following syntax:

sts graph [if] [in] [, options]

Again, notice that you can type sts graph and everything else is optional. Two options that may be useful are failure and by(varlist). If you type:


sts graph, failure


then you get the [1-S(t)] function graphically presented.

      If you had a third variable in your dataset (which this dataset does not), say some "drug", where 1=drug and 0=placebo, you could see the different survival curves for drug and placebo groups by typing the following:


sts graph, by(drug)

 

      Exploring the drop down menu for sts graph (which can be found in the Statistics/Survival Analysis/Graphs/Kaplan-Meier Survival Function) is another good way to find the various options available for the basic Kaplan-Meier plot.  The drop down menu, for example, has tick boxes for adding “at risk” tables and confidence intervals.  

In reply to Anjana Sharma

Re: Kaplan Meier curve

by Margaret -

Thanks, this was really helpful!

I am having a lot of trouble changing the text of the legends. This is my code right now:

sts graph, by(initialtx) addplot((line _t0 osyr)) ytitle("Overall survival probability") ytitle(, size(medlarge)) xtitle("Years from diagnosis") xtitle(, size(medium large)) title("Kaplan meier overall survival estimate") legend(label(1 "Surgery + XRT") label(2 "XRT") )

 

When I do this, the legend is the default legend that just showed my variable name and doesn't show the text that I want it to (as written in the above code). Is there a command to override the default legend text? 

Also, when I do this, a third line with the default title "analysis time when record begins" shows up. Is there a way to get rid of this?

 

Thank you!

-Margaret

In reply to Margaret

Re: Kaplan Meier curve

by Kristen -

Hi Margaret. Have you checked out the STATA graphics reference manual (posted on the website)? There is a whole section on legends on page 530.

In reply to Kristen

Re: Kaplan Meier curve

by Margaret -

Hi Kristen,

Yes, I actually looked at that page to write the code pasted in my last post. A legend does appear but it doesn't have the labels that I specify in my code, and I'm not sure if there's something I'm missing to override the default legend labels?

Thank you!

-Margaret