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.

## Details

Please see the reference given below.

## 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

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