-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e29e797
commit 309ea08
Showing
13 changed files
with
2,976 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{smcl} | ||
{* *! version 1.0.0}{...} | ||
{vieweralsosee "survsim parametric" "help survsim parametric"}{...} | ||
{vieweralsosee "survsim user" "help survsim user"}{...} | ||
{vieweralsosee "survsim model" "help survsim model"}{...} | ||
{vieweralsosee "survsim msm" "help survsim msm"}{...} | ||
{vieweralsosee "merlin" "help merlin"}{...} | ||
{vieweralsosee "galahad" "help galahad"}{...} | ||
{title:Title} | ||
|
||
{p2colset 5 16 16 2}{...} | ||
{p2col :{cmd:survsim} {hline 2}}Simulate survival data from a parametric distribution, | ||
a user-defined distribution, from a fitted {helpb merlin} model, from a cause-specific | ||
hazards competing risks model, or from a general multi-state model{p_end} | ||
{p2colreset}{...} | ||
|
||
|
||
{title:Description} | ||
|
||
{pstd} | ||
{cmd:survsim} simulates survival data from: | ||
{p_end} | ||
|
||
{phang2} | ||
{helpb survsim parametric:help survsim parametric} - a parametric distribution including the exponential, Gompertz and Weibull, | ||
and 2-component mixtures of them. Baseline covariates can be included, with specified associated log hazard ratios. | ||
Non-proportional hazards can also be included with all models; under an exponential or Weibull model covariates are interacted | ||
with log time, under a Gompertz model covariates are interacted with time. See {helpb survsim##paper1:Crowther and Lambert (2012)} | ||
for more details. | ||
{p_end} | ||
|
||
{phang2} | ||
{helpb survsim user:help survsim user} - a user-defined distribution. Survival times can be simulated from bespoke, | ||
user-defined [log] [cumulative] hazard functions. The function must be specified in Mata code (using colon operators), | ||
with survival times generated using a combination of numerical integration and root finding techniques. Time-dependent | ||
effects can also be specified with a user-defined function of time. See {helpb survsim##paper2:Crowther and Lambert (2013)} | ||
for more details. | ||
{p_end} | ||
|
||
{phang2} | ||
{helpb survsim model:help survsim model} - a fitted {helpb merlin} model. {helpb merlin} fits a broad class of survival models, | ||
including standard parametric models, spline-based survival models, and user-defined survival models. | ||
{p_end} | ||
|
||
{phang2} | ||
{helpb survsim msm:help survsim msm} - a competing risks or general multi-state model. Event times can be simulated from | ||
transition-specific hazards, where each transition hazard function can be a standard parametric distribution, or a | ||
user-defined complex hazard function. Covariates and time-dependent effects can be specified for each transition-specific | ||
hazard independently. | ||
{p_end} | ||
|
||
|
||
{title:Author} | ||
|
||
{pstd}{cmd:Michael J. Crowther}{p_end} | ||
{pstd}Red Door Analytics{p_end} | ||
{pstd}E-mail: {browse "mailto:[email protected]":[email protected]}{p_end} | ||
|
||
{phang}Please report any errors you may find.{p_end} | ||
|
||
|
||
{title:References} | ||
|
||
{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} | ||
|
||
{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} | ||
|
||
{marker paper1}{...} | ||
{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} | ||
|
||
{marker paper2}{...} | ||
{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} | ||
|
||
{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} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
TITLE: `SURVSIM' : module to simulate survival/time-to-event data | ||
|
||
DESCRIPTION/AUTHOR: survsim simulates survival data from a parametric distribution, | ||
a user-defined distribution, a cause-specific hazards competing risks model, a general | ||
multi-state model, or from an estimated -merlin- model. Baseline covariates and | ||
time-dependent effects can be specified when defining a data-generating model. | ||
Delayed entry/left truncation is allowed. | ||
|
||
Author: Michael J. Crowther, Red Door Analytics | ||
Support: email [email protected] | ||
|
||
Requires: Stata version 14.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
program define survsim_model | ||
version 14.2 | ||
|
||
syntax newvarname(min=1 max=2), /// | ||
/// | ||
Model(string) /// | ||
MAXTime(string) /// -Maximum simulated time- | ||
// | ||
|
||
local nvars : word count `varlist' | ||
local stime : word 1 of `varlist' | ||
local event : word 2 of `varlist' | ||
|
||
cap which merlin | ||
if _rc { | ||
display in yellow "You need to install the merlin package. This can be installed using," | ||
display in yellow ". {stata ssc install merlin}" | ||
exit 198 | ||
} | ||
cap which predictms | ||
if _rc { | ||
display in yellow "You need to install the multistate package. This can be installed using," | ||
display in yellow ". {stata ssc install multistate}" | ||
exit 198 | ||
} | ||
|
||
//====================================================================================================================// | ||
|
||
quietly { | ||
|
||
qui gen double `stime' = . | ||
cap drop _survsim_rc | ||
qui gen _survsim_rc = 0 | ||
tempvar modtouse | ||
gen byte `modtouse' = 1 | ||
local N = _N | ||
|
||
//make sure right censoring handled | ||
//-> gets replaced if less than row specific maxtime() afterwards | ||
tempvar tvar | ||
su `maxtime' | ||
gen `tvar' = `r(max)' in 1 | ||
|
||
predictms , models(`model') /// | ||
singleevent /// | ||
survsim(`stime') /// | ||
survsimtouse(`modtouse') /// | ||
n(`N') /// | ||
timevar(`tvar') /// | ||
probability /// | ||
simulate // | ||
|
||
} | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
{smcl} | ||
{* *! version 1.0.0}{...} | ||
{vieweralsosee "survsim" "help survsim"}{...} | ||
{vieweralsosee "survsim parametric" "help survsim parametric"}{...} | ||
{vieweralsosee "survsim user" "help survsim user"}{...} | ||
{vieweralsosee "survsim msm" "help survsim msm"}{...} | ||
{vieweralsosee "merlin" "help merlin"}{...} | ||
{vieweralsosee "galahad" "help galahad"}{...} | ||
{viewerjumpto "Syntax" "survsim model##syntax"}{...} | ||
{viewerjumpto "Description" "survsim model##description"}{...} | ||
{viewerjumpto "Options" "survsim model##options"}{...} | ||
{viewerjumpto "Examples" "survsim model##examples"}{...} | ||
{title:Title} | ||
|
||
{p2colset 5 16 16 2}{...} | ||
{p2col :{cmd:survsim} {hline 2}}Simulate survival data from a parametric distribution, | ||
a user-defined distribution, from a fitted {helpb merlin} model, from a cause-specific | ||
hazards competing risks model, or from a general multi-state model{p_end} | ||
{p2colreset}{...} | ||
|
||
|
||
{marker syntax}{...} | ||
{title:Syntax} | ||
|
||
{phang} | ||
Syntax for simulating survival times from a fitted {helpb merlin} survival model: | ||
|
||
{phang2} | ||
{cmd: survsim} {it:newvarname1} {it:newvarname2} {cmd:,} {opt mod:el(name)} {opt maxt:ime(#|varname)} | ||
|
||
|
||
{synoptset 36 tabbed}{...} | ||
{synopthdr:Options} | ||
{synoptline} | ||
{synopt:{opt mod:el(name)}}the {helpb estimates store} {it:name} of the fitted {helpb merlin} model; see details{p_end} | ||
{synopt:{opt maxt:ime(#|varname)}}right censoring time(s); either a common number or a {varname}{p_end} | ||
{synoptline} | ||
{p2colreset}{...} | ||
|
||
|
||
{marker description}{...} | ||
{title:Description} | ||
|
||
{pstd} | ||
{helpb survsim} simulates survival data from a parametric distribution, a user-defined distribution, from a fitted | ||
{helpb merlin} model, from a cause-specific hazards competing risks model, or from a Markov multi-state model. | ||
This help file centres on simulating from a fitted {helpb merlin} model. | ||
{p_end} | ||
{pstd} | ||
Survival times can be simulated from the estimated model, using the variables in your current dataset. The variables can simply | ||
be altered, to provide a flexible framework to simulate using the estimated parameter vector. | ||
{p_end} | ||
|
||
{pstd} | ||
{it:newvarname1} specifies the new variable name to contain the generated survival times. {it:newvarname2} specifies the | ||
new variable name to contain the generated event indicator. | ||
{p_end} | ||
|
||
|
||
{marker options}{...} | ||
{title:Options} | ||
|
||
{phang}{opt model(name)} specifies the name of the {helpb estimates store} object containing the estimates of the model | ||
fitted. The survival must be estimated using the {helpb merlin} command. For example,{p_end} | ||
|
||
{phang2}{cmd:. merlin (_t trt , family(weibull, failure(_d)))}{p_end} | ||
{phang2}{cmd:. estimates store m1}{p_end} | ||
{phang2}{cmd:. survsim stime died, model(m1) maxtime(10)}{p_end} | ||
|
||
{phang2}{cmd:survsim} will simulate from the fitted model, using covariate values that are in your current dataset.{p_end} | ||
|
||
{phang}{opt maxtime(#|varname)} specifies the right censoring time(s). Either a common maximum follow-up time {cmd:#} can be | ||
specified for all observations, or observation specific censoring times can be specified by using a {varname}. {p_end} | ||
|
||
|
||
{title:Remarks} | ||
|
||
{pstd}Always {helpb set seed}, to ensure reproducibility.{p_end} | ||
|
||
|
||
{marker examples}{...} | ||
{title:Examples} | ||
|
||
{phang}Simulate from a fitted Weibull survival model:{p_end} | ||
{phang2}{cmd:. webuse brcancer}{p_end} | ||
{phang2}{cmd:. stset rectime, failure(censrec) scale(365)}{p_end} | ||
{phang2}{cmd:. merlin (_t hormon , family(weibull, failure(_d)))}{p_end} | ||
{phang2}{cmd:. estimates store m1}{p_end} | ||
{phang2}{cmd:. survsim stime died, model(m1) maxtime(10)}{p_end} | ||
|
||
{phang}Simulate from a fitted Royston-Parmar spline-based survival model:{p_end} | ||
{phang2}{cmd:. webuse brcancer}{p_end} | ||
{phang2}{cmd:. stset rectime, failure(censrec) scale(365)}{p_end} | ||
{phang2}{cmd:. merlin (_t hormon , family(rp, failure(_d) df(3)))}{p_end} | ||
{phang2}{cmd:. estimates store m2}{p_end} | ||
{phang2}{cmd:. survsim stime died, model(m2) maxtime(10)}{p_end} | ||
|
||
|
||
{title:Author} | ||
|
||
{pstd}{cmd:Michael J. Crowther}{p_end} | ||
{pstd}Red Door Analytics{p_end} | ||
{pstd}E-mail: {browse "mailto:[email protected]":[email protected]}{p_end} | ||
|
||
{phang}Please report any errors you may find.{p_end} | ||
|
||
|
||
{title:References} | ||
|
||
{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} | ||
|
||
{marker paper1}{...} | ||
{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} | ||
|
||
{marker paper2}{...} | ||
{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} | ||
|
||
{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} | ||
|
Oops, something went wrong.