Creates a square matrix suitable for spatial statistics models.
diag_expand(...)
# S3 method for class 'list'
diag_expand(graph, self = is_self(graph), valued = is_valued(graph), ...)
# S3 method for class 'diffnet'
diag_expand(graph, self = is_self(graph), valued = is_valued(graph), ...)
# S3 method for class 'matrix'
diag_expand(graph, nper, self = is_self(graph), valued = is_valued(graph), ...)
# S3 method for class 'array'
diag_expand(graph, self = is_self(graph), valued = is_valued(graph), ...)
# S3 method for class 'dgCMatrix'
diag_expand(graph, nper, self = is_self(graph), valued = is_valued(graph), ...)
Further arguments to be passed to the method.
Any class of accepted graph format (see netdiffuseR-graphs
).
Logical scalar. When TRUE
autolinks (loops, self edges) are allowed (see details).
Logical scalar. When TRUE
weights will be considered. Otherwise non-zero values will be replaced by ones.
Integer scalar. Number of time periods of the graph.
A square matrix of class dgCMatrix
of
size (nnode(g)*nper)^2
# Simple example ------------------------------------------------------------
set.seed(23)
g <- rgraph_er(n=10, p=.5, t=2,undirected=TRUE)
# What we've done: A list with 2 bernoulli graphs
g
#> $`1`
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#> [[ suppressing 10 column names ‘1’, ‘2’, ‘3’ ... ]]
#>
#> 1 . 1 . 1 1 1 . . . .
#> 2 1 . . 1 1 1 1 . 1 1
#> 3 . . . . 1 . 1 1 1 1
#> 4 1 1 . . 1 . 1 . . .
#> 5 1 1 1 1 . 1 1 1 . 1
#> 6 1 1 . . 1 . 1 1 . .
#> 7 . 1 1 1 1 1 . 1 . .
#> 8 . . 1 . 1 1 1 . 1 1
#> 9 . 1 1 . . . . 1 . 1
#> 10 . 1 1 . 1 . . 1 1 .
#>
#> $`2`
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#> [[ suppressing 10 column names ‘1’, ‘2’, ‘3’ ... ]]
#>
#> 1 . 1 . . 1 . . . 1 .
#> 2 1 . . 1 . . . 1 . 1
#> 3 . . . . 1 1 1 . . 1
#> 4 . 1 . . 1 1 . 1 1 1
#> 5 1 . 1 1 . 1 . 1 . .
#> 6 . . 1 1 1 . . 1 1 .
#> 7 . . 1 . . . . 1 1 1
#> 8 . 1 . 1 1 1 1 . 1 .
#> 9 1 . . 1 . 1 1 1 . .
#> 10 . 1 1 1 . . 1 . . .
#>
#> attr(,"undirected")
#> [1] TRUE
# Expanding to a 20*20 matrix with structural zeros on the diagonal
# and on cell 'off' adjacency matrix
diag_expand(g)
#> 20 x 20 sparse Matrix of class "dgCMatrix"
#>
#> [1,] . 1 . 1 1 1 . . . . . . . . . . . . . .
#> [2,] 1 . . 1 1 1 1 . 1 1 . . . . . . . . . .
#> [3,] . . . . 1 . 1 1 1 1 . . . . . . . . . .
#> [4,] 1 1 . . 1 . 1 . . . . . . . . . . . . .
#> [5,] 1 1 1 1 . 1 1 1 . 1 . . . . . . . . . .
#> [6,] 1 1 . . 1 . 1 1 . . . . . . . . . . . .
#> [7,] . 1 1 1 1 1 . 1 . . . . . . . . . . . .
#> [8,] . . 1 . 1 1 1 . 1 1 . . . . . . . . . .
#> [9,] . 1 1 . . . . 1 . 1 . . . . . . . . . .
#> [10,] . 1 1 . 1 . . 1 1 . . . . . . . . . . .
#> [11,] . . . . . . . . . . . 1 . . 1 . . . 1 .
#> [12,] . . . . . . . . . . 1 . . 1 . . . 1 . 1
#> [13,] . . . . . . . . . . . . . . 1 1 1 . . 1
#> [14,] . . . . . . . . . . . 1 . . 1 1 . 1 1 1
#> [15,] . . . . . . . . . . 1 . 1 1 . 1 . 1 . .
#> [16,] . . . . . . . . . . . . 1 1 1 . . 1 1 .
#> [17,] . . . . . . . . . . . . 1 . . . . 1 1 1
#> [18,] . . . . . . . . . . . 1 . 1 1 1 1 . 1 .
#> [19,] . . . . . . . . . . 1 . . 1 . 1 1 1 . .
#> [20,] . . . . . . . . . . . 1 1 1 . . 1 . . .