Stata 15 help for sts graph

[ST] sts graph -- Graph the survivor, hazard, or cumulative hazard function

Syntax

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

options Description ------------------------------------------------------------------------- Main survival graph Kaplan-Meier survivor function; the default failure graph Kaplan-Meier failure function cumhaz graph Nelson-Aalen cumulative hazard function hazard graph smoothed hazard estimate by(varlist) estimate and graph separate functions for each group formed by varlist adjustfor(varlist) adjust the estimates to zero values of varlist strata(varlist) stratify on different groups of varlist separate show curves on separate graphs; default is to show curves one on top of another ci show pointwise confidence bands

At-risk table risktable show table of number at risk beneath graph risktable(risk_spec) show customized table of number at risk beneath graph

Options level(#) set confidence level; default is level(95) per(#) units to be used in reported rates noshow do not show st setting information tmax(#) show graph for t <= # tmin(#) show graph for t >= # noorigin begin survival (failure) curve at first exit time; default is to begin at t = 0 width(#[#...]) override default bandwidth(s) kernel(kernel) kernel function; use with hazard noboundary no boundary correction; use with hazard lost show number lost enter show number entered and number lost atrisk show numbers at risk at beginning of each interval censored(single) show one hash mark at each censoring time, no matter what number is censored censored(number) show one hash mark at each censoring time and number censored above hash mark censored(multiple) show multiple hash marks for multiple censoring at the same time censopts(hash_options) affect rendition of hash marks lostopts(marker_label_options) affect rendition of numbers lost atriskopts(marker_label_options) affect rendition of numbers at risk

Plot plotopts(cline_options) affect rendition of plotted lines plot#opts(cline_options) affect rendition of #th plotted line; may not be combined with separate

CI plot ciopts(area_options) affect rendition of confidence bands ci#opts(area_options) affect rendition of #th confidence band; may not be combined with separate

Add plots addplot(plot) add other plots to the generated graph

Y axis, X axis, Titles, Legend, Overall twoway_options any options documented in [G-3] twoway_options byopts(byopts) how subgraphs are combined, labeled, etc. -------------------------------------------------------------------------

where risk_spec is

[numlist][, table_options group(group)]

numlist specifies the points at which the number at risk is to be evaluated, table_options customizes the table of number at risk, and group(group) specifies a specific group/row for table_options to be applied.

table_options Description ------------------------------------------------------------------------- Main axis_label_options control table by using axis labeling options; seldom used order(order_spec) select which rows appear and their order righttitles place titles on right side of the table failevents show number failed in the at-risk table text_options affect rendition of table elements and titles

Row titles rowtitle([text][, rtext_options]) change title for a row

Title title([text][, ttext_options]) change overall table title -------------------------------------------------------------------------

where order_spec is

# ["text" ["text" ...]] [...]

text_options Description ------------------------------------------------------------------------- size(textsizestyle) size of text color(colorstyle) color of text justification(justificationstyle) text left-justified, centered, right-justified format(%fmt) format values per %fmt topgap(relativesize) margin above rows bottomgap(relativesize) margin beneath rows

style(textstyle) overall style of text ------------------------------------------------------------------------- style() does not appear in the dialog box.

rtext_options Description ------------------------------------------------------------------------- size(textsizestyle) size of text color(colorstyle) color of text justification(justificationstyle) text left-justified, centered, right-justified at(#) override x position of titles topgap(relativesize) margin above rows

style(textstyle) overall style of text ------------------------------------------------------------------------- style() does not appear in the dialog box.

ttext_options Description ------------------------------------------------------------------------- size(textsizestyle) size of text color(colorstyle) color of text justification(justificationstyle) text left-justified, centered, right-justified at(#) override x position of titles topgap(relativesize) margin above rows bottomgap(relativesize) margin beneath rows

style(textstyle) overall style of text ------------------------------------------------------------------------- style() does not appear in the dialog box.

group Description ------------------------------------------------------------------------- #rownum specify group by row number in table value specify group by value of group label specify group by text of value label associated with group -------------------------------------------------------------------------

hash_options Description ------------------------------------------------------------------------- line_options change look of dropped lines marker_label_options add marker labels; any options documented in [G-3] marker_label_options, except mlabel() -------------------------------------------------------------------------

risktable() may be repeated and is merged-explicit; see repeated options. You must stset your data before using sts graph; see [ST] stset. fweights, iweights, and pweights may be specified using stset; see [ST] stset.

Menu

Statistics > Survival analysis > Graphs > Survivor and cumulative hazard functions

Description

sts graph graphs the estimated survivor (failure) function, the Nelson-Aalen estimated cumulative (integrated) hazard function, or the estimated hazard function.

sts graph can be used with single- or multiple-record or single- or multiple-failure st data.

Options

+------+ ----+ Main +-------------------------------------------------------------

survival, failure, cumhaz, and hazard specify the function to graph.

survival specifies that the Kaplan-Meier survivor function be plotted. This option is the default if a function is not specified.

failure specifies that the Kaplan-Meier failure function, 1 - S(t+0), be plotted.

cumhaz specifies that the Nelson-Aalen estimate of the cumulative hazard function be plotted.

hazard specifies that an estimate of the hazard function be plotted. This estimate is calculated as a weighted kernel-density estimate using the estimated hazard contributions. These hazard contributions are the same as those obtained by sts generate newvar = h.

by(varlist) estimates a separate function for each by-group and plots all the functions on one graph. By-groups are identified by equal values of the variables in varlist. by() may not be combined with strata().

adjustfor(varlist) adjusts the estimate of the survivor or hazard functions to that for 0 values of varlist. If you want to adjust the function to values different from 0, you need to center the variables around those values before issuing the command. Say that you want to plot the survivor function adjusted to age of patients and the ages in your sample are 40 to 60 years. Then

. sts graph, adjustfor(age)

will graph the survivor function adjusted to age 0. If you want to adjust the function to age 40, type

. gen age40 = age - 40 . sts graph, adjustfor(age40)

adjustfor() is not available with cumhaz or ci.

If you specify adjustfor() with by(), sts fits separate Cox regression models for each group, using the adjustfor() variables as covariates. The separately calculated baseline survivor functions are then retrieved.

If you specify adjustfor() with strata(), sts fits a stratified-on-group Cox regression model using the adjustfor() variables as covariates. The stratified, baseline survivor function is then retrieved.

strata(varlist) produces estimates of the survivor (failure) or hazard functions stratified on variables in varlist and plots all the groups on one graph. It requires specifying adjustfor() and may not be combined with by().

If you have more than one strata() variable but need only one, use egen to create it; see [D] egen.

separate is meaningful only with by() or strata(); it requests that each group be placed on its own graph rather than one on top of the other. Sometimes curves have to be placed on separate graphs -- such as when you specify ci -- because otherwise it would be too confusing.

ci includes pointwise confidence bands. The default is not to produce these bands. ci is not allowed with adjustfor() or pweights.

+---------------+ ----+ At-risk table +----------------------------------------------------

risktable[([numlist][, table_options])] displays a table showing the number at risk beneath the plot. risktable may not be used with separate or adjustfor().

risktable displays the table in the default format with number at risk shown for each time reported on the x axis.

risktable([numlist][, table_options]) specifies that the number at risk be evaluated at the points specified in numlist or that the rendition of the table be changed by table_options.

There are two ways to change the points at which the numbers at risk are evaluated.

1. The x axis of the graph may be altered. For example:

. sts graph, xlabel(0(5)40) risktable

2. A numlist can be specified directly in the risktable() option, which affects only the at-risk table. For example:

. sts graph, risktable(0(5)40)

The two examples produce the same at-risk table, but the first also changes the time labels on the graph's x axis.

table_options affect the rendition of the at-risk table and may be any of the following:

group(#rownum|value|label) specifies that all the suboptions specified in the risktable() apply only to the specified group. Because the risktable() option may be repeated, this option allows different rows of the at-risk table to be displayed with different colors, font sizes, etc.

When both a value and a value label are matched, the value label takes precedence.

risktable() may be specified with or without the group() suboption. When specified without group(), each suboption is applied to all available groups or rows. risktable() specified without group() is considered to be global and is itself merged-explicit. See repeated options for more information on how repeated options are merged.

Consider the following example:

. sts graph, by(drug) risktable(, color(red) size(small)) risktable(, color(navy))

The example above would produce a table where all rows are colored navy with small text.

Combining global risktable() options with group-specific risktable() options can be useful. When global options are combined with group-specific options, group-specific options always take precedence.

Consider the following example:

. sts graph, by(drug) risktable(, color(navy)) risktable(, color(red) group(#1))

The example above would produce a table with the first row colored red and all remaining rows colored navy.

+------+ ----+ Main +----------------------------------------------------- axis_label_options control the table by using axis labeling options. These options are seldom used. See [G-3] axis_label_options.

order() specifies which and in what order rows are to appear in the at-risk table. Optionally, order() can be used to override the default text.

order(# # # ...) is the syntax used for identifying which rows to display and their order. order(1 2 3) would specify that row 1 is to appear first in the table, followed by row 2, followed by row 3. order(1 2 3) is the default if there are three groups. If there were four groups, order(1 2 3 4) would be the default, and so on. If there were four groups and you specified order(1 2 3), the fourth row would not appear in the at-risk table. If you specified order(2 1 3), row 2 would appear first, followed by row 1, followed by row 3.

order(# "text" # "text" ...) is the syntax used for specifying the row order and alternate row titles.

Consider the following at-risk table:

+------------------------------------+ | drug = 1 20 8 2 | | drug = 2 14 10 4 1 | | drug = 3 14 13 10 5 | +------------------------------------+ Specifying order(1 "Placebo" 3 2) would produce

+------------------------------------+ | Placebo 20 8 2 | | drug = 3 14 13 10 5 | | drug = 2 14 10 4 1 | +------------------------------------+ and specifying order(1 "Placebo" 3 "Drug 2" 2 "Drug 1") would produce

+------------------------------------+ | Placebo 20 8 2 | | Drug 2 14 13 10 5 | | Drug 1 14 10 4 1 | +------------------------------------+

righttitles specifies that row titles be placed to the right of the at-risk values. The default is to place row titles to the left of the at-risk values.

failevents specifies that the number of failure events be shown in parentheses, after the time in which the risk values were calculated.

text_options affect the rendition of both row titles and number at risk and may be any of the following:

size(textsizestyle) specifies the size of text.

color(colorstyle) specifies the color of text.

justification(justificationstyle) specifies how text elements are to be justified.

format(%fmt) specifies how numeric values are to be formatted.

topgap(relativesize) specifies how much space is to be placed above each row.

bottomgap(relativesize) specifies how much space is to be placed beneath each row.

style(textstyle) specifies the style of text. This option does not appear on the dialog box.

+------------+ ----+ Row titles +-----------------------------------------------

rowtitle([text] [, rtext_options]) changes the default text or rendition of row titles. Specifying rowtitle(, color(navy)) would change the color of all row titles to navy.

rowtitle() is often combined with group() to change the text or rendition of a title. Specifying rowtitle(Placebo) group(#2) would change the title of the second row to Placebo. Specifying rowtitle(, color(red)) group(#3) would change the color of the row title for the third row to red.

Row titles may include more than one line. Lines are specified one after the other, each enclosed in double quotes. Specifying rowtitle("Experimental drug") group(#1) would produce a one-line row title, and specifying rowtitle("Experimental" "Drug") group(#1) would produce a multiple-line row title.

rtext_options affect the rendition of both row titles and number at risk and may be any of the following:

size(textsizestyle) specifies the size of text.

color(colorstyle) specifies the color of text.

justification(justificationstyle) specifies how text elements are to be justified.

at(#) allows you to reposition row titles or the overall table title to align with a specific location on the x axis.

topgap(relativesize) specifies how much space is to be placed above each row.

style(textstyle) specifies the style of text. This option does not appear in the dialog box.

+-------+ ----+ Title +----------------------------------------------------

title([title] [, ttext_options]) may be used to override the default title for the at-risk table and affect the rendition of its text.

Titles may include one line of text or multiple lines. title("At-risk table") will produce a one-line title, and title("At-risk" "table") will produce a multiple-line title.

ttext_options affect the rendition of both row titles and number at risk and may be any of the following:

size(textsizestyle) specifies the size of text.

color(colorstyle) specifies the color of text.

justification(justificationstyle) specifies how text elements are to be justified.

at(#) allows you to reposition row titles or the overall table title to align with a specific location on the x axis.

at(rowtitles) places the overall table title at the default position calculated for the row titles. This option is sometimes useful for alignment when the default justification has not been used.

topgap(relativesize) specifies how much space is to be placed above each row.

bottomgap(relativesize) specifies how much space is to be placed beneath each row.

style(textstyle) specifies the style of text. This option does not appear on the dialog box.

+---------+ ----+ Options +----------------------------------------------------------

level(#) specifies the confidence level, as a percentage, for the pointwise confidence interval around the survivor, failure, or cumulative hazard function; see [R] level.

per(#) specifies the units used to report the survival or failure rates. For example, if the analysis time is in years, specifying per(100) results in rates per 100 person-years.

noshow prevents sts graph from showing the key st variables. This option is seldom used because most people type stset, show or stset, noshow to set whether they want to see these variables mentioned at the top of the output of every st command; see [ST] stset.

tmax(#) specifies that the plotted curve be graphed only for t <= #. This option does not affect the calculation of the function, rather the portion that is displayed.

tmin(#) specifies that the plotted curve be graphed only for t >= #. This option does not affect the calculation of the function, rather the portion that is displayed.

noorigin requests that the plot of the survival (failure) curve begin at the first exit time instead of beginning at t=0 (the default). This option is ignored when cumhaz or hazard is specified.

width(# [# ...]) is for use with hazard and specifies the bandwidth to be used in the kernel smooth used to plot the estimated hazard function. If width() is not specified, a default bandwidth is used as described in [R] kdensity. If it is used with by(), multiple bandwidths may be specified, one for each group. If there are more groups than the k bandwidths specified, the default bandwidth is used for the k+1, ... remaining groups. If any bandwidth is specified as . (dot), the default bandwidth is used for that group.

kernel(kernel) is for use with hazard and specifies the kernel function to be used in calculating the weighted kernel-density estimate required to produce a smoothed hazard-function estimator. The default kernel is Epanechnikov, yet kernel may be any of the kernels supported by kdensity; see [R] kdensity.

noboundary is for use with hazard. It specifies that no boundary-bias adjustments are to be made when calculating the smoothed hazard-function estimator. By default, the smoothed hazards are adjusted near the boundaries. If the epan2, biweight, or rectangular kernel is used, the bias correction near the boundary is performed using boundary kernels. For other kernels, the plotted range of the smoothed hazard function is restricted to be within one bandwidth of each endpoint. For these other kernels, specifying noboundary merely removes this range restriction.

lost specifies that the numbers lost be shown on the plot. These numbers are shown as small numbers over the flat parts of the function.

If enter is not specified, the numbers displayed are the number censored minus the number who enter. If you do specify enter, the numbers displayed are the pure number censored. The underlying logic is described in [ST] sts.

lost may not be used with hazard.

enter specifies that the number who enter be shown on the graph, as well as the number lost. The number who enter are shown as small numbers beneath the flat parts of the plotted function.

enter may not be used with hazard.

atrisk specifies that the numbers at risk at the beginning of each interval be shown on the plot. The numbers at risk are shown as small numbers beneath the flat parts of the plotted function.

atrisk may not be used with hazard.

censored(single | number | multiple) specifies that hash marks be placed on the graph to indicate censored observations.

censored(single) places one hash mark at each censoring time, regardless of the number of censorings at that time.

censored(number) places one hash mark at each censoring time and displays the number of censorings about the hash mark.

censored(multiple) places multiple hash marks for multiple censorings at the same time. For instance, if 3 observations are censored at time 5, three hash marks are placed at time 5. censored(multiple) is intended for use when there are few censored observations; if there are too many censored observations, the graph can look bad. In such cases, we recommend that censored(number) be used.

censored() may not be used with hazard.

censopts(hash_options) specifies options that affect how the hash marks for censored observations are rendered; see [G-3] line_options. When combined with censored(number), censopts() also specifies how the count of censoring is rendered; see [G-3] marker_label_options, except mlabel() is not allowed.

lostopts(marker_label_options) specifies options that affect how the numbers lost are rendered; see [G-3] marker_label_options. This option implies the lost option.

atriskopts(marker_label_options) specifies options that affect how the numbers at risk are rendered; see [G-3] marker_label_options. This option implies the atrisk option.

+------+ ----+ Plot +-------------------------------------------------------------

plotopts(cline_options) affects the rendition of the plotted lines; see [G-3] cline_options. This option may not be combined with by( varlist) or strata(varlist), unless separate is also specified.

plot#opts(cline_options) affects the rendition of the #th plotted line; see [G-3] cline_options. This option may not be combined with separate.

+---------+ ----+ CI plot +----------------------------------------------------------

ciopts(area_options) affects the rendition of the confidence bands; see [G-3] area_options. This option may not be combined with by(varlist) or strata(varlist), unless separate is also specified.

ci#opts(area_options) affects the rendition of the #th confidence band; see [G-3] area_options. This option may not be combined with separate.

+-----------+ ----+ Add plots +--------------------------------------------------------

addplot(plot) provides a way to add other plots to the generated graph; see [G-3] addplot_option.

+-----------------------------------------+ ----+ Y axis, X axis, Titles, Legend, Overall +--------------------------

twoway_options are any of the options documented in [G-3] twoway_options. These include options for titling the graph (see [G-3] title_options) and for saving the graph to disk (see [G-3] saving_option).

byopts(byopts) affects the appearance of the combined graph when by() or adjustfor() is specified, including the overall graph title and the organization of subgraphs. byopts() may not be specified with separate. See [G-3] by_option.

Example: Including the number lost on the graph

Setup . webuse drug2b

Graph the survivor functions for the two categories of drug and include the number lost due to censoring as small numbers on the plots . sts graph, by(drug) lost

Same as above, but show the number entered and the number lost . sts graph, by(drug) enter

Example: Graphing the Nelson-Aalen cumulative hazard function

Setup . webuse drug2

Graph the cumulative hazard functions for the two categories of drug . sts graph, cumhaz by(drug)

Same as above, but include the number lost due to censoring as small numbers on the plots . sts graph, cumhaz by(drug) lost

Example: Graphing the hazard function

Graph the hazard functions for the two categories of drug . sts graph, hazard by(drug)

Same as above, but use a Gaussian kernel with a bandwidth of 5 for drug = 0 and 7 for drug = 1 . sts graph, hazard by(drug) kernel(gauss) width(5 7)

Example: Adding an at-risk table

Graph the survivor functions for the two categories of drug in one plot, including an at-risk table below the graph . sts graph, by(drug) risktable

Same as above, but put the legend inside the plot rather than below it . sts graph, by(drug) risktable legend(ring(0) position(2) rows(2))

Graph the survivor functions for the two categories of drug in one plot, including an at-risk table below the graph and using the specified row titles and order of rows for the at-risk table . sts graph, by(drug) risktable(, order(1 "Placebo" 2 "Test drug"))

Same as above, but left-justify the row titles in the at-risk table . sts graph, by(drug) risktable(, order(1 "Placebo" 2 "Test drug") rowtitle(, justification(left)))

Same as above, but align the table title with the rwo titles . sts graph, by(drug) risktable(, order(1 "Placebo" 2 "Test drug") rowtitle(, justification(left)) title(, at(rowtitle)))

Video example

How to graph survival curves


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index