**[ST] stcox PH-assumption tests** -- Tests of proportional-hazards assumption

__Syntax__

Check proportional-hazards assumption:

Log-log plot of survival

**stphplot** [*if*] **,** {**by(***varname***)** | __str__**ata(***varname***)**} [*stphplot_options*]

Kaplan-Meier and predicted survival plot

**stcoxkm** [*if*] **,** **by(***varname***)** [*stcoxkm_options*]

Using Schoenfeld residuals

**estat** **phtest** [**,** *phtest_options*]

*stphplot_options* Description
-------------------------------------------------------------------------
Main
* **by(***varname***)** fit separate Cox models; the default
* __str__**ata(***varname***)** fit stratified Cox model
__adj__**ust(***varlist***)** adjust to average values of *varlist*
__z__**ero** adjust to zero values of *varlist*; use
with **adjust()**

Options
__noneg__**ative** plot ln{-ln(survival)}
__nolnt__**ime** plot curves against analysis time
__nosh__**ow** do not show st setting information

Plot
__plot____#__**opts(***stphplot_plot_options***)** affect rendition of the *#*th connected
line and *#*th plotted points

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

Y axis, X axis, Titles, Legend, Overall
*twoway_options* any options other than **by()** documented
in **[G-3]** *twoway_options*
-------------------------------------------------------------------------
* Either **by(***varname***)** or **strata(***varname***)** is required with **stphplot**.

*stphplot_plot_options* Description
-------------------------------------------------------------------------
*cline_options* change look of lines or connecting
method
*marker_options* change look of markers (color, size,
etc.)
-------------------------------------------------------------------------

*stcoxkm_options* Description
-------------------------------------------------------------------------
Main
* **by(***varname***)** report the nominal or ordinal
covariate
__tie__**s(**__bre__**slow)** use Breslow method to handle tied
failures
__tie__**s(**__efr__**on)** use Efron method to handle tied
failures
__tie__**s(exactm)** use exact marginal-likelihood method
to handle tied failures
__tie__**s(exactp)** use exact partial-likelihood method to
handle tied failures
__sep__**arate** draw separate plot for predicted and
observed curves
__nosh__**ow** do not show st setting information

Observed plot
__obsop__**ts(***stcoxkm_plot_options***)** affect rendition of the observed curve
__obs____#__**opts(***stcoxkm_plot_options***)** affect rendition of the *#*th observed
curve; not allowed with **separate**

Predicted plot
__predop__**ts(***stcoxkm_plot_options***)** affect rendition of the predicted
curve
__pred____#__**opts(***stcoxkm_plot_options***)** affect rendition of the *#*th predicted
curve; not allowed with **separate**

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

Y axis, X axis, Titles, Legend, Overall
*twoway_options* any options other than **by()** documented
in **[G-3]** *twoway_options*
__byop__**ts(***byopts***)** how subgraphs are combined, labeled,
etc.
-------------------------------------------------------------------------
* **by(***varname***)** is required with **stcoxkm**.

*stcoxkm_plot_options* Description
-------------------------------------------------------------------------
*connect_options* change look of connecting method
*marker_options* change look of markers (color, size,
etc.)
-------------------------------------------------------------------------

You must **stset** your data before using **stphplot** and **stcoxkm**; see **[ST]**
**stset**.
**fweight**s, **iweight**s, and **pweight**s may be specified using **stset**; see **[ST]**
**stset**.

