Generate a new random graph from a given graph by randomly adding/removing edges
Source:R/games.R
sample_correlated_gnp.Rd
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 Erdős-Rényi graph and you know the original edge probability of the Erdős-Rényi 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.
References
Lyzinski, V., Fishkind, D. E., Priebe, C. E. (2013). Seeded graph matching for correlated Erdős-Rényi graphs. https://arxiv.org/abs/1304.7844
See also
Random graph models (games)
erdos.renyi.game()
,
sample_()
,
sample_bipartite()
,
sample_chung_lu()
,
sample_correlated_gnp_pair()
,
sample_degseq()
,
sample_dot_product()
,
sample_fitness()
,
sample_fitness_pl()
,
sample_forestfire()
,
sample_gnm()
,
sample_gnp()
,
sample_grg()
,
sample_growing()
,
sample_hierarchical_sbm()
,
sample_islands()
,
sample_k_regular()
,
sample_last_cit()
,
sample_pa()
,
sample_pa_age()
,
sample_pref()
,
sample_sbm()
,
sample_smallworld()
,
sample_traits_callaway()
,
sample_tree()
Examples
g <- sample_gnp(1000, .1)
g2 <- sample_correlated_gnp(g, corr = 0.5)
cor(as.vector(g[]), as.vector(g2[]))
#> [1] 0.499866
g
#> IGRAPH d22f594 U--- 1000 49982 -- Erdos-Renyi (gnp) graph
#> + attr: name (g/c), type (g/c), loops (g/l), p (g/n)
#> + edges from d22f594:
#> [1] 1-- 5 7--10 8--10 8--11 11--14 13--15 10--16 11--16 7--19 10--19
#> [11] 16--19 4--20 5--22 6--23 16--23 22--23 2--24 18--24 9--25 16--25
#> [21] 21--25 24--25 4--26 24--26 13--27 17--27 23--27 14--28 18--28 21--28
#> [31] 1--29 7--30 19--30 3--31 21--31 1--32 18--32 21--32 12--33 13--33
#> [41] 28--33 9--34 20--34 25--34 7--35 8--35 26--35 28--35 29--35 33--35
#> [51] 1--36 13--36 28--36 29--36 28--37 34--37 15--38 31--38 37--38 9--39
#> [61] 13--39 22--39 32--39 1--40 8--40 2--41 8--41 12--41 15--41 19--41
#> [71] 13--42 26--42 33--42 19--43 25--43 33--43 7--44 15--44 16--44 21--44
#> + ... omitted several edges
g2
#> IGRAPH d5efd3a U--- 1000 49602 -- Correlated random graph
#> + attr: name (g/c), corr (g/n), p (g/n)
#> + edges from d5efd3a:
#> [1] 1-- 2 8--10 5--11 8--11 5--12 10--12 8--15 13--15 2--16 10--16
#> [11] 11--16 17--19 5--20 5--22 19--22 6--23 16--23 19--23 22--23 2--24
#> [21] 18--24 19--24 9--25 12--25 24--25 23--26 24--26 23--27 4--28 14--28
#> [31] 18--28 21--28 1--29 11--29 3--30 7--30 19--30 9--31 21--31 4--32
#> [41] 18--32 21--32 6--33 12--33 13--33 16--33 4--35 7--35 8--35 10--35
#> [51] 20--35 26--35 29--35 33--35 8--36 18--36 22--36 28--36 29--36 2--37
#> [61] 25--37 28--37 31--37 7--38 15--38 26--38 31--38 37--38 9--39 13--39
#> [71] 22--39 29--39 1--40 17--40 22--40 29--40 2--41 9--42 13--42 33--42
#> + ... omitted several edges