**[ST] streg postestimation** -- Postestimation tools for streg

__Postestimation commands__

The following postestimation command is of special interest after **streg**:

Command Description
-------------------------------------------------------------------------
**stcurve** plot the survivor, hazard, and cumulative hazard
functions
-------------------------------------------------------------------------

The following standard postestimation commands are also available:

Command Description
-------------------------------------------------------------------------
**contrast** contrasts and ANOVA-style joint tests of estimates
**estat ic** Akaike's and Schwarz's Bayesian information criteria
(AIC and BIC)
**estat summarize** summary statistics for the estimation sample
**estat vce** variance-covariance matrix of the estimators (VCE)
**estat** (svy) postestimation statistics for survey data
**estimates** cataloging estimation results
* **hausman** Hausman's specification test
**lincom** point estimates, standard errors, testing, and
inference for linear combinations of coefficients
**linktest** link test for model specification
* **lrtest** likelihood-ratio test
**margins** marginal means, predictive margins, marginal effects,
and average marginal effects
**marginsplot** graph the results from margins (profile plots,
interaction plots, etc.)
**nlcom** point estimates, standard errors, testing, and
inference for nonlinear combinations of coefficients
**predict** predictions, residuals, influence statistics, and
other diagnostic measures
**predictnl** point estimates, standard errors, testing, and
inference for generalized predictions
**pwcompare** pairwise comparisons of estimates
**suest** seemingly unrelated estimation
**test** Wald tests of simple and composite linear hypotheses
**testnl** Wald tests of nonlinear hypotheses
-------------------------------------------------------------------------
* **hausman** and **lrtest** are not appropriate with **svy** estimation results.

__Syntax for predict__

**predict** [*type*] *newvar* [*if*] [*in*] [**,** *statistic* *options*]

**predict** [*type*] {*stub******|*newvarlist*} [*if*] [*in*]**,** __sc__**ores**

*statistic* Description
-------------------------------------------------------------------------
Main
__med__**ian** **time** median survival time; the default
__med__**ian** __lnt__**ime** median ln(survival time)
**mean time** mean survival time
**mean** __lnt__**ime** mean ln(survival time)
__ha__**zard** hazard
**hr** hazard ratio, also known as the relative hazard
**xb** linear prediction xb
**stdp** standard error of the linear prediction; SE(xb)
__s__**urv** S(t|t_0)
* __csu__**rv** S(t|earliest t_0 for subject)
* __csn__**ell** Cox-Snell residuals
* __mg__**ale** martingale-like residuals
* __dev__**iance** deviance residuals
-------------------------------------------------------------------------

*options* Description
-------------------------------------------------------------------------
**oos** make *statistic* available in and out of sample
__nooff__**set** ignore the **offset()** variable specified in **streg**
__alpha__**1** predict *statistic* conditional on frailty value equal
to one
__uncond__**itional** predict *statistic* unconditionally on the frailty
__marg__**inal** synonym for **unconditional**
__part__**ial** produce observation-level results
-------------------------------------------------------------------------

Unstarred statistics are available both in and out of sample; type
**predict** *...* **if e(sample)** *...* if wanted only for the estimation sample.
Starred statistics are calculated for the estimation sample by default,
but the **oos** option makes them available both in and out of sample.
When no option is specified, the predicted median survival time is
calculated for all models. The predicted hazard ratio, option **hr**, is
available only for the exponential, Weibull, and Gompertz models. The
**mean time** and **mean lntime** options are not available for the Gompertz
model. Unconditional estimates of **mean time** and **mean lntime** are not
available if **frailty()** was specified with **streg**.
**csnell**, **mgale**, and **deviance** are not allowed with **svy** estimation results.

__Menu for predict__

**Statistics > Postestimation**

__Description for predict__

**predict** creates a new variable containing predictions such as median and
mean survival times; hazards; hazard ratios; linear predictions; standard
errors; probabilities; Cox-Snell, martingale-like, and deviance
residuals.

