Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
263 lines (155 sloc) 7.97 KB
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.width=8,
fig.height=6,
fig.path="figs/",
echo = TRUE
)
```
Welcome to the *epicontacts* package!
---------------------------------------
<br>
[![Travis-CI Build Status](https://travis-ci.org/reconhub/epicontacts.svg?branch=master)](https://travis-ci.org/reconhub/epicontacts)
[![Build status](https://ci.appveyor.com/api/projects/status/7fj30xjlesja0vbr/branch/master?svg=true)](https://ci.appveyor.com/project/thibautjombart/epicontacts/branch/master)
[![Coverage Status](https://codecov.io/github/reconhub/epicontacts/coverage.svg?branch=master)](https://codecov.io/github/reconhub/epicontacts?branch=master)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/epicontacts)](https://cran.r-project.org/package=epicontacts)
[![CRAN Downloads](https://cranlogs.r-pkg.org/badges/epicontacts)](https://cran.r-project.org/package=epicontacts)
[![Downloads from Rstudio mirror](https://cranlogs.r-pkg.org/badges/grand-total/epicontacts)](http://www.r-pkg.org/pkg/epicontacts)
<br>
# Installing the package
To install the current stable, CRAN version of the package, type:
```{r install, eval = FALSE}
install.packages("epicontacts")
```
To benefit from the latest features and bug fixes, install the development, *github* version of the package using:
```{r install2, eval = FALSE}
devtools::install_github("reconhub/epicontacts")
```
Note that this requires the package *devtools* installed.
# What does it do?
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.
# Resources
## Vignettes
An overview of *epicontacts* is provided below in the worked example below.
More detailed tutorials are distributed as vignettes with the package:
```{r, vignettes2, eval = FALSE}
vignette("overview", package="epicontacts")
vignette("customize_plot", package="epicontacts")
vignette("epicontacts_class", package="epicontacts")
```
## Websites
The following websites are available:
- The official *epicontacts* website, providing an overview of the package's functionalities, up-to-date tutorials and documentation: <br>
[http://www.repidemicsconsortium.org/epicontacts/](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: <br>
[http://github.com/reconhub/epicontacts](http://github.com/reconhub/epicontacts)
- The *epicontacts* page on CRAN: <br>
[https://CRAN.R-project.org/package=epicontacts](https://CRAN.R-project.org/package=epicontacts)
## Getting help online
Bug reports and feature requests should be posted on *github* using the [*issue*](http://github.com/reconhub/epicontacts/issues) system. All other questions should be posted on the **RECON forum**: <br>
[http://www.repidemicsconsortium.org/forum/](http://www.repidemicsconsortium.org/forum/)
# A quick overview
The following worked example provides a brief overview of the package's
functionalities. See the [*vignettes section*](#vignettes) for more detailed
tutorials.
## Obtaining an *epicontacts* object
*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*.
```{r}
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`).
## Simple analyses
First, we plot the *epicontacts* object:
```{r, eval = FALSE}
plot(x, selector = FALSE)
```
<img src="https://github.com/reconhub/epicontacts/raw/master/figs/plot_x.png" width="600px">
This is a screenshot of the actual plot. For interactive graphs, see the [introductory vignette](http://www.repidemicsconsortium.org/epicontacts/articles/epicontacts.html).
We can look for patterns of contacts between genders:
```{r, eval = FALSE}
plot(x, "sex", col_pal = spectral)
```
<img src="https://github.com/reconhub/epicontacts/raw/master/figs/plot_x_gender.png" width="600px">
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:
```{r, check_gender}
get_pairwise(x, attribute = "sex")
```
However, one can specify the function to be used to compare the attributes of
connected nodes; for instance:
```{r, test_gender}
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):
```{r, si}
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")
```
# Contributors (by alphabetic order):
- [Finlay Campbell](https://github.com/finlaycampbell)
- [Thomas Crellen](https://github.com/tc13)
- [Thibaut Jombart](https://github.com/thibautjombart)
- [Nistara Randhawa](https://github.com/nistara)
- Bertrand Sudre
See details of contributions on: <br>
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](CONDUCT.md). By participating in this project you agree to abide by its terms.
**Maintainer:** Finlay Campbell (f.campbell15@imperial)
You can’t perform that action at this time.