***************** Background ***************** This addresses two main points, how to specify a model for the library using distributions defined by hazards and why such a specification, with its initial conditions, is sufficient to define the trajectory for a model. The Hazard from Survival Analysis ================================== Discrete case ---------------- The discrete case is much easier to understand than the continuous case because it can be explained without employing any results from calculus. Throughout this section, :math:`\bf{X}` will be assumed to real-valued random variable. For example, :math:`\bf{X}` could represent latent periods for measles. It frequently happens that random samples of the real valued variables such as :math:`\bf{X}` are actually analyzed on a discrete scale. For example Stocks' data on latent periods of measles in :ref:`latent_period` is based on daily visits by patients. The (cumulative) distribution of :math:`\bf{X}` is defined as .. math:: F_{X}(k) = \mathcal{P}[x \le k] assuming :math:`F_{X}(\infty) = 1`. The density can be expressed as the difference in adjacent values of the distribution .. math:: :nowrap: \begin{eqnarray} f_{X}(k) & = & \mathcal{P}[X=k] \\ & = & \mathcal{P}[X\le k] - \mathcal{P}[X \le k-1 ] \\ & = & F_{X}(k) - F_{X}(k-1) \end{eqnarray} For Stocks' data in :ref:`latent_period`, the density at day :math:`k` should be interpreted as the probability of the appearance of symptoms since the previous visit on day :math:`k-1`. The *hazard* is defined as the conditional probability that the value of a random selection from :math:`\bf{X}` equals :math:`k` given it this value is already known to exceed :math:`k-1`. Using the usual rules for computing conditional probabilities, the hazard is given by the following ratio .. math:: \begin{eqnarray} h_{X}(k) & = & \mathcal{P}[X=k\; |\; k-1 0`. Stochastic processes with shift invariant state transition probabilities are called *stationary*. When we examined hazard rates above, we were examining the rate of transitions for a Markov process. The overall probability of the next state of the Markov process is called the core matrix, .. math:: \mathcal{P}[Z_{t} | Z_{s} ]=Q_{ij}(t_{n+1}-t_n) indicating a state change between the states :math:`(s_i,s_j)`. The derivative of this is a rate, .. math:: q_{ij}(t_{n+1}-t_n)=\frac{dQ_{ij}(t_{n+1}-t_n)}{dt}, which is a joint distribution over states and time intervals. Normalization for this quantity sums over possible states and future times, .. math:: 1=\int_0^\infty \sum_j q_{ij}(s)ds. The survival, in terms of the core matrix, is .. math:: G_i(\tau)=1-\int_0^\tau \sum_k q_{ik}(s)ds. This means our hazard is .. math:: \lambda_{ij}(\tau)=\frac{q_{ij}(\tau)}{1-\int_0^\tau \sum_k q_{ik}(s)ds}. For the measles example, the set of future states :math:`j` of each individual include symptomatic and all the possible other ways an individual leaves the study, so you can think of :math:`j=\mbox{left town}`. In practice, we build a hazard in two steps. First, count the probability over all time for any one eventual state :math:`j`. This is the same stochastic probability :math:`\pi_{ij}` that is seen in Markov chains. Second, measure the distribution of times at which intervals enter each new state :math:`j`, given that they are headed to that state. This is called the holding time, :math:`h_{ij}(\tau)`, and is a conditional probability. Together, these two give us the core matrix, .. math:: q_{ij}(\tau)=\pi_{ij}h_{ij}(\tau). Note that :math:`h_{ij}(\tau)` is a density whose integral :math:`H_{ij}(\tau)` is a cumulative distribution. If we write the same equation in terms of probabilities, we see that it amounts to separating the Markov process into a marginal and conditional distribution. .. math:: \begin{eqnarray} q_{ij}(\tau)&=&\frac{d}{d\tau}P[Z_t|Z_s]\\ &=&\frac{d}{d\tau}P[s_j|s_i,t_n]P[t_{n-1}-t_n\le\tau|s_i,s_j,t_n]\\ & = & P[s_j|s_i,t_n]\frac{d}{d\tau}P[t_{n-1}-t_n\le\tau|s_i,s_j,t_n] \\ & = & \pi_{ij}\frac{d}{d\tau}H_{ij}(\tau) \\ & = & \pi_{ij}h_{ij}(\tau) \end{eqnarray} Choosing the other option for the marginal gives us the waiting time formulation for the core matrix. It corresponds to asking first what is the distribution of times at which the next event happens, no matter which event, and then asking which events are more likely given the time of the event. .. math:: \begin{eqnarray} q_{ij}(\tau)&=&\frac{d}{d\tau}P[Z_t|Z_s]\\ &=&\frac{d}{d\tau}P[s_j|s_i,t_n,t_{n+1}]P[t_{n-1}-t_n\le\tau|s_i,t_n]\\ & = & \frac{d}{d\tau}(\Pi_{ij}(\tau)W_i(\tau)) \\ & = & \pi_{ij}(\tau)\frac{d}{d\tau}W_i(\tau) \\ & = & \pi_{ij}(\tau)w_{i}(\tau) \end{eqnarray} While the waiting time density :math:`w_i(\tau)`, is the derivative of the waiting time, we won't end up needing to relation :math:`\pi_{ij}(\tau)` to :math:`\Pi_{ij}(\tau)` when finding trajectories or computing hazards, so the more complicated relationship won't be a problem.