epiverse-trace / epichains

Methods for simulating and analysing the sizes and lengths of infectious disease transmission chains from branching process models
https://epiverse-trace.github.io/epichains/
Other
7 stars 2 forks source link

Plotting with `{epicontacts}` #255

Open jamesmbaazam opened 6 months ago

jamesmbaazam commented 6 months ago

To plot with the {epicontacts} package, we need to create an <epicontacts> object using the epicontacts::make_epicontacts() function. This function requires a linelist and a contacts data frame. Note the following:

library(epichains)
library(epicontacts)
set.seed(32)
chains_nbinom_offspring <- simulate_chains(
    n_chains = 10,
    pop = 100,
    percent_immune = 0,
    statistic = "size",
    offspring_dist = rnbinom,
    stat_threshold = 10,
    generation_time = function(n) rep(3, n),
    mu = 2,
    size = 0.2
)
chains_nbinom_offspring
#> `<epichains>` object
#> 
#> < epichains head (from first known infector) >
#> 
#>    chain infector infectee generation time
#> 11     1        1        2          2    3
#> 12     2        1        2          2    3
#> 13     2        1        3          2    3
#> 14     2        1        4          2    3
#> 15     2        1        5          2    3
#> 16     2        1        6          2    3
#> 
#> 
#> Number of chains: 10
#> Number of infectors (known): 5
#> Number of generations: 4
#> Use `as.data.frame(<object_name>)` to view the full output in the console.

# Select chain 2 because it has a lot of infections
chain2 <- chains_nbinom_offspring[chains_nbinom_offspring$chain == 2, ]

epc <- epicontacts::make_epicontacts(
    linelist = chain2,
    contacts = chain2,
    id = "infectee",
    from = "infectee",
    to = "infector",
    directed = FALSE
)

plot(epc)

Created on 2024-05-20 with reprex v2.1.0