epiverse-trace / epiparameter

R package with library of epidemiological parameters for infectious diseases and functions and classes for working with parameters
https://epiverse-trace.github.io/epiparameter
Other
33 stars 11 forks source link

read an `epiparameter::parameter_tbl()` output to get an `epidist` object #362

Open avallecam opened 3 months ago

avallecam commented 3 months ago

Would it be feasible to make an epiparameter::parameter_tbl() output suitable for accessing parameters via epidist_db()? This would be ideal for entries that do not fit the single_epidist = TRUE statement.

If we want to iteratively access parameters as in this reprex at https://github.com/epiverse-trace/howto/issues/36 we still need to extract the author name as a string to make this work.

library(tidyverse)
library(epiparameter)

# get set of epidist objects
epidist_input <- epiparameter::epidist_db(
  disease = "covid"
)
#> Returning 27 results that match the criteria (22 are parameterised). 
#> Use subset to filter by entry variables or single_epidist to return a single entry. 
#> To retrieve the citation for each use the 'get_citation' function

# table output
epidist_dataframe <- epidist_input %>% epiparameter::parameter_tbl() %>% 
  slice(8)

epidist_dataframe %>% glimpse()
#> Rows: 1
#> Columns: 7
#> $ disease           <chr> "COVID-19"
#> $ pathogen          <chr> "SARS-CoV-2"
#> $ epi_distribution  <chr> "serial interval"
#> $ prob_distribution <chr> "norm"
#> $ author            <chr> "Yang et al."
#> $ year              <dbl> 2020
#> $ sample_size       <dbl> 131

# convert data frame to epidist
epidist_db(
  disease = epidist_dataframe$disease,
  epi_dist = epidist_dataframe$epi_distribution,
  author = "Yang",
  subset = sample_size == 131
)
#> Returning 1 results that match the criteria (1 are parameterised). 
#> Use subset to filter by entry variables or single_epidist to return a single entry. 
#> To retrieve the citation for each use the 'get_citation' function
#> Disease: COVID-19
#> Pathogen: SARS-CoV-2
#> Epi Distribution: serial interval
#> Study: Yang L, Dai J, Zhao J, Wang Y, Deng P, Wang J (2020). "Estimation of
#> incubation period and serial interval of COVID-19: analysis of 178
#> cases and 131 transmission chains in Hubei province, China."
#> _Epidemiology and Infection_. doi:10.1017/S0950268820001338
#> <https://doi.org/10.1017/S0950268820001338>.
#> Distribution: norm
#> Parameters:
#>   mean: 4.600
#>   sd: 4.400

as_epidist(epidist_dataframe)
#> Error: <data.frame> input into as_epidist() cannot be converted to <epidist>

Created on 2024-07-29 with reprex v2.1.0