Skip to contents

Sample a new graph by perturbing the adjacency matrix of a given graph and shuffling its vertices.

Usage

sample_correlated_gnp(
  old.graph,
  corr,
  p = edge_density(old.graph),
  permutation = NULL
)

Arguments

old.graph

The original graph.

corr

A scalar in the unit interval, the target Pearson correlation between the adjacency matrices of the original and the generated graph (the adjacency matrix being used as a vector).

p

A numeric scalar, the probability of an edge between two vertices, it must in the open (0,1) interval. The default is the empirical edge density of the graph. If you are resampling an Erdos-Renyi graph and you know the original edge probability of the Erdos-Renyi model, you should supply that explicitly.

permutation

A numeric vector, a permutation vector that is applied on the vertices of the first graph, to get the second graph. If NULL, the vertices are not permuted.

Value

An unweighted graph of the same size as old.graph such that the correlation coefficient between the entries of the two adjacency matrices is corr. Note each pair of corresponding matrix entries is a pair of correlated Bernoulli random variables.

Details

Please see the reference given below.

References

Lyzinski, V., Fishkind, D. E., Priebe, C. E. (2013). Seeded graph matching for correlated Erdos-Renyi graphs. https://arxiv.org/abs/1304.7844

Examples

g <- sample_gnp(1000, .1)
g2 <- sample_correlated_gnp(g, corr = 0.5)
cor(as.vector(g[]), as.vector(g2[]))
#> [1] 0.4998541
g
#> IGRAPH 8dd5b5b U--- 1000 49966 -- Erdos-Renyi (gnp) graph
#> + attr: name (g/c), type (g/c), loops (g/l), p (g/n)
#> + edges from 8dd5b5b:
#>  [1]  1-- 2  2-- 3  4-- 7  2-- 8  4-- 8  4-- 9  2--10  5--10  4--11  7--11
#> [11]  2--12 11--13  2--14  2--15  4--15  6--15 11--15 12--16 16--17  3--18
#> [21]  9--18 11--19 19--20  2--21  1--22  6--22 12--24 15--24  1--25 14--26
#> [31]  6--27  5--28 19--28  5--29 15--29 19--29 23--29  2--30  3--30  1--31
#> [41]  2--31 27--31  1--32 14--32 28--32 15--33  9--34 16--34 32--34  7--35
#> [51] 12--35 21--35 32--35 12--36 13--36 19--36 23--36 26--36 29--36  7--37
#> [61] 28--37 33--37 13--38 19--38 24--39 28--39 29--39 31--39 14--40 15--40
#> [71] 16--40 37--40 12--41 39--41  2--42  6--42 25--42 27--42 35--42  4--43
#> + ... omitted several edges
g2
#> IGRAPH 5112617 U--- 1000 49613 -- Correlated random graph
#> + attr: name (g/c), corr (g/n), p (g/n)
#> + edges from 5112617:
#>  [1]  2-- 3  2-- 4  4-- 5  4-- 6  4-- 7  1-- 8  4-- 8  2--10  5--10  7--11
#> [11] 10--13  2--14  4--14  9--14 11--15  7--16  9--16 12--16  9--18  6--19
#> [21] 11--19 17--19 19--20  2--21  3--21 10--21  1--22  6--22  8--23 16--23
#> [31] 12--24 15--24 16--24  1--25 11--25 14--26  6--27  8--28 18--28 19--28
#> [41]  5--29 10--29 19--29 24--29 27--29  2--30  5--30 11--30  2--31 10--31
#> [51]  1--32 14--32 21--32 29--32 15--33 17--33  2--34  3--34  9--34 16--34
#> [61] 29--34 32--34 12--35 24--35 32--35  2--36 12--36 19--36 22--36  5--37
#> [71] 28--38 24--39 24--40 37--40 12--41 39--41  6--42 19--42 25--42 27--42
#> + ... omitted several edges