The Laplacian of a signed graph.

laplacian_matrix_signed(g, norm = FALSE, sparse = FALSE)

Arguments

g

igraph object with a sign edge attribute.

norm

Whether to calculate the normalized Laplacian. See definitions below.

sparse

Logical scalar, whether to return the result as a sparse matrix. The Matrix package is required for sparse matrices.

Value

a numeric matrix

Details

See laplacian_matrix of igraph for more details. In the signed case, D is a diagonal matrix containing the absolute values of row sums of the signed adjacency matrix.

Author

David Schoch

Examples

library(igraph)
g <- sample_islands_signed(3, 10, 5 / 10, 1)
laplacian_matrix_signed(g)
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
#>  [1,]    4   -1   -1    0    0   -1    0    0    0    -1     0     0     0
#>  [2,]   -1    7   -1    0    0   -1   -1   -1   -1    -1     0     0     0
#>  [3,]   -1   -1    5   -1    0    0   -1    0   -1     0     0     0     0
#>  [4,]    0    0   -1    4    0    0    0   -1   -1    -1     0     0     0
#>  [5,]    0    0    0    0    2    0    0   -1    0    -1     0     0     0
#>  [6,]   -1   -1    0    0    0    4    0    0    0    -1     1     0     0
#>  [7,]    0   -1   -1    0    0    0    3    0    0    -1     0     0     0
#>  [8,]    0   -1    0   -1   -1    0    0    4    0     0     0     0     0
#>  [9,]    0   -1   -1   -1    0    0    0    0    4    -1     0     0     0
#> [10,]   -1   -1    0   -1   -1   -1   -1    0   -1     7     0     0     0
#> [11,]    0    0    0    0    0    1    0    0    0     0     6     0    -1
#> [12,]    0    0    0    0    0    0    0    0    0     0     0     4    -1
#> [13,]    0    0    0    0    0    0    0    0    0     0    -1    -1     4
#> [14,]    0    0    0    0    0    0    0    0    0     0    -1     0     0
#> [15,]    0    0    0    0    0    0    0    0    0     0     0     0    -1
#> [16,]    0    0    0    0    0    0    0    0    0     0    -1    -1     0
#> [17,]    0    0    0    0    0    0    0    0    0     0    -1     0     0
#> [18,]    0    0    0    0    0    0    0    0    0     0     0     0    -1
#> [19,]    0    0    0    0    0    0    0    0    0     0    -1    -1     0
#> [20,]    0    0    0    0    0    0    0    0    0     0     0    -1     0
#> [21,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [22,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [23,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [24,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [25,]    0    0    0    0    0    0    0    1    0     0     0     0     0
#> [26,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [27,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [28,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [29,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [30,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#>       [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25]
#>  [1,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [2,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [3,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [4,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [5,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [6,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [7,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [8,]     0     0     0     0     0     0     0     0     0     0     0     1
#>  [9,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [10,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [11,]    -1     0    -1    -1     0    -1     0     0     0     0     0     0
#> [12,]     0     0    -1     0     0    -1    -1     0     0     0     0     0
#> [13,]     0    -1     0     0    -1     0     0     0     0     0     0     0
#> [14,]     6    -1    -1    -1    -1    -1     0     0     0     0     0     0
#> [15,]    -1     5    -1     0    -1    -1     0     0     0     0     0     0
#> [16,]    -1    -1     7     0    -1    -1     0     0     0     0     0     0
#> [17,]    -1     0     0     3     0    -1     0     0     0     0     0     0
#> [18,]    -1    -1    -1     0     6    -1    -1     0     0     0     0     0
#> [19,]    -1    -1    -1    -1    -1     8    -1     0     0     0     0     0
#> [20,]     0     0     0     0    -1    -1     3     0     0     0     0     0
#> [21,]     0     0     0     0     0     0     0     3     0     0    -1     0
#> [22,]     0     0     0     0     0     0     0     0     5    -1     0    -1
#> [23,]     0     0     0     0     0     0     0     0    -1     3     0     0
#> [24,]     0     0     0     0     0     0     0    -1     0     0     4     0
#> [25,]     0     0     0     0     0     0     0     0    -1     0     0     5
#> [26,]     0     0     0     0     0     0     0     0     0     0    -1    -1
#> [27,]     0     0     0     0     0     0     0    -1    -1     0    -1     0
#> [28,]     0     0     0     0     0     0     0     0    -1     0     0    -1
#> [29,]     0     0     1     0     0     0     0     0    -1    -1    -1     0
#> [30,]     0     0     0     0     0     0     0    -1     0    -1     0    -1
#>       [,26] [,27] [,28] [,29] [,30]
#>  [1,]     0     0     0     0     0
#>  [2,]     0     0     0     0     0
#>  [3,]     0     0     0     0     0
#>  [4,]     0     0     0     0     0
#>  [5,]     0     0     0     0     0
#>  [6,]     0     0     0     0     0
#>  [7,]     0     0     0     0     0
#>  [8,]     0     0     0     0     0
#>  [9,]     0     0     0     0     0
#> [10,]     0     0     0     0     0
#> [11,]     0     0     0     0     0
#> [12,]     0     0     0     0     0
#> [13,]     0     0     0     0     0
#> [14,]     0     0     0     0     0
#> [15,]     0     0     0     0     0
#> [16,]     0     0     0     1     0
#> [17,]     0     0     0     0     0
#> [18,]     0     0     0     0     0
#> [19,]     0     0     0     0     0
#> [20,]     0     0     0     0     0
#> [21,]     0    -1     0     0    -1
#> [22,]     0    -1    -1    -1     0
#> [23,]     0     0     0    -1    -1
#> [24,]    -1    -1     0    -1     0
#> [25,]    -1     0    -1     0    -1
#> [26,]     4     0    -1    -1     0
#> [27,]     0     6    -1    -1    -1
#> [28,]    -1    -1     4     0     0
#> [29,]    -1    -1     0     7    -1
#> [30,]     0    -1     0    -1     5
laplacian_matrix_signed(g, norm = TRUE)
#>             [,1]       [,2]       [,3]       [,4]       [,5]       [,6]
#>  [1,]  1.0000000 -0.1889822 -0.2236068  0.0000000  0.0000000 -0.2500000
#>  [2,] -0.1889822  1.0000000 -0.1690309  0.0000000  0.0000000 -0.1889822
#>  [3,] -0.2236068 -0.1690309  1.0000000 -0.2236068  0.0000000  0.0000000
#>  [4,]  0.0000000  0.0000000 -0.2236068  1.0000000  0.0000000  0.0000000
#>  [5,]  0.0000000  0.0000000  0.0000000  0.0000000  1.0000000  0.0000000
#>  [6,] -0.2500000 -0.1889822  0.0000000  0.0000000  0.0000000  1.0000000
#>  [7,]  0.0000000 -0.2182179 -0.2581989  0.0000000  0.0000000  0.0000000
#>  [8,]  0.0000000 -0.1889822  0.0000000 -0.2500000 -0.3535534  0.0000000
#>  [9,]  0.0000000 -0.1889822 -0.2236068 -0.2500000  0.0000000  0.0000000
#> [10,] -0.1889822 -0.1428571  0.0000000 -0.1889822 -0.2672612 -0.1889822
#> [11,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.2041241
#> [12,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [13,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [14,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [15,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [16,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [17,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [18,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [19,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [20,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [21,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [22,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [23,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [24,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [25,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [26,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [27,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [28,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [29,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [30,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>             [,7]       [,8]       [,9]      [,10]      [,11]      [,12]
#>  [1,]  0.0000000  0.0000000  0.0000000 -0.1889822  0.0000000  0.0000000
#>  [2,] -0.2182179 -0.1889822 -0.1889822 -0.1428571  0.0000000  0.0000000
#>  [3,] -0.2581989  0.0000000 -0.2236068  0.0000000  0.0000000  0.0000000
#>  [4,]  0.0000000 -0.2500000 -0.2500000 -0.1889822  0.0000000  0.0000000
#>  [5,]  0.0000000 -0.3535534  0.0000000 -0.2672612  0.0000000  0.0000000
#>  [6,]  0.0000000  0.0000000  0.0000000 -0.1889822  0.2041241  0.0000000
#>  [7,]  1.0000000  0.0000000  0.0000000 -0.2182179  0.0000000  0.0000000
#>  [8,]  0.0000000  1.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [9,]  0.0000000  0.0000000  1.0000000 -0.1889822  0.0000000  0.0000000
#> [10,] -0.2182179  0.0000000 -0.1889822  1.0000000  0.0000000  0.0000000
#> [11,]  0.0000000  0.0000000  0.0000000  0.0000000  1.0000000  0.0000000
#> [12,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  1.0000000
#> [13,]  0.0000000  0.0000000  0.0000000  0.0000000 -0.2041241 -0.2500000
#> [14,]  0.0000000  0.0000000  0.0000000  0.0000000 -0.1666667  0.0000000
#> [15,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [16,]  0.0000000  0.0000000  0.0000000  0.0000000 -0.1543033 -0.1889822
#> [17,]  0.0000000  0.0000000  0.0000000  0.0000000 -0.2357023  0.0000000
#> [18,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [19,]  0.0000000  0.0000000  0.0000000  0.0000000 -0.1443376 -0.1767767
#> [20,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000 -0.2886751
#> [21,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [22,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [23,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [24,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [25,]  0.0000000  0.2236068  0.0000000  0.0000000  0.0000000  0.0000000
#> [26,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [27,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [28,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [29,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [30,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>            [,13]      [,14]      [,15]      [,16]      [,17]      [,18]
#>  [1,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [2,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [3,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [4,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [5,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [6,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [7,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [8,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [9,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [10,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [11,] -0.2041241 -0.1666667  0.0000000 -0.1543033 -0.2357023  0.0000000
#> [12,] -0.2500000  0.0000000  0.0000000 -0.1889822  0.0000000  0.0000000
#> [13,]  1.0000000  0.0000000 -0.2236068  0.0000000  0.0000000 -0.2041241
#> [14,]  0.0000000  1.0000000 -0.1825742 -0.1543033 -0.2357023 -0.1666667
#> [15,] -0.2236068 -0.1825742  1.0000000 -0.1690309  0.0000000 -0.1825742
#> [16,]  0.0000000 -0.1543033 -0.1690309  1.0000000  0.0000000 -0.1543033
#> [17,]  0.0000000 -0.2357023  0.0000000  0.0000000  1.0000000  0.0000000
#> [18,] -0.2041241 -0.1666667 -0.1825742 -0.1543033  0.0000000  1.0000000
#> [19,]  0.0000000 -0.1443376 -0.1581139 -0.1336306 -0.2041241 -0.1443376
#> [20,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000 -0.2357023
#> [21,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [22,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [23,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [24,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [25,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [26,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [27,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [28,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [29,]  0.0000000  0.0000000  0.0000000  0.1428571  0.0000000  0.0000000
#> [30,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>            [,19]      [,20]      [,21]      [,22]      [,23]      [,24]
#>  [1,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [2,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [3,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [4,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [5,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [6,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [7,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [8,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [9,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [10,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [11,] -0.1443376  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [12,] -0.1767767 -0.2886751  0.0000000  0.0000000  0.0000000  0.0000000
#> [13,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [14,] -0.1443376  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [15,] -0.1581139  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [16,] -0.1336306  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [17,] -0.2041241  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [18,] -0.1443376 -0.2357023  0.0000000  0.0000000  0.0000000  0.0000000
#> [19,]  1.0000000 -0.2041241  0.0000000  0.0000000  0.0000000  0.0000000
#> [20,] -0.2041241  1.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [21,]  0.0000000  0.0000000  1.0000000  0.0000000  0.0000000 -0.2886751
#> [22,]  0.0000000  0.0000000  0.0000000  1.0000000 -0.2581989  0.0000000
#> [23,]  0.0000000  0.0000000  0.0000000 -0.2581989  1.0000000  0.0000000
#> [24,]  0.0000000  0.0000000 -0.2886751  0.0000000  0.0000000  1.0000000
#> [25,]  0.0000000  0.0000000  0.0000000 -0.2000000  0.0000000  0.0000000
#> [26,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000 -0.2500000
#> [27,]  0.0000000  0.0000000 -0.2357023 -0.1825742  0.0000000 -0.2041241
#> [28,]  0.0000000  0.0000000  0.0000000 -0.2236068  0.0000000  0.0000000
#> [29,]  0.0000000  0.0000000  0.0000000 -0.1690309 -0.2182179 -0.1889822
#> [30,]  0.0000000  0.0000000 -0.2581989  0.0000000 -0.2581989  0.0000000
#>            [,25]      [,26]      [,27]      [,28]      [,29]      [,30]
#>  [1,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [2,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [3,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [4,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [5,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [6,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [7,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [8,]  0.2236068  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [9,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [10,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [11,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [12,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [13,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [14,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [15,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [16,]  0.0000000  0.0000000  0.0000000  0.0000000  0.1428571  0.0000000
#> [17,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [18,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [19,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [20,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [21,]  0.0000000  0.0000000 -0.2357023  0.0000000  0.0000000 -0.2581989
#> [22,] -0.2000000  0.0000000 -0.1825742 -0.2236068 -0.1690309  0.0000000
#> [23,]  0.0000000  0.0000000  0.0000000  0.0000000 -0.2182179 -0.2581989
#> [24,]  0.0000000 -0.2500000 -0.2041241  0.0000000 -0.1889822  0.0000000
#> [25,]  1.0000000 -0.2236068  0.0000000 -0.2236068  0.0000000 -0.2000000
#> [26,] -0.2236068  1.0000000  0.0000000 -0.2500000 -0.1889822  0.0000000
#> [27,]  0.0000000  0.0000000  1.0000000 -0.2041241 -0.1543033 -0.1825742
#> [28,] -0.2236068 -0.2500000 -0.2041241  1.0000000  0.0000000  0.0000000
#> [29,]  0.0000000 -0.1889822 -0.1543033  0.0000000  1.0000000 -0.1690309
#> [30,] -0.2000000  0.0000000 -0.1825742  0.0000000 -0.1690309  1.0000000