diff --git a/NEWS.md b/NEWS.md index 2359720..02fcd7f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,10 @@ This is the development version of `primarycensoreddist` and is not yet ready fo * Split "Why it works" vignette into two separate vignettes, "Why it works" and "Analytic solutions for censored delay distributions". * Removed the need to assign functions to the global environment for `fitdistdoublecens()` by using `withr`. +## Documentation + +* Simplified the "Analytic solutions" vignette by removing verbose derivation details. + # primarycensoreddist 0.5.0 This release adds a new `{touchstone}` based benchmark suite to the package. It also adds a new "How it works" vignette which aims to give the reader more details into how the primary censored distributions work. diff --git a/vignettes/analytic-solutions.Rmd b/vignettes/analytic-solutions.Rmd index 99871a0..74ede60 100644 --- a/vignettes/analytic-solutions.Rmd +++ b/vignettes/analytic-solutions.Rmd @@ -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. @@ -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** @@ -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** @@ -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** diff --git a/vignettes/why-it-works.Rmd b/vignettes/why-it-works.Rmd index 6612471..e21e44f 100644 --- a/vignettes/why-it-works.Rmd +++ b/vignettes/why-it-works.Rmd @@ -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): @@ -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) $$ @@ -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