__Options for predict__

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

**median time** calculates the predicted median survival time in
analysis-time units. This is the prediction from time 0 conditional
on constant covariates. When no options are specified with **predict**,
the predicted median survival time is calculated for all models.

**median lntime** calculates the natural logarithm of what **median time**
produces.

**mean time** calculates the predicted mean survival time in analysis-time
units. This is the prediction from time 0 conditional on constant
covariates. This option is not available for Gompertz regressions
and is available for frailty models only if **alpha1** is specified, in
which case what you obtain is an estimate of the mean survival time
conditional on a frailty effect of one.

**mean lntime** predicts the mean of the natural logarithm of **time**. This
option is not available for Gompertz regression and is available for
frailty models only if **alpha1** is specified, in which case what you
obtain is an estimate of the mean log survival-time conditional on a
frailty effect of one.

**hazard** calculates the predicted hazard.

**hr** calculates the hazard ratio. This option is valid only for models
having a proportional-hazards parameterization.

**xb** calculates the linear prediction from the fitted model. That is, you
fit the model by estimating a set of parameters b0, b1, b2, ..., bk,
and the linear prediction is y = xb.

The x used in the calculation is obtained from the data currently in
memory and need not correspond to the data on the independent
variables used in estimating b.

**stdp** calculates the standard error of the prediction, that is, the
standard error of y.

**surv** calculates each observation's predicted survivor probability,
S(t|t0), where t_0 is **_t0**, the analysis time at which each record
became at risk. For multiple-record data, see the **csurv** option
below.

**csurv** calculates the predicted S(t|earliest t0) for each subject in
multiple-record data by calculating the conditional survivor values,
S(t|t0) (see the **surv** option above), and then multiplying them.

What you obtain from **surv** will differ from what you obtain from **csurv**
only if you have multiple records for that subject.

In the presence of gaps or delayed entry, the estimates obtained from
**csurv** can be different for subjects with gaps from those without
gaps, having the same covariate values, because the probability of
survival over gaps is assumed to be 1. Thus the predicted cumulative
conditional survivor function is not a smooth function of time **_t** for
constant values of the covariates. Use **stcurve, survival** to obtain a
smooth estimate of the cumulative survivor function S(t|x).

**csnell** calculates the Cox-Snell generalized residuals. For
multiple-record-per-subject data, by default only one value per
subject is calculated and it is placed on the last record for the
subject.

Adding the **partial** option will produce partial Cox-Snell residuals,
one for each record within subject; see **partial** below. Partial
Cox-Snell residuals are the additive contributions to a subject's
overall Cox-Snell residual. In single-record-per-subject data, the
partial Cox-Snell residuals are the Cox-Snell residuals.

**mgale** calculates the martingale-like residuals. For multiple-record
data, by default only one value per subject is calculated and it is
placed on the last record for the subject.

Adding the **partial** option will produce partial martingale residuals,
one for each record within subject; see **partial** below. Partial
martingale residuals are the additive contributions to a subject's
overall martingale residual. In single-record data, the partial
martingale residuals are the martingale residuals.

**deviance** calculates the deviance residuals. Deviance residuals are
martingale residuals that have been transformed to be more symmetric
about zero. For multiple-record data, by default only one value per
subject is calculated and it is placed on the last record for the
subject.

Adding the **partial** option will produce partial deviance residuals,
one for each record within subject; see **partial** below. Partial
deviance residuals are transformed partial martingale residuals. In
single-record data, the partial deviance residuals are the deviance
residuals.

**oos** makes **csurv**, **csnell**, **mgale**, and **deviance** available both in and out of
sample. **oos** also dictates that summations and other accumulations
take place over the sample as defined by **if** and **in**. By default, the
summations are taken over the estimation sample, with **if** and **in**
merely determining which values of *newvar* are to be filled in once
the calculation is finished.

**nooffset** is relevant only if you specified **offset(***varname***)** with **streg**.
It modifies the calculations made by **predict** so that they ignore the
offset variable; the linear prediction is treated as xb rather than
xb + offset.

