Skip to content

Commit

Permalink
get the code actually rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Sabanes Bove committed Apr 3, 2024
1 parent 8ea3b9b commit ff9de39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ makedocs(
sitename = "SafetySignalDetection",
format = Documenter.HTML(
assets = String["assets/citations.css"],
size_threshold = nothing
),
modules = [SafetySignalDetection],
pages = [
Expand Down
14 changes: 8 additions & 6 deletions docs/src/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Note that:
- The column `time` needs to be a `Float64` (time until adverse event or until last treatment or follow up).
- The column `trialindex` needs to be `Int64` (index of historical trials, starting from 1 and consecutively numbered).

```julia
```@example 1
using CSV
using DataFrames
using SafetySignalDetection
Expand Down Expand Up @@ -43,13 +43,14 @@ Note:
- The number of samples (e.g. 10,000) and the number of threads (1) need to be passed as integers. Otherwise the call will fail.
- We don't need to discard a burn in period now because the NUTS sampler is used internally and is discarding a burn in automatically already.

```julia
```@example 1
using Distributions
prior_a = Beta(1 / 3, 1 / 3)
prior_b = Beta(5, 5)
map_samples = meta_analytic_samples(df, prior_a, prior_b, 10_000, 1)
map_samples[1:5]
```

The resulting $\pi^{*}$ samples in `map_samples` are from the meta-analytic prior for the adverse event rate per unit of time in the control arm in the ongoing blinded trial.
Expand All @@ -63,7 +64,7 @@ Internally, the classic Expectation Maximization (EM) algorithm is used.
We can check the approximation graphically by overlaying the resulting probability density function with the
samples histogram.

```julia
```@example 1
using Plots
map_approx = fit_beta_mixture(map_samples, 2)
Expand All @@ -82,7 +83,7 @@ The important new ingredients here are:
- The prior on the experimental adverse event rate. This can be uninformative, or weakly informative using a diluted background rate distribution.
- The proportion of patients in the experimental treatment arm.

```julia
```@example 1
prior_exp = Beta(1, 1)
prior_ctrl = map_approx
exp_proportion = 0.5
Expand All @@ -92,19 +93,20 @@ df_current = DataFrame(CSV.File(csv_current_path))
df_current.y = map(x -> x == 1, df_current.y)
result = blinded_analysis_samples(df_current, prior_exp, prior_ctrl, exp_proportion, 10_000, 1)
first(result, 5)
```

## Summary

We can now e.g. look at the posterior probability that the rate in the experimental arm, $\pi_E$, is larger than the event rate in the control arm, $\pi_C$.

```julia
```@example 1
mean(result[!, :pi_exp] .> result[!, :pi_ctrl])
```

We can also create corresponding plots.

```julia
```@example 1
stephist(result[!, :pi_exp], label = "experimental arm", norm = :pdf)
stephist!(result[!, :pi_ctrl], label = "control arm", norm = :pdf)
```

0 comments on commit ff9de39

Please sign in to comment.