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)Either an integer vector of length \(n\) containing time of adoption
of the innovation, a matrix of size \(n \times Q\) (for multiple \(Q\) behaviors), or
a diffnet object (both for single or multiple behaviors).
Character vector of length \(n\). Labels (ids) of the vertices.
Integer scalar. Sets the lower bound of the time window (e.g. 1955).
Integer scalar. Sets the upper bound of the time window (e.g. 2000).
For a single behavior, a list of two \(n \times T\):
cumadopthas 1's for all years in which a node indicates having the innovation.
adopthas 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.
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.
# Random set of times of adoptions
times <- sample(c(NA, 2001:2005), 10, TRUE)
toa_mat(times)
#> $adopt
#> 2002 2003 2004 2005
#> 1 1 0 0 0
#> 2 0 0 0 1
#> 3 0 1 0 0
#> 4 0 0 0 0
#> 5 0 0 0 1
#> 6 0 0 0 1
#> 7 1 0 0 0
#> 8 0 0 0 1
#> 9 0 0 1 0
#> 10 1 0 0 0
#>
#> $cumadopt
#> 2002 2003 2004 2005
#> 1 1 1 1 1
#> 2 0 0 0 1
#> 3 0 1 1 1
#> 4 0 0 0 0
#> 5 0 0 0 1
#> 6 0 0 0 1
#> 7 1 1 1 1
#> 8 0 0 0 1
#> 9 0 0 1 1
#> 10 1 1 1 1
#>
# Now, suppose that we observe the graph from 2000 to 2006
toa_mat(times, t0=2000, t1=2006)
#> $adopt
#> 2000 2001 2002 2003 2004 2005 2006
#> 1 0 0 1 0 0 0 0
#> 2 0 0 0 0 0 1 0
#> 3 0 0 0 1 0 0 0
#> 4 0 0 0 0 0 0 0
#> 5 0 0 0 0 0 1 0
#> 6 0 0 0 0 0 1 0
#> 7 0 0 1 0 0 0 0
#> 8 0 0 0 0 0 1 0
#> 9 0 0 0 0 1 0 0
#> 10 0 0 1 0 0 0 0
#>
#> $cumadopt
#> 2000 2001 2002 2003 2004 2005 2006
#> 1 0 0 1 1 1 1 1
#> 2 0 0 0 0 0 1 1
#> 3 0 0 0 1 1 1 1
#> 4 0 0 0 0 0 0 0
#> 5 0 0 0 0 0 1 1
#> 6 0 0 0 0 0 1 1
#> 7 0 0 1 1 1 1 1
#> 8 0 0 0 0 0 1 1
#> 9 0 0 0 0 1 1 1
#> 10 0 0 1 1 1 1 1
#>
# 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
#> 2001 2002 2003 2004 2005 2006 2007 2008
#> 1 1 0 0 0 0 0 0 0
#> 2 0 0 0 1 0 0 0 0
#> 3 0 0 1 0 0 0 0 0
#> 4 0 0 0 0 0 0 0 1
#.. or a diffnet object
graph <- lapply(2001:2008, function(x) rgraph_er(4))
diffnet <- new_diffnet(graph, times)
#> Warning: Coercing -toa- into integer.
toa <- toa_mat(diffnet)
toa[[1]]$cumadopt # cumulative adoption matrix for the first behavior
#> 2001 2002 2003 2004 2005 2006 2007 2008
#> 1 1 1 1 1 1 1 1 1
#> 2 0 0 0 1 1 1 1 1
#> 3 0 0 1 1 1 1 1 1
#> 4 0 0 0 0 0 0 0 1