Skip to content

Commit

Permalink
Documentation support and release (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
ya0 committed Feb 29, 2024
1 parent cae4f42 commit bca8902
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
12 changes: 11 additions & 1 deletion docs/src/FirstExample.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,22 @@ plot!(sm, r, t-> ccdf(Weibull(1.2,100),t), label = "Baseline survival", color =
```
![](fig/sm.png)


Now we have to specify the support of our joint model. Currently this has to be done by hand. This is used to control the time-points in which we expect observations and is used for numerical procedures. So taking a support that is too big can lead to instabilities. If you redo the plot above with the time range 0 to 500 you will see that the individual survival curves "reaches" 0 around time 100 and the baseline survival "reaches" 0 before time 400.
```julia
JointSurvivalModels.support(dist::JointSurvivalModel) = (0.001, 500)
```


To simulate longitudinal measurements ``y_{ij}`` for individual ``i`` at time ``t_ij`` we assume a multiplicative error ``y_{ij} \sim N(m_i(t_{ij}), \sigma * m_i(t_{ij}) ), \sigma = 0.15``. Simulate ``9`` longitudinal measurements and survival times for each individual:
```julia
σ = 0.15
t_m = range(1,50,9)
Y = [[rand(Normal(m(i)(t_m[j]), σ * m(i)(t_m[j]))) for j in 1:9] for i in 1:n]
T = [rand(jm) for jm in joint_models]
```
Simulate joint survival times:
```julia
T = rand.(joint_models)
```
Additionally we assume right-censoring at ``50`` and no measurements after an event:
```julia
Expand Down
36 changes: 27 additions & 9 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
# JointSurvivalModels.jl

This package implements joint models in julia. It was designed to support the modeling of joint models with probabilistic programming, for example using the Turing.jl framework. Install it with:
This package implements joint models in Julia. It was designed to support the modeling of joint models with probabilistic programming, for example using the [Turing.jl](https://github.com/TuringLang/Turing.jl) framework. Install it with:

```julia
using Pkg
# needs public listing
#Pkg.add("JointSurvivalModels")
Pkg.add("JointSurvivalModels")
```


The `JointSurvivalModel` type implements a canonical formulation of joint models. It based on a joint hazard function $h(t) = h_0(t) \exp(\gamma' \cdot L(M(t)))$ with a baseline hazard $h_0$ and a link to joint models $L(M(t))$ and coefficients for the links $\gamma$. For a more detailed explanation see [`JointSurvivalModels`](@ref JointSurvivalModel).


### A simple example

The hazard of the exponential distribution $Exp(\alpha)$ is the constant function $x\mapsto \alpha$. For the joint longitudinal model we use a simple cosinus function. The joint hazard is then $h(t) = \alpha \exp(\gamma * \cos(t))$.
## Example

The hazard of the exponential distribution $\text{Exp}(\alpha)$ is the constant function $x\mapsto \alpha$. For the joint longitudinal model we use a simple cosinus function. The joint hazard is then $h(t) = \alpha \exp(\gamma * \cos(t))$.

```julia
constant_alpha(x) = 2
γ = 0.01
using JointSurvivalModels
constant_alpha(x) = 0.2
γ = 0.5
jm = JointSurvivalModel(constant_alpha, γ, cos)
```
Plotting the survival function vs the baseline hazard:
```julia
using StatsPlots, Distributions
r = range(0,12,100)
plot(r, ccdf(Exponential(1/0.2), r), label="Baseline survival")
plot!(r, ccdf(jm, r), label="Joint Survival")
```

For a more instructive example take a look at the documentation [First Example](@ref) or the case study found in `example/` in the project folder.

For the numeric calculation for the distribution a default support (0,10'000) is assumed. In particular the first events happen after $0$ and the interval (0,10'000) should contain nearly all of the probability mass of the target distribution. If you have different starting times for events or a time horizon that exceeds 10'000 then you can manually adjust the support, see [support in `HazardBasedDistribution`](@ref HazardBasedDistribution)


### Support

For the numeric calculation for the distribution a default support (0.001,10'000) is set. In particular the first events happen after $0$ and the interval (0,10'000) should contain nearly all of the probability mass of the target distribution. If you have different starting times for events or a time horizon that is lower or higher than 10'000 then you should manually adjust the support, see [support in `HazardBasedDistribution`](@ref HazardBasedDistribution). For example:

```julia
JointSurvivalModels.support(dist::HazardBasedDistribution) = (-100, 100)
```
2 changes: 1 addition & 1 deletion src/hazarddistribution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ When sampling with `rand` an ODE is solved over the support.
# Usage
You should adjust the support according to your data
```julia
JointSurvivalModels.support(dist:HazardBasedDistribution) = (-100, 1000)
JointSurvivalModels.support(dist::HazardBasedDistribution) = (-100, 1000)
```
"""
support(dist::HazardBasedDistribution) = (1e-4, 10_000)
Expand Down

0 comments on commit bca8902

Please sign in to comment.