# How to simulate right-censored Weibull PH survival times with time-varying covariate?

I am trying to simulate data coming from a joint model of longitudinal and survival data. Basically, my thought process is this.

1. I need to define a maximum follow-up time, F.
2. I need to define coefficients ($$\boldsymbol{\beta}$$, $$\sigma_t$$,generate X from some distribution, W from some distributions and define $$\alpha$$ and $$\gamma$$)
3. I need to use the max follow-up time to solve for integrals using the uniroot function.

For each individual i, I generate survival probabilities from the uniform distribution. $$$$\label{eq:uniroot1} S(t|W, X) \sim U(0,1)$$$$

For each individual, I am trying to solve: $$$$\int_0^F h(u|\textbf{W}, m_i(u)) \partial u + \log U(0,1) = 0$$$$ where I define here $$\textbf{W}$$ are baseline covariates and $$m_i(u)$$ is the time-varying covariate that is essentially "longitudinal marker" without the error term defined as follows: $$$$y_i(t) = m_i(t) + \epsilon_i(t) \\ m_i(t) = (\beta_0 + b_{i0}) + (\beta_1 + b_{i1})t + (\beta_2 X_{2i}) + \beta_3X_{2i}t \\$$$$

And the form of the Weibull PH is as follows:

$$$$\label{eq:weibullPH} (\sigma_t \exp(\alpha m_i(t) +\boldsymbol{\gamma}^T\textbf{W}_i))t^{\sigma_t-1}\\$$$$

Once I solve this equation, I can just generate C from Uniform(0, Max.FollowUpTime)to perform uniform censoring.

My questions are:

A. Does this seem like the right way to get survival times?

B. How do I define the maximum follow-up time such that it is a reasonable upper bound survival time for the values I defined in point 2.

Thank you for any pointers!

Question A. Although I haven't compared every detail, it looks like your approach is the same as that used by the R simsurv package. See the vignette on the technical background to the package, and the section of a vignette dealing specifically with joint modeling. I don't know that you need to define a maximum follow-up time, but that's certainly allowed for. My sense is that the numerical methods used by the package avoids some of the problems with evaluating the cumulative hazard out to long times, but I don't have experience with that.