Function for plotting the frequency distribution of community sizes from clique percolation community detection and testing for power-law.
1 2 3 4 5
List object taken from results of cpAlgorithm function; see also cpAlgorithm
string indicating the color of the line in the plot as described
in par; default is
Logical indicating whether fit of power-law should be tested; default is FALSE; see Details
The function takes the results of cpAlgorithm (see also cpAlgorithm),
that is, either the
list.of.communities.numbers or the
list.of.communities.labels and plots the community size distribution. If there
are no communities, no plot can be generated. An error is printed indicating this.
test.power.law = TRUE, test of a fit of a power-law is performed with the
function fit_power_law (see also fit_power_law). Fit is tested for
the entire distribution from the smallest community size onward (i.e., typically k
as specified in cpAlgorithm). Moreover, test uses the
plfit implementation of
fit_power_law. For other arguments, default values are used.
The function primarily plots the community size distribution. Additionally, it returns
a list with a data frame containing all community sizes and their frequencies
test.power.law = TRUE, a test of fit of a power-law
distribution is also returned as a list object with results from fit_power_law (see
Jens Lange, email@example.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
## Example with fictitious data # create qgraph object; 150 nodes; 1/7 of all edges are different from zero W <- matrix(c(0), nrow = 150, ncol = 150, byrow = TRUE) set.seed(4186) W[upper.tri(W)] <- sample(c(rep(0,6),1), length(W[upper.tri(W)]), replace = TRUE) rand_w <- stats::rnorm(length(which(W == 1)), mean = 0.3, sd = 0.1) W[which(W == 1)] <- rand_w W <- Matrix::forceSymmetric(W) W <- qgraph::qgraph(W, DoNotPlot = TRUE) # run clique percolation for weighted networks cp.results <- cpAlgorithm(W, k = 3, method = "weighted", I = 0.38) # plot community size distribution with blue line cp.size.dist <- cpCommunitySizeDistribution(cp.results$list.of.communities.numbers, color.line = "#0000ff") # test for power-law distribution cp.size.dist <- cpCommunitySizeDistribution(cp.results$list.of.communities.numbers, color.line = "#0000ff", test.power.law = TRUE) cp.size.dist$fit.power.law ## Example with Obama data set (see ?Obama) # get data data(Obama) # estimate network net <- qgraph::EBICglasso(qgraph::cor_auto(Obama), n = nrow(Obama)) # run clique percolation algorithm with specific k and I cpk3I.16 <- cpAlgorithm(net, k = 3, I = 0.16, method = "weighted") # plot community size distribution #the distribution is not very informative with four equally-sized communities Obama.size.dist <- cpCommunitySizeDistribution(cpk3I.16$list.of.communities.numbers)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.