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:
In make_epicontacts():
the "id" column has to be unique.
The linelist and contacts objects can be the same.
An object contains multiple independent chains with their own unique ids, so this won't work out of the box with make_epicontacts().
We will need a custom coercion function to create a list of <epicontacts> object from an <epichains> object.
We may also need a custom plotting method for a list of <epicontacts> objects that plots all the objects on the same "layer".
For now, we will have to select and visualise individual chains from the epichains object.
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)
To plot with the
{epicontacts}
package, we need to create an<epicontacts>
object using theepicontacts::make_epicontacts()
function. This function requires a linelist and a contacts data frame. Note the following:make_epicontacts()
:make_epicontacts()
.<epicontacts>
object from an<epichains>
object.We may also need a custom plotting method for a list of
<epicontacts>
objects that plots all the objects on the same "layer".For now, we will have to select and visualise individual chains from the epichains object.
Created on 2024-05-20 with reprex v2.1.0