Skip to content

Commit

Permalink
Use natural parameters in all examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmbaazam committed Dec 12, 2024
1 parent 88584d6 commit a6f95db
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 28 deletions.
6 changes: 5 additions & 1 deletion R/epinow.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@
#' )
#' # set an example reporting delay. In practice this should use an estimate
#' # from the literature or be estimated from data
#' reporting_delay <- LogNormal(mean = 2, sd = 1, max = 10)
#' reporting_delay <- LogNormal(
#' meanlog = Fixed(2),
#' sdlog = Fixed(1),
#' max = 10
#' )
#'
#' # example case data
#' reported_cases <- example_confirmed[1:40]
Expand Down
6 changes: 5 additions & 1 deletion R/estimate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@
#' )
#' # set an example reporting delay. In practice this should use an estimate
#' # from the literature or be estimated from data
#' reporting_delay <- LogNormal(mean = 2, sd = 1, max = 10)
#' reporting_delay <- LogNormal(
#' meanlog = Fixed(2),
#' sdlog = Fixed(1),
#' max = 10
#' )
#'
#' # for more examples, see the "estimate_infections examples" vignette
#' def <- estimate_infections(reported_cases,
Expand Down
15 changes: 10 additions & 5 deletions R/regional_epinow.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,16 @@
#' data = cases,
#' generation_time = gt_opts(example_generation_time),
#' delays = delay_opts(example_incubation_period + example_reporting_delay),
#' rt = rt_opts(prior = LogNormal(mean = 2, sd = 0.2)),
#' stan = stan_opts(
#' samples = 100, warmup = 200
#' ),
#' verbose = interactive()
#' rt = rt_opts(
#' prior = LogNormal(
#' meanlog = Fixed(2),
#' sdlog = Fixed(0.2)
#' ),
#' stan = stan_opts(
#' samples = 100, warmup = 200
#' ),
#' verbose = interactive()
#' )
#' )
#' options(old_opts)
#' }
Expand Down
7 changes: 6 additions & 1 deletion R/simulate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,12 @@ simulate_infections <- function(estimates, R, initial_infections,
#' est <- estimate_infections(reported_cases,
#' generation_time = generation_time_opts(example_generation_time),
#' delays = delay_opts(example_incubation_period + example_reporting_delay),
#' rt = rt_opts(prior = LogNormal(mean = 2, sd = 0.1), rw = 7),
#' rt = rt_opts(prior = LogNormal(
#' meanlog = Fixed(2),
#' sdlog = Fixed(0.1)
#' ),
#' rw = 7
#' ),
#' obs = obs_opts(scale = Normal(mean = 0.1, sd = 0.01)),
#' gp = NULL, horizon = 0
#' )
Expand Down
6 changes: 5 additions & 1 deletion man/epinow.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/estimate_infections.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion man/forecast_infections.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions man/regional_epinow.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions vignettes/EpiNow2.Rmd.orig
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ If data was not available we could instead specify an informed estimate of the l
To demonstrate, we choose a lognormal distribution with mean 2, standard deviation 1 and a maximum of 10. *This is just an example and unlikely to apply in any particular use case*.

```{r}
reporting_delay <- LogNormal(mean = 2, sd = 1, max = 10)
reporting_delay <- LogNormal(
meanlog = Fixed(2),
sdlog = Fixed(1),
max = 10
)
reporting_delay
```

Expand Down Expand Up @@ -94,7 +98,10 @@ estimates <- epinow(
data = reported_cases,
generation_time = gt_opts(example_generation_time),
delays = delay_opts(example_incubation_period + reporting_delay),
rt = rt_opts(prior = LogNormal(mean = 2, sd = 0.2)),
rt = rt_opts(prior = LogNormal(
meanlog = Fixed(2),
sdlog = Fixed(0.2)
)),
stan = stan_opts(cores = 4, control = list(adapt_delta = 0.99)),
verbose = interactive()
)
Expand Down Expand Up @@ -148,7 +155,13 @@ estimates <- regional_epinow(
data = reported_cases,
generation_time = gt_opts(example_generation_time),
delays = delay_opts(example_incubation_period + reporting_delay),
rt = rt_opts(prior = LogNormal(mean = 2, sd = 0.2), rw = 7),
rt = rt_opts(
prior = LogNormal(
meanlog = Fixed(2),
sdlog = Fixed(0.2)
),
rw = 7
),
gp = NULL,
stan = stan_opts(cores = 4, warmup = 250, samples = 1000)
)
Expand Down
11 changes: 9 additions & 2 deletions vignettes/epinow.Rmd.orig
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ This should be replaced with parameters relevant to the system that is being stu
library("EpiNow2")
options(mc.cores = 4)
reported_cases <- example_confirmed[1:60]
reporting_delay <- LogNormal(mean = 2, sd = 1, max = 10)
reporting_delay <- LogNormal(
meanlog = Fixed(2),
sdlog = Fixed(1),
max = 10
)
delay <- example_incubation_period + reporting_delay
rt_prior <- LogNormal(mean = 2, sd = 0.1)
rt_prior <- LogNormal(
meanlog = Fixed(2),
sdlog = Fixed(0.1)
)
```

We can then run the `epinow()` function with the same arguments as `estimate_infections()`.
Expand Down
15 changes: 11 additions & 4 deletions vignettes/estimate_infections_options.Rmd.orig
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ For the reporting delay, we use a lognormal distribution with mean of 2 days and
Note that the mean and standard deviation must be converted to the log scale, which can be done using the `convert_log_logmean()` function.

```{r reporting_delay}
reporting_delay <- LogNormal(mean = 2, sd = 1, max = 10)
reporting_delay <- LogNormal(
meanlog = Fixed(2),
sdlog = Fixed(1),
max = 10
)
reporting_delay
```

Expand All @@ -97,7 +101,10 @@ example_generation_time
Lastly we need to choose a prior for the initial value of the reproduction number. This is assumed by the model to be normally distributed and we can set the mean and the standard deviation. We decide to set the mean to 2 and the standard deviation to 1.

```{r initial_r}
rt_prior <- LogNormal(mean = 2, sd = 0.1)
rt_prior <- LogNormal(
meanlog = Fixed(2),
sdlog = Fixed(0.1)
)
```

# Running the model
Expand Down Expand Up @@ -172,8 +179,8 @@ Here, instead of doing so we assume that we know about truncation with mean of 1

```{r define_truncation}
trunc_dist <- LogNormal(
mean = Normal(0.5, 0.1),
sd = Normal(0.5, 0.1),
meanlog = Normal(0.5, 0.1),
sdlog = Normal(0.5, 0.1),
max = 3
)
trunc_dist
Expand Down
6 changes: 3 additions & 3 deletions vignettes/estimate_infections_workflow.Rmd.orig
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ In all cases, the distributions given can be *fixed* (i.e. have no uncertainty)
For example, to define a fixed gamma distribution with mean 3, standard deviation (sd) 1 and maximum value 10, you would write

```{r}
fixed_gamma <- Gamma(mean = 3, sd = 1, max = 10)
fixed_gamma <- Gamma(shape = 3, rate = 1, max = 10)
fixed_gamma
```

Expand All @@ -93,7 +93,7 @@ If distributions are variable, the values with uncertainty are treated as [prior
For example, to define a variable gamma distribution where uncertainty in the mean is given by a normal distribution with mean 3 and sd 2, and uncertainty in the standard deviation is given by a normal distribution with mean 1 and sd 0.1, with a maximum value 10, you would write

```{r}
uncertain_gamma <- Gamma(mean = Normal(3, 2), sd = Normal(1, 0.1), max = 10)
uncertain_gamma <- Gamma(shape = Normal(3, 2), rate = Normal(1, 0.1), max = 10)
uncertain_gamma
```

Expand Down Expand Up @@ -209,7 +209,7 @@ It can be changed using the `rt_opts()` function.
For example, if the user believes that at the very start of the data the reproduction number was 2, with uncertainty in this belief represented by a standard deviation of 1, they would use

```{r results = 'hide'}
rt_prior <- LogNormal(mean = 2, sd = 1)
rt_prior <- LogNormal(meanlog = Fixed(2), sdlog = Fixed(1))
rt_opts(prior = rt_prior)
```

Expand Down

0 comments on commit a6f95db

Please sign in to comment.