
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)
bipartite_gnm()
,
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.5006405
g
#> IGRAPH adf1477 U--- 1000 49982 -- Erdos-Renyi (gnp) graph
#> + attr: name (g/c), type (g/c), loops (g/l), p (g/n)
#> + edges from adf1477:
#> [1] 1-- 3 2-- 3 4-- 7 2-- 9 5--10 9--10 1--11 6--12 7--12 9--12
#> [11] 2--13 8--13 12--13 3--14 4--14 5--15 7--16 3--17 4--17 12--17
#> [21] 17--18 9--19 1--20 3--20 5--21 16--21 9--22 19--22 6--23 7--23
#> [31] 11--23 18--23 20--23 14--24 15--24 16--25 18--25 23--25 11--26 15--26
#> [41] 15--27 2--28 8--28 11--28 12--28 6--29 15--29 28--29 1--30 11--30
#> [51] 24--30 26--30 4--31 5--31 14--31 3--32 15--32 25--32 3--33 7--33
#> [61] 14--33 29--33 11--34 11--35 14--35 25--35 34--35 13--36 18--36 19--36
#> [71] 23--36 25--36 27--36 28--36 30--36 4--37 37--38 9--39 11--39 15--39
#> + ... omitted several edges
g2
#> IGRAPH 7b4e010 U--- 1000 49666 -- Correlated random graph
#> + attr: name (g/c), corr (g/n), p (g/n)
#> + edges from 7b4e010:
#> [1] 4-- 7 5--10 5--12 9--12 8--13 12--13 3--14 5--15 1--16 7--16
#> [11] 3--17 4--17 8--17 12--17 13--18 14--18 17--18 4--19 1--20 3--20
#> [21] 2--21 5--21 18--22 2--23 18--23 20--23 8--24 7--25 16--25 18--25
#> [31] 3--26 11--26 15--26 18--26 19--27 8--28 11--28 12--28 21--28 15--29
#> [41] 26--29 28--29 1--30 10--30 2--31 4--31 24--31 26--31 8--32 15--32
#> [51] 18--32 3--33 6--33 7--33 15--33 17--33 29--33 11--34 11--35 19--35
#> [61] 25--35 27--35 13--36 23--36 25--36 27--36 28--36 34--36 4--37 29--37
#> [71] 1--38 10--38 19--38 9--39 15--39 11--40 13--40 28--40 30--40 5--41
#> + ... omitted several edges