How could I generate time-to-event data from a piecewise exponential model with a binary covariate in R? Could someone point me to some R packages and/or walk through how to code this from scratch?
Asked
Active
Viewed 34 times
0
-
This seems to be more of a coding question than a stats question. To be clear, are you asking for how to create simulated data? If so, you could write the density function piecewise, find its cumulative density function (CDF) then take the CDF uniform probability random variate (on [0,1]) inverse. What language you do that in is irrelevant. – Carl Dec 21 '23 at 04:29
-
Sorry, to be clear, I do need help with the statistical part (I am new to simulating data) as well as the coding part. Thanks for the response. – Learner Dec 21 '23 at 04:42
-
OK, if the CDF inverse is unknown, one can use a "find the root" routine to backtrack from a random uniform probability to find the CDF realization, and repeat that many times to build up a dataset. It is fast enough to do it that way even for rather messy density functions. – Carl Dec 21 '23 at 05:14
-
The question for which this is identified as a duplicate has links to more details about coding issues, a link to an R package designed for simulating survival data, and a link to further pages on this site about this subject. It seems a bit strange to want to simulate from a piecewise exponential, but this method will apply. With a proportional hazards assumption underlying the (piecewise) exponential model and only a binary covariate, you only have two hazard functions to deal with. You might also need to deal with censoring, depending on your purpose in simulation. – EdM Dec 21 '23 at 16:10
-
If the other page and its links still leave you with a statistical as opposed to a coding question, consider asking that specific question as a new question on this site. – EdM Dec 21 '23 at 16:12
-
@Edm The exponential distribution is the only distribution to have a constant failure rate. – Carl Jan 29 '24 at 01:12