I am trying to follow along with a scientific journal. I am not used to running simulations so I could use a little help in R.

Here is the simulation from the paper.

For each experiment, we generate a training, validation, and testing set of N = 5000 observations, such that an observation represents a patient vector with d = 10 covariates, each drawn from a uniform distribution on [􀀀1; 1). We generate the death time T according to an exponential Cox model:

$T\sim Exp(\lambda(t;x))=Exp(\lambda_0\cdot e^{-h(x)})$

In both experiments, the risk function h(x) only depends on two of the ten covariates, and we demonstrate that DeepSurv is able to discern the relevant covariates from the noise. We then choose a censoring time to represent the ‘end of study,’ such that an average of 30-40 percent of the patients have an observed event in the dataset.

We first simulate patients to have a linear risk function for $x \in > R^{d}$ so that the linear proportional hazards assumption holds true:


Because the linear proportional hazards assumption holds true, we expect the linear CPH to accurately model the risk function 1

[1] Jared L. Katzman1, (2016), 'Deep Survival: A Deep Cox Proportional Hazards Network', arxiv.

This is what I have so far


#50,000 random uniforms
obs <- runif(50000,min = -1, max = .999)

#make uniforms a matrix
obs <- matrix(data = obs, nrow = 5000, ncol = 10)

is_censored <- sample(0:1,5000,TRUE,prob=c(0.40,0.60))

#time ??

I have the random uniform 5000x10 matrix and the column that will indicate censoring. I still need the time till death column which is where I am getting stuck. I am not sure how to pull $T$ from the distribution they specified and how to simulate the dependence of the first two covariates $h(x)=x_0+2x_1$

  • $\begingroup$ To state my question more clearly: 1. How to I get the column that represents the time to death. 2. How do I simulate the dependance structure of the risk function. $\endgroup$
    – Alex
    Commented Mar 17, 2017 at 15:49

1 Answer 1


I was able to find a partial answer. The survsim package in R provides a way to model survival times1.

I am still unable to figure out how to simulate dependance between two covariates.

[1]The R Package survsim for the Simulation of Simple and Complex Survival Data


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.