Skip to content

Commit 309ea08

Browse files
committed
v4.0.8 built for ssc
1 parent e29e797 commit 309ea08

13 files changed

+2976
-0
lines changed

ssc/version_4_0_8/survsim.ado

Lines changed: 434 additions & 0 deletions
Large diffs are not rendered by default.

ssc/version_4_0_8/survsim.sthlp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{smcl}
2+
{* *! version 1.0.0}{...}
3+
{vieweralsosee "survsim parametric" "help survsim parametric"}{...}
4+
{vieweralsosee "survsim user" "help survsim user"}{...}
5+
{vieweralsosee "survsim model" "help survsim model"}{...}
6+
{vieweralsosee "survsim msm" "help survsim msm"}{...}
7+
{vieweralsosee "merlin" "help merlin"}{...}
8+
{vieweralsosee "galahad" "help galahad"}{...}
9+
{title:Title}
10+
11+
{p2colset 5 16 16 2}{...}
12+
{p2col :{cmd:survsim} {hline 2}}Simulate survival data from a parametric distribution,
13+
a user-defined distribution, from a fitted {helpb merlin} model, from a cause-specific
14+
hazards competing risks model, or from a general multi-state model{p_end}
15+
{p2colreset}{...}
16+
17+
18+
{title:Description}
19+
20+
{pstd}
21+
{cmd:survsim} simulates survival data from:
22+
{p_end}
23+
24+
{phang2}
25+
{helpb survsim parametric:help survsim parametric} - a parametric distribution including the exponential, Gompertz and Weibull,
26+
and 2-component mixtures of them. Baseline covariates can be included, with specified associated log hazard ratios.
27+
Non-proportional hazards can also be included with all models; under an exponential or Weibull model covariates are interacted
28+
with log time, under a Gompertz model covariates are interacted with time. See {helpb survsim##paper1:Crowther and Lambert (2012)}
29+
for more details.
30+
{p_end}
31+
32+
{phang2}
33+
{helpb survsim user:help survsim user} - a user-defined distribution. Survival times can be simulated from bespoke,
34+
user-defined [log] [cumulative] hazard functions. The function must be specified in Mata code (using colon operators),
35+
with survival times generated using a combination of numerical integration and root finding techniques. Time-dependent
36+
effects can also be specified with a user-defined function of time. See {helpb survsim##paper2:Crowther and Lambert (2013)}
37+
for more details.
38+
{p_end}
39+
40+
{phang2}
41+
{helpb survsim model:help survsim model} - a fitted {helpb merlin} model. {helpb merlin} fits a broad class of survival models,
42+
including standard parametric models, spline-based survival models, and user-defined survival models.
43+
{p_end}
44+
45+
{phang2}
46+
{helpb survsim msm:help survsim msm} - a competing risks or general multi-state model. Event times can be simulated from
47+
transition-specific hazards, where each transition hazard function can be a standard parametric distribution, or a
48+
user-defined complex hazard function. Covariates and time-dependent effects can be specified for each transition-specific
49+
hazard independently.
50+
{p_end}
51+
52+
53+
{title:Author}
54+
55+
{pstd}{cmd:Michael J. Crowther}{p_end}
56+
{pstd}Red Door Analytics{p_end}
57+
{pstd}E-mail: {browse "mailto:[email protected]":[email protected]}{p_end}
58+
59+
{phang}Please report any errors you may find.{p_end}
60+
61+
62+
{title:References}
63+
64+
{phang}Bender R, Augustin T and Blettner M. Generating survival times to simulate Cox proportional hazards models. {it:Statistics in Medicine} 2005;24:1713-1723.{p_end}
65+
66+
{phang}Beyersmann J, Latouche A, Buchholz A and Schumacher M. Simulating competing risks data in survival analysis. {it:Statistics in Medicine} 2009;28:956-971.{p_end}
67+
68+
{marker paper1}{...}
69+
{phang}Crowther MJ and Lambert PC. {browse "http://www.stata-journal.com/article.html?article=st0275":Simulating complex survival data.}{it: The Stata Journal} 2012;12(4):674-687.{p_end}
70+
71+
{marker paper2}{...}
72+
{phang}Crowther MJ and Lambert PC. {browse "http://onlinelibrary.wiley.com/doi/10.1002/sim.5823/abstract":Simulating biologically plausible complex survival data.} {it:Statistics in Medicine} 2013;32(23):4118-4134.{p_end}
73+
74+
{phang}Jann, B. 2005. moremata: Stata module (Mata) to provide various functions. Available from http://ideas.repec.org/c/boc/bocode/s455001.html.{p_end}
75+

ssc/version_4_0_8/survsim_details.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
TITLE: `SURVSIM' : module to simulate survival/time-to-event data
2+
3+
DESCRIPTION/AUTHOR: survsim simulates survival data from a parametric distribution,
4+
a user-defined distribution, a cause-specific hazards competing risks model, a general
5+
multi-state model, or from an estimated -merlin- model. Baseline covariates and
6+
time-dependent effects can be specified when defining a data-generating model.
7+
Delayed entry/left truncation is allowed.
8+
9+
Author: Michael J. Crowther, Red Door Analytics
10+
Support: email [email protected]
11+
12+
Requires: Stata version 14.2

ssc/version_4_0_8/survsim_model.ado

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
program define survsim_model
3+
version 14.2
4+
5+
syntax newvarname(min=1 max=2), ///
6+
///
7+
Model(string) ///
8+
MAXTime(string) /// -Maximum simulated time-
9+
//
10+
11+
local nvars : word count `varlist'
12+
local stime : word 1 of `varlist'
13+
local event : word 2 of `varlist'
14+
15+
cap which merlin
16+
if _rc {
17+
display in yellow "You need to install the merlin package. This can be installed using,"
18+
display in yellow ". {stata ssc install merlin}"
19+
exit 198
20+
}
21+
cap which predictms
22+
if _rc {
23+
display in yellow "You need to install the multistate package. This can be installed using,"
24+
display in yellow ". {stata ssc install multistate}"
25+
exit 198
26+
}
27+
28+
//====================================================================================================================//
29+
30+
quietly {
31+
32+
qui gen double `stime' = .
33+
cap drop _survsim_rc
34+
qui gen _survsim_rc = 0
35+
tempvar modtouse
36+
gen byte `modtouse' = 1
37+
local N = _N
38+
39+
//make sure right censoring handled
40+
//-> gets replaced if less than row specific maxtime() afterwards
41+
tempvar tvar
42+
su `maxtime'
43+
gen `tvar' = `r(max)' in 1
44+
45+
predictms , models(`model') ///
46+
singleevent ///
47+
survsim(`stime') ///
48+
survsimtouse(`modtouse') ///
49+
n(`N') ///
50+
timevar(`tvar') ///
51+
probability ///
52+
simulate //
53+
54+
}
55+
56+
end

ssc/version_4_0_8/survsim_model.sthlp

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
{smcl}
2+
{* *! version 1.0.0}{...}
3+
{vieweralsosee "survsim" "help survsim"}{...}
4+
{vieweralsosee "survsim parametric" "help survsim parametric"}{...}
5+
{vieweralsosee "survsim user" "help survsim user"}{...}
6+
{vieweralsosee "survsim msm" "help survsim msm"}{...}
7+
{vieweralsosee "merlin" "help merlin"}{...}
8+
{vieweralsosee "galahad" "help galahad"}{...}
9+
{viewerjumpto "Syntax" "survsim model##syntax"}{...}
10+
{viewerjumpto "Description" "survsim model##description"}{...}
11+
{viewerjumpto "Options" "survsim model##options"}{...}
12+
{viewerjumpto "Examples" "survsim model##examples"}{...}
13+
{title:Title}
14+
15+
{p2colset 5 16 16 2}{...}
16+
{p2col :{cmd:survsim} {hline 2}}Simulate survival data from a parametric distribution,
17+
a user-defined distribution, from a fitted {helpb merlin} model, from a cause-specific
18+
hazards competing risks model, or from a general multi-state model{p_end}
19+
{p2colreset}{...}
20+
21+
22+
{marker syntax}{...}
23+
{title:Syntax}
24+
25+
{phang}
26+
Syntax for simulating survival times from a fitted {helpb merlin} survival model:
27+
28+
{phang2}
29+
{cmd: survsim} {it:newvarname1} {it:newvarname2} {cmd:,} {opt mod:el(name)} {opt maxt:ime(#|varname)}
30+
31+
32+
{synoptset 36 tabbed}{...}
33+
{synopthdr:Options}
34+
{synoptline}
35+
{synopt:{opt mod:el(name)}}the {helpb estimates store} {it:name} of the fitted {helpb merlin} model; see details{p_end}
36+
{synopt:{opt maxt:ime(#|varname)}}right censoring time(s); either a common number or a {varname}{p_end}
37+
{synoptline}
38+
{p2colreset}{...}
39+
40+
41+
{marker description}{...}
42+
{title:Description}
43+
44+
{pstd}
45+
{helpb survsim} simulates survival data from a parametric distribution, a user-defined distribution, from a fitted
46+
{helpb merlin} model, from a cause-specific hazards competing risks model, or from a Markov multi-state model.
47+
This help file centres on simulating from a fitted {helpb merlin} model.
48+
{p_end}
49+
{pstd}
50+
Survival times can be simulated from the estimated model, using the variables in your current dataset. The variables can simply
51+
be altered, to provide a flexible framework to simulate using the estimated parameter vector.
52+
{p_end}
53+
54+
{pstd}
55+
{it:newvarname1} specifies the new variable name to contain the generated survival times. {it:newvarname2} specifies the
56+
new variable name to contain the generated event indicator.
57+
{p_end}
58+
59+
60+
{marker options}{...}
61+
{title:Options}
62+
63+
{phang}{opt model(name)} specifies the name of the {helpb estimates store} object containing the estimates of the model
64+
fitted. The survival must be estimated using the {helpb merlin} command. For example,{p_end}
65+
66+
{phang2}{cmd:. merlin (_t trt , family(weibull, failure(_d)))}{p_end}
67+
{phang2}{cmd:. estimates store m1}{p_end}
68+
{phang2}{cmd:. survsim stime died, model(m1) maxtime(10)}{p_end}
69+
70+
{phang2}{cmd:survsim} will simulate from the fitted model, using covariate values that are in your current dataset.{p_end}
71+
72+
{phang}{opt maxtime(#|varname)} specifies the right censoring time(s). Either a common maximum follow-up time {cmd:#} can be
73+
specified for all observations, or observation specific censoring times can be specified by using a {varname}. {p_end}
74+
75+
76+
{title:Remarks}
77+
78+
{pstd}Always {helpb set seed}, to ensure reproducibility.{p_end}
79+
80+
81+
{marker examples}{...}
82+
{title:Examples}
83+
84+
{phang}Simulate from a fitted Weibull survival model:{p_end}
85+
{phang2}{cmd:. webuse brcancer}{p_end}
86+
{phang2}{cmd:. stset rectime, failure(censrec) scale(365)}{p_end}
87+
{phang2}{cmd:. merlin (_t hormon , family(weibull, failure(_d)))}{p_end}
88+
{phang2}{cmd:. estimates store m1}{p_end}
89+
{phang2}{cmd:. survsim stime died, model(m1) maxtime(10)}{p_end}
90+
91+
{phang}Simulate from a fitted Royston-Parmar spline-based survival model:{p_end}
92+
{phang2}{cmd:. webuse brcancer}{p_end}
93+
{phang2}{cmd:. stset rectime, failure(censrec) scale(365)}{p_end}
94+
{phang2}{cmd:. merlin (_t hormon , family(rp, failure(_d) df(3)))}{p_end}
95+
{phang2}{cmd:. estimates store m2}{p_end}
96+
{phang2}{cmd:. survsim stime died, model(m2) maxtime(10)}{p_end}
97+
98+
99+
{title:Author}
100+
101+
{pstd}{cmd:Michael J. Crowther}{p_end}
102+
{pstd}Red Door Analytics{p_end}
103+
{pstd}E-mail: {browse "mailto:[email protected]":[email protected]}{p_end}
104+
105+
{phang}Please report any errors you may find.{p_end}
106+
107+
108+
{title:References}
109+
110+
{phang}Bender R, Augustin T and Blettner M. Generating survival times to simulate Cox proportional hazards models. {it:Statistics in Medicine} 2005;24:1713-1723.{p_end}
111+
112+
{marker paper1}{...}
113+
{phang}Crowther MJ and Lambert PC. {browse "http://www.stata-journal.com/article.html?article=st0275":Simulating complex survival data.}{it: The Stata Journal} 2012;12(4):674-687.{p_end}
114+
115+
{marker paper2}{...}
116+
{phang}Crowther MJ and Lambert PC. {browse "http://onlinelibrary.wiley.com/doi/10.1002/sim.5823/abstract":Simulating biologically plausible complex survival data.} {it:Statistics in Medicine} 2013;32(23):4118-4134.{p_end}
117+
118+
{phang}Jann, B. 2005. moremata: Stata module (Mata) to provide various functions. Available from http://ideas.repec.org/c/boc/bocode/s455001.html.{p_end}
119+

0 commit comments

Comments
 (0)