*! version 1.0.0

A guide to predictions for stpm3

stpm3 has a range of useful post-estimation utilities.
This help file shows how to obtain various types of predictions conditional on covariate patterns.

For more examples see
https://pclambert.net/software/stpm3/.

Load data

It is easier to show through examples, so the best way to use this help file is to start without
a dataset in memory and load the data and then click through the different examples.

use https://www.pclambert.net/data/rott2b

stset os, failure(osi = 1) scale(12) exit(time 120)

(click to load data (clear current data first))

Example 1 - simple model with a single covariate

The model will include one binary covariate, hormon.
Predictions of the survival will be made at each level of hormon.
This can be done through the use of two at() options.

stpm3 i.hormon, scale(lncumhazard) df(5) eform

predict S0 S1, surv ci at1(hormon 0) at2(hormon 1) timevar(0 10)

frame stpm3_pred {

line S0 S1 tt

list in 1/10

}

(click to run.)

This has saved predictions to a new frame named stpm3_pred.
If you try running the command again, you will get an error as the frame now exists.
You could use frame(,replace)} or write to a different frame.

predict S0 S1, surv ci at1(hormon 0) at2(hormon 1) timevar(0 10) frame(p, replace)

frame p: describe

(click to run.)

If you look at what has been created in frame p it contains a time variable tt that has
100 equally spaced observations between 0 and 10. The predictions and lower and upper bounds
of the 95% confidence intervals are for each value of time.

Instead of using timevar(0 10) we could have created a time variable and then used
the timevar(varname) option.

range tt 0 10 100

predict S0 S1, surv ci at1(hormon 0) at2(hormon 1) timevar(tt) frame(p, replace)

frame p: list in 1/10

(click to run.)

It can be useful to have nicer spaced intervals. You can use the step() suboption to define the gap between
the time points. Below we use step(0.1), this enable us to list times at specific years.

predict S0 S1, surv ci at1(hormon 0) at2(hormon 1) timevar(0 10, step(0.1)) frame(p, replace)

frame p: list if inlist(tt,1,5,10), noobs

(click to run.)

The same could have been achieved by using the option n(101). This is shown below where we also
change the name of the time variable using the gen() suboption.

predict S0 S1, surv ci at1(hormon 0) at2(hormon 1) timevar(0 10, n(101) gen(time)) frame(p, replace)

frame p: list in 1/10

(click to run.)

You do not have to save data to a frame. If you use the merge option
the predictions will be merged with the current dataset.

predict S0 S1, surv ci at1(hormon 0) at2(hormon 1) timevar(0 10, step(0.1) gen(t)) merge

list t S0* S1* in 1/10

(click to run.)

Example 2 - Including more covariates

Now we will fit a model with more (3) covariates.
This will include the binary covariate hormon and the continuous covariates age and nodes.
Both age and nodes. will be modelled using natural splines with 3df (4 knots)
using stpm3 extendend functions.
We will also include an interaction between hormon and age.

stpm3 i.hormon##@ns(age,df(3)) i.size, scale(lncumhazard) df(5) eform

predict S0 S1, surv ci at1(hormon 0 age 60 size 3) at2(hormon 1 age 60 size 3) timevar(0 10, step(0.1)) frame(p, replace)

frame p {

line S0 S1 tt

list in 1/10

}

(click to run.)

Although the model is complex containing non-linear effects and interaction terms,
the prediction syntax is relatively easy. The only covariates in the model
are age, size and hormon. so all the predict command needs is the
age and the levels of size and hormon you want a prediction for.

If your model contains time-dependent effects using the tvc() option,
then the prediction command stays the same.

stpm3 i.hormon##@ns(age,df(3)) i.size, scale(lncumhazard) df(5) tvc(@ns(age,df(3))) dftvc(3)

predict S0 S1, surv ci at1(hormon 0 age 60 size 3) at2(hormon 1 age 60 size 3) timevar(0 10, step(0.1)) frame(p, replace)

frame p {

line S0 S1 tt

list in 1/10

}

(click to run.)