Skip to content

Commit

Permalink
add epiparameter get_parameters for epinow2 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
avallecam committed Mar 21, 2024
1 parent b9b836b commit 52899a0
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions episodes/delays-functions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ This episode requires you to be familiar with:

<!-- to activate for EpiNow2@dist-interfase
But still, we need to extract them as usable numbers. We use `epiparameter::get_parameters()` for this:
```{r}
covid_serialint_parameters <- epiparameter::get_parameters(covid_serialint)
covid_serialint_parameters
```
This gets a vector of class `<numeric>` useful as input for any other package!
:::::::::::::::::: callout
If we write the `[]` next to the last object create like in `covid_serialint_parameters[]`, within `[]` we can use the
Expand Down Expand Up @@ -342,6 +332,26 @@ quantile(covid_serialint_discrete, p = 0.999) %>%

:::::::::::::::::::::::::::::::::::::::::::

:::::::::::::::::::::::::::::: callout

### Log normal distributions

If you need the log normal **distribution parameters** instead of the summary statistics, we can use `epiparameter::get_parameters()`:

```{r}
covid_serialint_parameters <-
epiparameter::get_parameters(covid_serialint)
covid_serialint_parameters
```

This gets a vector of class `<numeric>` ready to use as input for any other package!

**BONUS TIP:** If we write the `[]` next to the last object create like in `covid_serialint_parameters[]`, within `[]` we can use the
Tab key <kbd>↹</kbd>
to use the [code completion feature](https://support.posit.co/hc/en-us/articles/205273297-Code-Completion-in-the-RStudio-IDE) and have a quick access to `covid_serialint_parameters["meanlog"]` and `covid_serialint_parameters["sdlog"]`. We invite you to try this out in code chunks and the R console!

::::::::::::::::::::::::::::::

## Plug-in `{epiparameter}` to `{EpiNow2}`

Expand All @@ -354,8 +364,8 @@ Now we can plug everything into the `EpiNow2::dist_spec()` function!
```{r}
serial_interval_covid <-
dist_spec(
mean = covid_serialint$summary_stats$mean,
sd = covid_serialint$summary_stats$sd,
mean = covid_serialint_parameters["meanlog"],
sd = covid_serialint_parameters["sdlog"],
max = covid_serialint_discrete_max,
distribution = "lognormal"
)
Expand Down Expand Up @@ -521,10 +531,13 @@ covid_serialint_discrete_max <-
discretise() %>%
quantile(p = 0.999)
covid_serialint_parameters <-
epiparameter::get_parameters(covid_serialint)
covid_serial_interval <-
dist_spec(
mean = covid_serialint$summary_stats$mean,
sd = covid_serialint$summary_stats$sd,
mean = covid_serialint_parameters["meanlog"],
sd = covid_serialint_parameters["sdlog"],
max = covid_serialint_discrete_max,
distribution = "lognormal"
)
Expand All @@ -543,10 +556,13 @@ covid_incubation_discrete_max <-
discretise() %>%
quantile(p = 0.999)
covid_incubation_parameters <-
epiparameter::get_parameters(covid_incubation)
covid_incubation_time <-
dist_spec(
mean = covid_incubation$summary_stats$mean,
sd = covid_incubation$summary_stats$sd,
mean = covid_incubation_parameters["meanlog"],
sd = covid_incubation_parameters["sdlog"],
max = covid_incubation_discrete_max,
distribution = "lognormal" # do not forget this!
)
Expand Down

0 comments on commit 52899a0

Please sign in to comment.