The Laplacian of a signed graph.

## Usage

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.

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.

David Schoch

## Examples

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,]    2    0    0    0    0   -1    0    0   -1     0     0     0     0
#>  [2,]    0    2    0    0   -1    0    0   -1    0     0     0     0     0
#>  [3,]    0    0    3   -1   -1   -1    0    0    0     0     0     0     0
#>  [4,]    0    0   -1    4    0   -1    0    0   -1    -1     0     0     0
#>  [5,]    0   -1   -1    0    5    0   -1   -1    0    -1     0     0     0
#>  [6,]   -1    0   -1   -1    0    4    0   -1    0     0     0     0     0
#>  [7,]    0    0    0    0   -1    0    3   -1    0     0     0     0     0
#>  [8,]    0   -1    0    0   -1   -1   -1    4    0     0     0     0     0
#>  [9,]   -1    0    0   -1    0    0    0    0    3    -1     0     0     0
#> [10,]    0    0    0   -1   -1    0    0    0   -1     4     0     0     0
#> [11,]    0    0    0    0    0    0    0    0    0     0     2    -1     0
#> [12,]    0    0    0    0    0    0    0    0    0     0    -1     4     0
#> [13,]    0    0    0    0    0    0    0    0    0     0     0     0     5
#> [14,]    0    0    0    0    0    0    0    0    0     0     0     0    -1
#> [15,]    0    0    0    0    0    0    0    0    0     0     0    -1     0
#> [16,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [17,]    0    0    0    0    0    0    0    0    0     0     0     0    -1
#> [18,]    0    0    0    0    0    0    0    0    0     0     0    -1    -1
#> [19,]    0    0    0    0    0    0    0    0    0     0     0    -1    -1
#> [20,]    0    0    0    0    0    0    0    0    0     0    -1     0    -1
#> [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     1     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    0    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    1    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     0
#>  [9,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [10,]     0     0     0     0     0     0     0     0     0     1     0     0
#> [11,]     0     0     0     0     0     0    -1     0     0     0     0     0
#> [12,]     0    -1     0     0    -1    -1     0     0     0     0     0     0
#> [13,]    -1     0     0    -1    -1    -1    -1     0     0     0     0     0
#> [14,]     3     0    -1    -1     0     0     0     0     0     0     0     0
#> [15,]     0     3    -1     0     0    -1     0     0     0     0     0     0
#> [16,]    -1    -1     4     0    -1     0    -1     0     0     0     0     0
#> [17,]    -1     0     0     3     0    -1     0     0     0     0     0     0
#> [18,]     0     0    -1     0     4     0    -1     0     0     0     0     0
#> [19,]     0    -1     0    -1     0     6    -1     0     0     0     0     1
#> [20,]     0     0    -1     0    -1    -1     5     0     0     0     0     0
#> [21,]     0     0     0     0     0     0     0     3    -1    -1     0     0
#> [22,]     0     0     0     0     0     0     0    -1     7    -1    -1    -1
#> [23,]     0     0     0     0     0     0     0    -1    -1     8    -1     0
#> [24,]     0     0     0     0     0     0     0     0    -1    -1     4     0
#> [25,]     0     0     0     0     0     1     0     0    -1     0     0     5
#> [26,]     0     0     0     0     0     0     0     0     0     0     0    -1
#> [27,]     0     0     0     0     0     0     0     0    -1    -1    -1     0
#> [28,]     0     0     0     0     0     0     0    -1    -1    -1     0    -1
#> [29,]     0     0     0     0     0     0     0     0     0    -1    -1     0
#> [30,]     0     0     0     0     0     0     0     0    -1    -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     1
#>  [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     0     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     0    -1     0     0
#> [22,]     0    -1    -1     0    -1
#> [23,]     0    -1    -1    -1    -1
#> [24,]     0    -1     0    -1     0
#> [25,]    -1     0    -1     0    -1
#> [26,]     4     0    -1    -1    -1
#> [27,]     0     6    -1    -1    -1
#> [28,]    -1    -1     7    -1     0
#> [29,]    -1    -1    -1     6    -1
#> [30,]    -1    -1     0    -1     7
laplacian_matrix_signed(g, norm = TRUE)
#>             [,1]       [,2]       [,3]       [,4]       [,5]       [,6]
#>  [1,]  1.0000000  0.0000000  0.0000000  0.0000000  0.0000000 -0.3535534
#>  [2,]  0.0000000  1.0000000  0.0000000  0.0000000 -0.3162278  0.0000000
#>  [3,]  0.0000000  0.0000000  1.0000000 -0.2886751 -0.2581989 -0.2886751
#>  [4,]  0.0000000  0.0000000 -0.2886751  1.0000000  0.0000000 -0.2500000
#>  [5,]  0.0000000 -0.3162278 -0.2581989  0.0000000  1.0000000  0.0000000
#>  [6,] -0.3535534  0.0000000 -0.2886751 -0.2500000  0.0000000  1.0000000
#>  [7,]  0.0000000  0.0000000  0.0000000  0.0000000 -0.2581989  0.0000000
#>  [8,]  0.0000000 -0.3535534  0.0000000  0.0000000 -0.2236068 -0.2500000
#>  [9,] -0.4082483  0.0000000  0.0000000 -0.2886751  0.0000000  0.0000000
#> [10,]  0.0000000  0.0000000  0.0000000 -0.2500000 -0.2236068  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.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.4082483  0.0000000  0.0000000  0.0000000
#>  [2,]  0.0000000 -0.3535534  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.2886751 -0.2500000  0.0000000  0.0000000
#>  [5,] -0.2581989 -0.2236068  0.0000000 -0.2236068  0.0000000  0.0000000
#>  [6,]  0.0000000 -0.2500000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [7,]  1.0000000 -0.2886751  0.0000000  0.0000000  0.0000000  0.0000000
#>  [8,] -0.2886751  1.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#>  [9,]  0.0000000  0.0000000  1.0000000 -0.2886751  0.0000000  0.0000000
#> [10,]  0.0000000  0.0000000 -0.2886751  1.0000000  0.0000000  0.0000000
#> [11,]  0.0000000  0.0000000  0.0000000  0.0000000  1.0000000 -0.3535534
#> [12,]  0.0000000  0.0000000  0.0000000  0.0000000 -0.3535534  1.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.2886751
#> [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.2500000
#> [19,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000 -0.2041241
#> [20,]  0.0000000  0.0000000  0.0000000  0.0000000 -0.3162278  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.1767767  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.2182179  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.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [12,]  0.0000000  0.0000000 -0.2886751  0.0000000  0.0000000 -0.2500000
#> [13,]  1.0000000 -0.2581989  0.0000000  0.0000000 -0.2581989 -0.2236068
#> [14,] -0.2581989  1.0000000  0.0000000 -0.2886751 -0.3333333  0.0000000
#> [15,]  0.0000000  0.0000000  1.0000000 -0.2886751  0.0000000  0.0000000
#> [16,]  0.0000000 -0.2886751 -0.2886751  1.0000000  0.0000000 -0.2500000
#> [17,] -0.2581989 -0.3333333  0.0000000  0.0000000  1.0000000  0.0000000
#> [18,] -0.2236068  0.0000000  0.0000000 -0.2500000  0.0000000  1.0000000
#> [19,] -0.1825742  0.0000000 -0.2357023  0.0000000 -0.2357023  0.0000000
#> [20,] -0.2000000  0.0000000  0.0000000 -0.2236068  0.0000000 -0.2236068
#> [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
#>            [,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.1767767  0.0000000
#> [11,]  0.0000000 -0.3162278  0.0000000  0.0000000  0.0000000  0.0000000
#> [12,] -0.2041241  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [13,] -0.1825742 -0.2000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [14,]  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [15,] -0.2357023  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [16,]  0.0000000 -0.2236068  0.0000000  0.0000000  0.0000000  0.0000000
#> [17,] -0.2357023  0.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [18,]  0.0000000 -0.2236068  0.0000000  0.0000000  0.0000000  0.0000000
#> [19,]  1.0000000 -0.1825742  0.0000000  0.0000000  0.0000000  0.0000000
#> [20,] -0.1825742  1.0000000  0.0000000  0.0000000  0.0000000  0.0000000
#> [21,]  0.0000000  0.0000000  1.0000000 -0.2182179 -0.2041241  0.0000000
#> [22,]  0.0000000  0.0000000 -0.2182179  1.0000000 -0.1336306 -0.1889822
#> [23,]  0.0000000  0.0000000 -0.2041241 -0.1336306  1.0000000 -0.1767767
#> [24,]  0.0000000  0.0000000  0.0000000 -0.1889822 -0.1767767  1.0000000
#> [25,]  0.1825742  0.0000000  0.0000000 -0.1690309  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.1543033 -0.1443376 -0.2041241
#> [28,]  0.0000000  0.0000000 -0.2182179 -0.1428571 -0.1336306  0.0000000
#> [29,]  0.0000000  0.0000000  0.0000000  0.0000000 -0.1443376 -0.2041241
#> [30,]  0.0000000  0.0000000  0.0000000 -0.1428571 -0.1336306  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.2182179
#>  [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.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.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.1825742  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.2182179  0.0000000  0.0000000
#> [22,] -0.1690309  0.0000000 -0.1543033 -0.1428571  0.0000000 -0.1428571
#> [23,]  0.0000000  0.0000000 -0.1443376 -0.1336306 -0.1443376 -0.1336306
#> [24,]  0.0000000  0.0000000 -0.2041241  0.0000000 -0.2041241  0.0000000
#> [25,]  1.0000000 -0.2236068  0.0000000 -0.1690309  0.0000000 -0.1690309
#> [26,] -0.2236068  1.0000000  0.0000000 -0.1889822 -0.2041241 -0.1889822
#> [27,]  0.0000000  0.0000000  1.0000000 -0.1543033 -0.1666667 -0.1543033
#> [28,] -0.1690309 -0.1889822 -0.1543033  1.0000000 -0.1543033  0.0000000
#> [29,]  0.0000000 -0.2041241 -0.1666667 -0.1543033  1.0000000 -0.1543033
#> [30,] -0.1690309 -0.1889822 -0.1543033  0.0000000 -0.1543033  1.0000000