diff --git a/apple-touch-icon-120x120.png b/apple-touch-icon-120x120.png index 61b09697..be1db20c 100644 Binary files a/apple-touch-icon-120x120.png and b/apple-touch-icon-120x120.png differ diff --git a/apple-touch-icon-152x152.png b/apple-touch-icon-152x152.png index 7823e751..511700c5 100644 Binary files a/apple-touch-icon-152x152.png and b/apple-touch-icon-152x152.png differ diff --git a/apple-touch-icon-180x180.png b/apple-touch-icon-180x180.png index da885a3b..caba2ca1 100644 Binary files a/apple-touch-icon-180x180.png and b/apple-touch-icon-180x180.png differ diff --git a/apple-touch-icon-60x60.png b/apple-touch-icon-60x60.png index 59b22fa4..9d0c0a69 100644 Binary files a/apple-touch-icon-60x60.png and b/apple-touch-icon-60x60.png differ diff --git a/apple-touch-icon-76x76.png b/apple-touch-icon-76x76.png index 398f5d75..aa664de9 100644 Binary files a/apple-touch-icon-76x76.png and b/apple-touch-icon-76x76.png differ diff --git a/apple-touch-icon.png b/apple-touch-icon.png index 00082291..1d44c24f 100644 Binary files a/apple-touch-icon.png and b/apple-touch-icon.png differ diff --git a/articles/interventions_files/figure-html/simulate_chains_ind_control-1.png b/articles/interventions_files/figure-html/simulate_chains_ind_control-1.png index 5901c6b2..c77b6cf9 100644 Binary files a/articles/interventions_files/figure-html/simulate_chains_ind_control-1.png and b/articles/interventions_files/figure-html/simulate_chains_ind_control-1.png differ diff --git a/articles/interventions_files/figure-html/simulate_chains_pop_control-1.png b/articles/interventions_files/figure-html/simulate_chains_pop_control-1.png index adcd456f..faf2225c 100644 Binary files a/articles/interventions_files/figure-html/simulate_chains_pop_control-1.png and b/articles/interventions_files/figure-html/simulate_chains_pop_control-1.png differ diff --git a/articles/interventions_files/figure-html/simulate_chains_truncated-1.png b/articles/interventions_files/figure-html/simulate_chains_truncated-1.png index 31eff0c2..3110e9dc 100644 Binary files a/articles/interventions_files/figure-html/simulate_chains_truncated-1.png and b/articles/interventions_files/figure-html/simulate_chains_truncated-1.png differ diff --git a/articles/interventions_files/figure-html/uncontrolled_chains_plot-1.png b/articles/interventions_files/figure-html/uncontrolled_chains_plot-1.png index 8fe08176..c89c40aa 100644 Binary files a/articles/interventions_files/figure-html/uncontrolled_chains_plot-1.png and b/articles/interventions_files/figure-html/uncontrolled_chains_plot-1.png differ diff --git a/favicon-16x16.png b/favicon-16x16.png index 310df10c..eb8bc93f 100644 Binary files a/favicon-16x16.png and b/favicon-16x16.png differ diff --git a/favicon-32x32.png b/favicon-32x32.png index 927fc433..9e8d91a7 100644 Binary files a/favicon-32x32.png and b/favicon-32x32.png differ diff --git a/index.html b/index.html index 192108de..01b0a0c7 100644 --- a/index.html +++ b/index.html @@ -99,111 +99,12 @@
-
- - - -

epichains is an R package to simulate, analyse, and visualize the size and length of branching processes with a given offspring distribution. These models are often used in infectious disease epidemiology, where the chains represent chains of transmission, and the offspring distribution represents the distribution of secondary infections caused by an infected individual.

-

epichains re-implements bpmodels by providing bespoke functions and data structures that allow easy manipulation and interoperability with other Epiverse-TRACE packages, for example, superspreading and epiparameter, and potentially some existing packages for handling transmission chains, for example, epicontacts.

-

epichains is developed at the Centre for the Mathematical Modelling of Infectious Diseases at the London School of Hygiene and Tropical Medicine as part of the Epiverse Initiative.

-
-

Installation -

-

The latest development version of the epichains package can be installed via

-
-# check whether {pak} is installed
-if (!require("pak")) install.packages("pak")
-pak::pak("epiverse-trace/epichains")
-

To load the package, use

- -
-
-

Quick start -

-

epichains provides two main functions:

-
    -
  • simulate_chains(): simulates transmission chains using a simple branching process model that accepts an index number of cases that seed the outbreak, a distribution of offspring per case, and a chain statistic to track (size or length/duration). It optionally accepts other population related inputs such as the population size (defaults to Inf) and percentage of the population initially immune (defaults to 0). This function returns an object with columns that track information on who infected whom, the generation of infection and, if a generation time function is specified, the time of infection.

  • -
  • simulate_summary(): provides a performant version of simulate_chains() that only tracks and return a vector of realized chain sizes or lengths/durations for each index case without details of the infection tree.

  • -
  • likelihood(): calculates the loglikelihood (or likelihood, depending on the value of log) of observing a vector of transmission chain sizes or lengths.

  • -
-

The objects returned by the simulate_*() functions can be summarised with summary(). Running summary() on the output of simulate_chains() will return the same output as simulate_summary() using the same inputs.

-

Objects returned from simulate_chains() can be aggregated into a <data.frame> of cases per time or generation with the function aggregate(). The aggregated results can also be passed on to plot() with its own arguments to customize the resulting plots.

-

Each of the listed functionalities is demonstrated in detail in the “Getting Started” vignette.

-
-
-

Package vignettes -

-

The theory behind the models provided here can be found in the theory vignette.

-

We have also collated a bibliography of branching process applications in epidemiology. These can be found in the literature vignette.

-

Specific use cases of epichains can be found in the online documentation as package vignettes, under “Articles”.

-
-
- -

As far as we know, below are the existing R packages for simulating branching processes and transmission chains.

-
    -
  • bpmodels: provides methods for analysing the size and length of transmission chains from branching process models. epichains is intended to supersede {bpmodels}.

  • -
  • ringbp: a branching process model, parameterised to the 2019-nCoV outbreak, and used to quantify the potential effectiveness of contact tracing and isolation of cases.

  • -
  • covidhm: code for simulating COVID-19 dynamics in a range of scenarios across a real-world social network. The model is conceptually based on {ringbp}.

  • -
  • epicontacts: provides methods for handling, analysing, and visualizing transmission chains and contact-tracing data/linelists.

  • -
  • simulist: uses a branching process model to simulate individual-level infectious disease outbreak data, including line lists and contact tracing data. This package is part of the Epiverse-TRACE Initiative.

  • -
  • superspreading: provides a set of functions to estimate and understand individual-level variation in transmission of infectious diseases from data on secondary cases. These are useful for understanding the role of superspreading in the spread of infectious diseases and for informing public health interventions.

  • -
  • earlyR: estimates the reproduction number (R), in the early stages of an outbreak. The model requires a specified serial interval distribution, characterised by the mean and standard deviation of the (Gamma) distribution, and data on daily disease incidence, including only confirmed and probable cases.

  • -
  • projections: uses data on daily incidence, the serial interval (time between onsets of infectors and infectees) and the reproduction number to simulate plausible epidemic trajectories and project future incidence. It relies on a branching process where daily incidence follows a Poisson or a Negative Binomial distribution governed by a force of infection.

  • -
  • simulacr: simulates outbreaks for specified values of reproduction number, incubation period, duration of infectiousness, and optionally reporting delays. Outputs a linelist stored as a data.frame with the class outbreak, including information on transmission chains; the output can be converted to <epicontacts> objects for visualisation.

  • -
  • outbreakr: implements a Bayesian approach for reconstructing outbreak data from pathogen genome sequences. It also implements a tool for outbreak simulation.

  • -
  • outbreakr2: a Bayesian framework for integrating epidemiological and genetic data to reconstruct transmission trees of densely sampled outbreaks. It re-implements, generalises and replaces the model of outbreaker, and uses a modular approach which enables fine customisation of priors, likelihoods and parameter movements.

  • -
  • o2geosocial: integrates geographical and social contact data to reconstruct transmission chains. It combines the age group, location, onset date and genotype of cases to infer their import status, and their likely infector.

  • -
  • nosoi: simulates agent-based transmission chains by taking into account the influence of multiple variables on the transmission process (e.g. dual-host systems (such as arboviruses), within-host viral dynamics, transportation, population structure), alone or taken together, to create complex but relatively intuitive epidemiological simulations.

  • -
  • TransPhylo: reconstructs infectious disease transmission using genomic data.

  • -
-
-
-

Reporting bugs -

-

To report a bug please open an issue.

-
-
-

Contribute -

-

We welcome contributions to enhance the package’s functionalities. If you wish to do so, please follow the package contributing guide.

-
-
-

Code of conduct -

-

Please note that the epichains project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

-
-
-

Citing this package -

-
-citation("epichains")
-#> To cite package 'epichains' in publications use:
-#> 
-#>   Azam J, Finger F, Funk S (2024). _epichains: Simulating and Analysing
-#>   Transmission Chain Statistics Using Branching Process Models_. R
-#>   package version 0.0.0.9999,
-#>   https://epiverse-trace.github.io/epichains/,
-#>   <https://github.com/epiverse-trace/epichains>.
-#> 
-#> A BibTeX entry for LaTeX users is
-#> 
-#>   @Manual{,
-#>     title = {epichains: Simulating and Analysing Transmission Chain Statistics Using
-#> Branching Process Models},
-#>     author = {James M. Azam and Flavio Finger and Sebastian Funk},
-#>     year = {2024},
-#>     note = {R package version 0.0.0.9999, 
-#> https://epiverse-trace.github.io/epichains/},
-#>     url = {https://github.com/epiverse-trace/epichains},
-#>   }
-
-
+
+Provides methods to simulate and analyse the size and length + of branching processes with an arbitrary offspring distribution. These + can be used, for example, to analyse the distribution of chain sizes + or length of infectious disease outbreaks, as discussed in Farrington + et al. (2003) <doi:10.1093/biostatistics/4.2.279>.
diff --git a/pkgdown.yml b/pkgdown.yml index a1e072f7..49102ec2 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -7,7 +7,7 @@ articles: interventions: interventions.html projecting_incidence: projecting_incidence.html theoretical_background: theoretical_background.html -last_built: 2024-03-12T17:53Z +last_built: 2024-03-15T13:46Z urls: reference: https://epiverse-trace.github.io/epichains/reference article: https://epiverse-trace.github.io/epichains/articles diff --git a/reference/epichains.html b/reference/epichains.html index 9475459f..7885fd1a 100644 --- a/reference/epichains.html +++ b/reference/epichains.html @@ -103,7 +103,14 @@

Usage

-
epichains(tree_df, index_cases, statistic, offspring_dist, stat_max, track_pop)
+
epichains(
+  tree_df,
+  index_cases,
+  offspring_dist,
+  track_pop,
+  statistic = c("size", "length"),
+  stat_max = Inf
+)
@@ -118,16 +125,6 @@

