Title: | Handling, Visualisation and Analysis of Epidemiological Contacts |
---|---|
Description: | A collection of tools for representing epidemiological contact data, composed of case line lists and contacts between cases. Also contains procedures for data handling, interactive graphics, and statistics. |
Authors: | Finlay Campbell [aut, cre], Thibaut Jombart [aut], Nistara Randhawa [aut], Bertrand Sudre [aut], VP Nagraj [aut], Thomas Crellen [aut], Zhian N. Kamvar [aut] |
Maintainer: | Finlay Campbell <[email protected]> |
License: | GPL (>=2) |
Version: | 1.1.4 |
Built: | 2024-11-22 04:37:12 UTC |
Source: | https://github.com/reconhub/epicontacts |
The "[" operator can be used to subset epicontacts
objects,
retaining a specified set of case identifiers (i
for the linelist,
j
for contacts). Note that unlike most classical R objects, there is
no replacement method for epicontacts
objects, i.e. no
operations such as foo[i] <- bar
.
## S3 method for class 'epicontacts' x[ i, j, k = TRUE, l = TRUE, contacts = c("both", "either", "from", "to"), ... ]
## S3 method for class 'epicontacts' x[ i, j, k = TRUE, l = TRUE, contacts = c("both", "either", "from", "to"), ... ]
x |
An |
i |
A character vector containing case ID to be retained in the
linelist; alternatively, an integer or logical vector used to subset the
rows of the |
j |
A character vector containing case ID to be retained in the
contacts; alternatively, an integer or logical vector used to subset
the rows of the |
k |
An integer, logical, or character vector subsetting the
supplementary columns of |
l |
An integer, logical, or character vector subsetting the
supplementary columns of |
contacts |
A character string indicating the rules for retaining
contacts when |
... |
Not used (there for compatibility with generic). |
Details on the 'contacts' argument; possible values are:
'both': contacts are retained only if both cases are in j
'either': contacts are retained if at least one of the cases is in
j
'from': contacts are retained only if the source ('from') is in
j
'to': contacts are retained only if the recipient ('to') is in j
Thibaut Jombart ([email protected])
thin
to retain matching cases in linelist or contacts.
if (require(outbreaks)) { ## build data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id = "case_id", to = "case_id", from = "infector", directed = TRUE) ## subset first 10 linelist cases x[1:10] ## same, remove contacts x[1:10, j = FALSE] ## subset first 10 contacts x[j = 1:10] ## remove the metadata x[k = FALSE, j = FALSE] ## keep contacts where both cases are in linelist x[j = get_id(x, "linelist"), contacts = "both"] ## keep contacts from a specific case '916d0a' x[j = "916d0a", contacts = "from"] ## more complex: keep all cases and contacts with > 4 secondary contacts ## i) find cases to keep temp <- table(x$contacts$from) temp[temp > 4] to.keep <- names(temp)[temp > 4] to.keep ## subset the contacts y <- x[j = to.keep, contacts = "either"] y ## keep only relevant entries in the linelist y <- thin(y) ## visualise result plot(y) }
if (require(outbreaks)) { ## build data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id = "case_id", to = "case_id", from = "infector", directed = TRUE) ## subset first 10 linelist cases x[1:10] ## same, remove contacts x[1:10, j = FALSE] ## subset first 10 contacts x[j = 1:10] ## remove the metadata x[k = FALSE, j = FALSE] ## keep contacts where both cases are in linelist x[j = get_id(x, "linelist"), contacts = "both"] ## keep contacts from a specific case '916d0a' x[j = "916d0a", contacts = "from"] ## more complex: keep all cases and contacts with > 4 secondary contacts ## i) find cases to keep temp <- table(x$contacts$from) temp[temp > 4] to.keep <- names(temp)[temp > 4] to.keep ## subset the contacts y <- x[j = to.keep, contacts = "either"] y ## keep only relevant entries in the linelist y <- thin(y) ## visualise result plot(y) }
This function creates an igraph object from a given epicontacts
object containing a 'contacts' dataframe.
## S3 method for class 'epicontacts' as.igraph(x, ...)
## S3 method for class 'epicontacts' as.igraph(x, ...)
x |
An |
... |
Further arguments passed to |
An igraph
object (from the igraph
package). Note: any
column called "name" in the original linelist will be stored as a new
vertex attribute in the igraph
object named 'epicontacts_name'.
This is due to the inherent behaviour of igraph creating its own 'name'
vertex attribute.
Nistara Randhawa ([email protected])
if (require(outbreaks) && require(igraph)) { ## build data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id = "case_id", to = "case_id", from ="infector", directed = TRUE) ## subset data - keep 50 cases from linelist with contacts ids <- get_id(x, "common")[1:50] ids x <- x[ids, ids] ## make igraph object with associated attributes from epicontacts object net <- as.igraph(x) net plot(net, vertex.label = "", vertex.size = 10, vertex.color = cases_pal(50)) }
if (require(outbreaks) && require(igraph)) { ## build data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id = "case_id", to = "case_id", from ="infector", directed = TRUE) ## subset data - keep 50 cases from linelist with contacts ids <- get_id(x, "common")[1:50] ids x <- x[ids, ids] ## make igraph object with associated attributes from epicontacts object net <- as.igraph(x) net plot(net, vertex.label = "", vertex.size = 10, vertex.color = cases_pal(50)) }
The object codeawesome
is a character vector of fontawesome codes,
named after their aliases.
codeawesome
codeawesome
An object of class character
of length 519.
Thibaut Jombart
This function identifies transitive clusters (i.e. connected components) as well as the number of members in each cluster, and adds this information to the linelist data.
get_clusters( x, output = c("epicontacts", "data.frame"), member_col = "cluster_member", size_col = "cluster_size", override = FALSE )
get_clusters( x, output = c("epicontacts", "data.frame"), member_col = "cluster_member", size_col = "cluster_size", override = FALSE )
x |
An |
output |
A character string indicating the type of output: either an
|
member_col |
Name of column to which cluster membership is assigned to in the linelist. Default name is 'cluster_member'. |
size_col |
Name of column to which cluster sizes are assigned to in the linelist. Default name is 'cluster_size'. |
override |
Logical value indicating whether cluster member and size columns should be overwritten if they already exist in the linelist. Default is 'FALSE'. |
An epicontacts
object whose 'linelist' dataframe
contains new columns corresponding to cluster membership and size, or a
data.frame containing member ids, cluster memberships as factors,
and associated cluster sizes. All ids that were originally in the 'contacts'
dataframe but not in the linelist will also be added to the linelist.
Nistara Randhawa ([email protected])
if (require(outbreaks)) { ## build data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id = "case_id", to = "case_id", from = "infector", directed = TRUE) ## add cluster membership and sizes to epicontacts 'linelist' y <- get_clusters(x, output = "epicontacts") y ## return a data.frame with linelist member ids and cluster memberships as ## factors z <- get_clusters(x, output = "data.frame") head(z) }
if (require(outbreaks)) { ## build data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id = "case_id", to = "case_id", from = "infector", directed = TRUE) ## add cluster membership and sizes to epicontacts 'linelist' y <- get_clusters(x, output = "epicontacts") y ## return a data.frame with linelist member ids and cluster memberships as ## factors z <- get_clusters(x, output = "data.frame") head(z) }
This function computes the number of contacts per cases in a
epicontacts
dataset. Whenever contacts are directed, the
argument 'type' can be used to specify which kind of contact should be
considered: 'in' (towards the case), 'out' (from the case), or 'both'.
get_degree(x, type = c("in", "out", "both"), only_linelist = FALSE)
get_degree(x, type = c("in", "out", "both"), only_linelist = FALSE)
x |
an |
type |
the type of degree to be computed (see description); if contacts are not directed, this will be forced to 'both' |
only_linelist |
a logical indicating if cases whose degree is computed should be from the linelist exclusively |
Thibaut Jombart ([email protected])
## make epicontacts object if (require(outbreaks)) { x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id="case_id", to="case_id", from="infector", directed=TRUE) x ## compute in-degree deg_in <- get_degree(x) table(deg_in) ## compute out-degree deg_out <- get_degree(x, "out") barplot(table(deg_out), main = "Reproduction number distribution") mtext(side = 3, "(based on case out-degree)") }
## make epicontacts object if (require(outbreaks)) { x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id="case_id", to="case_id", from="infector", directed=TRUE) x ## compute in-degree deg_in <- get_degree(x) table(deg_in) ## compute out-degree deg_out <- get_degree(x, "out") barplot(table(deg_out), main = "Reproduction number distribution") mtext(side = 3, "(based on case out-degree)") }
This accessor is used to extract unique identifiers from
epicontacts
objects. The argument 'which' can be used to
specify if IDs should include: linelist only ('linelist'), contacts only
('contacts'), the union of both ('all'), or the intersection of both
('common'); two additional options are 'from' (ID 'giving' contacts) and 'to'
(ID 'receiving' contacts).
get_id( x, which = c("linelist", "contacts", "all", "common", "from", "to"), na.rm = TRUE )
get_id( x, which = c("linelist", "contacts", "all", "common", "from", "to"), na.rm = TRUE )
x |
an |
which |
the type of ID to return (see description); value can be 'linelist', 'contacts', 'all', 'common', 'from' or 'to'. |
na.rm |
a 'logical' indicating if 'NA' should be removed from the output ('TRUE', default) or not. |
x a character vector of unique identifiers
Thibaut Jombart ([email protected])
if (require(outbreaks)) { ## build data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id="case_id", to="case_id", from="infector", directed=TRUE) ## get identifiers id1 <- get_id(x, "linelist") id2 <- get_id(x, "contacts") id3 <- get_id(x, "all") id4 <- get_id(x, "common") ## check intersections and unions all.equal(union(id1, id2), id3) all.equal(intersect(id1, id2), id4) }
if (require(outbreaks)) { ## build data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id="case_id", to="case_id", from="infector", directed=TRUE) ## get identifiers id1 <- get_id(x, "linelist") id2 <- get_id(x, "contacts") id3 <- get_id(x, "all") id4 <- get_id(x, "common") ## check intersections and unions all.equal(union(id1, id2), id3) all.equal(intersect(id1, id2), id4) }
This function extract attributes of cases involved in contacts using case
information provided in the linelist of an epicontacts
dataset. If not provided, the function used to process attributes will adjust
to the type of attribute selected (see details).
get_pairwise(x, attribute, f = NULL, hard_NA = TRUE)
get_pairwise(x, attribute, f = NULL, hard_NA = TRUE)
x |
an |
attribute |
the attribute to be examined between contact pairs |
f |
a function processing the attributes of 'from' and 'to' |
hard_NA |
a logical indicating if the output should be NA whenever one of the paired values is NA (TRUE, default); otherwise, 'NA' may be treated as another character (e.g. when pasting paired values) |
Thibaut Jombart ([email protected]) Tom Crellen ([email protected])
if (require(outbreaks)) { ## example using MERS outbreak in Korea, 2014 head(mers_korea_2015[[1]]) head(mers_korea_2015[[2]]) x <- make_epicontacts(linelist=mers_korea_2015[[1]], contacts=mers_korea_2015[[2]], directed=TRUE) ## estimate serial interval (onset->onset) SI <- get_pairwise(x, "dt_onset") SI summary(SI) hist(SI, col="grey", border="white", xlab="Days after symptoms", main="MERS Korea 2014 - Serial Interval") ## check gender mixing: get_pairwise(x, "sex") # not good, we want 2-way table get_pairwise(x, "sex", f=table) # use custom function fisher.test(get_pairwise(x, "sex", f=table)) # test association }
if (require(outbreaks)) { ## example using MERS outbreak in Korea, 2014 head(mers_korea_2015[[1]]) head(mers_korea_2015[[2]]) x <- make_epicontacts(linelist=mers_korea_2015[[1]], contacts=mers_korea_2015[[2]], directed=TRUE) ## estimate serial interval (onset->onset) SI <- get_pairwise(x, "dt_onset") SI summary(SI) hist(SI, col="grey", border="white", xlab="Days after symptoms", main="MERS Korea 2014 - Serial Interval") ## check gender mixing: get_pairwise(x, "sex") # not good, we want 2-way table get_pairwise(x, "sex", f=table) # use custom function fisher.test(get_pairwise(x, "sex", f=table)) # test association }
This function creates a 3D graph from an epicontacts object
graph3D( x, node_color = "id", annot = TRUE, col_pal = cases_pal, NA_col = "lightgrey", g_title = "", bg_col = "white", label_col = "darkgrey", node_size = 1, edge_size = 0.5 )
graph3D( x, node_color = "id", annot = TRUE, col_pal = cases_pal, NA_col = "lightgrey", g_title = "", bg_col = "white", label_col = "darkgrey", node_size = 1, edge_size = 0.5 )
x |
An |
node_color |
An index or character string indicating which field of the
linelist should be used to color the nodes. Default is |
annot |
An index, logical, or character string indicating which fields
of the linelist should be used for annotating the nodes upon mouseover. The default
|
col_pal |
A color palette for the node_colors. |
NA_col |
The color used for unknown node_color. |
g_title |
The title of the graph. |
bg_col |
The background color of graph. |
label_col |
The color of the graph title and labels of groups. |
node_size |
The sizes of graph nodes. |
edge_size |
The width of graph edges. |
An htmlwidget object that is displayed using the object's show or print method.
(If you don't see your widget plot, try printing it with the print
function.)
All colors must be specified as color names like "red", "blue", etc. or as hexadecimal color values without opacity channel, for example "#FF0000", "#0a3e55" (upper or lower case hex digits are allowed).
Double-click or tap on the plot to reset the view.
Nistara Randhawa ([email protected]) Thibaut Jombart ([email protected]) VP Nagraj ([email protected])
Original rthreejs code by B. W. Lewis: https://github.com/bwlewis/rthreejs.
if (require(outbreaks)) { ## example using MERS outbreak in Korea, 2014 head(mers_korea_2015[[1]]) head(mers_korea_2015[[2]]) x <- make_epicontacts(linelist = mers_korea_2015$linelist, contacts = mers_korea_2015$contacts, directed = FALSE) ## Not run: graph3D(x) graph3D(x, annot = FALSE) graph3D(x, node_color = "sex", g_title = "MERS Korea 2014") graph3D(x, node_color = "sex", annot = c("sex", "age"), g_title = "MERS Korea 2014") ## End(Not run) }
if (require(outbreaks)) { ## example using MERS outbreak in Korea, 2014 head(mers_korea_2015[[1]]) head(mers_korea_2015[[2]]) x <- make_epicontacts(linelist = mers_korea_2015$linelist, contacts = mers_korea_2015$contacts, directed = FALSE) ## Not run: graph3D(x) graph3D(x, annot = FALSE) graph3D(x, node_color = "sex", g_title = "MERS Korea 2014") graph3D(x, node_color = "sex", annot = c("sex", "age"), g_title = "MERS Korea 2014") ## End(Not run) }
This function reads data stored as data.frame containing linelist (case information, where each row corresponds to a unique patient), and contacts between patients. Common identifiers should be used in the two data sources for matching to be achieved.
make_epicontacts( linelist, contacts, id = 1L, from = 1L, to = 2L, directed = FALSE )
make_epicontacts( linelist, contacts, id = 1L, from = 1L, to = 2L, directed = FALSE )
linelist |
a data.frame with at least one column providing unique patient identifiers |
contacts |
a data.frame that needs at least two columns indicating patients between which cases take place; these need not be referenced in the linelist |
id |
an index or name indicating which column in |
from |
an index or name indicating which column in |
to |
an index or name indicating which column in |
directed |
a logical indicating if contacts are directed or not; default
is |
An epicontacts
object can be created from two components:
a linelist provided as a data.frame
where columns are
different variables describing cases, and where each row is a different case.
and a contact list.
a contact list provided as a data.frame
where each row contains
unique pairs of contacts with unique features of contact in columns. The line
list and contact list should share an identification scheme for individuals.
An epicontacts
object in list format with three elements:
linelist
: data.frame of cases with first column 'id'
containing character vector of unique identifiers
contacts
: data.frame of contacts with first two columns named
'from' and 'to' indicating unique pairs of contact between individuals
directed
: indicator as to whether or not the contacts are to be
considered directed or not
Thibaut Jombart ([email protected])
https://foodborne.unl.edu/public/role/epidemiologist/lineLists.html
if (require(outbreaks)) { ## make epicontacts object from simulated Ebola data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts) ## test reordering of columns linelist <- ebola_sim$linelist[,rev(seq_len(ncol(ebola_sim$linelist)))] contacts <- ebola_sim$contacts[,rev(seq_len(ncol(ebola_sim$contacts)))] head(linelist) head(contacts) ## make object x <- make_epicontacts(linelist, contacts, id = "case_id", to = "case_id", from = "infector") head(x$linelist) head(x$contacts) }
if (require(outbreaks)) { ## make epicontacts object from simulated Ebola data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts) ## test reordering of columns linelist <- ebola_sim$linelist[,rev(seq_len(ncol(ebola_sim$linelist)))] contacts <- ebola_sim$contacts[,rev(seq_len(ncol(ebola_sim$contacts)))] head(linelist) head(contacts) ## make object x <- make_epicontacts(linelist, contacts, id = "case_id", to = "case_id", from = "infector") head(x$linelist) head(x$contacts) }
This function plots epicontacts
objects using various
approaches. The default method uses vis_epicontacts
.
## S3 method for class 'epicontacts' plot( x, node_color = "id", method = c("visNetwork", "graph3D"), thin = TRUE, ... )
## S3 method for class 'epicontacts' plot( x, node_color = "id", method = c("visNetwork", "graph3D"), thin = TRUE, ... )
x |
An |
node_color |
An integer or a character string indicating which attribute column in the linelist should be used to color the nodes. |
method |
A character string indicating the plotting method to be used; available values are "visNetwork" and "graph3D"; see details. |
thin |
A logical indicating if the data should be thinned with |
... |
Further arguments passed to the plotting methods. |
This function is merely a wrapper for other plotting functions in
the package, depending on the value of method
:
visNetwork
: calls the function vis_epicontacts
graph3D
: calls the function graph3D
Thibaut Jombart ([email protected])
vis_epicontacts
, which uses the package
visNetwork
, and codeawesome
for icon codes.
if (require(outbreaks)) { ## example using MERS outbreak in Korea, 2014 head(mers_korea_2015[[1]]) head(mers_korea_2015[[2]]) x <- make_epicontacts(linelist = mers_korea_2015[[1]], contacts = mers_korea_2015[[2]], directed=TRUE) ## Not run: plot(x) plot(x, "place_infect") plot(x, "loc_hosp", legend_max = 20, annot = TRUE) plot(x, "place_infect", node_shape = "sex", shapes = c(M = "male", F = "female")) plot(x, 4) plot(x, 4, method = "graph3D") ## End(Not run) }
if (require(outbreaks)) { ## example using MERS outbreak in Korea, 2014 head(mers_korea_2015[[1]]) head(mers_korea_2015[[2]]) x <- make_epicontacts(linelist = mers_korea_2015[[1]], contacts = mers_korea_2015[[2]], directed=TRUE) ## Not run: plot(x) plot(x, "place_infect") plot(x, "loc_hosp", legend_max = 20, annot = TRUE) plot(x, "place_infect", node_shape = "sex", shapes = c(M = "male", F = "female")) plot(x, 4) plot(x, 4, method = "graph3D") ## End(Not run) }
This method prints the content of epicontacts
objects, giving a brief
summary of the reported cases and contacts.
## S3 method for class 'epicontacts' print(x, ...)
## S3 method for class 'epicontacts' print(x, ...)
x |
an |
... |
further parameters to be passed to other methods (currently not used) |
Thibaut Jombart ([email protected])
This method outputs a printed summary of the content of
summary_epicontacts
objects.
## S3 method for class 'summary_epicontacts' print(x, ...)
## S3 method for class 'summary_epicontacts' print(x, ...)
x |
a |
... |
further parameters to be passed to other methods (currently not used) |
VP Nagraj ([email protected])
This function subsets an epicontacts
object by identifying
clusters of cases connected to specified cases.
subset_clusters_by_id(x, id)
subset_clusters_by_id(x, id)
x |
an |
id |
a character vector of case identifiers; the connected components attached to these cases will be retained in the output object. |
An epicontacts
object whose contact dataframe
corresponds to all clusters containing specified case id.
Nistara Randhawa ([email protected])
if (require(outbreaks)) { ## build data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id="case_id", to="case_id", from="infector", directed=TRUE) id <- "cac51e" ## it can be a vector of id as well ## subset based on cluster to which "cac51e" belongs x_subset <- subset_clusters_by_id(x, id) }
if (require(outbreaks)) { ## build data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id="case_id", to="case_id", from="infector", directed=TRUE) id <- "cac51e" ## it can be a vector of id as well ## subset based on cluster to which "cac51e" belongs x_subset <- subset_clusters_by_id(x, id) }
This function subsets an epicontacts
object based on defined
size(s) of clusters (clusters being groups of connected
individuals/nodes). Subsetting may be done by specifying a particular cluster
size of interest, minimum cluster size, maximum cluster size, or a range
(minimum and maximum) of cluster sizes.
subset_clusters_by_size(x, cs = NULL, cs_min = NULL, cs_max = NULL)
subset_clusters_by_size(x, cs = NULL, cs_min = NULL, cs_max = NULL)
x |
an |
cs |
cluster size to be used for subsetting |
cs_min |
minimum cluster size for subsetting |
cs_max |
maximum cluster size for subsetting |
An epicontacts
object whose contact dataframe corresponds to
all clusters of specified cluster sizes.
Nistara Randhawa ([email protected])
if (require(outbreaks)) { ## build data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id="case_id", to="case_id", from="infector", directed=TRUE) ## subset based on cluster size range x_subset <- subset_clusters_by_size(x, cs_min = 12, cs_max = 15) ## subset based on single cluster size x_subset <- subset_clusters_by_size(x, cs = 12) ## subset based on minimum cluster size x_subset <- subset_clusters_by_size(x, cs_min = 10) ## subset based on maximum cluster size x_subset <- subset_clusters_by_size(x, cs_max = 9) }
if (require(outbreaks)) { ## build data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id="case_id", to="case_id", from="infector", directed=TRUE) ## subset based on cluster size range x_subset <- subset_clusters_by_size(x, cs_min = 12, cs_max = 15) ## subset based on single cluster size x_subset <- subset_clusters_by_size(x, cs = 12) ## subset based on minimum cluster size x_subset <- subset_clusters_by_size(x, cs_min = 10) ## subset based on maximum cluster size x_subset <- subset_clusters_by_size(x, cs_max = 9) }
This function subsets an epicontacts
object based on node,
edge and/or cluster attributes. Specifying node attributes will return an
epicontacts
object containing only individuals with these
given attributes in the linelist. Specifying edge attributes will return
contacts with the attributes provided. Specifying cluster attributes will
return clusters of connected cases, and can be defined by ids (returning
clusters of cases connected to specified cases) or cluster sizes (returning
cluster of a specific, minimum or maximum size).
## S3 method for class 'epicontacts' subset( x, node_attribute = NULL, edge_attribute = NULL, cluster_id = NULL, cs = NULL, cs_min = NULL, cs_max = NULL, ... )
## S3 method for class 'epicontacts' subset( x, node_attribute = NULL, edge_attribute = NULL, cluster_id = NULL, cs = NULL, cs_min = NULL, cs_max = NULL, ... )
x |
an epi_contact object to be subsetted |
node_attribute |
a named list defining the node attribute name and node attribute value (as a single value or vector of values). Dates must be provided as a vector of date objects, defining the range of dates included in the subset. If only one date is provided, only node attributes with that date will be returned. |
edge_attribute |
a named list defining the edge attribute name and edge attribute value (as a single value or vector of values). Dates must be provided as a vector of date objects, defining the range of dates included in the subset. If only one date is provided, only edge attributes with that date will be returned. |
cluster_id |
a character vector of case identifiers; the connected components attached to these cases will be retained in the output object. |
cs |
cluster size to be used for subsetting |
cs_min |
minimum cluster size for subsetting |
cs_max |
maximum cluster size for subsetting |
... |
further arguments passed on to other methods |
Finlay Campbell ([email protected]), Nistara Randhawa ([email protected])
if (require(outbreaks)) { ## build data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id = "case_id", to = "case_id", from = "infector", directed = FALSE) ## subset based on node and edge attributes x_subset <- subset(x, node_attribute = list("gender" = "f"), edge_attribute = list("source" = "funeral")) ## subset a cluster connected to a given id ## (can be a vector of ids as well) ## here picking node with highest out-degree id <- names(which.max(get_degree(x, "out"))) x_subset <- thin(subset(x, cluster_id = id), 2) x_subset plot(x_subset) ## subset based on cluster size range x_subset <- subset(x, cs_min = 12, cs_max = 15) ## subset based on single cluster size x_subset <- subset(x, cs = 12) ## subset based on minimum cluster size x_subset <- subset(x, cs_min = 10) ## subset based on maximum cluster size x_subset <- subset(x, cs_max = 9) }
if (require(outbreaks)) { ## build data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id = "case_id", to = "case_id", from = "infector", directed = FALSE) ## subset based on node and edge attributes x_subset <- subset(x, node_attribute = list("gender" = "f"), edge_attribute = list("source" = "funeral")) ## subset a cluster connected to a given id ## (can be a vector of ids as well) ## here picking node with highest out-degree id <- names(which.max(get_degree(x, "out"))) x_subset <- thin(subset(x, cluster_id = id), 2) x_subset plot(x_subset) ## subset based on cluster size range x_subset <- subset(x, cs_min = 12, cs_max = 15) ## subset based on single cluster size x_subset <- subset(x, cs = 12) ## subset based on minimum cluster size x_subset <- subset(x, cs_min = 10) ## subset based on maximum cluster size x_subset <- subset(x, cs_max = 9) }
This method outputs a summary of the content of epicontacts
objects.
## S3 method for class 'epicontacts' summary(object, ...)
## S3 method for class 'epicontacts' summary(object, ...)
object |
an |
... |
further parameters to be passed to other methods (currently not used) |
VP Nagraj ([email protected])
This function can be used to remove ('thin') data from
epicontacts
objects to ensure stricter matching of linelists
and contacts. It has two behaviours, triggered by the argument what
:
either it thins data from $linelist
, keeping only cases that are in
$contacts
(thin = "linelist"
, default), or the converse,
i.e. removing contacts which are not fully documented in the linelist.
thin(x, what = "linelist")
thin(x, what = "linelist")
x |
An |
what |
A character string or integer determining which type of data is
removed ('thinned'). "linelist" / 1 indicates that only cases appearing
in |
Thibaut Jombart ([email protected])
if (require(outbreaks)) { ## build data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id = "case_id", to = "case_id", from = "infector", directed = TRUE) ## keep contacts from a specific case '916d0a' x <- x[j = "916d0a", contacts = "from"] }
if (require(outbreaks)) { ## build data x <- make_epicontacts(ebola_sim$linelist, ebola_sim$contacts, id = "case_id", to = "case_id", from = "infector", directed = TRUE) ## keep contacts from a specific case '916d0a' x <- x[j = "916d0a", contacts = "from"] }
These functions are used for defining palettes or colors in the
epicontacts
package. They include:
transp(col, alpha = 0.5) edges_pal(n) cases_pal(n) spectral(n) fac2col(x, pal = cases_pal, NA_col = "lightgrey", legend = FALSE)
transp(col, alpha = 0.5) edges_pal(n) cases_pal(n) spectral(n) fac2col(x, pal = cases_pal, NA_col = "lightgrey", legend = FALSE)
col |
A color vector to which transparency should be added. |
alpha |
The threshold to be used for transparency: 0 for full transparency, and 1 for full opacity. |
n |
An integer indicating the number of colors. |
x |
A character or a factor to be converted to colors. |
pal |
A color palette. |
NA_col |
The color to be used for NA values. |
legend |
A logical indicating if legend info should be added to the
output. If TRUE, the output will be a list, with colors in the
|
cases_pal
: discrete color palette used for cases (comes from the
dibbler
package)
spectral
: continuous color palette (comes from the
adegenet
package)
transp
: makes colors transparent (comes from the
adegenet
package)
fac2col
: translates a character or a factor to a color using a
palette (comes from the adegenet
package)
Thibaut Jombart [email protected]
barplot(1:5, col = cases_pal(5)) barplot(1:50, col = cases_pal(50))
barplot(1:5, col = cases_pal(5)) barplot(1:50, col = cases_pal(50))
This function plots epicontacts
objects using the
visNetwork
package. The produced object is an htmlwidget
which
will need rendering within a web browser.
vis_epicontacts( x, thin = TRUE, node_color = "id", label = "id", annot = TRUE, node_shape = NULL, shapes = NULL, edge_label = NULL, edge_color = NULL, legend = TRUE, legend_max = 10, x_axis = NULL, col_pal = cases_pal, NA_col = "lightgrey", edge_col_pal = edges_pal, width = "90%", height = "700px", selector = TRUE, editor = FALSE, edge_width = 3, ... )
vis_epicontacts( x, thin = TRUE, node_color = "id", label = "id", annot = TRUE, node_shape = NULL, shapes = NULL, edge_label = NULL, edge_color = NULL, legend = TRUE, legend_max = 10, x_axis = NULL, col_pal = cases_pal, NA_col = "lightgrey", edge_col_pal = edges_pal, width = "90%", height = "700px", selector = TRUE, editor = FALSE, edge_width = 3, ... )
x |
An |
thin |
A logical indicating if the data should be thinned with |
node_color |
An index or character string indicating which field of the linelist should be used to color the nodes. |
label |
An index, logical, or character string indicating which fields
of the linelist should be used for labelling the nodes. Logical will be
recycled if necessary, so that the default |
annot |
An index, logical, or character string indicating which fields
of the linelist should be used for annotating the nodes. Logical will be
recycled if necessary, so that the default |
node_shape |
An index or character string indicating which field of the linelist should be used to determine the shapes of the nodes. |
shapes |
A named vector of characters indicating which icon code should
be used for each value |
edge_label |
An index or character string indicating which field of the contacts data should be used to label the edges of the graph. |
edge_color |
An index or character string indicating which field of the contacts data should be used to color the edges of the graph. |
legend |
A logical indicating whether a legend should be added to the plot. |
legend_max |
The maximum number of groups for a legend to be displayed. |
x_axis |
Feature currently only available in development "timeline" branch. |
col_pal |
A color palette for the nodes. |
NA_col |
The color used for unknown group. |
edge_col_pal |
A color palette for the edges. |
width |
The width of the output, in html compatible format (e.g. '90%' or '800px'). |
height |
The height of the output, in html compatible format (e.g. '800px'). |
selector |
A logical indicating if the selector tool should be used; defaults to TRUE. |
editor |
A logical indicating if the editor tool should be used; defaults to FALSE. |
edge_width |
An integer indicating the width of the edges. Defaults to 3. |
... |
Further arguments to be passed to |
The same output as visNetwork
.
Thibaut Jombart ([email protected]) VP Nagraj ([email protected]) Zhian N. Kamvar ([email protected])
visNetwork
in the package visNetwork
.
edges_pal
and cases_pal
for color palettes used
if (require(outbreaks)) { ## example using MERS outbreak in Korea, 2014 head(mers_korea_2015[[1]]) head(mers_korea_2015[[2]]) x <- make_epicontacts(linelist=mers_korea_2015[[1]], contacts = mers_korea_2015[[2]], directed=TRUE) ## Not run: plot(x) plot(x, node_color = "place_infect") # show transmission tree with time as the horizontal axis, showing all nodes #' plot(x, node_color = "loc_hosp", legend_max=20, annot=TRUE) #' plot(x, "place_infect", node_shape = "sex", shapes = c(M = "male", F = "female")) plot(x, "sex", node_shape = "sex", shapes = c(F = "female", M = "male"), edge_label = "exposure", edge_color = "exposure") ## End(Not run) }
if (require(outbreaks)) { ## example using MERS outbreak in Korea, 2014 head(mers_korea_2015[[1]]) head(mers_korea_2015[[2]]) x <- make_epicontacts(linelist=mers_korea_2015[[1]], contacts = mers_korea_2015[[2]], directed=TRUE) ## Not run: plot(x) plot(x, node_color = "place_infect") # show transmission tree with time as the horizontal axis, showing all nodes #' plot(x, node_color = "loc_hosp", legend_max=20, annot=TRUE) #' plot(x, "place_infect", node_shape = "sex", shapes = c(M = "male", F = "female")) plot(x, "sex", node_shape = "sex", shapes = c(F = "female", M = "male"), edge_label = "exposure", edge_color = "exposure") ## End(Not run) }