Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotting with {epicontacts} #255

Open
jamesmbaazam opened this issue May 20, 2024 · 0 comments
Open

Plotting with {epicontacts} #255

jamesmbaazam opened this issue May 20, 2024 · 0 comments

Comments

@jamesmbaazam
Copy link
Member

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)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant