epiverse-trace / tutorials-middle

https://epiverse-trace.github.io/tutorials-middle/
Other
3 stars 1 forks source link

prefer to use natural parameter for lognormal distribution #81

Open avallecam opened 2 weeks ago

avallecam commented 2 weeks ago

If you supply the mean and sd, it does this conversion to meanlog and sdlog. This conversion is approximate for large samples

https://en.wikipedia.org/wiki/Log-normal_distribution#Generation_and_parameters

avallecam commented 2 weeks ago

for epinow2:

for cfr or epichains:

library(epiparameter)
library(EpiNow2)
#> 
#> Attaching package: 'EpiNow2'
#> The following objects are masked from 'package:epiparameter':
#> 
#>     discretise, discretize, get_parameters
#> The following object is masked from 'package:stats':
#> 
#>     Gamma

library(tidyverse)

# gamma -------------------------------------------------------------------

# subset one distribution for the generation time
ebola_serialinterval_raw <- epiparameter::epidist_db(
  disease = "ebola",
  epi_dist = "serial",
  single_epidist = TRUE
)
#> Using WHO Ebola Response Team, Agua-Agum J, Ariyarajah A, Aylward B, Blake I,
#> Brennan R, Cori A, Donnelly C, Dorigatti I, Dye C, Eckmanns T, Ferguson
#> N, Formenty P, Fraser C, Garcia E, Garske T, Hinsley W, Holmes D,
#> Hugonnet S, Iyengar S, Jombart T, Krishnan R, Meijers S, Mills H,
#> Mohamed Y, Nedjati-Gilani G, Newton E, Nouvellet P, Pelletier L,
#> Perkins D, Riley S, Sagrado M, Schnitzler J, Schumacher D, Shah A, Van
#> Kerkhove M, Varsaneux O, Kannangarage N (2015). "West African Ebola
#> Epidemic after One Year — Slowing but Not Yet under Control." _The New
#> England Journal of Medicine_. doi:10.1056/NEJMc1414992
#> <https://doi.org/10.1056/NEJMc1414992>.. 
#> To retrieve the citation use the 'get_citation' function

ebola_serialinterval_param <- epiparameter::get_parameters(ebola_serialinterval_raw)

ebola_serialinterval_discrete <- epiparameter::discretise(ebola_serialinterval_raw)

EpiNow2::Gamma(
  shape = ebola_serialinterval_param["shape"],
  scale = ebola_serialinterval_param["scale"],
  max = stats::quantile(ebola_serialinterval_discrete, p = 0.99)
)
#> - gamma distribution (max: 45):
#>   shape:
#>     2.2
#>   rate:
#>     0.15

EpiNow2::Gamma(
  mean = ebola_serialinterval_raw$summary_stats$mean,
  sd = ebola_serialinterval_raw$summary_stats$sd,
  max = stats::quantile(ebola_serialinterval_discrete, p = 0.99)
)
#> - gamma distribution (max: 45):
#>   shape:
#>     2.2
#>   rate:
#>     0.15

# lognormal ---------------------------------------------------------------

# get covid serial interval
covid_serialinterval_raw <-
  epiparameter::epidist_db(
    disease = "covid",
    epi_dist = "serial",
    single_epidist = TRUE
  )
#> Using Nishiura H, Linton N, Akhmetzhanov A (2020). "Serial interval of novel
#> coronavirus (COVID-19) infections." _International Journal of
#> Infectious Diseases_. doi:10.1016/j.ijid.2020.02.060
#> <https://doi.org/10.1016/j.ijid.2020.02.060>.. 
#> To retrieve the citation use the 'get_citation' function

covid_serialinterval_params <- epiparameter::get_parameters(covid_serialinterval_raw)

covid_serialinterval_discrete <- epiparameter::discretise(covid_serialinterval_raw)

EpiNow2::LogNormal(
  meanlog = covid_serialinterval_params["meanlog"],
  sdlog = covid_serialinterval_params["sdlog"],
  max = stats::quantile(covid_serialinterval_discrete, p = 0.99)
)
#> - lognormal distribution (max: 14):
#>   meanlog:
#>     1.4
#>   sdlog:
#>     0.57

EpiNow2::LogNormal(
  mean = covid_serialinterval_raw$summary_stats$mean,
  sd = covid_serialinterval_raw$summary_stats$sd,
  max = stats::quantile(covid_serialinterval_discrete, p = 0.99)
)
#> - lognormal distribution (max: 14):
#>   meanlog:
#>     1.4
#>   sdlog:
#>     0.57

Created on 2024-06-23 with reprex v2.1.0