Arguments -
  • "length": the total number of ancestors produced by a chain before -it goes extinct.

  • - - -
    offspring_dist

    Offspring distribution: a function like the ones provided by R to generate random numbers from given distributions (e.g., @@ -139,14 +136,24 @@

    Arguments +
  • "length": the total number of ancestors produced by a chain before +it goes extinct.

  • +

    + +
    stat_max

    A cut off for the chain statistic (size/length) being computed. Results above stat_max are set to stat_max. Defaults to Inf.

    - -
    track_pop
    -

    Was the susceptible population tracked? Logical

    -

    Value

    diff --git a/reference/epichains_summary.html b/reference/epichains_summary.html index e00511ea..2f7348b9 100644 --- a/reference/epichains_summary.html +++ b/reference/epichains_summary.html @@ -88,9 +88,9 @@

    Usage

    @@ -104,16 +104,6 @@

    Arguments -
  • "length": the total number of ancestors produced by a chain before -it goes extinct.

  • - - -
    offspring_dist

    Offspring distribution: a function like the ones provided by R to generate random numbers from given distributions (e.g., @@ -125,6 +115,16 @@

    Arguments +
  • "length": the total number of ancestors produced by a chain before +it goes extinct.

  • +

    + +
    stat_max

    A cut off for the chain statistic (size/length) being computed. Results above stat_max are set to stat_max. Defaults to Inf.

    diff --git a/search.json b/search.json index 88d32959..56a7802c 100644 --- a/search.json +++ b/search.json @@ -1 +1 @@ -[{"path":"https://epiverse-trace.github.io/epichains/CONTRIBUTING.html","id":null,"dir":"","previous_headings":"","what":"Contributing to epichains","title":"Contributing to epichains","text":"outlines propose change epichains.","code":""},{"path":"https://epiverse-trace.github.io/epichains/CONTRIBUTING.html","id":"making-changes","dir":"","previous_headings":"","what":"Making changes","title":"Contributing to epichains","text":"want make change, ’s good idea first file issue make sure someone team agrees ’s needed. ’ve found bug, please file issue illustrates bug minimal reprex (also help write unit test, needed). See bug report template. feature request see feature request.","code":""},{"path":"https://epiverse-trace.github.io/epichains/CONTRIBUTING.html","id":"pull-request-process","dir":"","previous_headings":"Making changes","what":"Pull request process","title":"Contributing to epichains","text":"See pull request template Fork package clone onto computer. haven’t done , recommend using usethis::create_from_github(\"epiverse-trace/epichains\", fork = TRUE). Install development dependencies devtools::install_dev_deps(), make sure package passes R CMD check running devtools::check(). R CMD check doesn’t pass cleanly, ’s good idea ask help continuing. Create Git branch pull request (PR). recommend using usethis::pr_init(\"brief-description--change\"). Make changes, commit git, create PR running usethis::pr_push(), following prompts browser. title PR briefly describe change. body PR contain Fixes #issue-number. user-facing changes, add bullet top NEWS.md (.e. just first header). Follow style described https://style.tidyverse.org/news.html.","code":""},{"path":"https://epiverse-trace.github.io/epichains/CONTRIBUTING.html","id":"code-style","dir":"","previous_headings":"Making changes","what":"Code style","title":"Contributing to epichains","text":"New code follow tidyverse style guide. can use styler package apply styles, please don’t restyle code nothing PR. use roxygen2, Markdown syntax, documentation. use testthat unit tests. Contributions test cases included easier accept.","code":""},{"path":"https://epiverse-trace.github.io/epichains/CONTRIBUTING.html","id":"code-of-conduct","dir":"","previous_headings":"","what":"Code of Conduct","title":"Contributing to epichains","text":"Please note epichains released Contributor Code Conduct. contributing project agree abide terms.","code":""},{"path":"https://epiverse-trace.github.io/epichains/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2023 epichains authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":[]},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"likelihood","dir":"Articles","previous_headings":"Chain likelihoods","what":"likelihood()","title":"Getting started with epichains","text":"function calculates likelihood/loglikelihood observing vector outbreak summaries obtained transmission chains. “Outbreak summaries” refer transmission chain sizes lengths/durations. likelihood() requires vector chain summaries (sizes lengths), chains, corresponding statistic calculate, statistic, offspring distribution, offspring_dist associated parameters. offspring_dist specified function used generate random numbers, .e. rpois Poisson, rnbinom negative binomial, custom function. closed-form solution available simulated replicates used estimate likelihoods. case likelihood() also requires nsim_offspring, number simulations run . argument explained next section. default, result log-likelihood log = FALSE, likelihoods returned. Let’s look following example estimate log-likelihood observing chain_sizes.","code":"set.seed(121) # example of observed chain sizes # randomly generate 20 chains of size between 1 to 10 chain_sizes <- sample(1:10, 20, replace = TRUE) chain_sizes #> [1] 4 7 4 9 1 3 7 5 1 8 10 2 1 2 4 5 10 6 8 7 # estimate loglikelihood of the observed chain sizes likelihood_eg <- likelihood( chains = chain_sizes, statistic = \"size\", offspring_dist = rpois, nsim_obs = 100, lambda = 0.5 ) # Print the estimate likelihood_eg #> [1] -67.82879"},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"joint-and-individual-log-likelihoods","dir":"Articles","previous_headings":"Chain likelihoods","what":"Joint and individual log-likelihoods","title":"Getting started with epichains","text":"likelihood(), default, returns joint log-likelihood. instead, individual log-likelihoods required, individual argument must set TRUE. return likelihoods instead, set log = FALSE.","code":"set.seed(121) # example of observed chain sizes # randomly generate 20 chains of size between 1 to 10 chain_sizes <- sample(1:10, 20, replace = TRUE) chain_sizes #> [1] 4 7 4 9 1 3 7 5 1 8 10 2 1 2 4 5 10 6 8 7 # estimate loglikelihood of the observed chain sizes likelihood_ind_eg <- likelihood( chains = chain_sizes, statistic = \"size\", offspring_dist = rpois, nsim_obs = 100, lambda = 0.5, individual = TRUE ) # Print the estimate likelihood_ind_eg #> [[1]] #> [1] -3.098612 -4.508584 -3.098612 -5.269208 -0.500000 -2.480829 -4.508584 #> [8] -3.622329 -0.500000 -4.900542 -5.619471 -1.693147 -0.500000 -1.693147 #> [15] -3.098612 -3.622329 -5.619471 -4.086190 -4.900542 -4.508584"},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"how-likelihood-works","dir":"Articles","previous_headings":"Chain likelihoods","what":"How likelihood() works","title":"Getting started with epichains","text":"epichains ships functions analytical solutions transmission chain “size” “length” distributions. size distributions, provide poisson, negative binomial, gamma-borel mixture. length distribution, provide poisson geometric distributions. can used likelihood() based specified offspring_dist statistic. analytical solution exist, provide offspring_ll(), uses simulations approximate probability distributions (using linear approximation cumulative distribution unobserved sizes/lengths). case, extra argument nsim_offspring must passed likelihood() specify number simulations used approximation. example, let’s look example chain_sizes observed want calculate likelihood drawn binomial distribution probability prob = 0.9.","code":"set.seed(121) # example of observed chain sizes; randomly generate 20 chains of size 1 to 10 chain_sizes <- sample(1:10, 20, replace = TRUE) # get their likelihood liks <- likelihood( chains = chain_sizes, offspring_dist = rbinom, statistic = \"size\", size = 1, prob = 0.9, nsim_offspring = 250 ) liks #> [1] -56.76805"},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"observation-probability","dir":"Articles","previous_headings":"Chain likelihoods","what":"Observation probability","title":"Getting started with epichains","text":"likelihood() uses argument obs_prob model observation probability. default, assumes perfect observation, obs_prob = 1 (See ?likelihood), meaning transmission events observed recorded data. observations imperfect, obs_prob must less 1. case imperfect observation, “true” chain sizes lengths simulated nsim_obs times, likelihood calculated simulations. example, probability observing case obs_prob = 0.30, use returns 10 likelihood values (nsim_obs = 10), can averaged come overall likelihood estimate. find usage likelihood() function, can run ?likelihood access R help file.","code":"set.seed(121) # example of observed chain sizes; randomly generate 20 chains of size 1 to 10 chain_sizes <- sample(1:10, 20, replace = TRUE) # get their likelihood liks <- likelihood( chains = chain_sizes, statistic = \"size\", offspring_dist = rpois, obs_prob = 0.3, lambda = 0.5, nsim_obs = 10 ) liks #> [1] -183.8670 -162.1382 -166.6720 -170.1077 -152.9557 -157.9814 -166.0587 #> [8] -174.8488 -156.4197 -160.0229"},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"transmission-chains-simulation","dir":"Articles","previous_headings":"","what":"Transmission chains simulation","title":"Getting started with epichains","text":"two simulation functions, herein referred collectively simulate_*() functions.","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"simulate_chains","dir":"Articles","previous_headings":"Transmission chains simulation","what":"simulate_chains()","title":"Getting started with epichains","text":"simulate_chains() simulates outbreak given number infections offspring distribution. default, assumes population infinite pre-existing immunity. function tracks returns information infectors (ancestors), infectees, generation infection, time, generation time function specified. Let’s look example simulate transmission tree \\(10\\) index cases. assume poisson offspring distribution mean, \\(\\text{lambda} = 0.9\\), generation time \\(3\\) days: Beyond defaults, simulate_chains() can also simulate outbreaks based specified population size pre-existing immunity susceptible pool runs . quick example simulate outbreak population size \\(1000\\) \\(10\\) index cases \\(10/%\\) pre-existing immunity. assume individuals poisson offspring distribution mean, \\(\\text{lambda} = 1\\), fixed generation time \\(3\\):","code":"set.seed(32) # Define generation time generation_time_fn <- function(n) { gt <- rep(3, n) return(gt) } sim_chains <- simulate_chains( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, generation_time = generation_time_fn, lambda = 0.9 ) head(sim_chains) #> infectee_id sim_id infector_id generation time #> 11 1 2 1 2 3 #> 12 2 2 1 2 3 #> 13 3 2 1 2 3 #> 14 4 2 1 2 3 #> 15 6 2 1 2 3 #> 16 7 2 1 2 3 set.seed(32) # Define generation time generation_time_fn <- function(n) { gt <- rep(3, n) return(gt) } sim_chains_with_pop <- simulate_chains( pop = 1000, index_cases = 10, percent_immune = 0.1, offspring_dist = rpois, statistic = \"size\", lambda = 1, generation_time = generation_time_fn ) head(sim_chains_with_pop) #> infectee_id sim_id infector_id generation time susc_pop #> 11 1 2 1 2 3 877 #> 12 2 2 1 2 3 877 #> 13 3 2 1 2 3 877 #> 14 4 2 1 2 3 877 #> 15 6 2 1 2 3 877 #> 16 7 2 1 2 3 877"},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"simulate_summary","dir":"Articles","previous_headings":"Transmission chains simulation","what":"simulate_summary()","title":"Getting started with epichains","text":"simulate_summary() performant version simulate_chains() track information infector infectee. returns eventual size length/duration transmission chain. function especially useful calculating numerical likelihoods likelihood(). example simulate previous examples without intervention, returning size \\(10\\) chains. assumes poisson offspring distribution mean \\(0.9\\).","code":"set.seed(123) simulate_summary_eg <- simulate_summary( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, lambda = 0.9 ) # Print the results simulate_summary_eg #> `epichains_summary` object #> #> [1] 1 Inf 4 4 Inf 1 2 Inf 5 3 #> #> Simulated tree sizes: #> #> Max: 5 #> Min: 1"},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"summarising","dir":"Articles","previous_headings":"Other functionalities","what":"Summarising","title":"Getting started with epichains","text":"can run summary() object returned simulate_chains() obtain chain summaries per index case. summary output simulate_summary() inputs used. simulate_summary() performant version simulate_chains(), hence, can use instead, interested summary simulated chains without details infection tree. can confirm two outputs using base::setequal()","code":"set.seed(32) # Define generation time generation_time_fn <- function(n) { gt <- rep(3, n) return(gt) } sim_chains <- simulate_chains( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, generation_time = generation_time_fn, lambda = 0.9 ) summary(sim_chains) #> `epichains_summary` object #> #> [1] Inf 2 Inf 2 1 Inf 3 Inf 9 1 #> #> Simulated tree sizes: #> #> Max: 9 #> Min: 1 # Example with simulate_summary() set.seed(32) simulate_summary_eg <- simulate_summary( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, lambda = 0.9 ) # Get summaries summary(simulate_summary_eg) #> $index_cases #> [1] 10 #> #> $max_stat #> [1] 9 #> #> $min_stat #> [1] 1 setequal( # summary of output from simulate_chains() summary(sim_chains), # results from simulate_summary() simulate_summary_eg ) #> [1] TRUE"},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"aggregating","dir":"Articles","previous_headings":"Other functionalities","what":"Aggregating","title":"Getting started with epichains","text":"can aggregate objects returned simulate_chains() columns “cases” either “generation” “time”, depending value . aggregate “time”, must specified generation time distribution (generation_time) simulation step.","code":"# Example with simulate_chains() set.seed(32) # Define generation time generation_time_fn <- function(n) { gt <- rep(3, n) return(gt) } sim_chains <- simulate_chains( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, generation_time = generation_time_fn, lambda = 0.9 ) aggregate(sim_chains, by = \"time\") #> time cases #> 1 0 10 #> 2 3 12 #> 3 6 14 #> 4 9 17 #> 5 12 3 #> 6 15 4 #> 7 18 3"},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"plotting","dir":"Articles","previous_headings":"Other functionalities","what":"Plotting","title":"Getting started with epichains","text":"Aggregated objects can easily plotted using base R ggplot2 little data manipulation. end--end example simulation aggregation plotting.","code":"# Run simulation with simulate_chains() set.seed(32) # Define generation time generation_time_fn <- function(n) { gt <- rep(3, n) return(gt) } sim_chains <- simulate_chains( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 1000, generation_time = generation_time_fn, lambda = 2 ) # Aggregate cases over time sim_chains_aggreg <- aggregate(sim_chains, by = \"time\") # Plot cases over time plot( sim_chains_aggreg, type = \"b\", col = \"red\", lwd = 2, xlab = \"Time\", ylab = \"Cases\" )"},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/articles/interventions.html","id":"reducing-the-strength-of-transmission","dir":"Articles","previous_headings":"","what":"Reducing the strength of transmission","title":"Modelling disease control interventions","text":"Following (Lloyd-Smith et al. 2005) consider two ways disease control interventions can reduce reproduction number: population-wide individual-specific control.","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/interventions.html","id":"population-wide-control","dir":"Articles","previous_headings":"Reducing the strength of transmission","what":"Population-wide control","title":"Modelling disease control interventions","text":"population-level control mean intervention reduces mean number offspring (.e. reproduction number) fixed proportion. example, reduce R 25% population level scale mu parameter 1.2 0.9:","code":"sims <- simulate_summary( index_cases = 200, offspring_dist = rnbinom, stat_max = 99, mu = 0.9, size = 0.5, statistic = \"size\" ) sims[is.infinite(sims)] <- 100 # Replace infections > 99 with 100 for plotting. ggplot(data.frame(x = sims), aes(x = x)) + geom_histogram(breaks = seq(0, 100, by = 5), closed = \"left\") + scale_x_continuous(breaks = c(0, 25, 50, 75, 100), labels = c(0, 25, 50, 75, \">99\")) + theme_bw()"},{"path":"https://epiverse-trace.github.io/epichains/articles/interventions.html","id":"individual-level-control-","dir":"Articles","previous_headings":"Reducing the strength of transmission","what":"Individual-level control.","title":"Modelling disease control interventions","text":"simulating population-level control now apply reduction (25%) instead assuming mean reduced apply 25% individuals transmit , whereas remaining 75% generate offspring uncontrolled case. , can longer use standard negative binomial distribution comes R. Instead, define random generator modified negative binomial distribution includes individual-level control control argument indicating level individual-level control (0: control; 1: full control): defined , can generate simulations :","code":"rnbinom_ind <- function(n, ..., control = 0) { ## initialise number of offspring to 0 offspring <- rep(0L, n) ## for each individual, decide whether they transmit further transmits <- rbinom(n = n, prob = 1 - control, size = 1) ## check if anyone transmits further if (any(transmits == 1L)) { ## for those that transmit, sample from negative binomial with given ## parameters offspring[which(transmits == 1L)] <- rnbinom(n = n, ...) } return(offspring) } sims <- simulate_summary( index_cases = 200, offspring_dist = rnbinom_ind, stat_max = 99, mu = 1.2, size = 0.5, control = 0.25, statistic = \"size\" ) sims[is.infinite(sims)] <- 100 # Replace infections > 99 with 100 for plotting. ggplot(data.frame(x = sims), aes(x = x)) + geom_histogram(breaks = seq(0, 100, by = 5), closed = \"left\") + scale_x_continuous(breaks = c(0, 25, 50, 75, 100), labels = c(0, 25, 50, 75, \">99\")) + theme_bw()"},{"path":"https://epiverse-trace.github.io/epichains/articles/interventions.html","id":"preventing-superspreading-events","dir":"Articles","previous_headings":"","what":"Preventing superspreading events","title":"Modelling disease control interventions","text":"Another way controlling disease prevent individuals spreading large number others, example preventing mass gatherings , generally, settings superspreading events can occur. can model truncating offspring distribution certain size. can done, example, using truncdist R package. use define truncated negative binomial offspring distribution: use simulate chains situation maximum secondary cases infected person can generate 10. can likened disease control strategy gatherings limited 10 people.","code":"rnbinom_truncated <- function(n, ..., max = Inf) { return(rtrunc(n = n, spec = \"nbinom\", b = max, ...)) } sims <- simulate_summary( index_cases = 200, offspring_dist = rnbinom_truncated, stat_max = 99, mu = 1.2, size = 0.5, max = 10, statistic = \"size\" ) sims[is.infinite(sims)] <- 100 # Replace infections > 99 with 100 for plotting. ggplot(data.frame(x = sims), aes(x = x)) + geom_histogram(breaks = seq(0, 100, by = 5), closed = \"left\") + scale_x_continuous(breaks = c(0, 25, 50, 75, 100), labels = c(0, 25, 50, 75, \">99\")) + theme_bw()"},{"path":"https://epiverse-trace.github.io/epichains/articles/interventions.html","id":"truncating-the-generation-interval","dir":"Articles","previous_headings":"","what":"Truncating the generation interval","title":"Modelling disease control interventions","text":"Lastly, consider situation generation interval shortened. model explicitly instead consider effect offspring distribution. example, generation interval gamma distribution shape = 25 rate = 5 (corresponding mean 5 standard deviation 1), stop transmission normally occur 6 days infection, can calculate proportion transmissions prevented words, prevent 16% infections example. value control can used examples study effect outbreak sizes.","code":"control <- 1 - pgamma(6, shape = 25, rate = 5) signif(control, 2) #> [1] 0.16"},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"overview","dir":"Articles","previous_headings":"","what":"Overview","title":"Projecting infectious disease incidence: a COVID-19 example","text":"Branching processes can used project stochastic infectious disease trends time provided can characterize distribution times successive cases (serial interval), distribution secondary cases produced single individual (offspring distribution). simulations can achieved epichains simulate_chains() function Pearson et al. (2020), Abbott et al. (2020) illustrate application COVID-19. purpose vignette use early data COVID-19 South Africa (Marivate Combrink 2020) illustrate epichains can used project outbreak. Let’s load required packages","code":"library(\"epichains\") library(\"dplyr\") library(\"ggplot2\") library(\"lubridate\")"},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"data","dir":"Articles","previous_headings":"","what":"Data","title":"Projecting infectious disease incidence: a COVID-19 example","text":"Included epichains cleaned time series first 15 days COVID-19 outbreak South Africa. can loaded memory follows: use first \\(5\\) observations demonstration. assume cases subset imported infect . Let us subset view aspect data.","code":"data(\"covid19_sa\", package = \"epichains\") seed_cases <- covid19_sa[1:5, ] head(seed_cases) #> # A tibble: 5 × 2 #> date cases #> #> 1 2020-03-05 1 #> 2 2020-03-07 1 #> 3 2020-03-08 1 #> 4 2020-03-09 4 #> 5 2020-03-11 6"},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"setting-up-the-inputs","dir":"Articles","previous_headings":"","what":"Setting up the inputs","title":"Projecting infectious disease incidence: a COVID-19 example","text":"now proceed set simulate_chains() simulations.","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"onset-times","dir":"Articles","previous_headings":"Setting up the inputs","what":"Onset times","title":"Projecting infectious disease incidence: a COVID-19 example","text":"simulate_chains() requires vector seeding times, t0, chain/individual/simulation. get , use observation date index case reference find difference observed dates reference. Using vector start times time series, create corresponding seeding time individual, ’ll call tf.","code":"days_since_index <- as.integer(seed_cases$date - min(seed_cases$date)) days_since_index #> [1] 0 2 3 4 6 t0 <- rep(days_since_index, seed_cases$cases) t0 #> [1] 0 2 3 4 4 4 4 6 6 6 6 6 6"},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"generation-time","dir":"Articles","previous_headings":"Setting up the inputs","what":"Generation time","title":"Projecting infectious disease incidence: a COVID-19 example","text":"epidemiology, generation time (also called generation interval) duration successive infectious events chain transmission. Similarly, serial interval duration observed symptom onset times successive cases transmission chain. generation interval often hard observe exact times infection hard measure hence, serial interval often used instead. , use serial interval interpret simulated case data represent symptom onset. example, assume based COVID-19 literature serial interval, S, log-normal distributed parameters, \\(\\mu = 4.7\\) \\(\\sigma = 2.9\\) (Pearson et al. 2020). log-normal distribution commonly used epidemiology characterise quantities serial interval large variance can positive-valued (Nishiura 2007; Limpert, Stahel, Abbt 2001). Note distribution described way, means \\(\\mu\\) \\(\\sigma\\) expected value standard deviation natural logarithm serial interval. Hence, order sample “back-transformed” measured serial interval expectation/mean, \\(E[S]\\) standard deviation, \\(SD [S]\\), can use following parametrisation: \\[\\begin{align} E[S] &= \\ln \\left( \\dfrac{\\mu^2}{(\\sqrt{\\mu^2 + \\sigma^2}} \\right) \\\\ SD [S] &= \\sqrt {\\ln \\left(1 + \\dfrac{\\sigma^2}{\\mu^2} \\right)} \\end{align}\\] See “log-normal_distribution” Wikipedia detailed explanation parametrisation. now set generation time function appropriate inputs. adopt R’s random lognormal distribution generator (rlnorm()) takes meanlog sdlog arguments, define parametrisation log_mean() log_sd() respectively wrap generation_time_fn() function. Moreover, generation_time_fn() takes one argument n required epichains (See ?epichains::simulate_chains), passed rlnorm() first argument determine number observations sample (See ?rlnorm).","code":"mu <- 4.7 sgma <- 2.9 log_mean <- log((mu^2) / (sqrt(sgma^2 + mu^2))) # log mean log_sd <- sqrt(log(1 + (sgma / mu)^2)) # log sd #' serial interval function generation_time <- function(n) { gt <- rlnorm(n, meanlog = log_mean, sdlog = log_sd) return(gt) }"},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"offspring-distribution","dir":"Articles","previous_headings":"Setting up the inputs","what":"Offspring distribution","title":"Projecting infectious disease incidence: a COVID-19 example","text":"Let us now set offspring distribution, distribution drives mechanism behind individual cases infect cases. appropriate way model offspring distribution capture population-level transmissibility (\\(R0\\)) individual-level heterogeneity transmission (“superspreading”). negative binomial distribution commonly used case (Lloyd-Smith et al. 2005). example, assume offspring distribution characterised negative binomial \\(mu = 2.5\\) (Abbott et al. 2020) \\(size = 0.58\\) (Wang et al. 2020). parameterization, \\(mu\\) represents \\(R_0\\), defined average number cases produced single individual entirely susceptible population. parameter \\(size\\) represents superspreading, , degree heterogeneity transmission single individuals.","code":"mu <- 2.5 size <- 0.58"},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"simulation-controls","dir":"Articles","previous_headings":"Setting up the inputs","what":"Simulation controls","title":"Projecting infectious disease incidence: a COVID-19 example","text":"example, simulate outbreaks end \\(21\\) days last date observations seed_cases dataset. simulate_chains() stochastic, meaning results different every time run set parameters. , therefore, run simulations \\(100\\) times aggregate results. Let us specify . Lastly, since, specified \\(R0 > 1\\), means epidemic potentially grow without end. Hence, must specify end point simulations. simulate_chains() provides stat_max argument purpose. stat_max, simulation cut . value specified, assumes value infinity. , assume maximum chain size \\(1000\\).","code":"#' Date to end simulation projection_window <- 21 tf <- max(days_since_index) + projection_window tf #> [1] 27 #' Number of simulations sim_rep <- 100 #' Maximum chain size allowed stat_max <- 1000"},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"modelling-assumptions","dir":"Articles","previous_headings":"","what":"Modelling assumptions","title":"Projecting infectious disease incidence: a COVID-19 example","text":"exercise makes following simplifying assumptions: cases observed. Cases observed exactly time infection. reporting delay. Reporting rate constant course epidemic. interventions implemented. Population homogeneous well-mixed. summarise whole set far, going simulate chain 100 times, projecting cases 21 days first 6 days, assuming outbreak size exceeds 1000 cases.","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"running-the-simulations","dir":"Articles","previous_headings":"","what":"Running the simulations","title":"Projecting infectious disease incidence: a COVID-19 example","text":"use function lapply() run simulations bind rows dplyr::bind_rows(). Let us view first rows simulation results.","code":"set.seed(1234) sim_chain_sizes <- lapply( seq_len(sim_rep), function(sim) { simulate_chains( index_cases = length(t0), offspring_dist = rnbinom, mu = mu, size = size, statistic = \"size\", stat_max = stat_max, generation_time = generation_time, t0 = t0, tf = tf ) %>% mutate(sim = sim) } ) sim_output <- bind_rows(sim_chain_sizes) head(sim_output) #> infectee_id sim_id infector_id generation time sim #> 14 3 2 1 2 8.123133 1 #> 15 7 2 1 2 7.022334 1 #> 16 8 2 1 2 14.294014 1 #> 17 9 2 1 2 10.066390 1 #> 18 12 2 1 2 7.335446 1 #> 19 13 2 1 2 7.466435 1"},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"post-processing","dir":"Articles","previous_headings":"","what":"Post-processing","title":"Projecting infectious disease incidence: a COVID-19 example","text":"Now, summarise simulation results. want plot individual simulated daily time series show median cases per day aggregated simulations. First, create daily time series per simulation aggregating number cases per day simulation. Next, add date column results simulation set. use date first case observed data reference start date. Now aggregate simulations day evaluate median daily cases across simulations.","code":"# Daily number of cases for each simulation incidence_ts <- sim_output %>% mutate(day = ceiling(time)) %>% count(sim, day, name = \"cases\") %>% as_tibble() head(incidence_ts) #> # A tibble: 6 × 3 #> sim day cases #> #> 1 1 0 1 #> 2 1 2 1 #> 3 1 3 1 #> 4 1 4 4 #> 5 1 6 6 #> 6 1 7 1 # Get start date from the observed data index_date <- min(seed_cases$date) index_date #> [1] \"2020-03-05\" # Add a dates column to each simulation result incidence_ts_by_date <- incidence_ts %>% group_by(sim) %>% mutate(date = index_date + days(seq(0, n() - 1))) %>% ungroup() head(incidence_ts_by_date) #> # A tibble: 6 × 4 #> sim day cases date #> #> 1 1 0 1 2020-03-05 #> 2 1 2 1 2020-03-06 #> 3 1 3 1 2020-03-07 #> 4 1 4 4 2020-03-08 #> 5 1 6 6 2020-03-09 #> 6 1 7 1 2020-03-10 # Median daily number of cases aggregated across all simulations median_daily_cases <- incidence_ts_by_date %>% group_by(date) %>% summarise(median_cases = median(cases)) %>% ungroup() %>% arrange(date) head(median_daily_cases) #> # A tibble: 6 × 2 #> date median_cases #> #> 1 2020-03-05 1 #> 2 2020-03-06 1 #> 3 2020-03-07 1 #> 4 2020-03-08 4 #> 5 2020-03-09 5 #> 6 2020-03-10 8"},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"visualization","dir":"Articles","previous_headings":"","what":"Visualization","title":"Projecting infectious disease incidence: a COVID-19 example","text":"now plot individual simulation results alongside median aggregated results. Figure 1: COVID-19 incidence South Africa projected two week window 2020. light gray lines represent individual simulations, red line represents median daily cases across simulations, black connected dots represent observed data, dashed vertical line marks beginning projection.","code":"# since all simulations may end at a different date, we will find the minimum # final date for all simulations for the purposes of visualisation. final_date <- incidence_ts_by_date %>% group_by(sim) %>% summarise(final_date = max(date), .groups = \"drop\") %>% summarise(min_final_date = min(final_date)) %>% pull(min_final_date) incidence_ts_by_date <- incidence_ts_by_date %>% filter(date <= final_date) median_daily_cases <- median_daily_cases %>% filter(date <= final_date) ggplot(data = incidence_ts_by_date) + geom_line( aes( x = date, y = cases, group = sim ), color = \"grey\", linewidth = 0.2, alpha = 0.25 ) + geom_line( data = median_daily_cases, aes( x = date, y = median_cases ), color = \"tomato3\", linewidth = 1.8 ) + geom_point( data = covid19_sa, aes( x = date, y = cases ), color = \"black\", size = 1.75, shape = 21 ) + geom_line( data = covid19_sa, aes( x = date, y = cases ), color = \"black\", linewidth = 1 ) + scale_x_continuous( breaks = seq( min(incidence_ts_by_date$date), max(incidence_ts_by_date$date), 5 ), labels = seq( min(incidence_ts_by_date$date), max(incidence_ts_by_date$date), 5 ) ) + scale_y_continuous( breaks = seq( 0, max(incidence_ts_by_date$cases), 30 ), labels = seq( 0, max(incidence_ts_by_date$cases), 30 ) ) + geom_vline( mapping = aes(xintercept = max(seed_cases$date)), linetype = \"dashed\" ) + labs(x = \"Date\", y = \"Daily cases\")"},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"branching-processes","dir":"Articles","previous_headings":"","what":"Branching processes","title":"Theoretical background for epichains","text":"Branching processes class models used model growth populations. assume member population produces number offspring, \\(Z\\), random variable probability mass function \\(p(Z = z | \\theta)\\), called offspring distribution. use long history epidemiology, population interpreted pathogen, offspring new hosts infects (Farrington, Kanaan, Gay 2003). call infected individuals cases methods applied contexts branching processes used.","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"simulation","dir":"Articles","previous_headings":"","what":"Simulation","title":"Theoretical background for epichains","text":"simulate branching process, start single case proceed discrete steps generations, drawing offspring distribution \\(p(Z=z | \\theta)\\) generate new cases case. Given infector \\(\\) infectee \\(j\\), can additionally assign distribution times \\(T\\) approximates infection event occurred. define \\(T\\) random variable distribution \\(f(T = t; \\theta)\\) can assign case \\(j\\) time \\(t_{j}\\) , case \\(j\\) affected case \\(\\) given \\(f(t_{j} - t_{} | \\theta)\\). identify timing cases time symptom onset serial interval, depending case definitions another interval.","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"summary-statistics","dir":"Articles","previous_headings":"Simulation","what":"Summary statistics","title":"Theoretical background for epichains","text":"Branching process simulations end gone extinct, , offspring produced, stopping criterion. summarise simulations, either study size length resulting chain cases. size \\(S\\) chain number cases occurred course simulation including initial case \\(S \\geq 1\\). length \\(L\\) chain number generations simulated including initial case \\(L \\geq 1\\).","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"inference","dir":"Articles","previous_headings":"","what":"Inference","title":"Theoretical background for epichains","text":"characterising chains cases size length can conduct inference learn underlying parameters \\(\\theta\\) observation chain sizes chain lengths (Blumberg Lloyd-Smith 2013). general possible subcritical branching processes, .e. ones mean number offspring less 1, otherwise branching process grow forever. However, can expand theory supercritical branching processes, .e. ones mean number offspring greater 1, defining cut chain size length beyond treat chain infinite size length, respectively.","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"size-and-length-distributions-for-some-offspring-distributions","dir":"Articles","previous_headings":"Inference","what":"Size and length distributions for some offspring distributions","title":"Theoretical background for epichains","text":"show equations size length distributions offspring distributions can derived analytically: Poisson, negative binomial, geometric, gamma-Borel mixture.","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"negative-binomial-and-special-cases","dir":"Articles","previous_headings":"Inference > Size and length distributions for some offspring distributions","what":"Negative binomial and special cases","title":"Theoretical background for epichains","text":"offspring distribution Poisson distribution, can interpret rate parameter \\(\\lambda\\) basic reproduction number \\(R_{0}\\) pathogen. general case offspring definition can overdispersed leading superspreading can use negative binomial offspring distribution mean \\(\\mu\\) overdispersion \\(k\\) Blumberg Lloyd-Smith (2013). case, mean parameter \\(\\mu\\) interpreted basic reproduction number \\(R_0\\) pathogen. negative binomial distribution arises Poisson-gamma mixture thus branching process negative binomial distributed offspring can interpreted one Poisson distributed offspring basic reproduction number \\(R_0\\) varies according gamma distribution. amount variation \\(R_0\\) interpreted individual-level variation transmission representing overdispersion superspreading, degree happens given overdispersion parameter \\(k\\).","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"size-distributions","dir":"Articles","previous_headings":"Inference > Size and length distributions for some offspring distributions > Negative binomial and special cases","what":"Size distributions","title":"Theoretical background for epichains","text":"probability \\(p\\) chain size \\(S\\) given \\(R_0\\) \\(k\\) branching process negative binomial offspring distribution given Eq. 9 Blumberg Lloyd-Smith (2013) \\[ p(S|R_0, k) = \\frac{\\Gamma(kS + S - 1)}{\\Gamma(kS)\\Gamma(S + 1)} \\frac{\\left(\\frac{R_0}{k}\\right)^{S - 1}}{\\left( 1 + \\frac{R_0}{k} \\right)^{kS + S - 1}} \\] \\(\\Gamma\\) gamma function. order estimate \\(S\\) given \\(R_0\\) \\(k\\) can define likelihood function \\(L(S) = p(S|R_0, k)\\). corresponding log-likelihood \\[\\begin{align} \\mathrm{LL}(S) = &\\log\\Gamma(kS + S - 1) - \\left(\\log\\Gamma(kS) + \\log\\Gamma(S - 1) \\right) \\\\ & + (S-1) \\log \\frac{R_0}{k} - (SR_0 + (S - 1)) \\log \\left(1 + \\frac{R_0}{k}\\right) \\end{align}\\] log-likelihood Poisson distributed offspring follows \\(k\\) tends infinity (corresponding Eq. 2.2 Farrington, Kanaan, Gay (2003)) \\[ \\mathrm{LL}(S) = (S - 1) \\log R_0 - S R_0 + (S - 2) \\log S - \\log\\Gamma(S) \\] cases point estimate basic reproduction number \\(\\hat{R_0}\\) related mean chain size \\(\\bar{S}\\) \\[ \\hat{R_0} = 1 - \\frac{1}{\\bar{S}} \\]","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"length-distributions","dir":"Articles","previous_headings":"Inference > Size and length distributions for some offspring distributions > Negative binomial and special cases","what":"Length distributions","title":"Theoretical background for epichains","text":"cumulative mass function \\(F(L)\\) observing chain length \\(L\\) offspring Poisson distributed given Eq. (2.5) Farrington, Kanaan, Gay (2003) (called “outbreak duration”): \\[ F(L) = e^{-R_0} E_L \\left( e^{R_0 e^{-R_0} } \\right) \\] \\(E_L(x)\\) iterated exponential function, \\(E_0(x) = 1\\), \\(E_{L + 1}(x) = x^{E_L(x)}\\). geometric distributed offspring (corresponding negative Binomial \\(k=1\\)) function given \\[ F(L) = \\frac{ 1- R_0^{L + 1} } {1 - R_0^{L - 2}} \\] cases \\(f(L)\\) denotes cumulative mass functions therefore probability observing chain length \\(L\\) therefore \\(f(L) - f(L - 1)\\).","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"gamma-borel-mixture","dir":"Articles","previous_headings":"Inference > Size and length distributions for some offspring distributions","what":"Gamma-Borel mixture","title":"Theoretical background for epichains","text":"probability distribution outbreak sizes branching process Poisson offspring distribution (Eq. 2.2 Farrington, Kanaan, Gay (2003)) special case Borel-Tanner distribution starting 1 individual. alternative negative binomial offspring distribution represents Poisson-gamma mixture Borel-gamma mixture. represent situations variation individual level chain level, .e. transmission chains homogeneous heterogeneity chains. case, can shown resulting log-likelihood chain sizes \\[\\begin{align} \\mathrm{LL}(S) = &\\log\\Gamma(k + S - 1) - \\left(\\log\\Gamma(k) + \\log\\Gamma(S + 1) \\right) \\\\ & + (S-1) \\log S - k \\log \\left(S + \\frac{R_0}{k}\\right) \\end{align}\\]","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"numerical-approximations-of-chain-size-and-length-distributions","dir":"Articles","previous_headings":"Inference","what":"Numerical approximations of chain size and length distributions","title":"Theoretical background for epichains","text":"analytic likelihoods available numerical approximation used derive distributions. order , simulation functionality used generate \\(n\\) simulated chains value cumulative mass function \\(P(S|\\theta)\\) observed \\(S\\) approximated empirical cumulative distribution function: \\[ P(S|\\theta) \\approx \\sum_i \\mathbf{1}(x_i <= S) \\] \\(\\mathbf{1}\\) indicator function \\(x_i\\) -th observed chain size (length, interest \\(L\\)). order improve approximation linear approximation applied values empirical distribution function (expense normalisation 1). (unnormalised) probability observing \\(S\\) given \\[ p(S|\\theta) = P(S|\\theta) - P(S - 1|\\theta) \\] equivalent relationship used \\(L\\).","code":""},{"path":"https://epiverse-trace.github.io/epichains/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"James M. Azam. Author, maintainer. Hugo Gruson. Contributor, reviewer. Zhian N. Kamvar. Contributor. Flavio Finger. Author. Sebastian Funk. Author. Karim Mané. Reviewer. Pratik Gupte. Reviewer.","code":""},{"path":"https://epiverse-trace.github.io/epichains/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Azam J, Finger F, Funk S (2024). epichains: Simulating Analysing Transmission Chain Statistics Using Branching Process Models. R package version 0.0.0.9999, https://epiverse-trace.github.io/epichains/, https://github.com/epiverse-trace/epichains.","code":"@Manual{, title = {epichains: Simulating and Analysing Transmission Chain Statistics Using Branching Process Models}, author = {James M. Azam and Flavio Finger and Sebastian Funk}, year = {2024}, note = {R package version 0.0.0.9999, https://epiverse-trace.github.io/epichains/}, url = {https://github.com/epiverse-trace/epichains}, }"},{"path":"https://epiverse-trace.github.io/epichains/index.html","id":"epichains-methods-for-simulating-and-analysing-the-size-and-length-of-transmission-chains-from-branching-process-models-","dir":"","previous_headings":"","what":"Simulating and Analysing Transmission Chain Statistics Using Branching Process\n Models","title":"Simulating and Analysing Transmission Chain Statistics Using Branching Process\n Models","text":"epichains R package simulate, analyse, visualize size length branching processes given offspring distribution. models often used infectious disease epidemiology, chains represent chains transmission, offspring distribution represents distribution secondary infections caused infected individual. epichains re-implements bpmodels providing bespoke functions data structures allow easy manipulation interoperability Epiverse-TRACE packages, example, superspreading epiparameter, potentially existing packages handling transmission chains, example, epicontacts. epichains developed Centre Mathematical Modelling Infectious Diseases London School Hygiene Tropical Medicine part Epiverse Initiative.","code":""},{"path":"https://epiverse-trace.github.io/epichains/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Simulating and Analysing Transmission Chain Statistics Using Branching Process\n Models","text":"latest development version epichains package can installed via load package, use","code":"# check whether {pak} is installed if (!require(\"pak\")) install.packages(\"pak\") pak::pak(\"epiverse-trace/epichains\") library(\"epichains\")"},{"path":"https://epiverse-trace.github.io/epichains/index.html","id":"quick-start","dir":"","previous_headings":"","what":"Quick start","title":"Simulating and Analysing Transmission Chain Statistics Using Branching Process\n Models","text":"epichains provides two main functions: simulate_chains(): simulates transmission chains using simple branching process model accepts index number cases seed outbreak, distribution offspring per case, chain statistic track (size length/duration). optionally accepts population related inputs population size (defaults Inf) percentage population initially immune (defaults 0). function returns object columns track information infected , generation infection , generation time function specified, time infection. simulate_summary(): provides performant version simulate_chains() tracks return vector realized chain sizes lengths/durations index case without details infection tree. likelihood(): calculates loglikelihood (likelihood, depending value log) observing vector transmission chain sizes lengths. objects returned simulate_*() functions can summarised summary(). Running summary() output simulate_chains() return output simulate_summary() using inputs. Objects returned simulate_chains() can aggregated cases per time generation function aggregate(). aggregated results can also passed plot() arguments customize resulting plots. listed functionalities demonstrated detail “Getting Started” vignette.","code":""},{"path":"https://epiverse-trace.github.io/epichains/index.html","id":"package-vignettes","dir":"","previous_headings":"","what":"Package vignettes","title":"Simulating and Analysing Transmission Chain Statistics Using Branching Process\n Models","text":"theory behind models provided can found theory vignette. also collated bibliography branching process applications epidemiology. can found literature vignette. Specific use cases epichains can found online documentation package vignettes, “Articles”.","code":""},{"path":"https://epiverse-trace.github.io/epichains/index.html","id":"related-r-packages","dir":"","previous_headings":"","what":"Related R packages","title":"Simulating and Analysing Transmission Chain Statistics Using Branching Process\n Models","text":"far know, existing R packages simulating branching processes transmission chains. bpmodels: provides methods analysing size length transmission chains branching process models. epichains intended supersede {bpmodels}. ringbp: branching process model, parameterised 2019-nCoV outbreak, used quantify potential effectiveness contact tracing isolation cases. covidhm: code simulating COVID-19 dynamics range scenarios across real-world social network. model conceptually based {ringbp}. epicontacts: provides methods handling, analysing, visualizing transmission chains contact-tracing data/linelists. simulist: uses branching process model simulate individual-level infectious disease outbreak data, including line lists contact tracing data. package part Epiverse-TRACE Initiative. superspreading: provides set functions estimate understand individual-level variation transmission infectious diseases data secondary cases. useful understanding role superspreading spread infectious diseases informing public health interventions. earlyR: estimates reproduction number (R), early stages outbreak. model requires specified serial interval distribution, characterised mean standard deviation (Gamma) distribution, data daily disease incidence, including confirmed probable cases. projections: uses data daily incidence, serial interval (time onsets infectors infectees) reproduction number simulate plausible epidemic trajectories project future incidence. relies branching process daily incidence follows Poisson Negative Binomial distribution governed force infection. simulacr: simulates outbreaks specified values reproduction number, incubation period, duration infectiousness, optionally reporting delays. Outputs linelist stored data.frame class outbreak, including information transmission chains; output can converted objects visualisation. outbreakr: implements Bayesian approach reconstructing outbreak data pathogen genome sequences. also implements tool outbreak simulation. outbreakr2: Bayesian framework integrating epidemiological genetic data reconstruct transmission trees densely sampled outbreaks. re-implements, generalises replaces model outbreaker, uses modular approach enables fine customisation priors, likelihoods parameter movements. o2geosocial: integrates geographical social contact data reconstruct transmission chains. combines age group, location, onset date genotype cases infer import status, likely infector. nosoi: simulates agent-based transmission chains taking account influence multiple variables transmission process (e.g. dual-host systems (arboviruses), within-host viral dynamics, transportation, population structure), alone taken together, create complex relatively intuitive epidemiological simulations. TransPhylo: reconstructs infectious disease transmission using genomic data.","code":""},{"path":"https://epiverse-trace.github.io/epichains/index.html","id":"reporting-bugs","dir":"","previous_headings":"","what":"Reporting bugs","title":"Simulating and Analysing Transmission Chain Statistics Using Branching Process\n Models","text":"report bug please open issue.","code":""},{"path":"https://epiverse-trace.github.io/epichains/index.html","id":"contribute","dir":"","previous_headings":"","what":"Contribute","title":"Simulating and Analysing Transmission Chain Statistics Using Branching Process\n Models","text":"welcome contributions enhance package’s functionalities. wish , please follow package contributing guide.","code":""},{"path":"https://epiverse-trace.github.io/epichains/index.html","id":"code-of-conduct","dir":"","previous_headings":"","what":"Code of conduct","title":"Simulating and Analysing Transmission Chain Statistics Using Branching Process\n Models","text":"Please note epichains project released Contributor Code Conduct. contributing project, agree abide terms.","code":""},{"path":"https://epiverse-trace.github.io/epichains/index.html","id":"citing-this-package","dir":"","previous_headings":"","what":"Citing this package","title":"Simulating and Analysing Transmission Chain Statistics Using Branching Process\n Models","text":"","code":"citation(\"epichains\") #> To cite package 'epichains' in publications use: #> #> Azam J, Finger F, Funk S (2024). _epichains: Simulating and Analysing #> Transmission Chain Statistics Using Branching Process Models_. R #> package version 0.0.0.9999, #> https://epiverse-trace.github.io/epichains/, #> . #> #> A BibTeX entry for LaTeX users is #> #> @Manual{, #> title = {epichains: Simulating and Analysing Transmission Chain Statistics Using #> Branching Process Models}, #> author = {James M. Azam and Flavio Finger and Sebastian Funk}, #> year = {2024}, #> note = {R package version 0.0.0.9999, #> https://epiverse-trace.github.io/epichains/}, #> url = {https://github.com/epiverse-trace/epichains}, #> }"},{"path":"https://epiverse-trace.github.io/epichains/reference/aggregate.epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"Aggregate cases in objects by ","title":"Aggregate cases in objects by ","text":"function provides quick way create time series cases generation time (serials_dist specified) simulated objects.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/aggregate.epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Aggregate cases in objects by ","text":"","code":"# S3 method for epichains aggregate(x, by = c(\"time\", \"generation\"), ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/aggregate.epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Aggregate cases in objects by ","text":"x object. variable aggregate . Options include \"time\" \"generation\". ... ignored.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/aggregate.epichains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Aggregate cases in objects by ","text":" object cases .","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/aggregate.epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Aggregate cases in objects by ","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/aggregate.epichains.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Aggregate cases in objects by ","text":"","code":"set.seed(32) chains <- simulate_chains( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, generation_time = function(n) rep(3, n), lambda = 2 ) chains #> `` object #> #> < tree head (from first known infector_id) > #> #> infectee_id sim_id infector_id generation time #> 11 1 2 1 2 3 #> 12 2 2 1 2 3 #> 13 3 2 1 2 3 #> 14 4 2 1 2 3 #> 15 5 2 1 2 3 #> 16 6 2 1 2 3 #> #> #> Trees simulated: 10 #> Number of infectors (known): 9 #> Number of generations: 4 #> Use `as.data.frame()` to view the full output in the console. # Aggregate cases per time cases_per_time <- aggregate(chains, by = \"time\") head(cases_per_time) #> time cases #> 1 0 10 #> 2 3 25 #> 3 6 61 #> 4 9 33 # Aggregate cases per generation cases_per_gen <- aggregate(chains, by = \"generation\") head(cases_per_gen) #> generation cases #> 1 1 10 #> 2 2 25 #> 3 3 61 #> 4 4 33"},{"path":"https://epiverse-trace.github.io/epichains/reference/complementary_logprob.html","id":null,"dir":"Reference","previous_headings":"","what":"Calculates the complementary log-probability — complementary_logprob","title":"Calculates the complementary log-probability — complementary_logprob","text":"Given x norm, calculates log(1-sum(exp(x)))","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/complementary_logprob.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Calculates the complementary log-probability — complementary_logprob","text":"","code":"complementary_logprob(x)"},{"path":"https://epiverse-trace.github.io/epichains/reference/complementary_logprob.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Calculates the complementary log-probability — complementary_logprob","text":"x log-probabilities","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/complementary_logprob.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Calculates the complementary log-probability — complementary_logprob","text":"value","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/complementary_logprob.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Calculates the complementary log-probability — complementary_logprob","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/covid19_sa.html","id":null,"dir":"Reference","previous_headings":"","what":"COVID-19 Data Repository for South Africa — covid19_sa","title":"COVID-19 Data Repository for South Africa — covid19_sa","text":"aggregated subset COVID-19 Data Repository South Africa created, maintained hosted Data Science Social Impact research group, led Dr. Vukosi Marivate.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/covid19_sa.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"COVID-19 Data Repository for South Africa — covid19_sa","text":"","code":"covid19_sa"},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/reference/covid19_sa.html","id":"covid-sa","dir":"Reference","previous_headings":"","what":"covid19_sa","title":"COVID-19 Data Repository for South Africa — covid19_sa","text":"data frame 19 rows 2 columns: date Date case reported cases Number cases","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/covid19_sa.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"COVID-19 Data Repository for South Africa — covid19_sa","text":"https://github.com/dsfsi/covid19za details data-raw/covid19_sa.R.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/covid19_sa.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"COVID-19 Data Repository for South Africa — covid19_sa","text":"data originally provided linelist subsetted cleaned data-raw/covid19_sa.R.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dborel.html","id":null,"dir":"Reference","previous_headings":"","what":"Density of the Borel distribution — dborel","title":"Density of the Borel distribution — dborel","text":"Density Borel distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dborel.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Density of the Borel distribution — dborel","text":"","code":"dborel(x, mu, log = FALSE)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dborel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Density of the Borel distribution — dborel","text":"x Vector quantiles; integer. mu mu parameter (poisson mean); non-negative. log Logical; TRUE, probabilities p given log(p).","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dborel.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Density of the Borel distribution — dborel","text":"Probability mass.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dborel.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Density of the Borel distribution — dborel","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dborel.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Density of the Borel distribution — dborel","text":"","code":"set.seed(32) dborel(1:5, 1) #> [1] 0.36787944 0.13533528 0.07468060 0.04884170 0.03509347"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-adjust_next_gen.html","id":null,"dir":"Reference","previous_headings":"","what":"Adjust new offspring if it exceeds the susceptible population size — .adjust_next_gen","title":"Adjust new offspring if it exceeds the susceptible population size — .adjust_next_gen","text":"function used internally, input checking performed , context used. Using directly recommended.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-adjust_next_gen.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Adjust new offspring if it exceeds the susceptible population size — .adjust_next_gen","text":"","code":".adjust_next_gen(next_gen, susc_pop)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-adjust_next_gen.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Adjust new offspring if it exceeds the susceptible population size — .adjust_next_gen","text":"next_gen numeric; vector next generation offspring susc_pop numeric; susceptible population size","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-adjust_next_gen.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Adjust new offspring if it exceeds the susceptible population size — .adjust_next_gen","text":"numeric; adjusted next generation offspring vector","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_generation_time_valid.html","id":null,"dir":"Reference","previous_headings":"","what":"Check if the generation_time argument is specified as a function — .check_generation_time_valid","title":"Check if the generation_time argument is specified as a function — .check_generation_time_valid","text":"Check generation_time argument specified function","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_generation_time_valid.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check if the generation_time argument is specified as a function — .check_generation_time_valid","text":"","code":".check_generation_time_valid(generation_time)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_generation_time_valid.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check if the generation_time argument is specified as a function — .check_generation_time_valid","text":"generation_time generation time function; name user-defined named anonymous function one argument n, representing number generation times sample.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_offspring_func_valid.html","id":null,"dir":"Reference","previous_headings":"","what":"Check if constructed random number generator for offspring exists\nand has an n argument. — .check_offspring_func_valid","title":"Check if constructed random number generator for offspring exists\nand has an n argument. — .check_offspring_func_valid","text":"Check constructed random number generator offspring exists n argument.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_offspring_func_valid.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check if constructed random number generator for offspring exists\nand has an n argument. — .check_offspring_func_valid","text":"","code":".check_offspring_func_valid(offspring_dist)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_offspring_func_valid.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check if constructed random number generator for offspring exists\nand has an n argument. — .check_offspring_func_valid","text":"offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_sim_args.html","id":null,"dir":"Reference","previous_headings":"","what":"Check inputs to simulate_chains() and simulate_summary() — .check_sim_args","title":"Check inputs to simulate_chains() and simulate_summary() — .check_sim_args","text":"Check inputs simulate_chains() simulate_summary()","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_sim_args.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check inputs to simulate_chains() and simulate_summary() — .check_sim_args","text":"","code":".check_sim_args( index_cases, statistic, offspring_dist, stat_max, pop, percent_immune )"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_sim_args.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check inputs to simulate_chains() and simulate_summary() — .check_sim_args","text":"index_cases Number index cases simulate transmission chains . statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. stat_max cut chain statistic (size/length) computed. Results stat_max set stat_max. Defaults Inf. pop ; Population size. Used alongside percent_immune. define susceptible population. Defaults Inf. percent_immune ; Percent population immune infection start simulation. Used alongside pop initialise susceptible population. Accepted values lie 0 1. Defaults 0. sim_func ; simulation function check","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_sim_args.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Check inputs to simulate_chains() and simulate_summary() — .check_sim_args","text":"NULL; called side effects","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_statistic_args.html","id":null,"dir":"Reference","previous_headings":"","what":"Check that the statistic and stat_max arguments are valid — .check_statistic_args","title":"Check that the statistic and stat_max arguments are valid — .check_statistic_args","text":"function treats two arguments related checks one place remove repeated checks several places package.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_statistic_args.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check that the statistic and stat_max arguments are valid — .check_statistic_args","text":"","code":".check_statistic_args(statistic, stat_max)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_statistic_args.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check that the statistic and stat_max arguments are valid — .check_statistic_args","text":"statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. stat_max cut chain statistic (size/length) computed. Results stat_max set stat_max. Defaults Inf.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_statistic_args.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Check that the statistic and stat_max arguments are valid — .check_statistic_args","text":"NULL; called side effects","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_time_args.html","id":null,"dir":"Reference","previous_headings":"","what":"Check inputs that control time events — .check_time_args","title":"Check inputs that control time events — .check_time_args","text":"function checks time-related inputs, .e., start time chain, t0, end time simulation, tf, generation time, generation_time. also checks generation_time argument specified tf specified go hand--hand.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_time_args.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check inputs that control time events — .check_time_args","text":"","code":".check_time_args(tf_specified, tf, generation_time, t0)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_time_args.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check inputs that control time events — .check_time_args","text":"tf_specified ; Whether tf argument specified. makes sense context function called, .e., simulate_chains(). tf specified, generation_time must specified. tf Cut-infection times (generation time given). Defaults Inf. generation_time generation time function; name user-defined named anonymous function one argument n, representing number generation times sample. t0 Start time (generation time given); either single value vector length index_cases (number initial cases) corresponding initial times. Defaults 0, meaning cases started time 0.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_time_args.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Check inputs that control time events — .check_time_args","text":"NULL; called side effects","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-get_statistic_func.html","id":null,"dir":"Reference","previous_headings":"","what":"Return a function for calculating chain statistics — .get_statistic_func","title":"Return a function for calculating chain statistics — .get_statistic_func","text":"Return function calculating chain statistics","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-get_statistic_func.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Return a function for calculating chain statistics — .get_statistic_func","text":"","code":".get_statistic_func(chain_statistic)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-get_statistic_func.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Return a function for calculating chain statistics — .get_statistic_func","text":"function calculating chain statistics","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-get_susceptible_offspring.html","id":null,"dir":"Reference","previous_headings":"","what":"Sample the number of susceptible offspring from all possible offspring — .get_susceptible_offspring","title":"Sample the number of susceptible offspring from all possible offspring — .get_susceptible_offspring","text":"Sample susceptible offspring infected possible offspring. function used internally, input checking performed , context used. Using directly recommended.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-get_susceptible_offspring.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Sample the number of susceptible offspring from all possible offspring — .get_susceptible_offspring","text":"","code":".get_susceptible_offspring(new_offspring, susc_pop, pop)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-get_susceptible_offspring.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Sample the number of susceptible offspring from all possible offspring — .get_susceptible_offspring","text":"new_offspring vector possible new offspring per chain produced .sample_possible_offspring() pop ; Population size. Used alongside percent_immune. define susceptible population. Defaults Inf.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-get_susceptible_offspring.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Sample the number of susceptible offspring from all possible offspring — .get_susceptible_offspring","text":"vector number offspring can infected given current susceptible population size","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-init_susc_pop.html","id":null,"dir":"Reference","previous_headings":"","what":"Adjust next generation vector to match susceptible population size — .init_susc_pop","title":"Adjust next generation vector to match susceptible population size — .init_susc_pop","text":"Calculates initial susceptible population size given total population size, percent immune, number index cases. function used internally, input checking performed , context used. Using directly recommended.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-init_susc_pop.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Adjust next generation vector to match susceptible population size — .init_susc_pop","text":"","code":".init_susc_pop(pop, percent_immune, index_cases)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-init_susc_pop.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Adjust next generation vector to match susceptible population size — .init_susc_pop","text":"pop ; Population size. Used alongside percent_immune. define susceptible population. Defaults Inf. percent_immune ; Percent population immune infection start simulation. Used alongside pop initialise susceptible population. Accepted values lie 0 1. Defaults 0. index_cases Number index cases simulate transmission chains .","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-init_susc_pop.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Adjust next generation vector to match susceptible population size — .init_susc_pop","text":"numeric; initial susceptible population size","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-sample_possible_offspring.html","id":null,"dir":"Reference","previous_headings":"","what":"Sample all possible offspring for the next generation — .sample_possible_offspring","title":"Sample all possible offspring for the next generation — .sample_possible_offspring","text":"Sample next generation offspring using offspring distribution associated parameters. function used internally, input checking performed , context used. Using directly recommended.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-sample_possible_offspring.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Sample all possible offspring for the next generation — .sample_possible_offspring","text":"","code":".sample_possible_offspring( offspring_func, offspring_func_pars, n_offspring, chains )"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-sample_possible_offspring.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Sample all possible offspring for the next generation — .sample_possible_offspring","text":"offspring_func function sample offspring offspring_func_pars list parameters offspring function n_offspring vector number offspring per chain chains Indices chains/infectors simulated","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-sample_possible_offspring.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Sample all possible offspring for the next generation — .sample_possible_offspring","text":"vector number offspring per chain","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-update_chain_stat.html","id":null,"dir":"Reference","previous_headings":"","what":"Determine and update the chain statistic being tracked — .update_chain_stat","title":"Determine and update the chain statistic being tracked — .update_chain_stat","text":"Determine update chain statistic tracked","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-update_chain_stat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Determine and update the chain statistic being tracked — .update_chain_stat","text":"","code":".update_chain_stat(stat_type, stat_latest, n_offspring)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-update_chain_stat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Determine and update the chain statistic being tracked — .update_chain_stat","text":"stat_type Chain statistic (size/length) update. stat_latest latest chain statistic vector updated. n_offspring vector offspring per chain.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-update_chain_stat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Determine and update the chain statistic being tracked — .update_chain_stat","text":"vector chain statistics (size/length).","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains-package.html","id":null,"dir":"Reference","previous_headings":"","what":"epichains: Simulating and Analysing Transmission Chain Statistics Using Branching Process Models — epichains-package","title":"epichains: Simulating and Analysing Transmission Chain Statistics Using Branching Process Models — epichains-package","text":"Provides methods simulate analyse size length branching processes arbitrary offspring distribution. can used, example, analyse distribution chain sizes length infectious disease outbreaks, discussed Farrington et al. (2003) doi:10.1093/biostatistics/4.2.279 .","code":""},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"epichains: Simulating and Analysing Transmission Chain Statistics Using Branching Process Models — epichains-package","text":"Maintainer: James M. Azam james.azam@lshtm.ac.uk (ORCID) Authors: Flavio Finger flavio.finger@epicentre.msf.org (ORCID) Sebastian Funk sebastian.funk@lshtm.ac.uk (ORCID) contributors: Hugo Gruson hugo@data.org (ORCID) [contributor, reviewer] Zhian N. Kamvar zkamvar@gmail.com (ORCID) [contributor] Karim Mané karim.mane@lshtm.ac.uk (ORCID) [reviewer] Pratik Gupte pratik.gupte@lshtm.ac.uk (ORCID) [reviewer]","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"Create an object — epichains","title":"Create an object — epichains","text":"epichains() constructs object, inherently object stores inputs passed simulate_tree() simulate_tree_from_pop() simulated output. stored attributes useful downstream analyses reproducibility. function checks validity object created ensure right columns column types. object contains simulated outbreak tree ids infector infectee, generation, optionally, time, number initial cases used simulation, statistic tracked, whether susceptible population tracked.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create an object — epichains","text":"","code":"epichains(tree_df, index_cases, statistic, offspring_dist, stat_max, track_pop)"},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create an object — epichains","text":"tree_df containing least columns \"infectee_id\", \"infector_id\", \"generation\". Also optional columns \"time\", \"chain_id\". index_cases Number index cases simulate transmission chains . statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. stat_max cut chain statistic (size/length) computed. Results stat_max set stat_max. Defaults Inf. track_pop susceptible population tracked? Logical","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create an object — epichains","text":" object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Create an object — epichains","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains_summary.html","id":null,"dir":"Reference","previous_headings":"","what":"Create an object — epichains_summary","title":"Create an object — epichains_summary","text":"epichains_summary() constructs object. object simulated tree sizes lengths. also stores information number initial cases used simulation, statistic tracked, intervention level.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains_summary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create an object — epichains_summary","text":"","code":"epichains_summary( chains_summary, index_cases, statistic, offspring_dist, stat_max )"},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains_summary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create an object — epichains_summary","text":"chains_summary chain sizes lengths. index_cases Number index cases simulate transmission chains . statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. stat_max cut chain statistic (size/length) computed. Results stat_max set stat_max. Defaults Inf.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains_summary.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create an object — epichains_summary","text":" object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains_summary.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Create an object — epichains_summary","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"Format method for class — format.epichains","title":"Format method for class — format.epichains","text":"Format method class","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Format method for class — format.epichains","text":"","code":"# S3 method for epichains format(x, ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Format method for class — format.epichains","text":"x object ... ignored","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Format method for class — format.epichains","text":"Invisibly returns . Called printing side-effects.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Format method for class — format.epichains","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains_summary.html","id":null,"dir":"Reference","previous_headings":"","what":"Format method for class — format.epichains_summary","title":"Format method for class — format.epichains_summary","text":"Format method class","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains_summary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Format method for class — format.epichains_summary","text":"","code":"# S3 method for epichains_summary format(x, ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains_summary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Format method for class — format.epichains_summary","text":"x object ... ignored","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains_summary.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Format method for class — format.epichains_summary","text":"Invisibly returns . Called printing side-effects.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains_summary.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Format method for class — format.epichains_summary","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/gborel_size_ll.html","id":null,"dir":"Reference","previous_headings":"","what":"Log-likelihood of the size of chains with gamma-Borel offspring distribution — gborel_size_ll","title":"Log-likelihood of the size of chains with gamma-Borel offspring distribution — gborel_size_ll","text":"Log-likelihood size chains gamma-Borel offspring distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/gborel_size_ll.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Log-likelihood of the size of chains with gamma-Borel offspring distribution — gborel_size_ll","text":"","code":"gborel_size_ll(x, size, prob, mu)"},{"path":"https://epiverse-trace.github.io/epichains/reference/gborel_size_ll.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Log-likelihood of the size of chains with gamma-Borel offspring distribution — gborel_size_ll","text":"x vector sizes size dispersion parameter (often called k ecological applications) prob probability success (parameterisation prob, see also NegBinomial) mu mean parameter","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/gborel_size_ll.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Log-likelihood of the size of chains with gamma-Borel offspring distribution — gborel_size_ll","text":"log-likelihood values","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/gborel_size_ll.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Log-likelihood of the size of chains with gamma-Borel offspring distribution — gborel_size_ll","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/geom_length_ll.html","id":null,"dir":"Reference","previous_headings":"","what":"Log-likelihood of the length of chains with geometric offspring distribution — geom_length_ll","title":"Log-likelihood of the length of chains with geometric offspring distribution — geom_length_ll","text":"Log-likelihood length chains geometric offspring distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/geom_length_ll.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Log-likelihood of the length of chains with geometric offspring distribution — geom_length_ll","text":"","code":"geom_length_ll(x, prob)"},{"path":"https://epiverse-trace.github.io/epichains/reference/geom_length_ll.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Log-likelihood of the length of chains with geometric offspring distribution — geom_length_ll","text":"x vector lengths prob probability geometric distribution mean 1/prob","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/geom_length_ll.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Log-likelihood of the length of chains with geometric offspring distribution — geom_length_ll","text":"log-likelihood values","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/geom_length_ll.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Log-likelihood of the length of chains with geometric offspring distribution — geom_length_ll","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/head.epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"head and tail method for class — head.epichains","title":"head and tail method for class — head.epichains","text":"head tail method class","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/head.epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"head and tail method for class — head.epichains","text":"","code":"# S3 method for epichains head(x, ...) # S3 method for epichains tail(x, ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/head.epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"head and tail method for class — head.epichains","text":"x object ... arguments passed methods","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/head.epichains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"head and tail method for class — head.epichains","text":"Object class data.frame","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/head.epichains.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"head and tail method for class — head.epichains","text":"returns top rows object. Note object originally sorted sim_id infector_id first unknown infectors (NA) dropped printing method. view full output, use .data.frame().","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/head.epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"head and tail method for class — head.epichains","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/head.epichains.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"head and tail method for class — head.epichains","text":"","code":"set.seed(32) chains_pois_offspring <- simulate_chains( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, generation_time = function(n) rep(3, n), lambda = 2 ) head(chains_pois_offspring) #> infectee_id sim_id infector_id generation time #> 11 1 2 1 2 3 #> 12 2 2 1 2 3 #> 13 3 2 1 2 3 #> 14 4 2 1 2 3 #> 15 5 2 1 2 3 #> 16 6 2 1 2 3 set.seed(32) chains_pois_offspring <- simulate_chains( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, generation_time = function(n) rep(3, n), lambda = 2 ) tail(chains_pois_offspring) #> infectee_id sim_id infector_id generation time #> 124 6 19 6 3 6 #> 125 2 19 7 4 9 #> 126 6 20 6 3 6 #> 127 2 20 7 4 9 #> 128 2 21 7 4 9 #> 129 2 22 8 4 9"},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"Test if x is an epichains object — is_epichains","title":"Test if x is an epichains object — is_epichains","text":"Test x epichains object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Test if x is an epichains object — is_epichains","text":"","code":"is_epichains(x)"},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Test if x is an epichains object — is_epichains","text":"x R object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Test if x is an epichains object — is_epichains","text":"logical, TRUE object FALSE otherwise","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Test if x is an epichains object — is_epichains","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains_summary.html","id":null,"dir":"Reference","previous_headings":"","what":"Test if x is an epichains_summary object — is_epichains_summary","title":"Test if x is an epichains_summary object — is_epichains_summary","text":"Test x epichains_summary object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains_summary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Test if x is an epichains_summary object — is_epichains_summary","text":"","code":"is_epichains_summary(x)"},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains_summary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Test if x is an epichains_summary object — is_epichains_summary","text":"x R object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains_summary.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Test if x is an epichains_summary object — is_epichains_summary","text":"logical, TRUE object epichains_summary FALSE otherwise","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains_summary.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Test if x is an epichains_summary object — is_epichains_summary","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/likelihood.html","id":null,"dir":"Reference","previous_headings":"","what":"Estimate the log-likelihood/likelihood for observed branching processes — likelihood","title":"Estimate the log-likelihood/likelihood for observed branching processes — likelihood","text":"Estimate log-likelihood/likelihood observed branching processes","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/likelihood.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Estimate the log-likelihood/likelihood for observed branching processes — likelihood","text":"","code":"likelihood( chains, statistic = c(\"size\", \"length\"), offspring_dist, nsim_obs, obs_prob = 1, log = TRUE, stat_max = Inf, exclude = NULL, individual = FALSE, ... )"},{"path":"https://epiverse-trace.github.io/epichains/reference/likelihood.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Estimate the log-likelihood/likelihood for observed branching processes — likelihood","text":"chains Vector chain summaries (sizes/lengths) statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. nsim_obs Number simulations log-likelihood/likelihood approximated imperfect observations. obs_prob Observation probability (assumed constant) log Logical; log-likelihoods transformed likelihoods? (Defaults TRUE). stat_max cut chain statistic (size/length) computed. Results specified value, set Inf. exclude vector indices sizes/lengths exclude log-likelihood calculation. individual TRUE, vector individual log-likelihood/likelihood contributions returned rather sum/product. ... parameters pass simulate_summary","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/likelihood.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Estimate the log-likelihood/likelihood for observed branching processes — likelihood","text":"log = TRUE joint log-likelihood (sum individual log-likelihoods), individual == FALSE (default) obs_prob == 1 (default), list individual log-likelihoods, individual == TRUE obs_prob == 1 (default), list individual log-likelihoods (length nsim_obs), individual == TRUE 0 <= obs_prob < 1, vector joint log-likelihoods (length nsim_obs), individual == FALSE 0 <= obs_prob < 1 (imperfect observation). log = FALSE, structure outputs returned, except likelihoods, instead log-likelihoods, calculated cases. Moreover, joint likelihoods product, instead sum, individual likelihoods.","code":""},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/reference/likelihood.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Estimate the log-likelihood/likelihood for observed branching processes — likelihood","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/likelihood.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Estimate the log-likelihood/likelihood for observed branching processes — likelihood","text":"","code":"# example of observed chain sizes set.seed(121) # randomly generate 20 chains of size 1 to 10 chain_sizes <- sample(1:10, 20, replace = TRUE) likelihood( chains = chain_sizes, statistic = \"size\", offspring_dist = rpois, nsim_obs = 100, lambda = 0.5 ) #> [1] -67.82879"},{"path":"https://epiverse-trace.github.io/epichains/reference/nbinom_size_ll.html","id":null,"dir":"Reference","previous_headings":"","what":"Log-likelihood of the size of chains with Negative-Binomial offspring\ndistribution — nbinom_size_ll","title":"Log-likelihood of the size of chains with Negative-Binomial offspring\ndistribution — nbinom_size_ll","text":"Log-likelihood size chains Negative-Binomial offspring distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/nbinom_size_ll.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Log-likelihood of the size of chains with Negative-Binomial offspring\ndistribution — nbinom_size_ll","text":"","code":"nbinom_size_ll(x, size, prob, mu)"},{"path":"https://epiverse-trace.github.io/epichains/reference/nbinom_size_ll.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Log-likelihood of the size of chains with Negative-Binomial offspring\ndistribution — nbinom_size_ll","text":"x vector sizes size dispersion parameter (often called k ecological applications) prob probability success (parameterisation prob, see also NegBinomial) mu mean parameter","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/nbinom_size_ll.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Log-likelihood of the size of chains with Negative-Binomial offspring\ndistribution — nbinom_size_ll","text":"log-likelihood values","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/nbinom_size_ll.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Log-likelihood of the size of chains with Negative-Binomial offspring\ndistribution — nbinom_size_ll","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/new_epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"Construct an object — new_epichains","title":"Construct an object — new_epichains","text":"new_epichains() constructs object supplied extra attributes passed individual arguments. meant lazy performant, creating object without checking arguments correctness. safe call new_epichains() called within epichains() arguments checked. create object, use epichains().","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/new_epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Construct an object — new_epichains","text":"","code":"new_epichains( tree_df, index_cases, statistic, offspring_dist, stat_max, track_pop )"},{"path":"https://epiverse-trace.github.io/epichains/reference/new_epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Construct an object — new_epichains","text":"tree_df containing least columns \"infectee_id\", \"infector_id\", \"generation\". Also optional columns \"time\", \"chain_id\". index_cases Number index cases simulate transmission chains . statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. stat_max cut chain statistic (size/length) computed. Results stat_max set stat_max. Defaults Inf. track_pop susceptible population tracked? Logical","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/new_epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Construct an object — new_epichains","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/new_epichains_summary.html","id":null,"dir":"Reference","previous_headings":"","what":"Construct a object — new_epichains_summary","title":"Construct a object — new_epichains_summary","text":"new_epichains_summary() constructs object supplied chain sizes lengths. also stores extra attributes passed individual arguments. new_epichains_summary() meant lazy performant, creating object without checking arguments correctness. safe call new_epichains_summary() called within epichains_summary() arguments checked. create new object safely, use epichains_summary().","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/new_epichains_summary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Construct a object — new_epichains_summary","text":"","code":"new_epichains_summary( chains_summary, index_cases, statistic, offspring_dist, stat_max )"},{"path":"https://epiverse-trace.github.io/epichains/reference/new_epichains_summary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Construct a object — new_epichains_summary","text":"chains_summary chain sizes lengths. index_cases Number index cases simulate transmission chains . statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. stat_max cut chain statistic (size/length) computed. Results stat_max set stat_max. Defaults Inf.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/new_epichains_summary.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Construct a object — new_epichains_summary","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/offspring_ll.html","id":null,"dir":"Reference","previous_headings":"","what":"Log-likelihood of the summary (size/length) of chains with generic offspring\ndistribution — offspring_ll","title":"Log-likelihood of the summary (size/length) of chains with generic offspring\ndistribution — offspring_ll","text":"log-likelihoods calculated crude approximation using simulated chain summaries linearly approximating missing values empirical cumulative distribution function (ecdf).","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/offspring_ll.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Log-likelihood of the summary (size/length) of chains with generic offspring\ndistribution — offspring_ll","text":"","code":"offspring_ll(x, offspring_dist, statistic, nsim_offspring = 100, ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/offspring_ll.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Log-likelihood of the summary (size/length) of chains with generic offspring\ndistribution — offspring_ll","text":"x Vector chain summaries (sizes/lengths) offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. nsim_offspring Number simulations offspring distribution approximating distribution chain statistic summary (size/length) ... parameters pass simulate_summary","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/offspring_ll.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Log-likelihood of the summary (size/length) of chains with generic offspring\ndistribution — offspring_ll","text":"log-likelihood values","code":""},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/reference/offspring_ll.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Log-likelihood of the summary (size/length) of chains with generic offspring\ndistribution — offspring_ll","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/offspring_ll.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Log-likelihood of the summary (size/length) of chains with generic offspring\ndistribution — offspring_ll","text":"","code":"set.seed(123) chain_size_ll <- offspring_ll( x = c(1, 5, 6, 8, 7, 8, 10), offspring_dist = rpois, statistic = \"size\", lambda = 0.82 )"},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_length_ll.html","id":null,"dir":"Reference","previous_headings":"","what":"Log-likelihood of the length of chains with Poisson offspring distribution — pois_length_ll","title":"Log-likelihood of the length of chains with Poisson offspring distribution — pois_length_ll","text":"Log-likelihood length chains Poisson offspring distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_length_ll.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Log-likelihood of the length of chains with Poisson offspring distribution — pois_length_ll","text":"","code":"pois_length_ll(x, lambda)"},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_length_ll.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Log-likelihood of the length of chains with Poisson offspring distribution — pois_length_ll","text":"x vector lengths lambda rate Poisson distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_length_ll.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Log-likelihood of the length of chains with Poisson offspring distribution — pois_length_ll","text":"log-likelihood values","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_length_ll.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Log-likelihood of the length of chains with Poisson offspring distribution — pois_length_ll","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_size_ll.html","id":null,"dir":"Reference","previous_headings":"","what":"Log-likelihood of the size of chains with Poisson offspring distribution — pois_size_ll","title":"Log-likelihood of the size of chains with Poisson offspring distribution — pois_size_ll","text":"Log-likelihood size chains Poisson offspring distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_size_ll.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Log-likelihood of the size of chains with Poisson offspring distribution — pois_size_ll","text":"","code":"pois_size_ll(x, lambda)"},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_size_ll.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Log-likelihood of the size of chains with Poisson offspring distribution — pois_size_ll","text":"x vector sizes lambda rate Poisson distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_size_ll.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Log-likelihood of the size of chains with Poisson offspring distribution — pois_size_ll","text":"log-likelihood values","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_size_ll.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Log-likelihood of the size of chains with Poisson offspring distribution — pois_size_ll","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"Print an object — print.epichains","title":"Print an object — print.epichains","text":"Print object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print an object — print.epichains","text":"","code":"# S3 method for epichains print(x, ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print an object — print.epichains","text":"x object. ... parameters passed print().","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Print an object — print.epichains","text":"Invisibly returns . Called side-effects.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Print an object — print.epichains","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains_summary.html","id":null,"dir":"Reference","previous_headings":"","what":"Print an object — print.epichains_summary","title":"Print an object — print.epichains_summary","text":"Print object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains_summary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print an object — print.epichains_summary","text":"","code":"# S3 method for epichains_summary print(x, ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains_summary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print an object — print.epichains_summary","text":"x object. ... ignored.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains_summary.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Print an object — print.epichains_summary","text":"Invisibly returns . Called side-effects.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains_summary.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Print an object — print.epichains_summary","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rbinom_size.html","id":null,"dir":"Reference","previous_headings":"","what":"Samples size (the number of trials) of a binomial distribution — rbinom_size","title":"Samples size (the number of trials) of a binomial distribution — rbinom_size","text":"Samples size parameter binomial distribution fixed x (number successes) p (success probability)","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rbinom_size.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Samples size (the number of trials) of a binomial distribution — rbinom_size","text":"","code":"rbinom_size(n, x, prob)"},{"path":"https://epiverse-trace.github.io/epichains/reference/rbinom_size.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Samples size (the number of trials) of a binomial distribution — rbinom_size","text":"n number samples generate x number successes prob probability success","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rbinom_size.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Samples size (the number of trials) of a binomial distribution — rbinom_size","text":"sampled sizes","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rbinom_size.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Samples size (the number of trials) of a binomial distribution — rbinom_size","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rborel.html","id":null,"dir":"Reference","previous_headings":"","what":"Generate random numbers from the Borel distribution — rborel","title":"Generate random numbers from the Borel distribution — rborel","text":"Random numbers generated simulating Poisson branching process","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rborel.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Generate random numbers from the Borel distribution — rborel","text":"","code":"rborel(n, mu, infinite = Inf)"},{"path":"https://epiverse-trace.github.io/epichains/reference/rborel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Generate random numbers from the Borel distribution — rborel","text":"n Number random variates generate. mu mu parameter (poisson mean); non-negative. infinite number treat infinite; simulations stopped number reached","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rborel.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Generate random numbers from the Borel distribution — rborel","text":"Vector random numbers","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rborel.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Generate random numbers from the Borel distribution — rborel","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rborel.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Generate random numbers from the Borel distribution — rborel","text":"","code":"set.seed(32) rborel(5, 1) #> [1] 25 50 114 5 1"},{"path":"https://epiverse-trace.github.io/epichains/reference/rgborel.html","id":null,"dir":"Reference","previous_headings":"","what":"Generate random numbers from a Gamma-Borel mixture distribution — rgborel","title":"Generate random numbers from a Gamma-Borel mixture distribution — rgborel","text":"Generate random numbers Gamma-Borel mixture distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rgborel.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Generate random numbers from a Gamma-Borel mixture distribution — rgborel","text":"","code":"rgborel(n, size, prob, mu, infinite = Inf)"},{"path":"https://epiverse-trace.github.io/epichains/reference/rgborel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Generate random numbers from a Gamma-Borel mixture distribution — rgborel","text":"n Number random variates generate. size dispersion parameter (often called k ecological applications) prob probability success (parameterisation prob, see also NegBinomial) mu mean parameter infinite number treat infinite; simulations stopped number reached","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rgborel.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Generate random numbers from a Gamma-Borel mixture distribution — rgborel","text":"Numeric vector random numbers","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rgborel.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Generate random numbers from a Gamma-Borel mixture distribution — rgborel","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rgen_length.html","id":null,"dir":"Reference","previous_headings":"","what":"Samples chain lengths with given observation probabilities — rgen_length","title":"Samples chain lengths with given observation probabilities — rgen_length","text":"Samples length transmission chain individual element observed binomial probability parameters n (number successes) p (success probability)","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rgen_length.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Samples chain lengths with given observation probabilities — rgen_length","text":"","code":"rgen_length(n, x, prob)"},{"path":"https://epiverse-trace.github.io/epichains/reference/rgen_length.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Samples chain lengths with given observation probabilities — rgen_length","text":"n number samples generate x observed chain lengths prob probability observation","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rgen_length.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Samples chain lengths with given observation probabilities — rgen_length","text":"sampled lengths","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rgen_length.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Samples chain lengths with given observation probabilities — rgen_length","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rnbinom_mean_disp.html","id":null,"dir":"Reference","previous_headings":"","what":"Negative binomial random numbers parametrized\nin terms of mean and dispersion coefficient — rnbinom_mean_disp","title":"Negative binomial random numbers parametrized\nin terms of mean and dispersion coefficient — rnbinom_mean_disp","text":"Negative binomial random numbers parametrized terms mean dispersion coefficient","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rnbinom_mean_disp.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Negative binomial random numbers parametrized\nin terms of mean and dispersion coefficient — rnbinom_mean_disp","text":"","code":"rnbinom_mean_disp(n, mn, disp)"},{"path":"https://epiverse-trace.github.io/epichains/reference/rnbinom_mean_disp.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Negative binomial random numbers parametrized\nin terms of mean and dispersion coefficient — rnbinom_mean_disp","text":"n number samples draw mn mean distribution; Must > 0. disp dispersion coefficient (var/mean); Must > 1.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rnbinom_mean_disp.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Negative binomial random numbers parametrized\nin terms of mean and dispersion coefficient — rnbinom_mean_disp","text":"vector containing random numbers","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rnbinom_mean_disp.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Negative binomial random numbers parametrized\nin terms of mean and dispersion coefficient — rnbinom_mean_disp","text":"Flavio Finger","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rnbinom_mean_disp.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Negative binomial random numbers parametrized\nin terms of mean and dispersion coefficient — rnbinom_mean_disp","text":"","code":"set.seed(32) rnbinom_mean_disp(n = 5, mn = 4, disp = 2) #> [1] 5 9 6 3 6"},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":null,"dir":"Reference","previous_headings":"","what":"Simulate transmission chains — simulate_chains","title":"Simulate transmission chains — simulate_chains","text":"Generates transmission chains using simple branching process model accepts index number cases seed outbreak, distribution offspring per case, chain size length/duration (statistic) track. optionally accepts population related inputs population size (defaults Inf) percentage population initially immune (defaults 0).","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Simulate transmission chains — simulate_chains","text":"","code":"simulate_chains( index_cases, statistic = c(\"size\", \"length\"), offspring_dist, ..., stat_max = Inf, pop = Inf, percent_immune = 0, generation_time = NULL, t0 = 0, tf = Inf )"},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Simulate transmission chains — simulate_chains","text":"index_cases Number index cases simulate transmission chains . statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. ... Parameters offspring distribution required R. stat_max cut chain statistic (size/length) computed. Results stat_max set stat_max. Defaults Inf. pop ; Population size. Used alongside percent_immune. define susceptible population. Defaults Inf. percent_immune ; Percent population immune infection start simulation. Used alongside pop initialise susceptible population. Accepted values lie 0 1. Defaults 0. generation_time generation time function; name user-defined named anonymous function one argument n, representing number generation times sample. t0 Start time (generation time given); either single value vector length index_cases (number initial cases) corresponding initial times. Defaults 0, meaning cases started time 0. tf Cut-infection times (generation time given). Defaults Inf.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Simulate transmission chains — simulate_chains","text":" object, basically columns infectee_id, sim_id (unique ID within simulation infectee), infector_id, generation, time (infection)","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":"calculating-chain-sizes-and-lengths","dir":"Reference","previous_headings":"","what":"Calculating chain sizes and lengths","title":"Simulate transmission chains — simulate_chains","text":"function simulates chain size individual \\(\\) time \\(t\\), \\(I_{t, }\\), : $$I_{t, } = \\sum_{}^{I_{t-1}}X_{t, },$$ chain length/duration individual \\(\\) time \\(t\\), \\(L_{t, }\\), : $$L_{t, } = {\\sf min}(1, X_{t, }), $$ \\(X_{t, }\\) secondary cases generated individual \\(\\) time \\(t\\), \\(I_{0, } = L_{0, } = 1\\). distribution secondary cases, \\(X_{t, }\\) modelled offspring distribution (offspring_dist).","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":"specifying-generation-time","dir":"Reference","previous_headings":"","what":"Specifying generation_time","title":"Simulate transmission chains — simulate_chains","text":"argument generation_time must specified function one argument, n. example, assuming want specify generation time random log-normally distributed variable meanlog = 0.58 sdlog = 1.58, define named function, call \"generation_time_fn\", one argument representing number generation times sample: generation_time_fn <- function(n){rlnorm(n, 0.58, 1.38)}, assign name function generation_time simulation function, .e. `simulate_*`(..., generation_time = generation_time_fn), ... arguments simulate_*() * placeholder rest simulation function's name. Alternatively, assign anonymous function generation_time simulate_*() call, .e. simulate_*(..., generation_time = function(n){rlnorm(n, 0.58, 1.38)}) simulate_*(..., generation_time = \\(n){rlnorm(n, 0.58, 1.38)}), ... arguments simulate_*().","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Simulate transmission chains — simulate_chains","text":"Jacob C. (2010). Branching processes: role epidemiology. International journal environmental research public health, 7(3), 1186–1204. doi:10.3390/ijerph7031204 Blumberg, S., J. O. Lloyd-Smith. 2013. \"Comparing Methods Estimating R0 Size Distribution Subcritical Transmission Chains.\" Epidemics 5 (3): 131–45. doi:10.1016/j.epidem.2013.05.002 . Farrington, C. P., M. N. Kanaan, N. J. Gay. 2003. \"Branching Process Models Surveillance Infectious Diseases Controlled Mass Vaccination.” Biostatistics (Oxford, England) 4 (2): 279–95. doi:10.1093/biostatistics/4.2.279 .","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Simulate transmission chains — simulate_chains","text":"James M. Azam, Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Simulate transmission chains — simulate_chains","text":"","code":"# Using a Poisson offspring distribution and simulating from an infinite # population up to chain size 10. set.seed(32) chains_pois_offspring <- simulate_chains( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, generation_time = function(n) rep(3, n), lambda = 2 ) chains_pois_offspring #> `` object #> #> < tree head (from first known infector_id) > #> #> infectee_id sim_id infector_id generation time #> 11 1 2 1 2 3 #> 12 2 2 1 2 3 #> 13 3 2 1 2 3 #> 14 4 2 1 2 3 #> 15 5 2 1 2 3 #> 16 6 2 1 2 3 #> #> #> Trees simulated: 10 #> Number of infectors (known): 9 #> Number of generations: 4 #> Use `as.data.frame()` to view the full output in the console. # Using a Negative binomial offspring distribution and simulating from a # finite population up to chain size 10. set.seed(32) chains_nbinom_offspring <- simulate_chains( index_cases = 10, pop = 100, percent_immune = 0, statistic = \"size\", offspring_dist = rnbinom, stat_max = 10, generation_time = function(n) rep(3, n), mu = 2, size = 0.2 ) chains_nbinom_offspring #> `` object #> #> < tree head (from first known infector_id) > #> #> infectee_id sim_id infector_id generation time susc_pop #> 11 1 2 1 2 3 53 #> 12 2 2 1 2 3 53 #> 13 3 2 1 2 3 53 #> 14 4 2 1 2 3 53 #> 15 5 2 1 2 3 53 #> 16 6 2 1 2 3 53 #> #> #> Trees simulated: 10 #> Number of infectors (known): 5 #> Number of generations: 4 #> Use `as.data.frame()` to view the full output in the console."},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":null,"dir":"Reference","previous_headings":"","what":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"Generates vector transmission chain sizes lengths value index case. uses simple branching process model accepts index number cases seed outbreak, distribution offspring per case, chain size length/duration (statistic) track. optionally accepts population related inputs population size (defaults Inf) percentage population initially immune (defaults 0).","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"","code":"simulate_summary( index_cases, statistic = c(\"size\", \"length\"), offspring_dist, ..., stat_max = Inf, pop = Inf, percent_immune = 0 )"},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"index_cases Number index cases simulate transmission chains . statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. ... Parameters offspring distribution required R. stat_max cut chain statistic (size/length) computed. Results specified value, set Inf. pop ; Population size. Used alongside percent_immune. define susceptible population. Defaults Inf. percent_immune ; Percent population immune infection start simulation. Used alongside pop initialise susceptible population. Accepted values lie 0 1. Defaults 0.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"vector chain sizes lengths (class ) value index case.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":"simulate-summary-vs-simulate-chains-","dir":"Reference","previous_headings":"","what":"simulate_summary() vs simulate_chains()","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"simulate_summary() time-invariant version simulate_chains(). particular, track details individual transmission events deals eventual chain statistics, , statistic realised chain dying . useful generating vector chain sizes lengths given number index cases, details infected timing infection interest. function used {epichains} calculating likelihoods likelihood() function sampling borel distribution (See ?epichains::rborel). used extensively vignette modelling disease control, data observed chain sizes lengths available.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":"calculating-chain-sizes-and-lengths","dir":"Reference","previous_headings":"","what":"Calculating chain sizes and lengths","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"function simulates chain size individual \\(\\) time \\(t\\), \\(I_{t, }\\), : $$I_{t, } = \\sum_{}^{I_{t-1}}X_{t, },$$ chain length/duration individual \\(\\) time \\(t\\), \\(L_{t, }\\), : $$L_{t, } = {\\sf min}(1, X_{t, }), $$ \\(X_{t, }\\) secondary cases generated individual \\(\\) time \\(t\\), \\(I_{0, } = L_{0, } = 1\\). distribution secondary cases, \\(X_{t, }\\) modelled offspring distribution (offspring_dist).","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"Jacob C. (2010). Branching processes: role epidemiology. International journal environmental research public health, 7(3), 1186–1204. doi:10.3390/ijerph7031204 Blumberg, S., J. O. Lloyd-Smith. 2013. \"Comparing Methods Estimating R0 Size Distribution Subcritical Transmission Chains.\" Epidemics 5 (3): 131–45. doi:10.1016/j.epidem.2013.05.002 . Farrington, C. P., M. N. Kanaan, N. J. Gay. 2003. \"Branching Process Models Surveillance Infectious Diseases Controlled Mass Vaccination.” Biostatistics (Oxford, England) 4 (2): 279–95. doi:10.1093/biostatistics/4.2.279 .","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"James M. Azam, Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"","code":"# Simulate chain sizes with a poisson offspring distribution, assuming an # infinite population and no immunity. set.seed(32) simulate_summary( index_cases = 20, statistic = \"size\", offspring_dist = rpois, stat_max = 10, lambda = 0.9 ) #> `epichains_summary` object #> #> [1] 6 7 5 7 1 Inf 3 4 6 1 9 1 Inf Inf 1 3 Inf Inf 2 #> [20] 5 #> #> Simulated tree sizes: #> #> Max: 9 #> Min: 1 # Simulate chain sizes with a negative binomial distribution and assuming # a finite population and 10% immunity. set.seed(32) simulate_summary( pop = 1000, percent_immune = 0.1, index_cases = 20, statistic = \"size\", offspring_dist = rnbinom, stat_max = 10, mu = 0.9, size = 0.36 ) #> `epichains_summary` object #> #> [1] 1 1 1 2 2 4 2 1 1 4 1 1 2 1 1 2 1 1 1 1 #> #> Simulated tree sizes: #> #> Max: 4 #> Min: 1"},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"Summary method for class — summary.epichains","title":"Summary method for class — summary.epichains","text":"calculates chain statistic (size/length) simulated chains returns object information returned equivalent simulate_summary() call.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Summary method for class — summary.epichains","text":"","code":"# S3 method for epichains summary(object, ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Summary method for class — summary.epichains","text":"object object ... ignored","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Summary method for class — summary.epichains","text":" object containing chain summary statistics follows: \"size\": total number cases produced chain goes extinct. \"length\": total number infectors produced chain goes extinct.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Summary method for class — summary.epichains","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Summary method for class — summary.epichains","text":"","code":"# Using a negative binomial offspring distribution and simulating from a # finite population up to chain size 10. set.seed(32) sim_chains_nbinom <- simulate_chains( index_cases = 10, pop = 100, percent_immune = 0, statistic = \"size\", offspring_dist = rnbinom, stat_max = 10, mu = 2, size = 0.2 ) # Summarise the simulated chains sim_chains_nbinom_summary <- summary(sim_chains_nbinom) sim_chains_nbinom_summary #> `epichains_summary` object #> #> [1] 3 Inf Inf 5 6 Inf 1 1 1 1 #> #> Simulated tree sizes: #> #> Max: 6 #> Min: 1 # Same results can be obtained using `simulate_summary()` set.seed(32) sim_summary_nbinom <- simulate_summary( index_cases = 10, pop = 100, percent_immune = 0, statistic = \"size\", offspring_dist = rnbinom, stat_max = 10, mu = 2, size = 0.2 ) sim_summary_nbinom #> `epichains_summary` object #> #> [1] 3 Inf Inf 5 6 Inf 1 1 1 1 #> #> Simulated tree sizes: #> #> Max: 6 #> Min: 1 # Check that the results are the same setequal(sim_chains_nbinom_summary, sim_summary_nbinom) #> [1] TRUE"},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains_summary.html","id":null,"dir":"Reference","previous_headings":"","what":"Summary method for class — summary.epichains_summary","title":"Summary method for class — summary.epichains_summary","text":"Summary method class","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains_summary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Summary method for class — summary.epichains_summary","text":"","code":"# S3 method for epichains_summary summary(object, ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains_summary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Summary method for class — summary.epichains_summary","text":"object object ... ignored","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains_summary.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Summary method for class — summary.epichains_summary","text":"List summaries","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains_summary.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Summary method for class — summary.epichains_summary","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"Validate an object — validate_epichains","title":"Validate an object — validate_epichains","text":"Validate object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Validate an object — validate_epichains","text":"","code":"validate_epichains(x)"},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Validate an object — validate_epichains","text":"x object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Validate an object — validate_epichains","text":"return.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Validate an object — validate_epichains","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains_summary.html","id":null,"dir":"Reference","previous_headings":"","what":"Validate an object — validate_epichains_summary","title":"Validate an object — validate_epichains_summary","text":"Validate object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains_summary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Validate an object — validate_epichains_summary","text":"","code":"validate_epichains_summary(x)"},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains_summary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Validate an object — validate_epichains_summary","text":"x object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains_summary.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Validate an object — validate_epichains_summary","text":"return.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains_summary.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Validate an object — validate_epichains_summary","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/news/index.html","id":"epichains-009999","dir":"Changelog","previous_headings":"","what":"epichains 0.0.9999","title":"epichains 0.0.9999","text":"epichains re-implementation bpmodels focus providing dedicated class data structures easy manipulation interoperability new tools Epiverse existing ecosystem. offspring_dist argument changed longer accept character string, instead now accepts function (#25, #167, #188). expands number possible functions user can use longer restricted distributions corresponding random number generator function starting r...(). example: ```r # possible earlier versions package. my_poisson_wrapper <- function(n) { rpois(n, lambda = 0.9) } chain_summary_raw <- simulate_summary( index_cases = 2, offspring_dist = my_poisson_wrapper, statistic = “length” ) adding functionality rgborel function also added; difference previous behaviour, ll function name informed string passed now needs function name; function actually called estimating likelihood corresponding ll function exists , principle, empty dummy function; however, function included documentation/clarity purposes, well simulations.","code":""},{"path":"https://epiverse-trace.github.io/epichains/news/index.html","id":"documentation-0-0-9999","dir":"Changelog","previous_headings":"","what":"Documentation","title":"epichains 0.0.9999","text":"vignette outlining simulate interventions added.","code":""},{"path":"https://epiverse-trace.github.io/epichains/news/index.html","id":"functions-0-0-9999","dir":"Changelog","previous_headings":"","what":"Functions","title":"epichains 0.0.9999","text":"simulate_tree(): simulate transmission trees given number initial cases. simulate_tree_from_pop(): simulate transmission trees given population size initial immunity. simulate_summary(): simulate vector observed transmission chains sizes/lengths given number chains. likelihood(): estimate likelihood/loglikelihood observing chains given sizes/lengths.","code":""},{"path":"https://epiverse-trace.github.io/epichains/news/index.html","id":"methods-0-0-9999","dir":"Changelog","previous_headings":"","what":"Methods","title":"epichains 0.0.9999","text":"Use print() summary() obtain insightful results compared previously {bpmodels}. Use aggregate() aggregate results simulate_tree() simulate_tree_from_pop() cases “generation” “time” (time simulated)","code":""}] +[{"path":"https://epiverse-trace.github.io/epichains/CONTRIBUTING.html","id":null,"dir":"","previous_headings":"","what":"Contributing to epichains","title":"Contributing to epichains","text":"outlines propose change epichains.","code":""},{"path":"https://epiverse-trace.github.io/epichains/CONTRIBUTING.html","id":"making-changes","dir":"","previous_headings":"","what":"Making changes","title":"Contributing to epichains","text":"want make change, ’s good idea first file issue make sure someone team agrees ’s needed. ’ve found bug, please file issue illustrates bug minimal reprex (also help write unit test, needed). See bug report template. feature request see feature request.","code":""},{"path":"https://epiverse-trace.github.io/epichains/CONTRIBUTING.html","id":"pull-request-process","dir":"","previous_headings":"Making changes","what":"Pull request process","title":"Contributing to epichains","text":"See pull request template Fork package clone onto computer. haven’t done , recommend using usethis::create_from_github(\"epiverse-trace/epichains\", fork = TRUE). Install development dependencies devtools::install_dev_deps(), make sure package passes R CMD check running devtools::check(). R CMD check doesn’t pass cleanly, ’s good idea ask help continuing. Create Git branch pull request (PR). recommend using usethis::pr_init(\"brief-description--change\"). Make changes, commit git, create PR running usethis::pr_push(), following prompts browser. title PR briefly describe change. body PR contain Fixes #issue-number. user-facing changes, add bullet top NEWS.md (.e. just first header). Follow style described https://style.tidyverse.org/news.html.","code":""},{"path":"https://epiverse-trace.github.io/epichains/CONTRIBUTING.html","id":"code-style","dir":"","previous_headings":"Making changes","what":"Code style","title":"Contributing to epichains","text":"New code follow tidyverse style guide. can use styler package apply styles, please don’t restyle code nothing PR. use roxygen2, Markdown syntax, documentation. use testthat unit tests. Contributions test cases included easier accept.","code":""},{"path":"https://epiverse-trace.github.io/epichains/CONTRIBUTING.html","id":"code-of-conduct","dir":"","previous_headings":"","what":"Code of Conduct","title":"Contributing to epichains","text":"Please note epichains released Contributor Code Conduct. contributing project agree abide terms.","code":""},{"path":"https://epiverse-trace.github.io/epichains/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2023 epichains authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":[]},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"likelihood","dir":"Articles","previous_headings":"Chain likelihoods","what":"likelihood()","title":"Getting started with epichains","text":"function calculates likelihood/loglikelihood observing vector outbreak summaries obtained transmission chains. “Outbreak summaries” refer transmission chain sizes lengths/durations. likelihood() requires vector chain summaries (sizes lengths), chains, corresponding statistic calculate, statistic, offspring distribution, offspring_dist associated parameters. offspring_dist specified function used generate random numbers, .e. rpois Poisson, rnbinom negative binomial, custom function. closed-form solution available simulated replicates used estimate likelihoods. case likelihood() also requires nsim_offspring, number simulations run . argument explained next section. default, result log-likelihood log = FALSE, likelihoods returned. Let’s look following example estimate log-likelihood observing chain_sizes.","code":"set.seed(121) # example of observed chain sizes # randomly generate 20 chains of size between 1 to 10 chain_sizes <- sample(1:10, 20, replace = TRUE) chain_sizes #> [1] 4 7 4 9 1 3 7 5 1 8 10 2 1 2 4 5 10 6 8 7 # estimate loglikelihood of the observed chain sizes likelihood_eg <- likelihood( chains = chain_sizes, statistic = \"size\", offspring_dist = rpois, nsim_obs = 100, lambda = 0.5 ) # Print the estimate likelihood_eg #> [1] -67.82879"},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"joint-and-individual-log-likelihoods","dir":"Articles","previous_headings":"Chain likelihoods","what":"Joint and individual log-likelihoods","title":"Getting started with epichains","text":"likelihood(), default, returns joint log-likelihood. instead, individual log-likelihoods required, individual argument must set TRUE. return likelihoods instead, set log = FALSE.","code":"set.seed(121) # example of observed chain sizes # randomly generate 20 chains of size between 1 to 10 chain_sizes <- sample(1:10, 20, replace = TRUE) chain_sizes #> [1] 4 7 4 9 1 3 7 5 1 8 10 2 1 2 4 5 10 6 8 7 # estimate loglikelihood of the observed chain sizes likelihood_ind_eg <- likelihood( chains = chain_sizes, statistic = \"size\", offspring_dist = rpois, nsim_obs = 100, lambda = 0.5, individual = TRUE ) # Print the estimate likelihood_ind_eg #> [[1]] #> [1] -3.098612 -4.508584 -3.098612 -5.269208 -0.500000 -2.480829 -4.508584 #> [8] -3.622329 -0.500000 -4.900542 -5.619471 -1.693147 -0.500000 -1.693147 #> [15] -3.098612 -3.622329 -5.619471 -4.086190 -4.900542 -4.508584"},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"how-likelihood-works","dir":"Articles","previous_headings":"Chain likelihoods","what":"How likelihood() works","title":"Getting started with epichains","text":"epichains ships functions analytical solutions transmission chain “size” “length” distributions. size distributions, provide poisson, negative binomial, gamma-borel mixture. length distribution, provide poisson geometric distributions. can used likelihood() based specified offspring_dist statistic. analytical solution exist, provide offspring_ll(), uses simulations approximate probability distributions (using linear approximation cumulative distribution unobserved sizes/lengths). case, extra argument nsim_offspring must passed likelihood() specify number simulations used approximation. example, let’s look example chain_sizes observed want calculate likelihood drawn binomial distribution probability prob = 0.9.","code":"set.seed(121) # example of observed chain sizes; randomly generate 20 chains of size 1 to 10 chain_sizes <- sample(1:10, 20, replace = TRUE) # get their likelihood liks <- likelihood( chains = chain_sizes, offspring_dist = rbinom, statistic = \"size\", size = 1, prob = 0.9, nsim_offspring = 250 ) liks #> [1] -56.76805"},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"observation-probability","dir":"Articles","previous_headings":"Chain likelihoods","what":"Observation probability","title":"Getting started with epichains","text":"likelihood() uses argument obs_prob model observation probability. default, assumes perfect observation, obs_prob = 1 (See ?likelihood), meaning transmission events observed recorded data. observations imperfect, obs_prob must less 1. case imperfect observation, “true” chain sizes lengths simulated nsim_obs times, likelihood calculated simulations. example, probability observing case obs_prob = 0.30, use returns 10 likelihood values (nsim_obs = 10), can averaged come overall likelihood estimate. find usage likelihood() function, can run ?likelihood access R help file.","code":"set.seed(121) # example of observed chain sizes; randomly generate 20 chains of size 1 to 10 chain_sizes <- sample(1:10, 20, replace = TRUE) # get their likelihood liks <- likelihood( chains = chain_sizes, statistic = \"size\", offspring_dist = rpois, obs_prob = 0.3, lambda = 0.5, nsim_obs = 10 ) liks #> [1] -183.8670 -162.1382 -166.6720 -170.1077 -152.9557 -157.9814 -166.0587 #> [8] -174.8488 -156.4197 -160.0229"},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"transmission-chains-simulation","dir":"Articles","previous_headings":"","what":"Transmission chains simulation","title":"Getting started with epichains","text":"two simulation functions, herein referred collectively simulate_*() functions.","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"simulate_chains","dir":"Articles","previous_headings":"Transmission chains simulation","what":"simulate_chains()","title":"Getting started with epichains","text":"simulate_chains() simulates outbreak given number infections offspring distribution. default, assumes population infinite pre-existing immunity. function tracks returns information infectors (ancestors), infectees, generation infection, time, generation time function specified. Let’s look example simulate transmission tree \\(10\\) index cases. assume poisson offspring distribution mean, \\(\\text{lambda} = 0.9\\), generation time \\(3\\) days: Beyond defaults, simulate_chains() can also simulate outbreaks based specified population size pre-existing immunity susceptible pool runs . quick example simulate outbreak population size \\(1000\\) \\(10\\) index cases \\(10/%\\) pre-existing immunity. assume individuals poisson offspring distribution mean, \\(\\text{lambda} = 1\\), fixed generation time \\(3\\):","code":"set.seed(32) # Define generation time generation_time_fn <- function(n) { gt <- rep(3, n) return(gt) } sim_chains <- simulate_chains( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, generation_time = generation_time_fn, lambda = 0.9 ) head(sim_chains) #> infectee_id sim_id infector_id generation time #> 11 1 2 1 2 3 #> 12 2 2 1 2 3 #> 13 3 2 1 2 3 #> 14 4 2 1 2 3 #> 15 6 2 1 2 3 #> 16 7 2 1 2 3 set.seed(32) # Define generation time generation_time_fn <- function(n) { gt <- rep(3, n) return(gt) } sim_chains_with_pop <- simulate_chains( pop = 1000, index_cases = 10, percent_immune = 0.1, offspring_dist = rpois, statistic = \"size\", lambda = 1, generation_time = generation_time_fn ) head(sim_chains_with_pop) #> infectee_id sim_id infector_id generation time susc_pop #> 11 1 2 1 2 3 877 #> 12 2 2 1 2 3 877 #> 13 3 2 1 2 3 877 #> 14 4 2 1 2 3 877 #> 15 6 2 1 2 3 877 #> 16 7 2 1 2 3 877"},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"simulate_summary","dir":"Articles","previous_headings":"Transmission chains simulation","what":"simulate_summary()","title":"Getting started with epichains","text":"simulate_summary() performant version simulate_chains() track information infector infectee. returns eventual size length/duration transmission chain. function especially useful calculating numerical likelihoods likelihood(). example simulate previous examples without intervention, returning size \\(10\\) chains. assumes poisson offspring distribution mean \\(0.9\\).","code":"set.seed(123) simulate_summary_eg <- simulate_summary( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, lambda = 0.9 ) # Print the results simulate_summary_eg #> `epichains_summary` object #> #> [1] 1 Inf 4 4 Inf 1 2 Inf 5 3 #> #> Simulated tree sizes: #> #> Max: 5 #> Min: 1"},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"summarising","dir":"Articles","previous_headings":"Other functionalities","what":"Summarising","title":"Getting started with epichains","text":"can run summary() object returned simulate_chains() obtain chain summaries per index case. summary output simulate_summary() inputs used. simulate_summary() performant version simulate_chains(), hence, can use instead, interested summary simulated chains without details infection tree. can confirm two outputs using base::setequal()","code":"set.seed(32) # Define generation time generation_time_fn <- function(n) { gt <- rep(3, n) return(gt) } sim_chains <- simulate_chains( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, generation_time = generation_time_fn, lambda = 0.9 ) summary(sim_chains) #> `epichains_summary` object #> #> [1] Inf 2 Inf 2 1 Inf 3 Inf 9 1 #> #> Simulated tree sizes: #> #> Max: 9 #> Min: 1 # Example with simulate_summary() set.seed(32) simulate_summary_eg <- simulate_summary( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, lambda = 0.9 ) # Get summaries summary(simulate_summary_eg) #> $index_cases #> [1] 10 #> #> $max_stat #> [1] 9 #> #> $min_stat #> [1] 1 setequal( # summary of output from simulate_chains() summary(sim_chains), # results from simulate_summary() simulate_summary_eg ) #> [1] TRUE"},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"aggregating","dir":"Articles","previous_headings":"Other functionalities","what":"Aggregating","title":"Getting started with epichains","text":"can aggregate objects returned simulate_chains() columns “cases” either “generation” “time”, depending value . aggregate “time”, must specified generation time distribution (generation_time) simulation step.","code":"# Example with simulate_chains() set.seed(32) # Define generation time generation_time_fn <- function(n) { gt <- rep(3, n) return(gt) } sim_chains <- simulate_chains( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, generation_time = generation_time_fn, lambda = 0.9 ) aggregate(sim_chains, by = \"time\") #> time cases #> 1 0 10 #> 2 3 12 #> 3 6 14 #> 4 9 17 #> 5 12 3 #> 6 15 4 #> 7 18 3"},{"path":"https://epiverse-trace.github.io/epichains/articles/epichains.html","id":"plotting","dir":"Articles","previous_headings":"Other functionalities","what":"Plotting","title":"Getting started with epichains","text":"Aggregated objects can easily plotted using base R ggplot2 little data manipulation. end--end example simulation aggregation plotting.","code":"# Run simulation with simulate_chains() set.seed(32) # Define generation time generation_time_fn <- function(n) { gt <- rep(3, n) return(gt) } sim_chains <- simulate_chains( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 1000, generation_time = generation_time_fn, lambda = 2 ) # Aggregate cases over time sim_chains_aggreg <- aggregate(sim_chains, by = \"time\") # Plot cases over time plot( sim_chains_aggreg, type = \"b\", col = \"red\", lwd = 2, xlab = \"Time\", ylab = \"Cases\" )"},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/articles/interventions.html","id":"reducing-the-strength-of-transmission","dir":"Articles","previous_headings":"","what":"Reducing the strength of transmission","title":"Modelling disease control interventions","text":"Following (Lloyd-Smith et al. 2005) consider two ways disease control interventions can reduce reproduction number: population-wide individual-specific control.","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/interventions.html","id":"population-wide-control","dir":"Articles","previous_headings":"Reducing the strength of transmission","what":"Population-wide control","title":"Modelling disease control interventions","text":"population-level control mean intervention reduces mean number offspring (.e. reproduction number) fixed proportion. example, reduce R 25% population level scale mu parameter 1.2 0.9:","code":"sims <- simulate_summary( index_cases = 200, offspring_dist = rnbinom, stat_max = 99, mu = 0.9, size = 0.5, statistic = \"size\" ) sims[is.infinite(sims)] <- 100 # Replace infections > 99 with 100 for plotting. ggplot(data.frame(x = sims), aes(x = x)) + geom_histogram(breaks = seq(0, 100, by = 5), closed = \"left\") + scale_x_continuous(breaks = c(0, 25, 50, 75, 100), labels = c(0, 25, 50, 75, \">99\")) + theme_bw()"},{"path":"https://epiverse-trace.github.io/epichains/articles/interventions.html","id":"individual-level-control-","dir":"Articles","previous_headings":"Reducing the strength of transmission","what":"Individual-level control.","title":"Modelling disease control interventions","text":"simulating population-level control now apply reduction (25%) instead assuming mean reduced apply 25% individuals transmit , whereas remaining 75% generate offspring uncontrolled case. , can longer use standard negative binomial distribution comes R. Instead, define random generator modified negative binomial distribution includes individual-level control control argument indicating level individual-level control (0: control; 1: full control): defined , can generate simulations :","code":"rnbinom_ind <- function(n, ..., control = 0) { ## initialise number of offspring to 0 offspring <- rep(0L, n) ## for each individual, decide whether they transmit further transmits <- rbinom(n = n, prob = 1 - control, size = 1) ## check if anyone transmits further if (any(transmits == 1L)) { ## for those that transmit, sample from negative binomial with given ## parameters offspring[which(transmits == 1L)] <- rnbinom(n = n, ...) } return(offspring) } sims <- simulate_summary( index_cases = 200, offspring_dist = rnbinom_ind, stat_max = 99, mu = 1.2, size = 0.5, control = 0.25, statistic = \"size\" ) sims[is.infinite(sims)] <- 100 # Replace infections > 99 with 100 for plotting. ggplot(data.frame(x = sims), aes(x = x)) + geom_histogram(breaks = seq(0, 100, by = 5), closed = \"left\") + scale_x_continuous(breaks = c(0, 25, 50, 75, 100), labels = c(0, 25, 50, 75, \">99\")) + theme_bw()"},{"path":"https://epiverse-trace.github.io/epichains/articles/interventions.html","id":"preventing-superspreading-events","dir":"Articles","previous_headings":"","what":"Preventing superspreading events","title":"Modelling disease control interventions","text":"Another way controlling disease prevent individuals spreading large number others, example preventing mass gatherings , generally, settings superspreading events can occur. can model truncating offspring distribution certain size. can done, example, using truncdist R package. use define truncated negative binomial offspring distribution: use simulate chains situation maximum secondary cases infected person can generate 10. can likened disease control strategy gatherings limited 10 people.","code":"rnbinom_truncated <- function(n, ..., max = Inf) { return(rtrunc(n = n, spec = \"nbinom\", b = max, ...)) } sims <- simulate_summary( index_cases = 200, offspring_dist = rnbinom_truncated, stat_max = 99, mu = 1.2, size = 0.5, max = 10, statistic = \"size\" ) sims[is.infinite(sims)] <- 100 # Replace infections > 99 with 100 for plotting. ggplot(data.frame(x = sims), aes(x = x)) + geom_histogram(breaks = seq(0, 100, by = 5), closed = \"left\") + scale_x_continuous(breaks = c(0, 25, 50, 75, 100), labels = c(0, 25, 50, 75, \">99\")) + theme_bw()"},{"path":"https://epiverse-trace.github.io/epichains/articles/interventions.html","id":"truncating-the-generation-interval","dir":"Articles","previous_headings":"","what":"Truncating the generation interval","title":"Modelling disease control interventions","text":"Lastly, consider situation generation interval shortened. model explicitly instead consider effect offspring distribution. example, generation interval gamma distribution shape = 25 rate = 5 (corresponding mean 5 standard deviation 1), stop transmission normally occur 6 days infection, can calculate proportion transmissions prevented words, prevent 16% infections example. value control can used examples study effect outbreak sizes.","code":"control <- 1 - pgamma(6, shape = 25, rate = 5) signif(control, 2) #> [1] 0.16"},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"overview","dir":"Articles","previous_headings":"","what":"Overview","title":"Projecting infectious disease incidence: a COVID-19 example","text":"Branching processes can used project stochastic infectious disease trends time provided can characterize distribution times successive cases (serial interval), distribution secondary cases produced single individual (offspring distribution). simulations can achieved epichains simulate_chains() function Pearson et al. (2020), Abbott et al. (2020) illustrate application COVID-19. purpose vignette use early data COVID-19 South Africa (Marivate Combrink 2020) illustrate epichains can used project outbreak. Let’s load required packages","code":"library(\"epichains\") library(\"dplyr\") library(\"ggplot2\") library(\"lubridate\")"},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"data","dir":"Articles","previous_headings":"","what":"Data","title":"Projecting infectious disease incidence: a COVID-19 example","text":"Included epichains cleaned time series first 15 days COVID-19 outbreak South Africa. can loaded memory follows: use first \\(5\\) observations demonstration. assume cases subset imported infect . Let us subset view aspect data.","code":"data(\"covid19_sa\", package = \"epichains\") seed_cases <- covid19_sa[1:5, ] head(seed_cases) #> # A tibble: 5 × 2 #> date cases #> #> 1 2020-03-05 1 #> 2 2020-03-07 1 #> 3 2020-03-08 1 #> 4 2020-03-09 4 #> 5 2020-03-11 6"},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"setting-up-the-inputs","dir":"Articles","previous_headings":"","what":"Setting up the inputs","title":"Projecting infectious disease incidence: a COVID-19 example","text":"now proceed set simulate_chains() simulations.","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"onset-times","dir":"Articles","previous_headings":"Setting up the inputs","what":"Onset times","title":"Projecting infectious disease incidence: a COVID-19 example","text":"simulate_chains() requires vector seeding times, t0, chain/individual/simulation. get , use observation date index case reference find difference observed dates reference. Using vector start times time series, create corresponding seeding time individual, ’ll call tf.","code":"days_since_index <- as.integer(seed_cases$date - min(seed_cases$date)) days_since_index #> [1] 0 2 3 4 6 t0 <- rep(days_since_index, seed_cases$cases) t0 #> [1] 0 2 3 4 4 4 4 6 6 6 6 6 6"},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"generation-time","dir":"Articles","previous_headings":"Setting up the inputs","what":"Generation time","title":"Projecting infectious disease incidence: a COVID-19 example","text":"epidemiology, generation time (also called generation interval) duration successive infectious events chain transmission. Similarly, serial interval duration observed symptom onset times successive cases transmission chain. generation interval often hard observe exact times infection hard measure hence, serial interval often used instead. , use serial interval interpret simulated case data represent symptom onset. example, assume based COVID-19 literature serial interval, S, log-normal distributed parameters, \\(\\mu = 4.7\\) \\(\\sigma = 2.9\\) (Pearson et al. 2020). log-normal distribution commonly used epidemiology characterise quantities serial interval large variance can positive-valued (Nishiura 2007; Limpert, Stahel, Abbt 2001). Note distribution described way, means \\(\\mu\\) \\(\\sigma\\) expected value standard deviation natural logarithm serial interval. Hence, order sample “back-transformed” measured serial interval expectation/mean, \\(E[S]\\) standard deviation, \\(SD [S]\\), can use following parametrisation: \\[\\begin{align} E[S] &= \\ln \\left( \\dfrac{\\mu^2}{(\\sqrt{\\mu^2 + \\sigma^2}} \\right) \\\\ SD [S] &= \\sqrt {\\ln \\left(1 + \\dfrac{\\sigma^2}{\\mu^2} \\right)} \\end{align}\\] See “log-normal_distribution” Wikipedia detailed explanation parametrisation. now set generation time function appropriate inputs. adopt R’s random lognormal distribution generator (rlnorm()) takes meanlog sdlog arguments, define parametrisation log_mean() log_sd() respectively wrap generation_time_fn() function. Moreover, generation_time_fn() takes one argument n required epichains (See ?epichains::simulate_chains), passed rlnorm() first argument determine number observations sample (See ?rlnorm).","code":"mu <- 4.7 sgma <- 2.9 log_mean <- log((mu^2) / (sqrt(sgma^2 + mu^2))) # log mean log_sd <- sqrt(log(1 + (sgma / mu)^2)) # log sd #' serial interval function generation_time <- function(n) { gt <- rlnorm(n, meanlog = log_mean, sdlog = log_sd) return(gt) }"},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"offspring-distribution","dir":"Articles","previous_headings":"Setting up the inputs","what":"Offspring distribution","title":"Projecting infectious disease incidence: a COVID-19 example","text":"Let us now set offspring distribution, distribution drives mechanism behind individual cases infect cases. appropriate way model offspring distribution capture population-level transmissibility (\\(R0\\)) individual-level heterogeneity transmission (“superspreading”). negative binomial distribution commonly used case (Lloyd-Smith et al. 2005). example, assume offspring distribution characterised negative binomial \\(mu = 2.5\\) (Abbott et al. 2020) \\(size = 0.58\\) (Wang et al. 2020). parameterization, \\(mu\\) represents \\(R_0\\), defined average number cases produced single individual entirely susceptible population. parameter \\(size\\) represents superspreading, , degree heterogeneity transmission single individuals.","code":"mu <- 2.5 size <- 0.58"},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"simulation-controls","dir":"Articles","previous_headings":"Setting up the inputs","what":"Simulation controls","title":"Projecting infectious disease incidence: a COVID-19 example","text":"example, simulate outbreaks end \\(21\\) days last date observations seed_cases dataset. simulate_chains() stochastic, meaning results different every time run set parameters. , therefore, run simulations \\(100\\) times aggregate results. Let us specify . Lastly, since, specified \\(R0 > 1\\), means epidemic potentially grow without end. Hence, must specify end point simulations. simulate_chains() provides stat_max argument purpose. stat_max, simulation cut . value specified, assumes value infinity. , assume maximum chain size \\(1000\\).","code":"#' Date to end simulation projection_window <- 21 tf <- max(days_since_index) + projection_window tf #> [1] 27 #' Number of simulations sim_rep <- 100 #' Maximum chain size allowed stat_max <- 1000"},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"modelling-assumptions","dir":"Articles","previous_headings":"","what":"Modelling assumptions","title":"Projecting infectious disease incidence: a COVID-19 example","text":"exercise makes following simplifying assumptions: cases observed. Cases observed exactly time infection. reporting delay. Reporting rate constant course epidemic. interventions implemented. Population homogeneous well-mixed. summarise whole set far, going simulate chain 100 times, projecting cases 21 days first 6 days, assuming outbreak size exceeds 1000 cases.","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"running-the-simulations","dir":"Articles","previous_headings":"","what":"Running the simulations","title":"Projecting infectious disease incidence: a COVID-19 example","text":"use function lapply() run simulations bind rows dplyr::bind_rows(). Let us view first rows simulation results.","code":"set.seed(1234) sim_chain_sizes <- lapply( seq_len(sim_rep), function(sim) { simulate_chains( index_cases = length(t0), offspring_dist = rnbinom, mu = mu, size = size, statistic = \"size\", stat_max = stat_max, generation_time = generation_time, t0 = t0, tf = tf ) %>% mutate(sim = sim) } ) sim_output <- bind_rows(sim_chain_sizes) head(sim_output) #> infectee_id sim_id infector_id generation time sim #> 14 3 2 1 2 8.123133 1 #> 15 7 2 1 2 7.022334 1 #> 16 8 2 1 2 14.294014 1 #> 17 9 2 1 2 10.066390 1 #> 18 12 2 1 2 7.335446 1 #> 19 13 2 1 2 7.466435 1"},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"post-processing","dir":"Articles","previous_headings":"","what":"Post-processing","title":"Projecting infectious disease incidence: a COVID-19 example","text":"Now, summarise simulation results. want plot individual simulated daily time series show median cases per day aggregated simulations. First, create daily time series per simulation aggregating number cases per day simulation. Next, add date column results simulation set. use date first case observed data reference start date. Now aggregate simulations day evaluate median daily cases across simulations.","code":"# Daily number of cases for each simulation incidence_ts <- sim_output %>% mutate(day = ceiling(time)) %>% count(sim, day, name = \"cases\") %>% as_tibble() head(incidence_ts) #> # A tibble: 6 × 3 #> sim day cases #> #> 1 1 0 1 #> 2 1 2 1 #> 3 1 3 1 #> 4 1 4 4 #> 5 1 6 6 #> 6 1 7 1 # Get start date from the observed data index_date <- min(seed_cases$date) index_date #> [1] \"2020-03-05\" # Add a dates column to each simulation result incidence_ts_by_date <- incidence_ts %>% group_by(sim) %>% mutate(date = index_date + days(seq(0, n() - 1))) %>% ungroup() head(incidence_ts_by_date) #> # A tibble: 6 × 4 #> sim day cases date #> #> 1 1 0 1 2020-03-05 #> 2 1 2 1 2020-03-06 #> 3 1 3 1 2020-03-07 #> 4 1 4 4 2020-03-08 #> 5 1 6 6 2020-03-09 #> 6 1 7 1 2020-03-10 # Median daily number of cases aggregated across all simulations median_daily_cases <- incidence_ts_by_date %>% group_by(date) %>% summarise(median_cases = median(cases)) %>% ungroup() %>% arrange(date) head(median_daily_cases) #> # A tibble: 6 × 2 #> date median_cases #> #> 1 2020-03-05 1 #> 2 2020-03-06 1 #> 3 2020-03-07 1 #> 4 2020-03-08 4 #> 5 2020-03-09 5 #> 6 2020-03-10 8"},{"path":"https://epiverse-trace.github.io/epichains/articles/projecting_incidence.html","id":"visualization","dir":"Articles","previous_headings":"","what":"Visualization","title":"Projecting infectious disease incidence: a COVID-19 example","text":"now plot individual simulation results alongside median aggregated results. Figure 1: COVID-19 incidence South Africa projected two week window 2020. light gray lines represent individual simulations, red line represents median daily cases across simulations, black connected dots represent observed data, dashed vertical line marks beginning projection.","code":"# since all simulations may end at a different date, we will find the minimum # final date for all simulations for the purposes of visualisation. final_date <- incidence_ts_by_date %>% group_by(sim) %>% summarise(final_date = max(date), .groups = \"drop\") %>% summarise(min_final_date = min(final_date)) %>% pull(min_final_date) incidence_ts_by_date <- incidence_ts_by_date %>% filter(date <= final_date) median_daily_cases <- median_daily_cases %>% filter(date <= final_date) ggplot(data = incidence_ts_by_date) + geom_line( aes( x = date, y = cases, group = sim ), color = \"grey\", linewidth = 0.2, alpha = 0.25 ) + geom_line( data = median_daily_cases, aes( x = date, y = median_cases ), color = \"tomato3\", linewidth = 1.8 ) + geom_point( data = covid19_sa, aes( x = date, y = cases ), color = \"black\", size = 1.75, shape = 21 ) + geom_line( data = covid19_sa, aes( x = date, y = cases ), color = \"black\", linewidth = 1 ) + scale_x_continuous( breaks = seq( min(incidence_ts_by_date$date), max(incidence_ts_by_date$date), 5 ), labels = seq( min(incidence_ts_by_date$date), max(incidence_ts_by_date$date), 5 ) ) + scale_y_continuous( breaks = seq( 0, max(incidence_ts_by_date$cases), 30 ), labels = seq( 0, max(incidence_ts_by_date$cases), 30 ) ) + geom_vline( mapping = aes(xintercept = max(seed_cases$date)), linetype = \"dashed\" ) + labs(x = \"Date\", y = \"Daily cases\")"},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"branching-processes","dir":"Articles","previous_headings":"","what":"Branching processes","title":"Theoretical background for epichains","text":"Branching processes class models used model growth populations. assume member population produces number offspring, \\(Z\\), random variable probability mass function \\(p(Z = z | \\theta)\\), called offspring distribution. use long history epidemiology, population interpreted pathogen, offspring new hosts infects (Farrington, Kanaan, Gay 2003). call infected individuals cases methods applied contexts branching processes used.","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"simulation","dir":"Articles","previous_headings":"","what":"Simulation","title":"Theoretical background for epichains","text":"simulate branching process, start single case proceed discrete steps generations, drawing offspring distribution \\(p(Z=z | \\theta)\\) generate new cases case. Given infector \\(\\) infectee \\(j\\), can additionally assign distribution times \\(T\\) approximates infection event occurred. define \\(T\\) random variable distribution \\(f(T = t; \\theta)\\) can assign case \\(j\\) time \\(t_{j}\\) , case \\(j\\) affected case \\(\\) given \\(f(t_{j} - t_{} | \\theta)\\). identify timing cases time symptom onset serial interval, depending case definitions another interval.","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"summary-statistics","dir":"Articles","previous_headings":"Simulation","what":"Summary statistics","title":"Theoretical background for epichains","text":"Branching process simulations end gone extinct, , offspring produced, stopping criterion. summarise simulations, either study size length resulting chain cases. size \\(S\\) chain number cases occurred course simulation including initial case \\(S \\geq 1\\). length \\(L\\) chain number generations simulated including initial case \\(L \\geq 1\\).","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"inference","dir":"Articles","previous_headings":"","what":"Inference","title":"Theoretical background for epichains","text":"characterising chains cases size length can conduct inference learn underlying parameters \\(\\theta\\) observation chain sizes chain lengths (Blumberg Lloyd-Smith 2013). general possible subcritical branching processes, .e. ones mean number offspring less 1, otherwise branching process grow forever. However, can expand theory supercritical branching processes, .e. ones mean number offspring greater 1, defining cut chain size length beyond treat chain infinite size length, respectively.","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"size-and-length-distributions-for-some-offspring-distributions","dir":"Articles","previous_headings":"Inference","what":"Size and length distributions for some offspring distributions","title":"Theoretical background for epichains","text":"show equations size length distributions offspring distributions can derived analytically: Poisson, negative binomial, geometric, gamma-Borel mixture.","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"negative-binomial-and-special-cases","dir":"Articles","previous_headings":"Inference > Size and length distributions for some offspring distributions","what":"Negative binomial and special cases","title":"Theoretical background for epichains","text":"offspring distribution Poisson distribution, can interpret rate parameter \\(\\lambda\\) basic reproduction number \\(R_{0}\\) pathogen. general case offspring definition can overdispersed leading superspreading can use negative binomial offspring distribution mean \\(\\mu\\) overdispersion \\(k\\) Blumberg Lloyd-Smith (2013). case, mean parameter \\(\\mu\\) interpreted basic reproduction number \\(R_0\\) pathogen. negative binomial distribution arises Poisson-gamma mixture thus branching process negative binomial distributed offspring can interpreted one Poisson distributed offspring basic reproduction number \\(R_0\\) varies according gamma distribution. amount variation \\(R_0\\) interpreted individual-level variation transmission representing overdispersion superspreading, degree happens given overdispersion parameter \\(k\\).","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"size-distributions","dir":"Articles","previous_headings":"Inference > Size and length distributions for some offspring distributions > Negative binomial and special cases","what":"Size distributions","title":"Theoretical background for epichains","text":"probability \\(p\\) chain size \\(S\\) given \\(R_0\\) \\(k\\) branching process negative binomial offspring distribution given Eq. 9 Blumberg Lloyd-Smith (2013) \\[ p(S|R_0, k) = \\frac{\\Gamma(kS + S - 1)}{\\Gamma(kS)\\Gamma(S + 1)} \\frac{\\left(\\frac{R_0}{k}\\right)^{S - 1}}{\\left( 1 + \\frac{R_0}{k} \\right)^{kS + S - 1}} \\] \\(\\Gamma\\) gamma function. order estimate \\(S\\) given \\(R_0\\) \\(k\\) can define likelihood function \\(L(S) = p(S|R_0, k)\\). corresponding log-likelihood \\[\\begin{align} \\mathrm{LL}(S) = &\\log\\Gamma(kS + S - 1) - \\left(\\log\\Gamma(kS) + \\log\\Gamma(S - 1) \\right) \\\\ & + (S-1) \\log \\frac{R_0}{k} - (SR_0 + (S - 1)) \\log \\left(1 + \\frac{R_0}{k}\\right) \\end{align}\\] log-likelihood Poisson distributed offspring follows \\(k\\) tends infinity (corresponding Eq. 2.2 Farrington, Kanaan, Gay (2003)) \\[ \\mathrm{LL}(S) = (S - 1) \\log R_0 - S R_0 + (S - 2) \\log S - \\log\\Gamma(S) \\] cases point estimate basic reproduction number \\(\\hat{R_0}\\) related mean chain size \\(\\bar{S}\\) \\[ \\hat{R_0} = 1 - \\frac{1}{\\bar{S}} \\]","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"length-distributions","dir":"Articles","previous_headings":"Inference > Size and length distributions for some offspring distributions > Negative binomial and special cases","what":"Length distributions","title":"Theoretical background for epichains","text":"cumulative mass function \\(F(L)\\) observing chain length \\(L\\) offspring Poisson distributed given Eq. (2.5) Farrington, Kanaan, Gay (2003) (called “outbreak duration”): \\[ F(L) = e^{-R_0} E_L \\left( e^{R_0 e^{-R_0} } \\right) \\] \\(E_L(x)\\) iterated exponential function, \\(E_0(x) = 1\\), \\(E_{L + 1}(x) = x^{E_L(x)}\\). geometric distributed offspring (corresponding negative Binomial \\(k=1\\)) function given \\[ F(L) = \\frac{ 1- R_0^{L + 1} } {1 - R_0^{L - 2}} \\] cases \\(f(L)\\) denotes cumulative mass functions therefore probability observing chain length \\(L\\) therefore \\(f(L) - f(L - 1)\\).","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"gamma-borel-mixture","dir":"Articles","previous_headings":"Inference > Size and length distributions for some offspring distributions","what":"Gamma-Borel mixture","title":"Theoretical background for epichains","text":"probability distribution outbreak sizes branching process Poisson offspring distribution (Eq. 2.2 Farrington, Kanaan, Gay (2003)) special case Borel-Tanner distribution starting 1 individual. alternative negative binomial offspring distribution represents Poisson-gamma mixture Borel-gamma mixture. represent situations variation individual level chain level, .e. transmission chains homogeneous heterogeneity chains. case, can shown resulting log-likelihood chain sizes \\[\\begin{align} \\mathrm{LL}(S) = &\\log\\Gamma(k + S - 1) - \\left(\\log\\Gamma(k) + \\log\\Gamma(S + 1) \\right) \\\\ & + (S-1) \\log S - k \\log \\left(S + \\frac{R_0}{k}\\right) \\end{align}\\]","code":""},{"path":"https://epiverse-trace.github.io/epichains/articles/theoretical_background.html","id":"numerical-approximations-of-chain-size-and-length-distributions","dir":"Articles","previous_headings":"Inference","what":"Numerical approximations of chain size and length distributions","title":"Theoretical background for epichains","text":"analytic likelihoods available numerical approximation used derive distributions. order , simulation functionality used generate \\(n\\) simulated chains value cumulative mass function \\(P(S|\\theta)\\) observed \\(S\\) approximated empirical cumulative distribution function: \\[ P(S|\\theta) \\approx \\sum_i \\mathbf{1}(x_i <= S) \\] \\(\\mathbf{1}\\) indicator function \\(x_i\\) -th observed chain size (length, interest \\(L\\)). order improve approximation linear approximation applied values empirical distribution function (expense normalisation 1). (unnormalised) probability observing \\(S\\) given \\[ p(S|\\theta) = P(S|\\theta) - P(S - 1|\\theta) \\] equivalent relationship used \\(L\\).","code":""},{"path":"https://epiverse-trace.github.io/epichains/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"James M. Azam. Author, maintainer. Hugo Gruson. Contributor, reviewer. Zhian N. Kamvar. Contributor. Flavio Finger. Author. Sebastian Funk. Author. Karim Mané. Reviewer. Pratik Gupte. Reviewer.","code":""},{"path":"https://epiverse-trace.github.io/epichains/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Azam J, Finger F, Funk S (2024). epichains: Simulating Analysing Transmission Chain Statistics Using Branching Process Models. R package version 0.0.0.9999, https://epiverse-trace.github.io/epichains/, https://github.com/epiverse-trace/epichains.","code":"@Manual{, title = {epichains: Simulating and Analysing Transmission Chain Statistics Using Branching Process Models}, author = {James M. Azam and Flavio Finger and Sebastian Funk}, year = {2024}, note = {R package version 0.0.0.9999, https://epiverse-trace.github.io/epichains/}, url = {https://github.com/epiverse-trace/epichains}, }"},{"path":"https://epiverse-trace.github.io/epichains/reference/aggregate.epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"Aggregate cases in objects by ","title":"Aggregate cases in objects by ","text":"function provides quick way create time series cases generation time (serials_dist specified) simulated objects.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/aggregate.epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Aggregate cases in objects by ","text":"","code":"# S3 method for epichains aggregate(x, by = c(\"time\", \"generation\"), ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/aggregate.epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Aggregate cases in objects by ","text":"x object. variable aggregate . Options include \"time\" \"generation\". ... ignored.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/aggregate.epichains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Aggregate cases in objects by ","text":" object cases .","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/aggregate.epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Aggregate cases in objects by ","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/aggregate.epichains.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Aggregate cases in objects by ","text":"","code":"set.seed(32) chains <- simulate_chains( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, generation_time = function(n) rep(3, n), lambda = 2 ) chains #> `` object #> #> < tree head (from first known infector_id) > #> #> infectee_id sim_id infector_id generation time #> 11 1 2 1 2 3 #> 12 2 2 1 2 3 #> 13 3 2 1 2 3 #> 14 4 2 1 2 3 #> 15 5 2 1 2 3 #> 16 6 2 1 2 3 #> #> #> Trees simulated: 10 #> Number of infectors (known): 9 #> Number of generations: 4 #> Use `as.data.frame()` to view the full output in the console. # Aggregate cases per time cases_per_time <- aggregate(chains, by = \"time\") head(cases_per_time) #> time cases #> 1 0 10 #> 2 3 25 #> 3 6 61 #> 4 9 33 # Aggregate cases per generation cases_per_gen <- aggregate(chains, by = \"generation\") head(cases_per_gen) #> generation cases #> 1 1 10 #> 2 2 25 #> 3 3 61 #> 4 4 33"},{"path":"https://epiverse-trace.github.io/epichains/reference/complementary_logprob.html","id":null,"dir":"Reference","previous_headings":"","what":"Calculates the complementary log-probability — complementary_logprob","title":"Calculates the complementary log-probability — complementary_logprob","text":"Given x norm, calculates log(1-sum(exp(x)))","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/complementary_logprob.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Calculates the complementary log-probability — complementary_logprob","text":"","code":"complementary_logprob(x)"},{"path":"https://epiverse-trace.github.io/epichains/reference/complementary_logprob.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Calculates the complementary log-probability — complementary_logprob","text":"x log-probabilities","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/complementary_logprob.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Calculates the complementary log-probability — complementary_logprob","text":"value","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/complementary_logprob.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Calculates the complementary log-probability — complementary_logprob","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/covid19_sa.html","id":null,"dir":"Reference","previous_headings":"","what":"COVID-19 Data Repository for South Africa — covid19_sa","title":"COVID-19 Data Repository for South Africa — covid19_sa","text":"aggregated subset COVID-19 Data Repository South Africa created, maintained hosted Data Science Social Impact research group, led Dr. Vukosi Marivate.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/covid19_sa.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"COVID-19 Data Repository for South Africa — covid19_sa","text":"","code":"covid19_sa"},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/reference/covid19_sa.html","id":"covid-sa","dir":"Reference","previous_headings":"","what":"covid19_sa","title":"COVID-19 Data Repository for South Africa — covid19_sa","text":"data frame 19 rows 2 columns: date Date case reported cases Number cases","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/covid19_sa.html","id":"source","dir":"Reference","previous_headings":"","what":"Source","title":"COVID-19 Data Repository for South Africa — covid19_sa","text":"https://github.com/dsfsi/covid19za details data-raw/covid19_sa.R.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/covid19_sa.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"COVID-19 Data Repository for South Africa — covid19_sa","text":"data originally provided linelist subsetted cleaned data-raw/covid19_sa.R.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dborel.html","id":null,"dir":"Reference","previous_headings":"","what":"Density of the Borel distribution — dborel","title":"Density of the Borel distribution — dborel","text":"Density Borel distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dborel.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Density of the Borel distribution — dborel","text":"","code":"dborel(x, mu, log = FALSE)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dborel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Density of the Borel distribution — dborel","text":"x Vector quantiles; integer. mu mu parameter (poisson mean); non-negative. log Logical; TRUE, probabilities p given log(p).","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dborel.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Density of the Borel distribution — dborel","text":"Probability mass.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dborel.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Density of the Borel distribution — dborel","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dborel.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Density of the Borel distribution — dborel","text":"","code":"set.seed(32) dborel(1:5, 1) #> [1] 0.36787944 0.13533528 0.07468060 0.04884170 0.03509347"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-adjust_next_gen.html","id":null,"dir":"Reference","previous_headings":"","what":"Adjust new offspring if it exceeds the susceptible population size — .adjust_next_gen","title":"Adjust new offspring if it exceeds the susceptible population size — .adjust_next_gen","text":"function used internally, input checking performed , context used. Using directly recommended.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-adjust_next_gen.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Adjust new offspring if it exceeds the susceptible population size — .adjust_next_gen","text":"","code":".adjust_next_gen(next_gen, susc_pop)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-adjust_next_gen.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Adjust new offspring if it exceeds the susceptible population size — .adjust_next_gen","text":"next_gen numeric; vector next generation offspring susc_pop numeric; susceptible population size","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-adjust_next_gen.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Adjust new offspring if it exceeds the susceptible population size — .adjust_next_gen","text":"numeric; adjusted next generation offspring vector","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_generation_time_valid.html","id":null,"dir":"Reference","previous_headings":"","what":"Check if the generation_time argument is specified as a function — .check_generation_time_valid","title":"Check if the generation_time argument is specified as a function — .check_generation_time_valid","text":"Check generation_time argument specified function","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_generation_time_valid.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check if the generation_time argument is specified as a function — .check_generation_time_valid","text":"","code":".check_generation_time_valid(generation_time)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_generation_time_valid.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check if the generation_time argument is specified as a function — .check_generation_time_valid","text":"generation_time generation time function; name user-defined named anonymous function one argument n, representing number generation times sample.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_offspring_func_valid.html","id":null,"dir":"Reference","previous_headings":"","what":"Check if constructed random number generator for offspring exists\nand has an n argument. — .check_offspring_func_valid","title":"Check if constructed random number generator for offspring exists\nand has an n argument. — .check_offspring_func_valid","text":"Check constructed random number generator offspring exists n argument.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_offspring_func_valid.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check if constructed random number generator for offspring exists\nand has an n argument. — .check_offspring_func_valid","text":"","code":".check_offspring_func_valid(offspring_dist)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_offspring_func_valid.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check if constructed random number generator for offspring exists\nand has an n argument. — .check_offspring_func_valid","text":"offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_sim_args.html","id":null,"dir":"Reference","previous_headings":"","what":"Check inputs to simulate_chains() and simulate_summary() — .check_sim_args","title":"Check inputs to simulate_chains() and simulate_summary() — .check_sim_args","text":"Check inputs simulate_chains() simulate_summary()","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_sim_args.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check inputs to simulate_chains() and simulate_summary() — .check_sim_args","text":"","code":".check_sim_args( index_cases, statistic, offspring_dist, stat_max, pop, percent_immune )"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_sim_args.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check inputs to simulate_chains() and simulate_summary() — .check_sim_args","text":"index_cases Number index cases simulate transmission chains . statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. stat_max cut chain statistic (size/length) computed. Results stat_max set stat_max. Defaults Inf. pop ; Population size. Used alongside percent_immune. define susceptible population. Defaults Inf. percent_immune ; Percent population immune infection start simulation. Used alongside pop initialise susceptible population. Accepted values lie 0 1. Defaults 0. sim_func ; simulation function check","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_sim_args.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Check inputs to simulate_chains() and simulate_summary() — .check_sim_args","text":"NULL; called side effects","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_statistic_args.html","id":null,"dir":"Reference","previous_headings":"","what":"Check that the statistic and stat_max arguments are valid — .check_statistic_args","title":"Check that the statistic and stat_max arguments are valid — .check_statistic_args","text":"function treats two arguments related checks one place remove repeated checks several places package.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_statistic_args.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check that the statistic and stat_max arguments are valid — .check_statistic_args","text":"","code":".check_statistic_args(statistic, stat_max)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_statistic_args.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check that the statistic and stat_max arguments are valid — .check_statistic_args","text":"statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. stat_max cut chain statistic (size/length) computed. Results stat_max set stat_max. Defaults Inf.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_statistic_args.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Check that the statistic and stat_max arguments are valid — .check_statistic_args","text":"NULL; called side effects","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_time_args.html","id":null,"dir":"Reference","previous_headings":"","what":"Check inputs that control time events — .check_time_args","title":"Check inputs that control time events — .check_time_args","text":"function checks time-related inputs, .e., start time chain, t0, end time simulation, tf, generation time, generation_time. also checks generation_time argument specified tf specified go hand--hand.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_time_args.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check inputs that control time events — .check_time_args","text":"","code":".check_time_args(tf_specified, tf, generation_time, t0)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_time_args.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check inputs that control time events — .check_time_args","text":"tf_specified ; Whether tf argument specified. makes sense context function called, .e., simulate_chains(). tf specified, generation_time must specified. tf Cut-infection times (generation time given). Defaults Inf. generation_time generation time function; name user-defined named anonymous function one argument n, representing number generation times sample. t0 Start time (generation time given); either single value vector length index_cases (number initial cases) corresponding initial times. Defaults 0, meaning cases started time 0.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-check_time_args.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Check inputs that control time events — .check_time_args","text":"NULL; called side effects","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-get_statistic_func.html","id":null,"dir":"Reference","previous_headings":"","what":"Return a function for calculating chain statistics — .get_statistic_func","title":"Return a function for calculating chain statistics — .get_statistic_func","text":"Return function calculating chain statistics","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-get_statistic_func.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Return a function for calculating chain statistics — .get_statistic_func","text":"","code":".get_statistic_func(chain_statistic)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-get_statistic_func.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Return a function for calculating chain statistics — .get_statistic_func","text":"function calculating chain statistics","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-get_susceptible_offspring.html","id":null,"dir":"Reference","previous_headings":"","what":"Sample the number of susceptible offspring from all possible offspring — .get_susceptible_offspring","title":"Sample the number of susceptible offspring from all possible offspring — .get_susceptible_offspring","text":"Sample susceptible offspring infected possible offspring. function used internally, input checking performed , context used. Using directly recommended.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-get_susceptible_offspring.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Sample the number of susceptible offspring from all possible offspring — .get_susceptible_offspring","text":"","code":".get_susceptible_offspring(new_offspring, susc_pop, pop)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-get_susceptible_offspring.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Sample the number of susceptible offspring from all possible offspring — .get_susceptible_offspring","text":"new_offspring vector possible new offspring per chain produced .sample_possible_offspring() pop ; Population size. Used alongside percent_immune. define susceptible population. Defaults Inf.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-get_susceptible_offspring.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Sample the number of susceptible offspring from all possible offspring — .get_susceptible_offspring","text":"vector number offspring can infected given current susceptible population size","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-init_susc_pop.html","id":null,"dir":"Reference","previous_headings":"","what":"Adjust next generation vector to match susceptible population size — .init_susc_pop","title":"Adjust next generation vector to match susceptible population size — .init_susc_pop","text":"Calculates initial susceptible population size given total population size, percent immune, number index cases. function used internally, input checking performed , context used. Using directly recommended.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-init_susc_pop.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Adjust next generation vector to match susceptible population size — .init_susc_pop","text":"","code":".init_susc_pop(pop, percent_immune, index_cases)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-init_susc_pop.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Adjust next generation vector to match susceptible population size — .init_susc_pop","text":"pop ; Population size. Used alongside percent_immune. define susceptible population. Defaults Inf. percent_immune ; Percent population immune infection start simulation. Used alongside pop initialise susceptible population. Accepted values lie 0 1. Defaults 0. index_cases Number index cases simulate transmission chains .","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-init_susc_pop.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Adjust next generation vector to match susceptible population size — .init_susc_pop","text":"numeric; initial susceptible population size","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-sample_possible_offspring.html","id":null,"dir":"Reference","previous_headings":"","what":"Sample all possible offspring for the next generation — .sample_possible_offspring","title":"Sample all possible offspring for the next generation — .sample_possible_offspring","text":"Sample next generation offspring using offspring distribution associated parameters. function used internally, input checking performed , context used. Using directly recommended.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-sample_possible_offspring.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Sample all possible offspring for the next generation — .sample_possible_offspring","text":"","code":".sample_possible_offspring( offspring_func, offspring_func_pars, n_offspring, chains )"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-sample_possible_offspring.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Sample all possible offspring for the next generation — .sample_possible_offspring","text":"offspring_func function sample offspring offspring_func_pars list parameters offspring function n_offspring vector number offspring per chain chains Indices chains/infectors simulated","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-sample_possible_offspring.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Sample all possible offspring for the next generation — .sample_possible_offspring","text":"vector number offspring per chain","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-update_chain_stat.html","id":null,"dir":"Reference","previous_headings":"","what":"Determine and update the chain statistic being tracked — .update_chain_stat","title":"Determine and update the chain statistic being tracked — .update_chain_stat","text":"Determine update chain statistic tracked","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-update_chain_stat.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Determine and update the chain statistic being tracked — .update_chain_stat","text":"","code":".update_chain_stat(stat_type, stat_latest, n_offspring)"},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-update_chain_stat.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Determine and update the chain statistic being tracked — .update_chain_stat","text":"stat_type Chain statistic (size/length) update. stat_latest latest chain statistic vector updated. n_offspring vector offspring per chain.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/dot-update_chain_stat.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Determine and update the chain statistic being tracked — .update_chain_stat","text":"vector chain statistics (size/length).","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains-package.html","id":null,"dir":"Reference","previous_headings":"","what":"epichains: Simulating and Analysing Transmission Chain Statistics Using Branching Process Models — epichains-package","title":"epichains: Simulating and Analysing Transmission Chain Statistics Using Branching Process Models — epichains-package","text":"Provides methods simulate analyse size length branching processes arbitrary offspring distribution. can used, example, analyse distribution chain sizes length infectious disease outbreaks, discussed Farrington et al. (2003) doi:10.1093/biostatistics/4.2.279 .","code":""},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"epichains: Simulating and Analysing Transmission Chain Statistics Using Branching Process Models — epichains-package","text":"Maintainer: James M. Azam james.azam@lshtm.ac.uk (ORCID) Authors: Flavio Finger flavio.finger@epicentre.msf.org (ORCID) Sebastian Funk sebastian.funk@lshtm.ac.uk (ORCID) contributors: Hugo Gruson hugo@data.org (ORCID) [contributor, reviewer] Zhian N. Kamvar zkamvar@gmail.com (ORCID) [contributor] Karim Mané karim.mane@lshtm.ac.uk (ORCID) [reviewer] Pratik Gupte pratik.gupte@lshtm.ac.uk (ORCID) [reviewer]","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"Create an object — epichains","title":"Create an object — epichains","text":"epichains() constructs object, inherently object stores inputs passed simulate_tree() simulate_tree_from_pop() simulated output. stored attributes useful downstream analyses reproducibility. function checks validity object created ensure right columns column types. object contains simulated outbreak tree ids infector infectee, generation, optionally, time, number initial cases used simulation, statistic tracked, whether susceptible population tracked.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create an object — epichains","text":"","code":"epichains( tree_df, index_cases, offspring_dist, track_pop, statistic = c(\"size\", \"length\"), stat_max = Inf )"},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create an object — epichains","text":"tree_df containing least columns \"infectee_id\", \"infector_id\", \"generation\". Also optional columns \"time\", \"chain_id\". index_cases Number index cases simulate transmission chains . offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. track_pop susceptible population tracked? Logical statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. stat_max cut chain statistic (size/length) computed. Results stat_max set stat_max. Defaults Inf.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create an object — epichains","text":" object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Create an object — epichains","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains_summary.html","id":null,"dir":"Reference","previous_headings":"","what":"Create an object — epichains_summary","title":"Create an object — epichains_summary","text":"epichains_summary() constructs object. object simulated tree sizes lengths. also stores information number initial cases used simulation, statistic tracked, intervention level.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains_summary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create an object — epichains_summary","text":"","code":"epichains_summary( chains_summary, index_cases, offspring_dist, statistic = c(\"size\", \"length\"), stat_max = Inf )"},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains_summary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create an object — epichains_summary","text":"chains_summary chain sizes lengths. index_cases Number index cases simulate transmission chains . offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. stat_max cut chain statistic (size/length) computed. Results stat_max set stat_max. Defaults Inf.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains_summary.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create an object — epichains_summary","text":" object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/epichains_summary.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Create an object — epichains_summary","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"Format method for class — format.epichains","title":"Format method for class — format.epichains","text":"Format method class","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Format method for class — format.epichains","text":"","code":"# S3 method for epichains format(x, ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Format method for class — format.epichains","text":"x object ... ignored","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Format method for class — format.epichains","text":"Invisibly returns . Called printing side-effects.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Format method for class — format.epichains","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains_summary.html","id":null,"dir":"Reference","previous_headings":"","what":"Format method for class — format.epichains_summary","title":"Format method for class — format.epichains_summary","text":"Format method class","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains_summary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Format method for class — format.epichains_summary","text":"","code":"# S3 method for epichains_summary format(x, ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains_summary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Format method for class — format.epichains_summary","text":"x object ... ignored","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains_summary.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Format method for class — format.epichains_summary","text":"Invisibly returns . Called printing side-effects.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/format.epichains_summary.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Format method for class — format.epichains_summary","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/gborel_size_ll.html","id":null,"dir":"Reference","previous_headings":"","what":"Log-likelihood of the size of chains with gamma-Borel offspring distribution — gborel_size_ll","title":"Log-likelihood of the size of chains with gamma-Borel offspring distribution — gborel_size_ll","text":"Log-likelihood size chains gamma-Borel offspring distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/gborel_size_ll.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Log-likelihood of the size of chains with gamma-Borel offspring distribution — gborel_size_ll","text":"","code":"gborel_size_ll(x, size, prob, mu)"},{"path":"https://epiverse-trace.github.io/epichains/reference/gborel_size_ll.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Log-likelihood of the size of chains with gamma-Borel offspring distribution — gborel_size_ll","text":"x vector sizes size dispersion parameter (often called k ecological applications) prob probability success (parameterisation prob, see also NegBinomial) mu mean parameter","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/gborel_size_ll.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Log-likelihood of the size of chains with gamma-Borel offspring distribution — gborel_size_ll","text":"log-likelihood values","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/gborel_size_ll.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Log-likelihood of the size of chains with gamma-Borel offspring distribution — gborel_size_ll","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/geom_length_ll.html","id":null,"dir":"Reference","previous_headings":"","what":"Log-likelihood of the length of chains with geometric offspring distribution — geom_length_ll","title":"Log-likelihood of the length of chains with geometric offspring distribution — geom_length_ll","text":"Log-likelihood length chains geometric offspring distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/geom_length_ll.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Log-likelihood of the length of chains with geometric offspring distribution — geom_length_ll","text":"","code":"geom_length_ll(x, prob)"},{"path":"https://epiverse-trace.github.io/epichains/reference/geom_length_ll.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Log-likelihood of the length of chains with geometric offspring distribution — geom_length_ll","text":"x vector lengths prob probability geometric distribution mean 1/prob","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/geom_length_ll.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Log-likelihood of the length of chains with geometric offspring distribution — geom_length_ll","text":"log-likelihood values","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/geom_length_ll.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Log-likelihood of the length of chains with geometric offspring distribution — geom_length_ll","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/head.epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"head and tail method for class — head.epichains","title":"head and tail method for class — head.epichains","text":"head tail method class","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/head.epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"head and tail method for class — head.epichains","text":"","code":"# S3 method for epichains head(x, ...) # S3 method for epichains tail(x, ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/head.epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"head and tail method for class — head.epichains","text":"x object ... arguments passed methods","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/head.epichains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"head and tail method for class — head.epichains","text":"Object class data.frame","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/head.epichains.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"head and tail method for class — head.epichains","text":"returns top rows object. Note object originally sorted sim_id infector_id first unknown infectors (NA) dropped printing method. view full output, use .data.frame().","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/head.epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"head and tail method for class — head.epichains","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/head.epichains.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"head and tail method for class — head.epichains","text":"","code":"set.seed(32) chains_pois_offspring <- simulate_chains( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, generation_time = function(n) rep(3, n), lambda = 2 ) head(chains_pois_offspring) #> infectee_id sim_id infector_id generation time #> 11 1 2 1 2 3 #> 12 2 2 1 2 3 #> 13 3 2 1 2 3 #> 14 4 2 1 2 3 #> 15 5 2 1 2 3 #> 16 6 2 1 2 3 set.seed(32) chains_pois_offspring <- simulate_chains( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, generation_time = function(n) rep(3, n), lambda = 2 ) tail(chains_pois_offspring) #> infectee_id sim_id infector_id generation time #> 124 6 19 6 3 6 #> 125 2 19 7 4 9 #> 126 6 20 6 3 6 #> 127 2 20 7 4 9 #> 128 2 21 7 4 9 #> 129 2 22 8 4 9"},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"Test if x is an epichains object — is_epichains","title":"Test if x is an epichains object — is_epichains","text":"Test x epichains object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Test if x is an epichains object — is_epichains","text":"","code":"is_epichains(x)"},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Test if x is an epichains object — is_epichains","text":"x R object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Test if x is an epichains object — is_epichains","text":"logical, TRUE object FALSE otherwise","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Test if x is an epichains object — is_epichains","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains_summary.html","id":null,"dir":"Reference","previous_headings":"","what":"Test if x is an epichains_summary object — is_epichains_summary","title":"Test if x is an epichains_summary object — is_epichains_summary","text":"Test x epichains_summary object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains_summary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Test if x is an epichains_summary object — is_epichains_summary","text":"","code":"is_epichains_summary(x)"},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains_summary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Test if x is an epichains_summary object — is_epichains_summary","text":"x R object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains_summary.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Test if x is an epichains_summary object — is_epichains_summary","text":"logical, TRUE object epichains_summary FALSE otherwise","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/is_epichains_summary.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Test if x is an epichains_summary object — is_epichains_summary","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/likelihood.html","id":null,"dir":"Reference","previous_headings":"","what":"Estimate the log-likelihood/likelihood for observed branching processes — likelihood","title":"Estimate the log-likelihood/likelihood for observed branching processes — likelihood","text":"Estimate log-likelihood/likelihood observed branching processes","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/likelihood.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Estimate the log-likelihood/likelihood for observed branching processes — likelihood","text":"","code":"likelihood( chains, statistic = c(\"size\", \"length\"), offspring_dist, nsim_obs, obs_prob = 1, log = TRUE, stat_max = Inf, exclude = NULL, individual = FALSE, ... )"},{"path":"https://epiverse-trace.github.io/epichains/reference/likelihood.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Estimate the log-likelihood/likelihood for observed branching processes — likelihood","text":"chains Vector chain summaries (sizes/lengths) statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. nsim_obs Number simulations log-likelihood/likelihood approximated imperfect observations. obs_prob Observation probability (assumed constant) log Logical; log-likelihoods transformed likelihoods? (Defaults TRUE). stat_max cut chain statistic (size/length) computed. Results specified value, set Inf. exclude vector indices sizes/lengths exclude log-likelihood calculation. individual TRUE, vector individual log-likelihood/likelihood contributions returned rather sum/product. ... parameters pass simulate_summary","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/likelihood.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Estimate the log-likelihood/likelihood for observed branching processes — likelihood","text":"log = TRUE joint log-likelihood (sum individual log-likelihoods), individual == FALSE (default) obs_prob == 1 (default), list individual log-likelihoods, individual == TRUE obs_prob == 1 (default), list individual log-likelihoods (length nsim_obs), individual == TRUE 0 <= obs_prob < 1, vector joint log-likelihoods (length nsim_obs), individual == FALSE 0 <= obs_prob < 1 (imperfect observation). log = FALSE, structure outputs returned, except likelihoods, instead log-likelihoods, calculated cases. Moreover, joint likelihoods product, instead sum, individual likelihoods.","code":""},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/reference/likelihood.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Estimate the log-likelihood/likelihood for observed branching processes — likelihood","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/likelihood.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Estimate the log-likelihood/likelihood for observed branching processes — likelihood","text":"","code":"# example of observed chain sizes set.seed(121) # randomly generate 20 chains of size 1 to 10 chain_sizes <- sample(1:10, 20, replace = TRUE) likelihood( chains = chain_sizes, statistic = \"size\", offspring_dist = rpois, nsim_obs = 100, lambda = 0.5 ) #> [1] -67.82879"},{"path":"https://epiverse-trace.github.io/epichains/reference/nbinom_size_ll.html","id":null,"dir":"Reference","previous_headings":"","what":"Log-likelihood of the size of chains with Negative-Binomial offspring\ndistribution — nbinom_size_ll","title":"Log-likelihood of the size of chains with Negative-Binomial offspring\ndistribution — nbinom_size_ll","text":"Log-likelihood size chains Negative-Binomial offspring distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/nbinom_size_ll.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Log-likelihood of the size of chains with Negative-Binomial offspring\ndistribution — nbinom_size_ll","text":"","code":"nbinom_size_ll(x, size, prob, mu)"},{"path":"https://epiverse-trace.github.io/epichains/reference/nbinom_size_ll.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Log-likelihood of the size of chains with Negative-Binomial offspring\ndistribution — nbinom_size_ll","text":"x vector sizes size dispersion parameter (often called k ecological applications) prob probability success (parameterisation prob, see also NegBinomial) mu mean parameter","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/nbinom_size_ll.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Log-likelihood of the size of chains with Negative-Binomial offspring\ndistribution — nbinom_size_ll","text":"log-likelihood values","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/nbinom_size_ll.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Log-likelihood of the size of chains with Negative-Binomial offspring\ndistribution — nbinom_size_ll","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/new_epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"Construct an object — new_epichains","title":"Construct an object — new_epichains","text":"new_epichains() constructs object supplied extra attributes passed individual arguments. meant lazy performant, creating object without checking arguments correctness. safe call new_epichains() called within epichains() arguments checked. create object, use epichains().","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/new_epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Construct an object — new_epichains","text":"","code":"new_epichains( tree_df, index_cases, statistic, offspring_dist, stat_max, track_pop )"},{"path":"https://epiverse-trace.github.io/epichains/reference/new_epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Construct an object — new_epichains","text":"tree_df containing least columns \"infectee_id\", \"infector_id\", \"generation\". Also optional columns \"time\", \"chain_id\". index_cases Number index cases simulate transmission chains . statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. stat_max cut chain statistic (size/length) computed. Results stat_max set stat_max. Defaults Inf. track_pop susceptible population tracked? Logical","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/new_epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Construct an object — new_epichains","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/new_epichains_summary.html","id":null,"dir":"Reference","previous_headings":"","what":"Construct a object — new_epichains_summary","title":"Construct a object — new_epichains_summary","text":"new_epichains_summary() constructs object supplied chain sizes lengths. also stores extra attributes passed individual arguments. new_epichains_summary() meant lazy performant, creating object without checking arguments correctness. safe call new_epichains_summary() called within epichains_summary() arguments checked. create new object safely, use epichains_summary().","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/new_epichains_summary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Construct a object — new_epichains_summary","text":"","code":"new_epichains_summary( chains_summary, index_cases, statistic, offspring_dist, stat_max )"},{"path":"https://epiverse-trace.github.io/epichains/reference/new_epichains_summary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Construct a object — new_epichains_summary","text":"chains_summary chain sizes lengths. index_cases Number index cases simulate transmission chains . statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. stat_max cut chain statistic (size/length) computed. Results stat_max set stat_max. Defaults Inf.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/new_epichains_summary.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Construct a object — new_epichains_summary","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/offspring_ll.html","id":null,"dir":"Reference","previous_headings":"","what":"Log-likelihood of the summary (size/length) of chains with generic offspring\ndistribution — offspring_ll","title":"Log-likelihood of the summary (size/length) of chains with generic offspring\ndistribution — offspring_ll","text":"log-likelihoods calculated crude approximation using simulated chain summaries linearly approximating missing values empirical cumulative distribution function (ecdf).","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/offspring_ll.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Log-likelihood of the summary (size/length) of chains with generic offspring\ndistribution — offspring_ll","text":"","code":"offspring_ll(x, offspring_dist, statistic, nsim_offspring = 100, ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/offspring_ll.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Log-likelihood of the summary (size/length) of chains with generic offspring\ndistribution — offspring_ll","text":"x Vector chain summaries (sizes/lengths) offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. nsim_offspring Number simulations offspring distribution approximating distribution chain statistic summary (size/length) ... parameters pass simulate_summary","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/offspring_ll.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Log-likelihood of the summary (size/length) of chains with generic offspring\ndistribution — offspring_ll","text":"log-likelihood values","code":""},{"path":[]},{"path":"https://epiverse-trace.github.io/epichains/reference/offspring_ll.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Log-likelihood of the summary (size/length) of chains with generic offspring\ndistribution — offspring_ll","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/offspring_ll.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Log-likelihood of the summary (size/length) of chains with generic offspring\ndistribution — offspring_ll","text":"","code":"set.seed(123) chain_size_ll <- offspring_ll( x = c(1, 5, 6, 8, 7, 8, 10), offspring_dist = rpois, statistic = \"size\", lambda = 0.82 )"},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_length_ll.html","id":null,"dir":"Reference","previous_headings":"","what":"Log-likelihood of the length of chains with Poisson offspring distribution — pois_length_ll","title":"Log-likelihood of the length of chains with Poisson offspring distribution — pois_length_ll","text":"Log-likelihood length chains Poisson offspring distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_length_ll.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Log-likelihood of the length of chains with Poisson offspring distribution — pois_length_ll","text":"","code":"pois_length_ll(x, lambda)"},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_length_ll.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Log-likelihood of the length of chains with Poisson offspring distribution — pois_length_ll","text":"x vector lengths lambda rate Poisson distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_length_ll.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Log-likelihood of the length of chains with Poisson offspring distribution — pois_length_ll","text":"log-likelihood values","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_length_ll.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Log-likelihood of the length of chains with Poisson offspring distribution — pois_length_ll","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_size_ll.html","id":null,"dir":"Reference","previous_headings":"","what":"Log-likelihood of the size of chains with Poisson offspring distribution — pois_size_ll","title":"Log-likelihood of the size of chains with Poisson offspring distribution — pois_size_ll","text":"Log-likelihood size chains Poisson offspring distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_size_ll.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Log-likelihood of the size of chains with Poisson offspring distribution — pois_size_ll","text":"","code":"pois_size_ll(x, lambda)"},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_size_ll.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Log-likelihood of the size of chains with Poisson offspring distribution — pois_size_ll","text":"x vector sizes lambda rate Poisson distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_size_ll.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Log-likelihood of the size of chains with Poisson offspring distribution — pois_size_ll","text":"log-likelihood values","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/pois_size_ll.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Log-likelihood of the size of chains with Poisson offspring distribution — pois_size_ll","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"Print an object — print.epichains","title":"Print an object — print.epichains","text":"Print object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print an object — print.epichains","text":"","code":"# S3 method for epichains print(x, ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print an object — print.epichains","text":"x object. ... parameters passed print().","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Print an object — print.epichains","text":"Invisibly returns . Called side-effects.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Print an object — print.epichains","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains_summary.html","id":null,"dir":"Reference","previous_headings":"","what":"Print an object — print.epichains_summary","title":"Print an object — print.epichains_summary","text":"Print object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains_summary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print an object — print.epichains_summary","text":"","code":"# S3 method for epichains_summary print(x, ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains_summary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print an object — print.epichains_summary","text":"x object. ... ignored.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains_summary.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Print an object — print.epichains_summary","text":"Invisibly returns . Called side-effects.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/print.epichains_summary.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Print an object — print.epichains_summary","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rbinom_size.html","id":null,"dir":"Reference","previous_headings":"","what":"Samples size (the number of trials) of a binomial distribution — rbinom_size","title":"Samples size (the number of trials) of a binomial distribution — rbinom_size","text":"Samples size parameter binomial distribution fixed x (number successes) p (success probability)","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rbinom_size.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Samples size (the number of trials) of a binomial distribution — rbinom_size","text":"","code":"rbinom_size(n, x, prob)"},{"path":"https://epiverse-trace.github.io/epichains/reference/rbinom_size.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Samples size (the number of trials) of a binomial distribution — rbinom_size","text":"n number samples generate x number successes prob probability success","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rbinom_size.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Samples size (the number of trials) of a binomial distribution — rbinom_size","text":"sampled sizes","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rbinom_size.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Samples size (the number of trials) of a binomial distribution — rbinom_size","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rborel.html","id":null,"dir":"Reference","previous_headings":"","what":"Generate random numbers from the Borel distribution — rborel","title":"Generate random numbers from the Borel distribution — rborel","text":"Random numbers generated simulating Poisson branching process","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rborel.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Generate random numbers from the Borel distribution — rborel","text":"","code":"rborel(n, mu, infinite = Inf)"},{"path":"https://epiverse-trace.github.io/epichains/reference/rborel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Generate random numbers from the Borel distribution — rborel","text":"n Number random variates generate. mu mu parameter (poisson mean); non-negative. infinite number treat infinite; simulations stopped number reached","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rborel.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Generate random numbers from the Borel distribution — rborel","text":"Vector random numbers","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rborel.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Generate random numbers from the Borel distribution — rborel","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rborel.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Generate random numbers from the Borel distribution — rborel","text":"","code":"set.seed(32) rborel(5, 1) #> [1] 25 50 114 5 1"},{"path":"https://epiverse-trace.github.io/epichains/reference/rgborel.html","id":null,"dir":"Reference","previous_headings":"","what":"Generate random numbers from a Gamma-Borel mixture distribution — rgborel","title":"Generate random numbers from a Gamma-Borel mixture distribution — rgborel","text":"Generate random numbers Gamma-Borel mixture distribution","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rgborel.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Generate random numbers from a Gamma-Borel mixture distribution — rgborel","text":"","code":"rgborel(n, size, prob, mu, infinite = Inf)"},{"path":"https://epiverse-trace.github.io/epichains/reference/rgborel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Generate random numbers from a Gamma-Borel mixture distribution — rgborel","text":"n Number random variates generate. size dispersion parameter (often called k ecological applications) prob probability success (parameterisation prob, see also NegBinomial) mu mean parameter infinite number treat infinite; simulations stopped number reached","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rgborel.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Generate random numbers from a Gamma-Borel mixture distribution — rgborel","text":"Numeric vector random numbers","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rgborel.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Generate random numbers from a Gamma-Borel mixture distribution — rgborel","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rgen_length.html","id":null,"dir":"Reference","previous_headings":"","what":"Samples chain lengths with given observation probabilities — rgen_length","title":"Samples chain lengths with given observation probabilities — rgen_length","text":"Samples length transmission chain individual element observed binomial probability parameters n (number successes) p (success probability)","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rgen_length.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Samples chain lengths with given observation probabilities — rgen_length","text":"","code":"rgen_length(n, x, prob)"},{"path":"https://epiverse-trace.github.io/epichains/reference/rgen_length.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Samples chain lengths with given observation probabilities — rgen_length","text":"n number samples generate x observed chain lengths prob probability observation","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rgen_length.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Samples chain lengths with given observation probabilities — rgen_length","text":"sampled lengths","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rgen_length.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Samples chain lengths with given observation probabilities — rgen_length","text":"Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rnbinom_mean_disp.html","id":null,"dir":"Reference","previous_headings":"","what":"Negative binomial random numbers parametrized\nin terms of mean and dispersion coefficient — rnbinom_mean_disp","title":"Negative binomial random numbers parametrized\nin terms of mean and dispersion coefficient — rnbinom_mean_disp","text":"Negative binomial random numbers parametrized terms mean dispersion coefficient","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rnbinom_mean_disp.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Negative binomial random numbers parametrized\nin terms of mean and dispersion coefficient — rnbinom_mean_disp","text":"","code":"rnbinom_mean_disp(n, mn, disp)"},{"path":"https://epiverse-trace.github.io/epichains/reference/rnbinom_mean_disp.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Negative binomial random numbers parametrized\nin terms of mean and dispersion coefficient — rnbinom_mean_disp","text":"n number samples draw mn mean distribution; Must > 0. disp dispersion coefficient (var/mean); Must > 1.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rnbinom_mean_disp.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Negative binomial random numbers parametrized\nin terms of mean and dispersion coefficient — rnbinom_mean_disp","text":"vector containing random numbers","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rnbinom_mean_disp.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Negative binomial random numbers parametrized\nin terms of mean and dispersion coefficient — rnbinom_mean_disp","text":"Flavio Finger","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/rnbinom_mean_disp.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Negative binomial random numbers parametrized\nin terms of mean and dispersion coefficient — rnbinom_mean_disp","text":"","code":"set.seed(32) rnbinom_mean_disp(n = 5, mn = 4, disp = 2) #> [1] 5 9 6 3 6"},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":null,"dir":"Reference","previous_headings":"","what":"Simulate transmission chains — simulate_chains","title":"Simulate transmission chains — simulate_chains","text":"Generates transmission chains using simple branching process model accepts index number cases seed outbreak, distribution offspring per case, chain size length/duration (statistic) track. optionally accepts population related inputs population size (defaults Inf) percentage population initially immune (defaults 0).","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Simulate transmission chains — simulate_chains","text":"","code":"simulate_chains( index_cases, statistic = c(\"size\", \"length\"), offspring_dist, ..., stat_max = Inf, pop = Inf, percent_immune = 0, generation_time = NULL, t0 = 0, tf = Inf )"},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Simulate transmission chains — simulate_chains","text":"index_cases Number index cases simulate transmission chains . statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. ... Parameters offspring distribution required R. stat_max cut chain statistic (size/length) computed. Results stat_max set stat_max. Defaults Inf. pop ; Population size. Used alongside percent_immune. define susceptible population. Defaults Inf. percent_immune ; Percent population immune infection start simulation. Used alongside pop initialise susceptible population. Accepted values lie 0 1. Defaults 0. generation_time generation time function; name user-defined named anonymous function one argument n, representing number generation times sample. t0 Start time (generation time given); either single value vector length index_cases (number initial cases) corresponding initial times. Defaults 0, meaning cases started time 0. tf Cut-infection times (generation time given). Defaults Inf.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Simulate transmission chains — simulate_chains","text":" object, basically columns infectee_id, sim_id (unique ID within simulation infectee), infector_id, generation, time (infection)","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":"calculating-chain-sizes-and-lengths","dir":"Reference","previous_headings":"","what":"Calculating chain sizes and lengths","title":"Simulate transmission chains — simulate_chains","text":"function simulates chain size individual \\(\\) time \\(t\\), \\(I_{t, }\\), : $$I_{t, } = \\sum_{}^{I_{t-1}}X_{t, },$$ chain length/duration individual \\(\\) time \\(t\\), \\(L_{t, }\\), : $$L_{t, } = {\\sf min}(1, X_{t, }), $$ \\(X_{t, }\\) secondary cases generated individual \\(\\) time \\(t\\), \\(I_{0, } = L_{0, } = 1\\). distribution secondary cases, \\(X_{t, }\\) modelled offspring distribution (offspring_dist).","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":"specifying-generation-time","dir":"Reference","previous_headings":"","what":"Specifying generation_time","title":"Simulate transmission chains — simulate_chains","text":"argument generation_time must specified function one argument, n. example, assuming want specify generation time random log-normally distributed variable meanlog = 0.58 sdlog = 1.58, define named function, call \"generation_time_fn\", one argument representing number generation times sample: generation_time_fn <- function(n){rlnorm(n, 0.58, 1.38)}, assign name function generation_time simulation function, .e. `simulate_*`(..., generation_time = generation_time_fn), ... arguments simulate_*() * placeholder rest simulation function's name. Alternatively, assign anonymous function generation_time simulate_*() call, .e. simulate_*(..., generation_time = function(n){rlnorm(n, 0.58, 1.38)}) simulate_*(..., generation_time = \\(n){rlnorm(n, 0.58, 1.38)}), ... arguments simulate_*().","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Simulate transmission chains — simulate_chains","text":"Jacob C. (2010). Branching processes: role epidemiology. International journal environmental research public health, 7(3), 1186–1204. doi:10.3390/ijerph7031204 Blumberg, S., J. O. Lloyd-Smith. 2013. \"Comparing Methods Estimating R0 Size Distribution Subcritical Transmission Chains.\" Epidemics 5 (3): 131–45. doi:10.1016/j.epidem.2013.05.002 . Farrington, C. P., M. N. Kanaan, N. J. Gay. 2003. \"Branching Process Models Surveillance Infectious Diseases Controlled Mass Vaccination.” Biostatistics (Oxford, England) 4 (2): 279–95. doi:10.1093/biostatistics/4.2.279 .","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Simulate transmission chains — simulate_chains","text":"James M. Azam, Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_chains.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Simulate transmission chains — simulate_chains","text":"","code":"# Using a Poisson offspring distribution and simulating from an infinite # population up to chain size 10. set.seed(32) chains_pois_offspring <- simulate_chains( index_cases = 10, statistic = \"size\", offspring_dist = rpois, stat_max = 10, generation_time = function(n) rep(3, n), lambda = 2 ) chains_pois_offspring #> `` object #> #> < tree head (from first known infector_id) > #> #> infectee_id sim_id infector_id generation time #> 11 1 2 1 2 3 #> 12 2 2 1 2 3 #> 13 3 2 1 2 3 #> 14 4 2 1 2 3 #> 15 5 2 1 2 3 #> 16 6 2 1 2 3 #> #> #> Trees simulated: 10 #> Number of infectors (known): 9 #> Number of generations: 4 #> Use `as.data.frame()` to view the full output in the console. # Using a Negative binomial offspring distribution and simulating from a # finite population up to chain size 10. set.seed(32) chains_nbinom_offspring <- simulate_chains( index_cases = 10, pop = 100, percent_immune = 0, statistic = \"size\", offspring_dist = rnbinom, stat_max = 10, generation_time = function(n) rep(3, n), mu = 2, size = 0.2 ) chains_nbinom_offspring #> `` object #> #> < tree head (from first known infector_id) > #> #> infectee_id sim_id infector_id generation time susc_pop #> 11 1 2 1 2 3 53 #> 12 2 2 1 2 3 53 #> 13 3 2 1 2 3 53 #> 14 4 2 1 2 3 53 #> 15 5 2 1 2 3 53 #> 16 6 2 1 2 3 53 #> #> #> Trees simulated: 10 #> Number of infectors (known): 5 #> Number of generations: 4 #> Use `as.data.frame()` to view the full output in the console."},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":null,"dir":"Reference","previous_headings":"","what":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"Generates vector transmission chain sizes lengths value index case. uses simple branching process model accepts index number cases seed outbreak, distribution offspring per case, chain size length/duration (statistic) track. optionally accepts population related inputs population size (defaults Inf) percentage population initially immune (defaults 0).","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"","code":"simulate_summary( index_cases, statistic = c(\"size\", \"length\"), offspring_dist, ..., stat_max = Inf, pop = Inf, percent_immune = 0 )"},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"index_cases Number index cases simulate transmission chains . statistic ; Chain statistic track stopping criteria chain simulated stat_max Inf. Can one : \"size\": total number cases produced chain goes extinct. \"length\": total number ancestors produced chain goes extinct. offspring_dist Offspring distribution: function like ones provided R generate random numbers given distributions (e.g., rpois Poisson). specifically, function needs accept least one argument, n, number random numbers generate. can accept arguments, passed random number generating functions. Examples can provided rpois Poisson distributed offspring, rnbinom negative binomial offspring, custom functions. ... Parameters offspring distribution required R. stat_max cut chain statistic (size/length) computed. Results specified value, set Inf. pop ; Population size. Used alongside percent_immune. define susceptible population. Defaults Inf. percent_immune ; Percent population immune infection start simulation. Used alongside pop initialise susceptible population. Accepted values lie 0 1. Defaults 0.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"vector chain sizes lengths (class ) value index case.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":"simulate-summary-vs-simulate-chains-","dir":"Reference","previous_headings":"","what":"simulate_summary() vs simulate_chains()","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"simulate_summary() time-invariant version simulate_chains(). particular, track details individual transmission events deals eventual chain statistics, , statistic realised chain dying . useful generating vector chain sizes lengths given number index cases, details infected timing infection interest. function used {epichains} calculating likelihoods likelihood() function sampling borel distribution (See ?epichains::rborel). used extensively vignette modelling disease control, data observed chain sizes lengths available.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":"calculating-chain-sizes-and-lengths","dir":"Reference","previous_headings":"","what":"Calculating chain sizes and lengths","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"function simulates chain size individual \\(\\) time \\(t\\), \\(I_{t, }\\), : $$I_{t, } = \\sum_{}^{I_{t-1}}X_{t, },$$ chain length/duration individual \\(\\) time \\(t\\), \\(L_{t, }\\), : $$L_{t, } = {\\sf min}(1, X_{t, }), $$ \\(X_{t, }\\) secondary cases generated individual \\(\\) time \\(t\\), \\(I_{0, } = L_{0, } = 1\\). distribution secondary cases, \\(X_{t, }\\) modelled offspring distribution (offspring_dist).","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"Jacob C. (2010). Branching processes: role epidemiology. International journal environmental research public health, 7(3), 1186–1204. doi:10.3390/ijerph7031204 Blumberg, S., J. O. Lloyd-Smith. 2013. \"Comparing Methods Estimating R0 Size Distribution Subcritical Transmission Chains.\" Epidemics 5 (3): 131–45. doi:10.1016/j.epidem.2013.05.002 . Farrington, C. P., M. N. Kanaan, N. J. Gay. 2003. \"Branching Process Models Surveillance Infectious Diseases Controlled Mass Vaccination.” Biostatistics (Oxford, England) 4 (2): 279–95. doi:10.1093/biostatistics/4.2.279 .","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"James M. Azam, Sebastian Funk","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/simulate_summary.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Simulate a vector of transmission chains sizes/lengths — simulate_summary","text":"","code":"# Simulate chain sizes with a poisson offspring distribution, assuming an # infinite population and no immunity. set.seed(32) simulate_summary( index_cases = 20, statistic = \"size\", offspring_dist = rpois, stat_max = 10, lambda = 0.9 ) #> `epichains_summary` object #> #> [1] 6 7 5 7 1 Inf 3 4 6 1 9 1 Inf Inf 1 3 Inf Inf 2 #> [20] 5 #> #> Simulated tree sizes: #> #> Max: 9 #> Min: 1 # Simulate chain sizes with a negative binomial distribution and assuming # a finite population and 10% immunity. set.seed(32) simulate_summary( pop = 1000, percent_immune = 0.1, index_cases = 20, statistic = \"size\", offspring_dist = rnbinom, stat_max = 10, mu = 0.9, size = 0.36 ) #> `epichains_summary` object #> #> [1] 1 1 1 2 2 4 2 1 1 4 1 1 2 1 1 2 1 1 1 1 #> #> Simulated tree sizes: #> #> Max: 4 #> Min: 1"},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"Summary method for class — summary.epichains","title":"Summary method for class — summary.epichains","text":"calculates chain statistic (size/length) simulated chains returns object information returned equivalent simulate_summary() call.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Summary method for class — summary.epichains","text":"","code":"# S3 method for epichains summary(object, ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Summary method for class — summary.epichains","text":"object object ... ignored","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Summary method for class — summary.epichains","text":" object containing chain summary statistics follows: \"size\": total number cases produced chain goes extinct. \"length\": total number infectors produced chain goes extinct.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Summary method for class — summary.epichains","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Summary method for class — summary.epichains","text":"","code":"# Using a negative binomial offspring distribution and simulating from a # finite population up to chain size 10. set.seed(32) sim_chains_nbinom <- simulate_chains( index_cases = 10, pop = 100, percent_immune = 0, statistic = \"size\", offspring_dist = rnbinom, stat_max = 10, mu = 2, size = 0.2 ) # Summarise the simulated chains sim_chains_nbinom_summary <- summary(sim_chains_nbinom) sim_chains_nbinom_summary #> `epichains_summary` object #> #> [1] 3 Inf Inf 5 6 Inf 1 1 1 1 #> #> Simulated tree sizes: #> #> Max: 6 #> Min: 1 # Same results can be obtained using `simulate_summary()` set.seed(32) sim_summary_nbinom <- simulate_summary( index_cases = 10, pop = 100, percent_immune = 0, statistic = \"size\", offspring_dist = rnbinom, stat_max = 10, mu = 2, size = 0.2 ) sim_summary_nbinom #> `epichains_summary` object #> #> [1] 3 Inf Inf 5 6 Inf 1 1 1 1 #> #> Simulated tree sizes: #> #> Max: 6 #> Min: 1 # Check that the results are the same setequal(sim_chains_nbinom_summary, sim_summary_nbinom) #> [1] TRUE"},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains_summary.html","id":null,"dir":"Reference","previous_headings":"","what":"Summary method for class — summary.epichains_summary","title":"Summary method for class — summary.epichains_summary","text":"Summary method class","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains_summary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Summary method for class — summary.epichains_summary","text":"","code":"# S3 method for epichains_summary summary(object, ...)"},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains_summary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Summary method for class — summary.epichains_summary","text":"object object ... ignored","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains_summary.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Summary method for class — summary.epichains_summary","text":"List summaries","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/summary.epichains_summary.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Summary method for class — summary.epichains_summary","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains.html","id":null,"dir":"Reference","previous_headings":"","what":"Validate an object — validate_epichains","title":"Validate an object — validate_epichains","text":"Validate object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Validate an object — validate_epichains","text":"","code":"validate_epichains(x)"},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Validate an object — validate_epichains","text":"x object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Validate an object — validate_epichains","text":"return.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Validate an object — validate_epichains","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains_summary.html","id":null,"dir":"Reference","previous_headings":"","what":"Validate an object — validate_epichains_summary","title":"Validate an object — validate_epichains_summary","text":"Validate object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains_summary.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Validate an object — validate_epichains_summary","text":"","code":"validate_epichains_summary(x)"},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains_summary.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Validate an object — validate_epichains_summary","text":"x object","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains_summary.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Validate an object — validate_epichains_summary","text":"return.","code":""},{"path":"https://epiverse-trace.github.io/epichains/reference/validate_epichains_summary.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"Validate an object — validate_epichains_summary","text":"James M. Azam","code":""},{"path":"https://epiverse-trace.github.io/epichains/news/index.html","id":"epichains-009999","dir":"Changelog","previous_headings":"","what":"epichains 0.0.9999","title":"epichains 0.0.9999","text":"epichains re-implementation bpmodels focus providing dedicated class data structures easy manipulation interoperability new tools Epiverse existing ecosystem. offspring_dist argument changed longer accept character string, instead now accepts function (#25, #167, #188). expands number possible functions user can use longer restricted distributions corresponding random number generator function starting r...(). example: ```r # possible earlier versions package. my_poisson_wrapper <- function(n) { rpois(n, lambda = 0.9) } chain_summary_raw <- simulate_summary( index_cases = 2, offspring_dist = my_poisson_wrapper, statistic = “length” ) adding functionality rgborel function also added; difference previous behaviour, ll function name informed string passed now needs function name; function actually called estimating likelihood corresponding ll function exists , principle, empty dummy function; however, function included documentation/clarity purposes, well simulations.","code":""},{"path":"https://epiverse-trace.github.io/epichains/news/index.html","id":"documentation-0-0-9999","dir":"Changelog","previous_headings":"","what":"Documentation","title":"epichains 0.0.9999","text":"vignette outlining simulate interventions added.","code":""},{"path":"https://epiverse-trace.github.io/epichains/news/index.html","id":"functions-0-0-9999","dir":"Changelog","previous_headings":"","what":"Functions","title":"epichains 0.0.9999","text":"simulate_tree(): simulate transmission trees given number initial cases. simulate_tree_from_pop(): simulate transmission trees given population size initial immunity. simulate_summary(): simulate vector observed transmission chains sizes/lengths given number chains. likelihood(): estimate likelihood/loglikelihood observing chains given sizes/lengths.","code":""},{"path":"https://epiverse-trace.github.io/epichains/news/index.html","id":"methods-0-0-9999","dir":"Changelog","previous_headings":"","what":"Methods","title":"epichains 0.0.9999","text":"Use print() summary() obtain insightful results compared previously {bpmodels}. Use aggregate() aggregate results simulate_tree() simulate_tree_from_pop() cases “generation” “time” (time simulated)","code":""}]