knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.width=8, fig.height=6, fig.path="figs/", echo = TRUE )
To install the current stable, CRAN version of the package, type:
install.packages("epicontacts")
To benefit from the latest features and bug fixes, install the development, github version of the package using:
devtools::install_github("reconhub/epicontacts")
Note that this requires the package devtools installed.
The main features of the package include:
epicontacts
: a new S3 class for storing linelists and contacts data
make_epicontacts
: a constructor for the new epicontacts
class
get_id
: access unique IDs in an epicontacts
with various options
get_pairwise
: extract attributes of record(s) in contacts database using
information provided in the linelist data of an epicontacts
object.
get_degree
: access degree of cases in epicontacts
with various options
x[i,j,contacts]
: subset an epicontacts
object by retaining specified
cases
thin
: retains matching cases in linelist / contacts
summary
: summary for epicontacts
objects
plot
: plot for epicontacts
objects; various types of plot are
available; default to vis_epicontacts
vis_epicontacts
: plot an epicontacts
object using visNetwork
as.igraph.epicontacts
: create an igraph
object from an epicontacts object
get_clusters
: assign clusters and corresponding cluster sizes to
linelist of an epicontacts object (clusters being groups of connected
individuals/nodes).
subset_clusters_by_id
: subset an epicontacts
object based on a IDs of
cases of interest.
subset_clusters_by_size
: subset an epicontacts
object based on size(s)
of clusters (clusters being groups of connected individuals/nodes).
graph3D
: 3D graph from an epicontacts
object.
An overview of epicontacts is provided below in the worked example below. More detailed tutorials are distributed as vignettes with the package:
vignette("overview", package="epicontacts") vignette("customize_plot", package="epicontacts") vignette("epicontacts_class", package="epicontacts")
The following websites are available:
The official epicontacts website, providing an overview of the package's functionalities, up-to-date tutorials and documentation:
http://www.repidemicsconsortium.org/epicontacts/
The epicontacts project on github, useful for developers, contributors, and users wanting to post issues, bug reports and feature requests:
http://github.com/reconhub/epicontacts
The epicontacts page on CRAN:
https://CRAN.R-project.org/package=epicontacts
Bug reports and feature requests should be posted on github using the issue system. All other questions should be posted on the RECON forum:
http://www.repidemicsconsortium.org/forum/
The following worked example provides a brief overview of the package's functionalities. See the vignettes section for more detailed tutorials.
epicontacts need two types of data:
a linelist, i.e. a spreadsheet documenting cases where columns are variables and rows correspond to unique cases
a list of edges, defining connections between cases, identified by their unique identifier
There does not need to be an one-to-one correspondance between cases documented in the linelist and those appearing in the contacts. However, links will be made between the two sources of data whenever unique identifiers match. This will be especially handy when subsetting data, or when characterising contacts in terms of 'node' (case) properties.
We illustrate the construction of an epicontacts using contact data from a
Middle East Respiratory Syndrom coronavirus (MERS CoV) from South Korea in 2015,
available as the dataset mers_korea_2015
in the package outbreaks.
library(outbreaks) library(epicontacts) names(mers_korea_2015) dim(mers_korea_2015$linelist) dim(mers_korea_2015$contacts) x <- make_epicontacts(linelist = mers_korea_2015$linelist, contacts = mers_korea_2015$contacts, directed = TRUE) x class(x) summary(x)
In practice, the linelist and contacts will usually be imported from a text file
(e.g. .txt, .csv) or a spreadsheet (e.g. .ods, .xls) using usual import
functions (e.g. read.table
, read.csv
, gdata::read.xls
).
First, we plot the epicontacts object:
plot(x, selector = FALSE)
This is a screenshot of the actual plot. For interactive graphs, see the introductory vignette.
We can look for patterns of contacts between genders:
plot(x, "sex", col_pal = spectral)
There is no obvious signs of non-random mixing patterns, but this is worth
testing. The function get_pairwise
is particularly useful for this. In its
basic form, it reports nodes of attributes for all contacts. For instance:
get_pairwise(x, attribute = "sex")
However, one can specify the function to be used to compare the attributes of connected nodes; for instance:
sex_tab <- get_pairwise(x, attribute = "sex", f = table) sex_tab fisher.test(sex_tab)
Indeed, there are no patterns of association between genders. We can also use this function to compute delays between dates. For instance, to get the distribution of the serial interval (delay between primary and secondary onset):
si <- get_pairwise(x, attribute = "dt_onset") si summary(si) hist(si, col = "grey", border = "white", nclass = 30, xlab = "Time to secondary onset (days)", main = "Distribution of the serial interval")
See details of contributions on:
https://github.com/reconhub/epicontacts/graphs/contributors
Contributions are welcome via pull requests.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Maintainer: Finlay Campbell (finlaycampbell93@gmail.com)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.