Skip to content

Commit

Permalink
remove spare lines of code
Browse files Browse the repository at this point in the history
  • Loading branch information
seabbs committed Oct 4, 2024
1 parent 7180ddc commit d09c143
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
17 changes: 6 additions & 11 deletions vignettes/analytic-solutions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ $$
\int_t^{t+w_P} f_T(z) z~ dz (\#eq:partexp)
$$

can be reduced to an analytic expression.
can be reduced to an analytic expression.

The insight here is that this will be possible for any distribution where the average of the distribution can be calculated analytically, which includes commonly used non-negative distributions such as the Gamma, Log-Normal and Weibull distributions.

Expand Down Expand Up @@ -118,10 +118,8 @@ $$
By substituting equation \@ref(eq:gammapartexp) into equation \@ref(eq:disccensunifprim) we can solve for the survival function of $S_+$ in terms of analytically available functions:

$$
\begin{aligned}
Q_{S_+}(t; k, \theta) &= Q_T(t + w_P; k, \theta) + { 1 \over w_P} \left( {1 \over \Gamma(k) \theta^k} \int_t^{t+w_P} z^{k-1} \exp(-z/\theta) (z-t)~ dz \right), \\
&= Q_T(t + w_P; k, \theta) + { 1 \over w_P} \big[ k \theta \Delta_{w_P}F_T(t; k+1, \theta) - t \Delta_{w_P}F_T(t; k, \theta) \big].
\end{aligned} (\#eq:survgammaunifprim)
Q_{S_+}(t; k, \theta) = Q_T(t + w_P; k, \theta) + { 1 \over w_P} \big[ k \theta \Delta_{w_P}F_T(t; k+1, \theta) - t \Delta_{w_P}F_T(t; k, \theta) \big].
(\#eq:survgammaunifprim)
$$

**Gamma discrete censored delay distribution**
Expand Down Expand Up @@ -176,10 +174,7 @@ $$
By substituting equation \@ref(eq:lognormpartexp) into equation \@ref(eq:disccensunifprim) we can solve for the survival function of $S_+$ in terms of analytically available functions:

$$
\begin{aligned}
Q_{S+}(t ;\mu, \sigma) &= Q_T(t + w_P;\mu, \sigma) + { 1 \over w_P} \int_t^{t+w_P} {1 \over z \sigma \sqrt{2\pi}} \exp\left( - {(\log(z) - \mu)^2 \over 2 \sigma^2} \right) (z-t)~ dz, \\
&= Q_T(t + w_P;\mu, \sigma) + { 1 \over w_P} \Big[ e^{\mu + \frac{1}{2} \sigma^2} \Delta_{w_P}F_T(t; \mu + \sigma^2, \sigma) - t\Delta_{w_P}F_T(t; \mu, \sigma) \Big]
\end{aligned}
Q_{S+}(t ;\mu, \sigma) = Q_T(t + w_P;\mu, \sigma) + { 1 \over w_P} \Big[ e^{\mu + \frac{1}{2} \sigma^2} \Delta_{w_P}F_T(t; \mu + \sigma^2, \sigma) - t\Delta_{w_P}F_T(t; \mu, \sigma) \Big]
$$

**Log-Normal discrete censored delay distribution**
Expand Down Expand Up @@ -233,11 +228,11 @@ $$
\end{aligned} (\#eq:weibullpartexp)
$$

Where
Where

$$
g(t; \lambda, k) = \gamma(1 + 1/k, (t/\lambda)^k) = \frac{1}{k}\gamma(1/k, (t/\lambda)^k) - \frac{t}{\lambda}e^{-(t/\lambda)^k}.
$$
$$
is a reparametrisation of the lower incomplete gamma function.

**Survival function of $S_{+}$ for Weibull distribution**
Expand Down
8 changes: 2 additions & 6 deletions vignettes/why-it-works.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Note that in ["Getting started"](primarycensoreddist.html#compute-the-primary-ev

### Probability of secondary event time within a secondary censoring window

Having constructed the survival function of $S_+$ with equation \@ref(eq:survivalfunc), using numerical quadrature or in some other way, we can calculate the probability mass of a secondary event time falling within a observed secondary censoring window of length $w_S$ that begins at time $n - w_S$ _after_ the primary censoring window. This is the probability that the censored delay time $T_c$ is $n$.
Having constructed the survival function of $S_+$ with equation \@ref(eq:survivalfunc), using numerical quadrature or in some other way, we can calculate the probability mass of a secondary event time falling within a observed secondary censoring window of length $w_S$ that begins at time $n - w_S$ _after_ the primary censoring window. This is the probability that the censored delay time $T_c$ is $n$.

This gives the censored delay time probability [by integrating over censored values](https://mc-stan.org/docs/stan-users-guide/truncation-censoring.html#integrating-out-censored-values):

Expand Down Expand Up @@ -156,7 +156,7 @@ Then, by using integration by parts, we get:

$$
\begin{split}
\int_{P_L}^{P_R} g_P(x|P_L, P_R) \big[F(S_R - x) - F(S_L - x)\big] dx &=
\int_{P_L}^{P_R} g_P(x|P_L, P_R) \big[F(S_R - x) - F(S_L - x)\big] dx &=
F(S_R - P_R) - F(S_L - P_R) \\ & - \int_{P_L}^{P_R} G_P(x|P_L, P_R) \big[f(S_L - x) - f(S_R - x)\big] dx
\end{split} (\#eq:park)
$$
Expand Down Expand Up @@ -189,8 +189,4 @@ which is same as equation \@ref(eq:seccensorprob).

In this derivation, we have used that $G_P(x|-w_P, 0)$ is the distribution function from the time _from_ the start of the primary interval _until_ primary event time, and $F_{C_P}$ is the distribution function of the time _until_ the end of the primary event window _from_ the primary event time. Therefore, $G_P(-p|-w_P, 0) = Pr(P < -p | P \in (-w_P, 0)) = 1 - Pr(C_P \leq p) = 1 - F_{C_P}(p)$.

# Acknowledgements

We thank Sang Woo Park (gh: `@parksw3`) for making demonstrating the direct link between the approach taken in this note and the approach taken in Park et al[@Park2024]. The connection between the two approaches written above is substantially from [his comment](https://github.com/epinowcast/primarycensoreddist/issues/83#issuecomment-2359365128).

# References

0 comments on commit d09c143

Please sign in to comment.