EVOLUTION-MANAGER
Edit File: cohesive_blocks.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Calculate Cohesive Blocks</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for cohesive_blocks {igraph}"><tr><td>cohesive_blocks {igraph}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Calculate Cohesive Blocks</h2> <h3>Description</h3> <p>Calculates cohesive blocks for objects of class <code>igraph</code>. </p> <h3>Usage</h3> <pre> cohesive_blocks(graph, labels = TRUE) ## S3 method for class 'cohesiveBlocks' length(x) blocks(blocks) graphs_from_cohesive_blocks(blocks, graph) ## S3 method for class 'cohesiveBlocks' cohesion(x, ...) hierarchy(blocks) parent(blocks) ## S3 method for class 'cohesiveBlocks' print(x, ...) ## S3 method for class 'cohesiveBlocks' summary(object, ...) ## S3 method for class 'cohesiveBlocks' plot( x, y, colbar = rainbow(max(cohesion(x)) + 1), col = colbar[max_cohesion(x) + 1], mark.groups = blocks(x)[-1], ... ) plot_hierarchy( blocks, layout = layout_as_tree(hierarchy(blocks), root = 1), ... ) export_pajek(blocks, graph, file, project.file = TRUE) max_cohesion(blocks) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>graph</code></td> <td> <p>For <code>cohesive_blocks</code> a graph object of class <code>igraph</code>. It must be undirected and simple. (See <code><a href="simplify.html">is_simple</a></code>.) </p> <p>For <code>graphs_from_cohesive_blocks</code> and <code>export_pajek</code> the same graph must be supplied whose cohesive block structure is given in the <code>blocks</code> argument.</p> </td></tr> <tr valign="top"><td><code>labels</code></td> <td> <p>Logical scalar, whether to add the vertex labels to the result object. These labels can be then used when reporting and plotting the cohesive blocks.</p> </td></tr> <tr valign="top"><td><code>blocks, x, object</code></td> <td> <p>A <code>cohesiveBlocks</code> object, created with the <code>cohesive_blocks</code> function.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Additional arguments. <code>plot_hierarchy</code> and <code>plot</code> pass them to <code>plot.igraph</code>. <code>print</code> and <code>summary</code> ignore them.</p> </td></tr> <tr valign="top"><td><code>y</code></td> <td> <p>The graph whose cohesive blocks are supplied in the <code>x</code> argument.</p> </td></tr> <tr valign="top"><td><code>colbar</code></td> <td> <p>Color bar for the vertex colors. Its length should be at least <i>m+1</i>, where <i>m</i> is the maximum cohesion in the graph. Alternatively, the vertex colors can also be directly specified via the <code>col</code> argument.</p> </td></tr> <tr valign="top"><td><code>col</code></td> <td> <p>A vector of vertex colors, in any of the usual formats. (Symbolic color names (e.g. ‘red’, ‘blue’, etc.) , RGB colors (e.g. ‘#FF9900FF’), integer numbers referring to the current palette. By default the given <code>colbar</code> is used and vertices with the same maximal cohesion will have the same color.</p> </td></tr> <tr valign="top"><td><code>mark.groups</code></td> <td> <p>A list of vertex sets to mark on the plot by circling them. By default all cohesive blocks are marked, except the one corresponding to the all vertices.</p> </td></tr> <tr valign="top"><td><code>layout</code></td> <td> <p>The layout of a plot, it is simply passed on to <code>plot.igraph</code>, see the possible formats there. By default the Reingold-Tilford layout generator is used.</p> </td></tr> <tr valign="top"><td><code>file</code></td> <td> <p>Defines the file (or connection) the Pajek file is written to. </p> <p>If the <code>project.file</code> argument is <code>TRUE</code>, then it can be a filename (with extension), a file object, or in general any king of connection object. The file/connection will be opened if it wasn't already. </p> <p>If the <code>project.file</code> argument is <code>FALSE</code>, then several files are created and <code>file</code> must be a character scalar containing the base name of the files, without extension. (But it can contain the path to the files.) </p> <p>See also details below.</p> </td></tr> <tr valign="top"><td><code>project.file</code></td> <td> <p>Logical scalar, whether to create a single Pajek project file containing all the data, or to create separated files for each item. See details below.</p> </td></tr> </table> <h3>Details</h3> <p>Cohesive blocking is a method of determining hierarchical subsets of graph vertices based on their structural cohesion (or vertex connectivity). For a given graph <i>G</i>, a subset of its vertices <i>S</i> is said to be maximally <i>k</i>-cohesive if there is no superset of <i>S</i> with vertex connectivity greater than or equal to <i>k</i>. Cohesive blocking is a process through which, given a <i>k</i>-cohesive set of vertices, maximally <i>l</i>-cohesive subsets are recursively identified with <i>l>k</i>. Thus a hierarchy of vertex subsets is found, with the entire graph <i>G</i> at its root. </p> <p>The function <code>cohesive_blocks</code> implements cohesive blocking. It returns a <code>cohesiveBlocks</code> object. <code>cohesiveBlocks</code> should be handled as an opaque class, i.e. its internal structure should not be accessed directly, but through the functions listed here. </p> <p>The function <code>length</code> can be used on <code>cohesiveBlocks</code> objects and it gives the number of blocks. </p> <p>The function <code>blocks</code> returns the actual blocks stored in the <code>cohesiveBlocks</code> object. They are returned in a list of numeric vectors, each containing vertex ids. </p> <p>The function <code>graphs_from_cohesive_blocks</code> is similar, but returns the blocks as (induced) subgraphs of the input graph. The various (graph, vertex and edge) attributes are kept in the subgraph. </p> <p>The function <code>cohesion</code> returns a numeric vector, the cohesion of the different blocks. The order of the blocks is the same as for the <code>blocks</code> and <code>graphs_from_cohesive_blocks</code> functions. </p> <p>The block hierarchy can be queried using the <code>hierarchy</code> function. It returns an igraph graph, its vertex ids are ordered according the order of the blocks in the <code>blocks</code> and <code>graphs_from_cohesive_blocks</code>, <code>cohesion</code>, etc. functions. </p> <p><code>parent</code> gives the parent vertex of each block, in the block hierarchy, for the root vertex it gives 0. </p> <p><code>plot_hierarchy</code> plots the hierarchy tree of the cohesive blocks on the active graphics device, by calling <code>igraph.plot</code>. </p> <p>The <code>export_pajek</code> function can be used to export the graph and its cohesive blocks in Pajek format. It can either export a single Pajek project file with all the information, or a set of files, depending on its <code>project.file</code> argument. If <code>project.file</code> is <code>TRUE</code>, then the following information is written to the file (or connection) given in the <code>file</code> argument: (1) the input graph, together with its attributes, see <code><a href="write_graph.html">write_graph</a></code> for details; (2) the hierarchy graph; and (3) one binary partition for each cohesive block. If <code>project.file</code> is <code>FALSE</code>, then the <code>file</code> argument must be a character scalar and it is used as the base name for the generated files. If <code>file</code> is ‘basename’, then the following files are created: (1) ‘basename.net’ for the original graph; (2) ‘basename_hierarchy.net’ for the hierarchy graph; (3) ‘basename_block_x.net’ for each cohesive block, where ‘x’ is the number of the block, starting with one. </p> <p><code>max_cohesion</code> returns the maximal cohesion of each vertex, i.e. the cohesion of the most cohesive block of the vertex. </p> <p>The generic function <code>summary</code> works on <code>cohesiveBlocks</code> objects and it prints a one line summary to the terminal. </p> <p>The generic function <code>print</code> is also defined on <code>cohesiveBlocks</code> objects and it is invoked automatically if the name of the <code>cohesiveBlocks</code> object is typed in. It produces an output like this: </p> <pre> Cohesive block structure: B-1 c 1, n 23 '- B-2 c 2, n 14 oooooooo.. .o......oo ooo '- B-4 c 5, n 7 ooooooo... .......... ... '- B-3 c 2, n 10 ......o.oo o.oooooo.. ... '- B-5 c 3, n 4 ......o.oo o......... ... </pre> <p>The left part shows the block structure, in this case for five blocks. The first block always corresponds to the whole graph, even if its cohesion is zero. Then cohesion of the block and the number of vertices in the block are shown. The last part is only printed if the display is wide enough and shows the vertices in the blocks, ordered by vertex ids. ‘o’ means that the vertex is included, a dot means that it is not, and the vertices are shown in groups of ten. </p> <p>The generic function <code>plot</code> plots the graph, showing one or more cohesive blocks in it. </p> <h3>Value</h3> <p><code>cohesive_blocks</code> returns a <code>cohesiveBlocks</code> object. </p> <p><code>blocks</code> returns a list of numeric vectors, containing vertex ids. </p> <p><code>graphs_from_cohesive_blocks</code> returns a list of igraph graphs, corresponding to the cohesive blocks. </p> <p><code>cohesion</code> returns a numeric vector, the cohesion of each block. </p> <p><code>hierarchy</code> returns an igraph graph, the representation of the cohesive block hierarchy. </p> <p><code>parent</code> returns a numeric vector giving the parent block of each cohesive block, in the block hierarchy. The block at the root of the hierarchy has no parent and <code>0</code> is returned for it. </p> <p><code>plot_hierarchy</code>, <code>plot</code> and <code>export_pajek</code> return <code>NULL</code>, invisibly. </p> <p><code>max_cohesion</code> returns a numeric vector with one entry for each vertex, giving the cohesion of its most cohesive block. </p> <p><code>print</code> and <code>summary</code> return the <code>cohesiveBlocks</code> object itself, invisibly. </p> <p><code>length</code> returns a numeric scalar, the number of blocks. </p> <h3>Author(s)</h3> <p>Gabor Csardi <a href="mailto:csardi.gabor@gmail.com">csardi.gabor@gmail.com</a> for the current implementation, Peter McMahan (<a href="https://socialsciences.uchicago.edu/news/alumni-profile-peter-mcmahan-phd17-sociology">https://socialsciences.uchicago.edu/news/alumni-profile-peter-mcmahan-phd17-sociology</a>) wrote the first version in R. </p> <h3>References</h3> <p>J. Moody and D. R. White. Structural cohesion and embeddedness: A hierarchical concept of social groups. <em>American Sociological Review</em>, 68(1):103–127, Feb 2003. </p> <h3>See Also</h3> <p><code><a href="vertex_connectivity.html">cohesion</a></code> </p> <h3>Examples</h3> <pre> ## The graph from the Moody-White paper mw <- graph_from_literal(1-2:3:4:5:6, 2-3:4:5:7, 3-4:6:7, 4-5:6:7, 5-6:7:21, 6-7, 7-8:11:14:19, 8-9:11:14, 9-10, 10-12:13, 11-12:14, 12-16, 13-16, 14-15, 15-16, 17-18:19:20, 18-20:21, 19-20:22:23, 20-21, 21-22:23, 22-23) mwBlocks <- cohesive_blocks(mw) # Inspect block membership and cohesion mwBlocks blocks(mwBlocks) cohesion(mwBlocks) # Save results in a Pajek file ## Not run: export_pajek(mwBlocks, mw, file="/tmp/mwBlocks.paj") ## End(Not run) # Plot the results plot(mwBlocks, mw) ## The science camp network camp <- graph_from_literal(Harry:Steve:Don:Bert - Harry:Steve:Don:Bert, Pam:Brazey:Carol:Pat - Pam:Brazey:Carol:Pat, Holly - Carol:Pat:Pam:Jennie:Bill, Bill - Pauline:Michael:Lee:Holly, Pauline - Bill:Jennie:Ann, Jennie - Holly:Michael:Lee:Ann:Pauline, Michael - Bill:Jennie:Ann:Lee:John, Ann - Michael:Jennie:Pauline, Lee - Michael:Bill:Jennie, Gery - Pat:Steve:Russ:John, Russ - Steve:Bert:Gery:John, John - Gery:Russ:Michael) campBlocks <- cohesive_blocks(camp) campBlocks plot(campBlocks, camp, vertex.label=V(camp)$name, margin=-0.2, vertex.shape="rectangle", vertex.size=24, vertex.size2=8, mark.border=1, colbar=c(NA, NA,"cyan","orange") ) </pre> <hr /><div style="text-align: center;">[Package <em>igraph</em> version 1.3.5 <a href="00Index.html">Index</a>]</div> </body></html>