# AFT models in Stata with time-varying covariates

The AFT models from Stata's streg can handle time-varying covaraites. In particular, the manual states that

streg is suitable only for data that have been stset. By stsetting your data, you define the variables _t0, _t, and _d, which serve as the trivariate response variable $$(t_0, t, d)$$. Each response corresponds to a period under observation, $$(t_0, t]$$, resulting in either failure $$(d = 1)$$ or right-censoring $$(d = 0)$$ at time $$t$$. As a result, streg is appropriate for data exhibiting delayed entry, gaps, time-varying covariates, and even multiple-failure data.

The question is how this actually works? Suppose that I use a log-normal distribution. Then the density and survival function without time-varying covariates is

\begin{align*} f(t\mid \vec x)&= \frac 1{t\sigma\sqrt{2\pi}}\exp\left(- \frac{(\log t - \vec x^\top\vec\beta)^2}{2\sigma^2}\right) \\ S(t \mid \vec x) &= 1 - \Phi\left( \frac{\log t - \vec x^\top\vec\beta}{\sigma} \right) \end{align*}

and the hazard is given by $$\lambda (t\mid\vec x) = f(t\mid\vec x)S(t \mid \vec x)^{-1}$$. This is fairly easy to interpret as it states that $$\log T \mid \vec x$$ is normally distributed with mean $$\vec x^\top\vec\beta$$ and variance $$\sigma^2$$.

What I presume that what streg does is the following: Suppose that $$\vec x(t)$$ is the time-varying covariates which is modeled as having jumps as is typical. Then the assumptions is the the hazards is given by $$\lambda (t\mid\vec x(t)) = f(t\mid\vec x(t))S(t \mid \vec x(t))^{-1}$$. Is this correct? If not, how does streg handle the time-varying covariates?

Given EdM's answer, the model is in counting process setup like I state above. Thus, suppose that we look at left-truncation time $$t_i$$ with covariate $$\vec x_i$$. Let

$$D(t, \vec x) = \Phi\left( \frac{\log t - \vec x^\top\vec\beta}{\sigma} \right)$$

Then the density, CDF, and survival function are:

\begin{align*} f(t\mid\vec x_i, t_i) &= \begin{cases} \frac{f(t\mid \vec x_i)}{S(t_i \mid \vec x_i)} & t \geq t_i \\ 0 & t < t_i \end{cases} \\ F(t \mid \vec x_i, t_i) &= \begin{cases} \frac{D(t, \vec x_i) - D(t_i, \vec x_i)}{S(t_i \mid \vec x_i)} & t \geq t_i \\ 0 & t < t_i \end{cases} \\ &= \begin{cases} \frac{D(t, \vec x_i) - D(t_i, \vec x_i)}{1 - D(t_i, \vec x_i)} & t \geq t_i \\ 0 & t < t_i \end{cases} \\ S(t\mid\vec x_i, t_i) &= 1 - F(t \mid \vec x_i, t_i) = \begin{cases} \frac{1 - D(t, \vec x_i)}{1 - D(t_i, \vec x_i)} & t \geq t_i \\ 1 & t < t_i \end{cases} \\ &= \begin{cases} \frac{S(t, \vec x_i)}{S(t_i, \vec x_i)} & t \geq t_i \\ 1 & t < t_i \end{cases} \end{align*}

Thus, the hazard is

$$\lambda(t\mid \vec x_i, t_i) = \frac{f(t\mid\vec x_i, t_i)}{S(t\mid\vec x_i, t_i)} = \frac{f(t\mid\vec x_i)}{S(t\mid\vec x_i)} = \lambda(t \mid \vec x_i)$$

as I stated in my question.

The distribution of the survival time is not that obvious I guess but I figure that it is best expressed in terms of the hazards. In particular, suppose that covariates are given by:

$$\vec x(t) = \begin{cases} \vec x_1 & t < t_1 \\ \vec x_2 & t_1 \leq t < t_2 \\ \vdots & \vdots \\ \vec x_k & t_{k - 1} \leq t < t_k \end{cases}$$

for some $$k \geq 1$$. Then the hazard is

$$\lambda(t \mid \vec x(t)) = \begin{cases} \lambda(t\mid \vec x_1) & t < t_1 \\ \lambda(t\mid \vec x_2) & t_1 \leq t < t_2 \\ \vdots & \vdots \\ \lambda(t\mid \vec x_k) & t_{k - 1} \leq t < t_k \end{cases}$$

In the data format you describe (also called "counting process" format), an observation is considered left-truncated at $$t_0$$ (no information until after that time).

Your formula is the definition of the instantaneous hazard, given covariate values. Technically, the software to solve a parametric AFT model finds parameter values that maximize the likelihood of the data (covariate values and event times).

For a case left-truncated at $$t_0$$ having an event at $$t$$, the contribution to likelihood is proportional to $$f(t)/S(t_0)$$, with $$f(t)$$ and $$S(t_0)$$ determined for the corresponding covariate values.* That's the classic parametric modeling approach (which I assume Stata implements).

*This page summarizes the likelihood expressions for combinations of events and left or right censorings and truncations.

• Thank you for your answer. Of course, the observations must be handled as left-truncated! This answered my questions assuming that this is correct (see the updated question). A few remarks: I does really matter how I express the model (hazard, survival function, density, etc.). Ultimately, I can derive the likelihood I need from any of them. The likelihood is only proportional to $f(t)/S(t_0)$ if there is an event. Commented Jul 3, 2021 at 9:17
• Oh right, you do state that:" For a case left-truncated at $t_0$ having an event at $t$, ..." Commented Jul 3, 2021 at 9:21