**alpha1**, when used after fitting a frailty model, specifies that *statistic*
be predicted conditional on a frailty value equal to one. This is
the default for shared-frailty models.

**unconditional** and **marginal**, when used after fitting a frailty model,
specify that *statistic* be predicted unconditional on the frailty.
That is, the prediction is averaged over the frailty distribution.
This is the default for unshared-frailty models.

**partial** is relevant only for multiple-record data and is valid with
**csnell**, **mgale**, and **deviance**. Specifying **partial** will produce
"partial" versions of these statistics, where one value is calculated
for each record instead of one for each subject. The subjects are
determined by the **id()** option of **stset**.

Specify **partial** if you wish to perform diagnostics on individual
records rather than on individual subjects. For example, a partial
deviance can be used to diagnose the fitted characteristics of an
individual record rather than those of the set of records for a given
subject.

**scores** calculates equation-level score variables. The number of score
variables created depends upon the chosen distribution.

The first new variable will always contain the partial derivative of
the log likelihood with respect to the linear prediction (regression
equation) from the fitted model.

The subsequent new variables will contain the partial derivative of
the log likelihood with respect to the ancillary parameters. For
example, in the generalized gamma model, the second new variable will
contain the partial derivative of the log likelihood with respect to
the linear prediction (sigma equation), and the third new variable
will contain the partial derivative of the log likelihood with
respect to the linear prediction (kappa equation).

__Syntax for margins__

**margins** [*marginlist*] [**,** *options*]

**margins** [*marginlist*] **,** __pr__**edict(***statistic *...**)** [__pr__**edict(***statistic *...**)**
...] [*options*]

*statistic* Description
-------------------------------------------------------------------------
__med__**ian** **time** median survival time; the default
__med__**ian** __lnt__**ime** median ln(survival time)
**mean time** mean survival time
**mean** __lnt__**ime** mean ln(survival time)
**hr** hazard ratio, also known as the relative hazard
**xb** linear prediction xb
__ha__**zard** not allowed with **margins**
**stdp** not allowed with **margins**
__s__**urv** not allowed with **margins**
__csu__**rv** not allowed with **margins**
__csn__**ell** not allowed with **margins**
__mg__**ale** not allowed with **margins**
__dev__**iance** not allowed with **margins**
-------------------------------------------------------------------------

Statistics not allowed with **margins** are functions of stochastic
quantities other than **e(b)**.

For the full syntax, see **[R] margins**.

__Menu for margins__

**Statistics > Postestimation**

__Description for margins__

**margins** estimates margins of response for median and mean survival times,
hazard ratios, and linear predictions.

__Examples__

---------------------------------------------------------------------------
Setup
**. webuse kva**

Fit Weibull survival model
**. streg load bearings, d(weibull)**

Predict median survival time
**. predict time, time**

Predict log-median survival time
**. predict lntime, lntime**

---------------------------------------------------------------------------
Setup
**. webuse cancer, clear**

Map value for **drug** into 0 for placebo and 1 for nonplacebo
**. replace drug = drug == 2 | drug == 3**

Declare data to be survival-time data
**. stset studytime, failure(died)**

Fit exponential survival model
**. streg age drug, d(exp)**

Predict Cox-Snell residuals
**. predict double cs, csnell**

**stset** the data again with **cs** as failure-time variable
**. stset cs, failure(died)**

Create **km** containing Kaplan-Meier survival estimates
**. sts generate km = s**

Create **H**, the cumulative hazard
**. generate double H = -ln(km)**

Plot **H** against **cs**, specifying **cs** twice to obtain reference line
**. line H cs cs, sort**

Fit lognormal survival model
**. streg age drug, d(lnormal)**

Predict deviance residuals
**. predict dev, deviance**

Plot deviance residuals
**. scatter dev studytime, yline(0) m(o)**
---------------------------------------------------------------------------