Learn R Programming

OutbreakTools (version 0.1-11)

obkContacts-class: Formal class "obkContacts"

Description

The class obkContacts is a formal (S4) class for storing contact data between individuals. Contacts can be static, or change in time (dynamic) at specified dates. Contacts are handled as network and networkDynamic objects, for static and dynamic contacts, respectively. See the corresponding packages for more information on this data structure.

An obkContacts object can be constructed from individual identifiers (stored as character vectors), representing the 'sender' and 'receiver' individuals, whether the contacts should be regarded as directed, with optional information about the timing of contacts.

Usage

get.contacts(x, ...)
get.ncontacts(x, ...)
## S3 method for class 'obkContacts':
get.ncontacts(x, from=NULL, to=NULL, \dots)
## S3 method for class 'obkContacts':
get.contacts(x, from=NULL, to=NULL, \dots)

## S3 method for class 'obkContacts': show(object)

## S3 method for class 'obkContacts': plot(x, y=NULL, labels=get.individuals(x), ...)

## S3 method for class 'obkContacts': as.matrix(x, matrix.type=c("adjacency","incidence","edgelist"), use.labels=TRUE, ...)

## S3 method for class 'obkContacts': as.data.frame(x, row.names=NULL, optional=FALSE, use.labels=TRUE, \dots)

Arguments

x,object
an obkContacts object.
y
used for compatibility with the generic definition of plot; unused.
labels
a vector of characters giving annotation for the vertices.
matrix.type
a character indicating which type of matrix to extract(adjacency, incidence, or edge matrix).
from,to
dates indicating the time span to consider for active contacts (for dynamic networks only).
...
arguments passed to other methods; currently not used, except for plot.
row.names,optional
unused arguments, there for compatibility with the generic as.data.frame.
use.labels
a logical indicating whether labels should be used to indicate individuals, as opposed to their index in the network.

Examples

Run this code
## THIS IS A TOY EXAMPLE ##
cf <- c("a", "b", "a", "c", "d")
ct <- c("b", "c", "c", "d", "b")
onset <- c(1, 2, 3, 4, 5)
terminus <- c(1.2, 4, 3.5, 4.1, 6)
oc.static <- new("obkContacts",cf,ct,FALSE) # static network
oc.dynamic <- new("obkContacts",cf,ct,FALSE,onset,terminus)
oc.static
oc.dynamic

plot(oc.static, main="Contact network")



## PLOTTING A DYNAMIC CONTACT NETWORK ##
## LOAD DATA
data(ToyOutbreak) # ToyOutbreak includes a dynamic contact network

## PLOT THE STATIC NETWORK
plot(ToyOutbreak@contacts)

## PLOT THE DYNAMIC NETWORK OVER THE FIRST 4 DAYS OF THE OUTBREAK
par(mfrow=c(2,2))

plot(ToyOutbreak@contacts)

plot(get.contacts(ToyOutbreak, from=0, to=2), displaylabels=TRUE,
     main="Contact network - days 1-2")

plot(get.contacts(ToyOutbreak, from=2.9, to=3.1), displaylabels=TRUE,
     main="Contact network - day 3")

plot(get.contacts(ToyOutbreak, from=3.9, to=4.1), displaylabels=TRUE,
     main="Contact network - day 4")

par(mfrow=c(1,1))

# extract matrices of adjacency, incidence, or edge list
as.matrix(ToyOutbreak@contacts)
as.matrix(ToyOutbreak@contacts, "incidence")
as.matrix(ToyOutbreak@contacts, "edgelist")

as.data.frame(ToyOutbreak@contacts)

Run the code above in your browser using DataLab