ExpectedCommunities {fake} | R Documentation |
Expected community structure
Description
Computes expected metrics related to the community structure of a graph simulated with given parameters.
Usage
ExpectedCommunities(pk, nu_within = 0.1, nu_between = 0, nu_mat = NULL)
Arguments
pk |
vector of the number of variables per group in the simulated
dataset. The number of nodes in the simulated graph is |
nu_within |
probability of having an edge between two nodes belonging to
the same group, as defined in |
nu_between |
probability of having an edge between two nodes belonging
to different groups, as defined in |
nu_mat |
matrix of probabilities of having an edge between nodes
belonging to a given pair of node groups defined in |
Details
Given a group of nodes, the within degree d^w_i
of node
i
is defined as the number of nodes from the same group node i
is connected to. The between degree d^b_i
is the number of nodes from
other groups node i
is connected to. A weak community in the network
is defined as a group of nodes for which the total within degree (sum of
the d^w_i
for all nodes in the community) is stricly greater than the
total between degree (sum of d^b_i
for all nodes in the community).
For more details, see
Network Science by
Albert-Laszlo Barabasi.
The expected total within and between degrees for the groups defined in
pk
in a network simulated using SimulateAdjacency
can be
computed given the group sizes (stored in pk
) and probabilities of
having an edge between nodes from a given group pair (defined by
nu_within
and nu_between
or by nu_mat
). The expected
presence of weak communities can be inferred from these quantities.
The expected modularity, measuring the difference between observed and
expected number of within-community edges, is also returned. For more
details on this metric, see modularity
.
Value
A list with:
total_within_degree_c |
total within degree by node group, i.e. sum of expected within degree over all nodes in a given group. |
total_between_degree |
total between degree by node group, i.e. sum of expected between degree over all nodes in a given group. |
weak_community |
binary indicator for a given node group to be an expected weak community. |
total_number_edges_c |
matrix of expected number of edges between nodes from a given node pair. |
modularity |
expected modularity (see
|
See Also
SimulateGraphical
, SimulateAdjacency
,
MinWithinProba
Examples
# Simulation parameters
pk <- rep(20, 4)
nu_within <- 0.8
nu_between <- 0.1
# Expected metrics
expected <- ExpectedCommunities(
pk = pk,
nu_within = nu_within,
nu_between = nu_between
)
# Example of simulated graph
set.seed(1)
theta <- SimulateAdjacency(
pk = pk,
nu_within = nu_within,
nu_between = nu_between
)
# Comparing observed and expected numbers of edges
bigblocks <- BlockMatrix(pk)
BlockStructure(pk)
sum(theta[which(bigblocks == 2)]) / 2
expected$total_number_edges_c[1, 2]
# Comparing observed and expected modularity
igraph::modularity(igraph::graph_from_adjacency_matrix(theta, mode = "undirected"),
membership = rep.int(1:length(pk), times = pk)
)
expected$modularity