Creates an \(n \times n\) matrix, or for \(Q\) behaviors, a list of length \(Q\) containing \(n \times n\) matrices, that indicates the difference in adoption times between each pair of nodes.
toa_diff(obj, t0 = NULL, labels = 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).
Integer scalar. Sets the lower bound of the time window (e.g. 1955).
Character vector of length \(n\). Labels (ids) of the vertices.
An \(n \times n\) anti-symmetric matrix (or a list of them, for \(Q\) behaviors) indicating the difference in times of adoption between each pair of nodes.
Each cell \(ij\) of the resulting matrix is calculated as \(toa_j - toa_i\), so that whenever its positive it means that the j-th individual (alter) adopted the innovation sooner.
# For a single behavior -----------------------------------------------------
# Generating a random vector of time
set.seed(123)
times <- sample(2000:2005, 10, TRUE)
# Computing the TOA differences
toa_diff(times)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> [1,] 0 3 0 -1 -1 3 0 2 1 3
#> [2,] -3 0 -3 -4 -4 0 -3 -1 -2 0
#> [3,] 0 3 0 -1 -1 3 0 2 1 3
#> [4,] 1 4 1 0 0 4 1 3 2 4
#> [5,] 1 4 1 0 0 4 1 3 2 4
#> [6,] -3 0 -3 -4 -4 0 -3 -1 -2 0
#> [7,] 0 3 0 -1 -1 3 0 2 1 3
#> [8,] -2 1 -2 -3 -3 1 -2 0 -1 1
#> [9,] -1 2 -1 -2 -2 2 -1 1 0 2
#> [10,] -3 0 -3 -4 -4 0 -3 -1 -2 0
# For Q=2 behaviors ---------------------------------------------------------
# Generating a matrix time
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)
# Computing the TOA differences
toa_diff(times)
#> [[1]]
#> [,1] [,2] [,3] [,4]
#> [1,] 0 3 2 7
#> [2,] -3 0 -1 4
#> [3,] -2 1 0 5
#> [4,] -7 -4 -5 0
#>
#> [[2]]
#> [,1] [,2] [,3] [,4]
#> [1,] 0 4 5 7
#> [2,] -4 0 1 3
#> [3,] -5 -1 0 2
#> [4,] -7 -3 -2 0
#>
# Or, from a diffnet object
graph <- lapply(2001:2008, function(x) rgraph_er(4))
diffnet <- new_diffnet(graph, times)
#> Warning: Coercing -toa- into integer.
# Computing the TOA differences
toa_diff(diffnet)
#> [[1]]
#> [,1] [,2] [,3] [,4]
#> [1,] 0 3 2 7
#> [2,] -3 0 -1 4
#> [3,] -2 1 0 5
#> [4,] -7 -4 -5 0
#>
#> [[2]]
#> [,1] [,2] [,3] [,4]
#> [1,] 0 4 5 7
#> [2,] -4 0 1 3
#> [3,] -5 -1 0 2
#> [4,] -7 -3 -2 0
#>