*phtest_options* Description
-------------------------------------------------------------------------
Main
**log** use natural logarithm time-scaling function
**km** use 1-KM product-limit estimate as the
time-scaling function
**rank** use rank of analysis time as the time-scaling
function
**time(***varname***)** use *varname* containing a monotone
transformation of analysis time as the
time-scaling function
**plot(***varname***)** plot smoothed, scaled Schoenfeld residuals
versus time
__bw__**idth(***#***)** use bandwidth of *#*; default is **bwidth(0.8)**
__d__**etail** test proportional-hazards assumption separately
for each covariate

Scatterplot
*marker_options* change look of markers (color, size, etc.)
*marker_label_options* add marker labels; change look or position

Smoothed line
__lineop__**ts(***cline_options***)** affect rendition of the smoothed line

Y axis, X axis, Titles, Legend, Overall
*twoway_options* any options other than **by()** documented in **[G-3]**
*twoway_options*
-------------------------------------------------------------------------
**estat** **phtest** is not appropriate after estimation with **svy**.

__Menu__

__stphplot__

**Statistics > Survival analysis > Regression models >** **Graphically**
**assess proportional-hazards assumption**

__stcoxkm__

**Statistics > Survival analysis > Regression models >** **Kaplan-Meier**
**versus predicted survival**

__estat phtest__

**Statistics > Survival analysis > Regression models >** **Test**
**proportional-hazards assumption**

__Description__

**stphplot** plots -ln{-ln(survival)} curves for each category of a nominal
or ordinal covariate versus ln(analysis time). These are often referred
to as "log-log" plots. Optionally, these estimates can be adjusted for
covariates. The proportional-hazards assumption is not violated when the
curves are parallel.

**stcoxkm** plots Kaplan-Meier observed survival curves and compares them
with the Cox predicted curves for the same variable. The closer the
observed values are to the predicted, the less likely it is that the
proportional-hazards assumption has been violated.

**estat phtest** tests the proportional-hazards assumption on the basis of
Schoenfeld residuals after fitting a model with **stcox**.

__Options for stphplot__

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

**by(***varname***)** specifies the nominal or ordinal covariate. Either **by()** or
**strata()** is required with **stphplot**.

**strata(***varname***)** is an alternative to **by()**. Rather than fitting separate
Cox models for each value of *varname*, **strata()** fits one stratified
Cox model. You must also specify **adjust(***varlist***)** with the
**strata(***varname***)** option; see **[ST] sts graph**.

**adjust(***varlist***)** adjusts the estimates to that for the average values of
the *varlist* specified. The estimates can also be adjusted to zero
values of *varlist* by specifying the **zero** option. **adjust(***varlist***)** can
be specified with **by()**; it is required with **strata(***varname***)**.

**zero** is used with **adjust()** to specify that the estimates be adjusted to
the 0 values of the *varlist* rather than to the average values.

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

**nonegative** specifies that ln{-ln(survival)} be plotted instead of
-ln{-ln(survival)}.

**nolntime** specifies that curves be plotted against analysis time instead
of against ln(analysis time).

**noshow** prevents **stphplot** 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**.

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

**plot***#***opts(***stphplot_plot_options***)** affects the rendition of the *#*th
connected line and *#*th plotted points; see **[G-3]** *cline_options* and
**[G-3]** *marker_options*.

+-----------+
----+ 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*,
excluding **by()**. These include options for titling the graph (see
**[G-3]** *title_options*) and for saving the graph to disk (see **[G-3]**
*saving_option*).

__Options for stcoxkm__

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

**by(***varname***)** specifies the nominal or ordinal covariate. **by()** is
required.

**ties(breslow** | **efron** | **exactm** | **exactp)** specifies one of the methods
available to **stcox** for handling tied failures. If none is specified,
**ties(breslow)** is assumed; see **[ST] stcox**.

**separate** produces separate plots of predicted and observed values for
each value of the variable specified with **by()**.

**noshow** prevents **stcoxkm** 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**.

+---------------+
----+ Observed plot +----------------------------------------------------

**obsopts(***stcoxkm_plot_options***)** affects the rendition of the observed
curve; see **[G-3]** *connect_options* and **[G-3]** *marker_options*.

**obs***#***opts(***stcoxkm_plot_options***)** affects the rendition of the *#*th observed
curve; see **[G-3]** *connect_options* and **[G-3]** *marker_options*. This
option is not allowed with **separate**.

+----------------+
----+ Predicted plot +---------------------------------------------------

**predopts(***stcoxkm_plot_options***)** affects the rendition of the predicted
curve; see **[G-3]** *connect_options* and **[G-3]** *marker_options*.

**pred***#***opts(***stcoxkm_plot_options***)** affects the rendition of the *#*th
predicted curve; see **[G-3]** *connect_options* and **[G-3]** *marker_options*.
This option is not allowed 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*,
excluding **by()**. 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()** and
**separate** are specified, including the overall graph title and the
organization of subgraphs. See **[G-3]** *by_option*.

__Options for estat phtest__

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

**log**, **km**, **rank**, and **time()** are used to specify the time scaling function.

By default, **estat phtest** performs the tests using the identity
function, that is, analysis time itself.

**log** specifies that the natural log of analysis time be used.

**km** specifies that 1 minus the Kaplan-Meier product-limit estimate be
used.

**rank** specifies that the rank of analysis time be used.

**time(***varname***)** specifies a variable containing an arbitrary monotonic
transformation of analysis time. You must ensure that *varname* is a
monotonic transform.

**plot(***varname***)** specifies that a scatterplot and smoothed plot of scaled
Schoenfeld residuals versus time be produced for the covariate
specified by *varname*. By default, the smoothing is performed using
the running-mean method implemented in **lowess, mean noweight**; see **[R]**
**lowess**.

**bwidth(***#***)** specifies the bandwidth. Centered subsets of **bwidth()***N
observations are used for calculating smoothed values for each point
in the data except for endpoints, where smaller, uncentered subsets
are used. The greater the **bwidth()**, the greater the smoothing. The
default is **bwidth(0.8)**.

**detail** specifies that a separate test of the proportional-hazards
assumption be produced for each covariate in the Cox model. By
default, **estat phtest** produces only the global test.

+--------------+
----+ Scatterplot +-----------------------------------------------------

*marker_options* affect the rendition of markers drawn at the plotted
points, including their shape, size, color, and outline; see **[G-3]**
*marker_options*.

*marker_label_options* specify if and how the markers are to be labeled;
see **[G-3]** *marker_label_options*.

+---------------+
----+ Smoothed line +----------------------------------------------------

**lineopts(***cline_options***)** affects the rendition of the smoothed line; see
**[G-3]** *cline_options*.

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

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

__Examples__

---------------------------------------------------------------------------
Setup
**. webuse leukemia**
**. stset weeks, failure(relapse) noshow**

Check proportional-hazards assumption for **treatment1** using **stphplot**
**. stphplot, by(treatment1)**

Same as above, but adjust for white-blood-cell count
**. stphplot, by(treatment1) adj(wbc2 wbc3)**

Check proportional-hazards assumption for **treatment1** using **stcoxkm**
**. stcoxkm, by(treatment1)**

Check proportional-hazards assumption for **treatment2** using **stphplot**
**. stphplot, by(treatment2)**

Check proportional-hazards assumption for **treatment2** using **stcoxkm**
**. stcoxkm, by(treatment2) separate**

---------------------------------------------------------------------------
Setup
**. webuse leukemia**

Declare data to be survival-time data
**. stset weeks, failure(relapse)**

Fit Cox model
**. stcox treatment2 wbc2 wbc3**

Test proportional-hazards assumption based on Schoenfeld residuals
**. estat phtest, rank detail**

---------------------------------------------------------------------------

__Video example__

How to fit a Cox proportional hazards model and check
proportional-hazards assumption

__Stored results__

**estat phtest** stores the following in **r()**:

Scalars
**r(df)** global test degrees of freedom
**r(chi2)** global test chi-squared
**r(p)** global test p-value

Matrices
**r(phtest)** separate tests for each covariate