Simulating time to event data with a lagged treatment effect

Hi all,

My post is more of a preamble to before I need to use Stan. I’m currently trying to simulate some time to event data from a Weibull distribution. The trick is that I want to simulate the data when the treatment has some proposed effect on the hazard after a lag time L. I could really use a second pair of eyes to tell me if this makes any sense at all.

Some brief theory when survival time has a Weibull distribution

Suppose that under the placebo condition, survival time follows a Weibull distribution T_0 \sim \textrm{Weibull}(k, \, \lambda) where k>0 and \lambda > 0 are the shape and scale parameters respectively. Let t be the time from randomisation.

Let h_0(t) be the hazard function under the placebo condition. Then for t \geq 0,

\begin{align*} h_0(t) = \frac{k}{\lambda} \left(\frac{t}{\lambda} \right)^{k-1} \end{align*}

Let S_0(t) be the survival function under the placebo condition. Then for t \geq 0,

\begin{align*} S_0(t) = \exp\left[- \int_{0}^{t} h_0 (u) du \right] = \exp\left[{-\left(\frac{t}{\lambda} \right)^{k}}\right] \end{align*}

Let H_0(t) be the cumulative hazard function under the placebo condition. Then for t \geq 0,

\begin{align*} H_0(t) = \int_{0}^{t} h_0 (u) du = -\ln{[S_0(t)]} \end{align*}

Delayed treatment effect

Suppose that the treatment exerts its effect by scaling the hazard function by \theta < 1 (on the hazard ratio scale) after a lag period L from randomisation.

h_1(t) = \begin{cases} h_0(t), & 0 \leq t < L \\ \theta \, h_0(t), & L \leq t \end{cases}

The survival function under treatment S_1(t) is then:

\begin{align*} S_1(t) &= \exp \left[-\int_{0}^{t} h_1(u) du \right] \\ &= \begin{cases} S_0(t), & 0 \leq t < L \\ \exp{\left[-\left(H_0(L) + \int_{L}^{t} h_1(u)du \right) \right]}, & L \leq t \end{cases} \\ &= \begin{cases} S_0(t), & 0 \leq t < L \\ \exp{\left[-\left(H_0(L) + \theta H_0(t) - \theta H_0(L) \right) \right]}, & L \leq t \end{cases} \\ &= \begin{cases} S_0(t), & 0 \leq t < L \\ \exp{\left[-\left( \theta H_0(t) + (1-\theta)H_0(L) \right) \right]}, & L \leq t \end{cases} \\ &= \begin{cases} S_0(t), & 0 \leq t < L \\ \exp{\left[\theta\ln S_0(t) + (1-\theta)\ln S_0(L) \right]}, & L \leq t \end{cases} \\ &= \begin{cases} S_0(t), & 0 \leq t < L \\ \left[S_0(t)\right]^{\theta} \, \left[S_0(L)\right]^{1-\theta}, & L \leq t \end{cases} \end{align*}

Proposed idea

With the closed form equation to S_1(t), I can generate a random survival time by generating a random uniform random variable u from a \textrm{Unif}(0, 1). Solve for the particular value of t^{*} that satisfies:

u = 1 - S_1(t^{*})

i.e. the method of inverse transform sampling.

# u is a random variate from the uniform U(0,1)
# shape is the weibull shape parameter
# scale is the weibull scale parameter
# lag is the lag period after which the hazard will be scaled. Defaults to 0
# hr is the scaling factor on the hazard function. Defaults to 1
rweibull.delayed <- function(u, shape, scale, lag=0, hr=1) {
  
  # u could be a vector
  
  # First check if F^-1 (u) = t < lag
  # If it is, then return this t
  t = qweibull(u, scale=scale, shape=shape, lower.tail = T)
  
  # If more than lag, return a t from the part of the survival function that has been modified by the scaled hazard
  t = ifelse(t > lag, 
             (uniroot(function(x) 1 - (pweibull(x, shape=shape, scale=scale, lower.tail = F)^hr) * (pweibull(lag, shape=shape, scale=scale, lower.tail = F)^(1-hr)) - u,
                    c(0, 1e9), tol = 0.00001))$root,
             t)
  
  return(t)
  
}
1 Like

Sorry this didn’t get answered sooner.

This is unlikely to be actually true, so it’s more of a supposition that a Weibull distribution will be a reasonable approximation, which is something that should be tested, not assumed.

Are you sure there’s really a discrete change point like this? If so, the best thing to do is model it. Rather than using a fixed hazard function, let the hazard function change.

This looks like it still has integrals inside of it. Assuming you can solve them, then what you’re proposing makes sense.

You could try a shifted lognormal as that contains the lag you want to model explicitly