Generate a network with pre-specified dyad census
number of vertices in the graph.
if method == "probability"
, the probability of obtaining a
mutual dyad; otherwise, the number of mutual dyads.
if method == "probability"
, the probability of obtaining an
asymmetric dyad; otherwise, the number of asymmmetric dyads.
if method == "probability"
, the probability of obtaining a
null dyad; otherwise, the number of null dyads.
either "probability"
or "exact"
, see details
output class, either "igraph"
, "network"
,
"matrix"
, or "edgelist"
a graph with the desired MAN property
Two approaches are offered, the exact
method and the probability
method.
When method == "probability"
, the graph is generated based on
independent draws from a multinomial distribution. This will rarely yield a
graph with these exact probabilities, but large graphs will get quite close.
When values are passed to this function that do not add up to 1, they will be
rescaled to do so (and a message is printed to the console).
When method == "exact"
, the graph is generated with this exact MAN
count, as long as they add up to the actualnumber of edges in the graph.
This function largely builds on the rguman
function.
The main difference is that we allow multiple classes of output and generate
only a single conditioned graph. When a large number of MAN-conditioned
graphs are to be generated, rguman
is potentially more
efficient.
create_census_graph(10, mut = 45, asym = 0, null = 0, method = "exact")
#> IGRAPH c77a748 U--- 10 45 --
#> + edges from c77a748:
#> [1] 1-- 2 1-- 3 1-- 4 1-- 5 1-- 6 1-- 7 1-- 8 1-- 9 1--10 2-- 3 2-- 4 2-- 5
#> [13] 2-- 6 2-- 7 2-- 8 2-- 9 2--10 3-- 4 3-- 5 3-- 6 3-- 7 3-- 8 3-- 9 3--10
#> [25] 4-- 5 4-- 6 4-- 7 4-- 8 4-- 9 4--10 5-- 6 5-- 7 5-- 8 5-- 9 5--10 6-- 7
#> [37] 6-- 8 6-- 9 6--10 7-- 8 7-- 9 7--10 8-- 9 8--10 9--10
# empty graph
create_census_graph(10, mut = 0, asym = 0, null = 45, method = "exact")
#> IGRAPH c77c039 U--- 10 0 --
#> + edges from c77c039:
create_census_graph(10, mut = 0, asym = 0, null = 45, method = "probability")
#> Probabilities did not add to 1, they have been rescaled
#> IGRAPH c77cb19 U--- 10 0 --
#> + edges from c77cb19:
create_census_graph(10, mut = 0, asym = 0, null = 1, method = "probability")
#> IGRAPH c77d9da U--- 10 0 --
#> + edges from c77d9da:
create_census_graph(10, mut = 0, asym = 45, null = 0, method = "exact") |>
snafun::count_dyads()
#> Mutual Asymmetric Null
#> 0 45 0
# will be rescaled
create_census_graph(10, mut = 0, asym = 45, null = 0, method = "probability") |>
snafun::count_dyads()
#> Probabilities did not add to 1, they have been rescaled
#> Mutual Asymmetric Null
#> 0 45 0
create_census_graph(10, mut = 0, asym = 1, null = 0, method = "probability") |>
snafun::count_dyads()
#> Mutual Asymmetric Null
#> 0 45 0
create_census_graph(10, mut = .25, asym = .30, null = .45, method = "probability") |>
snafun::count_dyads()
#> Mutual Asymmetric Null
#> 15 14 16
create_census_graph(10, method = "probability", graph = "igraph")
#> IGRAPH c78252d D--- 10 42 --
#> + edges from c78252d:
#> [1] 1-> 2 1-> 3 1-> 4 1-> 7 1-> 9 2-> 3 2-> 6 2-> 7 2-> 8 2->10
#> [11] 3-> 2 3-> 8 4-> 1 4-> 5 4->10 5-> 2 5-> 4 5-> 6 5-> 7 5-> 9
#> [21] 6-> 1 6-> 2 6-> 4 6-> 5 6-> 8 6->10 7-> 1 7-> 3 7-> 9 7->10
#> [31] 8-> 2 8-> 3 8-> 4 8-> 7 9-> 2 9-> 4 9-> 8 10-> 2 10-> 4 10-> 5
#> [41] 10-> 8 10-> 9
create_census_graph(10, method = "probability", graph = "network")
#> Network attributes:
#> vertices = 10
#> directed = TRUE
#> hyper = FALSE
#> loops = FALSE
#> multiple = FALSE
#> bipartite = FALSE
#> total edges= 46
#> missing edges= 0
#> non-missing edges= 46
#>
#> Vertex attribute names:
#> vertex.names
#>
#> No edge attributes
create_census_graph(10, method = "probability", graph = "edgelist")
#> from to
#> 1 1 3
#> 2 1 4
#> 3 1 9
#> 4 2 1
#> 5 2 3
#> 6 2 4
#> 7 2 5
#> 8 2 8
#> 9 2 9
#> 10 3 1
#> 11 3 2
#> 12 3 4
#> 13 3 5
#> 14 3 6
#> 15 3 7
#> 16 3 9
#> 17 3 10
#> 18 4 2
#> 19 4 3
#> 20 4 7
#> 21 4 8
#> 22 5 2
#> 23 5 3
#> 24 5 7
#> 25 5 8
#> 26 5 9
#> 27 5 10
#> 28 6 1
#> 29 6 2
#> 30 6 3
#> 31 6 5
#> 32 6 7
#> 33 6 8
#> 34 6 9
#> 35 7 1
#> 36 7 2
#> 37 7 3
#> 38 7 4
#> 39 7 5
#> 40 7 8
#> 41 7 10
#> 42 8 1
#> 43 8 5
#> 44 8 7
#> 45 9 1
#> 46 9 2
#> 47 9 4
#> 48 9 6
#> 49 9 7
#> 50 9 8
#> 51 10 5
#> 52 10 7
#> 53 10 9
create_census_graph(10, method = "probability", graph = "matrix")
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> [1,] 0 0 0 0 1 1 1 1 1 0
#> [2,] 1 0 0 0 0 1 0 0 0 1
#> [3,] 1 1 0 0 0 1 1 0 1 1
#> [4,] 1 1 1 0 1 0 0 1 1 1
#> [5,] 0 1 1 0 0 1 1 1 0 1
#> [6,] 1 0 0 1 0 0 0 1 0 0
#> [7,] 0 0 0 0 1 0 0 0 0 1
#> [8,] 1 0 1 0 1 1 0 0 0 0
#> [9,] 0 0 0 0 0 0 1 1 0 0
#> [10,] 0 1 1 1 1 1 1 1 0 0