toa_mat | R Documentation |
For a single behavior, creates two matrices recording times of adoption of the innovation. One matrix
records the time period of adoption for each node with zeros elsewhere. The
second records the cumulative time of adoption such that there are ones for
the time of adoption and every time period thereafter. For Q
behaviors,
creates a list of length Q
, where each element contains those two
matrices for each behavior.
toa_mat(obj, labels = NULL, t0 = NULL, t1 = NULL)
obj |
Either an integer vector of length |
labels |
Character vector of length |
t0 |
Integer scalar. Sets the lower bound of the time window (e.g. 1955). |
t1 |
Integer scalar. Sets the upper bound of the time window (e.g. 2000). |
In order to be able to work with time ranges other than 1,\dots, T
the function receives as input the boundary labels of the time windows through
the variables t0
and t
. While by default the function assumes that
the the boundaries are given by the range of the times
vector, the user
can set a personalized time range exceeding the one given by the times
vector. For instance, times of adoption may range between 2001 and 2005 but the
actual data, the network, is observed between 2000 and 2005 (so there is not
left censoring in the data), hence, the user could write:
adopmats <- toa_mat(times, t0=2000, t1=2005)
That way the resulting cumadopt
and adopt
matrices would have
2005 - 2000 + 1 = 6 columns instead of 2005 - 2001 + 1 = 5 columns, with the
first column of the two matrices containing only zeros (as the first adoption
happend after the year 2000).
For multiple behaviors, the input can be a matrix or a diffnet
object.
In this case, the output will be a list, with each element replicating the output
for a single diffusion: a matrix recording the time period of adoption for
each node, and a second matrix with ones from the moment the node adopts the behavior.
For a single behavior, a list of two n \times T
:
cumadopt |
has 1's for all years in which a node indicates having the innovation. |
adopt |
has 1's only for the year of adoption and 0 for the rest. |
For Q
behaviors, a list of length Q
, each element containing
cumadopt
ans adopt
matrices.
George G. Vega Yon, Thomas W. Valente, and AnĂbal Olivera M.
# Random set of times of adoptions
times <- sample(c(NA, 2001:2005), 10, TRUE)
toa_mat(times)
# Now, suppose that we observe the graph from 2000 to 2006
toa_mat(times, t0=2000, t1=2006)
# For multiple behaviors, the input can be a matrix..
times_1 <- c(2001L, 2004L, 2003L, 2008L)
times_2 <- c(2001L, 2005L, 2006L, 2008L)
times <- matrix(c(times_1, times_2), nrow = 4, ncol = 2)
toa <- toa_mat(times)
toa[[1]]$adopt # time period of adoption for the first behavior
#.. or a diffnet object
graph <- lapply(2001:2008, function(x) rgraph_er(4))
diffnet <- new_diffnet(graph, times)
toa <- toa_mat(diffnet)
toa[[1]]$cumadopt # cumulative adoption matrix for the first behavior
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.