Dynamic Path Diagrams

Total Page:16

File Type:pdf, Size:1020Kb

Dynamic Path Diagrams Dynamic Path Diagrams E. F. Haghish Center for Medical Biometry and Medical Informatics (IMBI) University of Freiburg, Germany and Department of Mathematics and Computer Science University of Southern Denmark [email protected] Abstract. Diagrams are frequently used in data analysis and visualization. Stata provides an SEM builder interface to develop SEM path diagrams, execute the analysis, and export the analysis diagram to an image file. However, this process is manual and cannot be reproduced in an automated analy- sis. This article introduces the diagram package which renders \DOT" (Graph Descriptive Language) diagrams and exports them to a variety of formats including PDF, PNG, JPEG, GIF, and BMP with adjustable resolution within Stata. Rendering diagrams from a markup language provides the possibility to create diagrams for different purposes, which increases their applications beyond building SEM models. The article discusses potential applications of the package in data analysis and vi- sualization and provides several examples for generating dynamic path diagrams, producing path diagrams from data sets, and visualizing func- tion call for Stata ado-programs. Keywords: Graphviz, graphics, DOT, diagram, reproducible research, vi- sualization, SEM 1 Introduction Evaluating relationship among variables is one of the primary concepts in statis- tics. In order to represent and visualize multivariate analytic models, often path diagrams are used, where arrows point out the relationship between vari- ables. The relationship is visualized using a one-headed arrow indicating one variable's direct effect on the other, whereas two-headed arrow indicating un- analyzed correlation. The residual variance is shown by arrows not originating from a variable (Mitchell 1992; Li et al. 1975). Despite their popularity for visualizing relationships between variables in Path Analysis and Structural Equation Models (SEM) (Andersson et al. 1999), the applications of path diagrams are not limited to statistical models. Path diagrams are commonly applied to visualize a summary, process, hierarchical structure, or interconnected systems such as networks, profiling statistical pack- ages, and visualizing computer software in general (Haghish 2016a). Nevertheless, the popular commercial statistical packages such as Stata and SPSS Amos provide an SEM builder interface for the users to build a path 1 diagram, execute the analysis, and export the resulting diagram to an image file manually. As a result, this process cannot be reproduced automatically. Moreover, the SEM builder interface limits applications of path diagrams to modeling the relationship between variables, neglecting all other potential uses of path diagrams for data visualization. While there have been a few attempts for developing a diagram in R (Haghish 2016c; Murrell 2015; Sadeghi and Marchetti 2012; Murrell 2015), Stata commu- nity has not made any endeavor to develop a graphical system for creating reproducible diagrams. Yet, both statistical languages lack a comprehensive package that can execute SEM models and generate an automated path dia- gram. In the current article I introduce the diagram package, which renders diagrams written in DOT (Graph Descriptive Language) (Gansner et al. 2006). DOT is a simple, intuitive, and yet highly customizable markup language for drawing reproducible diagrams (Gansner and North 2000). I will also provide several example programs for generating dynamic diagrams to demonstrate the potential applications of the package for data visualization. 2 DOT graph descriptive language The DOT markup is a graph description language that specifies the relation between different elements of a diagram. DOT was invented in 1988 and was included in Graphviz software (Ellson et al. 2002). DOT1 can create two types of diagrams which are directed and undirected diagrams, as shown in figure 1. The syntax of the DOT language is available at http://www.graphviz.org/ content/dot-language. Example . diagram `"digraph directed -> "node 1"; directed -> "node 2";"´, /// export(directed.pdf) . diagram `"graph undirected -- "node 1"; undirected -- "node 2";"´, /// export(undirected.pdf) 2.1 Using DOT language for data visualization DOT is not the only markup language available for generating path diagrams. GraphML (Brandes et al. 2014), Graph eXchange Language (GXL) (Winter et al. 2002; Holt et al. 2006), and Graph Modelling Language (GML) (Himsolt 1997) are only a few of markup languages available for creating diagrams from a script. However, compared to these languages, DOT has several advantages, particularly for statistics and data science applications. In contrast to GraphML and GXL which are based on XML, DOT is easy-to- read and easy-to-write for humans due to its simple syntax. In addition, DOT is 1Initially, DOT markup { which is rendered with dot program { could only create directed diagrams and the undirected layouts were added later on with neato program (North 2004). Therefore, the DOT markup should not be conflicted with dot program. 2 directed undirected node 1 node 2 node 1 node 2 Figure 1: Example of directed and undirected graphs highly customizable, allowing detailed manipulation of different elements of the graph. Despite its syntactic simplicity, DOT is also a compact language where many arguments for customizing the nodes, edges, and the overall graph can be written one after another. Moreover, there is plenty of free software available for rendering DOT diagrams such as Graphviz ? and DotEditor. Another benefit of DOT markup is that not only it can be rendered automatically by several engines and customizable options, but also, the user can strictly draw the diagram by specifying the coordinates of the center of each node (see section 5.1). Finally, the DOT markup has been available for many years, which means there is a large and supportive online community to ask help from. Using the same script file but a different rendering program, the DOT dia- grams can be rendered differently. The diagram package supports dot, neato, fdp, twopi, circo, and osage (Gansner 2004; Gansner et al. 2006; North 2004). Any of these programs can be specified to render the DOT diagram using the engine(name) option (see section 4). The examples provided in the current article only feature the dot and neato programs. The reader is referred to http://graphviz.org/Documentation.php for documentation, manual, and journal articles related to algorithms used in these programs. 2.2 Elements of DOT diagram The biggest advantage of the DOT language compared to XML languages such as GraphML and GXL is that it is human readable and it is based on a simple structure. Often, DOT diagrams are created by defining three types of objects, which are graph, node, and edge (Tsoukalos 2004). The graph object defines the graph type (directed or undirected) and can take arguments for general customizations of the diagram, whereas nodes define and customize the nodes of the diagram and edges define the connections between the nodes. DOT can also define a subgraph object, which puts the nodes in a cluster and can nest other subgraphs as well. 2.3 DOT customization The DOT markup language can highly customize any of the four objects (graph, subgraph, node, and edge), whether individually or globally, changing attributes of all objects in a graph. The customization allows changing shapes, thick- 3 ness, color, background color, labels, and many more attributes of nodes, edges, subgraphs, and graphs. While memorizing the arguments for a DOT new- bie imposes a learning curve, an IDE for developing interactive graphs could be of a great help for both learning the markup as well as building and cus- tomizing DOT graphs. A list of IDEs for DOT is provided on the Graphviz website at list of DOT editors and resources and I recommend DotEditor (visit http://vincenthee.github.io/DotEditor/) which allows building and customizing the graph using GUI interface and is available for Windows, Mac- intosh, and Linux operating systems free of charge. Explaining the attributes of each of these objects is beyond the purpose of the current manuscript. The reader is referred to http://graphviz.org/ content/attrs for a complete list of graph, node, and edge attributes. 3 diagram package 3.1 Installation The diagram package relies on webimage package (Haghish 2016b) package to adjust the resolution of the diagram and export it to PNG, GIF, JPEG, BMP, or PDF format. Both packages can be installed from SSC server: . ssc install diagram . ssc install webimage In addition, phantomJS (?Friesel 2014) software is required, which is a head- less WebKit scriptable with a JavaScript API. phantomJS is an open-source soft- ware, available for Windows, Mac, and Linux free of charge. Using phantomJS, the webimage package can render any webpage or web-based application to an image. The path to phantomJS software should be given to diagram package using the phantomjs(str) (see section 4). Alternatively, the path to phantomJS software can be permanently defined as shown below: . diagram setpath "/path/to/phantomJS" In the example below I first define the path to the executable phantomJS software on my Mac permanently and then test the installation of the diagram package by rendering a directed diagram that includes two nodes named Hello and World. To preserve the highest image quality without enlarging the diagram (using the magnify option), I export it to PDF format. Example . diagram setpath "/Applications/phantomjs/bin/phantomjs" . diagram "digraph fHello -> Worldg", export(helloworld.pdf) 4 Hello World Figure 2: Example of directed and undirected graphs 4 Syntax The main command of the package is diagram that renders DOT diagrams and export them to graphical files. 4.1 diagram command The diagram command can be used in two different ways, by rendering DOT script directly or reading a file that includes the DOT script. diagram using filename j "DOT-script" ,e xport(name) replace magnify(real) phantomjs(str) engine(name) The diagram options are explained below: export(name) specifies the filename and the file extension of the exported image.
Recommended publications
  • The Hitchhiker's Guide to Graph Exchange Formats
    The Hitchhiker’s Guide to Graph Exchange Formats Prof. Matthew Roughan [email protected] http://www.maths.adelaide.edu.au/matthew.roughan/ Work with Jono Tuke UoA June 4, 2015 M.Roughan (UoA) Hitch Hikers Guide June 4, 2015 1 / 31 Graphs Graph: G(N; E) I N = set of nodes (vertices) I E = set of edges (links) Often we have additional information, e.g., I link distance I node type I graph name M.Roughan (UoA) Hitch Hikers Guide June 4, 2015 2 / 31 Why? To represent data where “connections” are 1st class objects in their own right I storing the data in the right format improves access, processing, ... I it’s natural, elegant, efficient, ... Many, many datasets M.Roughan (UoA) Hitch Hikers Guide June 4, 2015 3 / 31 ISPs: Internode: layer 3 http: //www.internode.on.net/pdf/network/internode-domestic-ip-network.pdf M.Roughan (UoA) Hitch Hikers Guide June 4, 2015 4 / 31 ISPs: Level 3 (NA) http://www.fiberco.org/images/Level3-Metro-Fiber-Map4.jpg M.Roughan (UoA) Hitch Hikers Guide June 4, 2015 5 / 31 Telegraph submarine cables http://en.wikipedia.org/wiki/File:1901_Eastern_Telegraph_cables.png M.Roughan (UoA) Hitch Hikers Guide June 4, 2015 6 / 31 Electricity grid M.Roughan (UoA) Hitch Hikers Guide June 4, 2015 7 / 31 Bus network (Adelaide CBD) M.Roughan (UoA) Hitch Hikers Guide June 4, 2015 8 / 31 French Rail http://www.alleuroperail.com/europe-map-railways.htm M.Roughan (UoA) Hitch Hikers Guide June 4, 2015 9 / 31 Protocol relationships M.Roughan (UoA) Hitch Hikers Guide June 4, 2015 10 / 31 Food web M.Roughan (UoA) Hitch Hikers
    [Show full text]
  • 5Th LACCEI International Latin American and Caribbean
    Twelfth LACCEI Latin American and Caribbean Conference for Engineering and Technology (LACCEI’2014) ”Excellence in Engineering To Enhance a Country’s Productivity” July 22 - 24, 2014 Guayaquil, Ecuador. Biological Network Exploration Tool: BioNetXplorer Carlos Roberto Arias Arévalo Universidad Tecnológica Centroamericana, Tegucigalpa, Honduras, [email protected] ABSTRACT BioNetXplorer is a standalone application that allows the integration of more than twenty topological and biological properties of the nodes of a biological network, and that displays them in a intuitive, easy to use interface. Along this functionality the application can also perform graphical shortest paths analysis and shortest paths scoring of genes, due to the intensive computational requirement of the later it has the potential to connect to a Hadoop cluster for faster computation. Keywords: Biological Network, Topological Analysis RESUMEN BioNetXplorer es una aplicación de escritorio que permite la integración de más de veinte propiedades topológicas y biológicas de los nodos de una red biológica, mostrando esta información en un interfaz intuitivo y fácil de usar. Además de esta funcionalidad la aplicación también realiza análisis de caminos más cortos de manera gráfica, y la evaluación de puntuación de genes por medio de caminos más cortos. Debido a las necesidades intensivas de computación de esta última funcionalidad el software tiene el potencial de conectarse a un clúster de Hadoop para computación más rápida. Palabras claves: Red Biológica, Análisis Topológico 1. INTRODUCTION With the increasing amount of available biological network information, network analysis is becoming more popular among researchers in the bioinformatics field, therefore there is an increasing need for diverse network analysis tools that facilitate the study of biological networks, analysis tools that integrate both topological and biological data, and that can display the most information in an integrated graphical interface.
    [Show full text]
  • Network Analysis in R
    Network Analysis in R Douglas Ashton ‐ dashton@mango‐solutions.com Workshop Aims Import/Export network data Visualising your network Descriptive stats Inference (statnet suite) Also available as a two‐day training course! http://bit.ly/NetsWork01 About me Doug Ashton Physicist (statistical) for 10 years Monte Carlo Networks At Mango for 1.5 years Windsurfer Twitter: @dougashton Web: www.dougashton.net GitHub: dougmet Networks are everywhere Networks in R R matrices (and sparse matrices in Matrix) igraph package Gabor Csardi statnet package University of Washington suite of packages Representing Networks Terminology Nodes and edges Directed Matrix Representation Code whether each possible edge exists or not. 0, no edge A = { ij 1, edge exists Example ⎛ 0 0 1 1 ⎞ ⎜ 1 0 0 0 ⎟ A = ⎜ ⎟ ⎜ 0 0 0 1 ⎟ ⎝ 0 1 0 0 ⎠ Matrices in R Create the matrix Matrix operations A <‐ rbind(c(0,1,0), c(1,0,1), c(1,0,0)) # Matrix multiply nodeNames <‐ c("A","B","C") A %*% A dimnames(A) <‐ list(nodeNames, nodeNames) A ## A B C ## A 1 0 1 ## A B C ## B 1 1 0 ## A 0 1 0 ## C 0 1 0 ## B 1 0 1 ## C 1 0 0 Gives the number of paths of length 2. Could also use sparse matrices from the Matrix # Matrix multiply package. A %*% A %*% A %*% A ## A B C ## A 1 1 1 ## B 2 1 1 ## C 1 1 0 Gives the number of paths of length 4. Edge List Representation It is much more compact to just list the edges. We can use a two‐column matrix ⎡ A B ⎤ ⎢ B A ⎥ E = ⎢ ⎥ ⎢ B C ⎥ ⎣ C A ⎦ which is represented in R as el <‐ rbind(c("A","B"), c("B","A"), c("B","C"), c("C","A")) el ## [,1] [,2] ## [1,] "A" "B" ## [2,] "B" "A" ## [3,] "B" "C" ## [4,] "C" "A" Representation in igraph igraph has its own efficient data structures for storing networks.
    [Show full text]
  • GOLD 3 Un Lenguaje De Programación Imperativo Para La Manipulación De Grafos Y Otras Estructuras De Datos
    GOLD 3 Un lenguaje de programación imperativo para la manipulación de grafos y otras estructuras de datos Autor Alejandro Sotelo Arévalo UNIVERSIDAD DE LOS ANDES Asesora Silvia Takahashi Rodríguez, Ph.D. UNIVERSIDAD DE LOS ANDES TESIS DE MAESTRÍA EN INGENIERÍA DEPARTAMENTO DE INGENIERÍA DE SISTEMAS Y COMPUTACIÓN FACULTAD DE INGENIERÍA UNIVERSIDAD DE LOS ANDES BOGOTÁ D.C., COLOMBIA ENERO 27 DE 2012 > > > A las personas que más quiero en este mundo: mi madre Gladys y mi novia Alexandra. > > > Abstract Para disminuir el esfuerzo en la programación de algoritmos sobre grafos y otras estructuras de datos avanzadas es necesario contar con un lenguaje de propósito específico que se preocupe por mejorar la legibilidad de los programas y por acelerar el proceso de desarrollo. Este lenguaje debe mezclar las virtudes del pseudocódigo con las de un lenguaje de alto nivel como Java o C++ para que pueda ser fácilmente entendido por un matemático, por un científico o por un ingeniero. Además, el lenguaje debe ser fácilmente interpretado por las máquinas y debe poder competir con la expresividad de los lenguajes de propósito general. GOLD (Graph Oriented Language Domain) satisface este objetivo, siendo un lenguaje de propósito específico imperativo lo bastante cercano al lenguaje utilizado en el texto Introduction to Algorithms de Thomas Cormen et al. [1] como para ser considerado una especie de pseudocódigo y lo bastante cercano al lenguaje Java como para poder utilizar la potencia de su librería estándar y del entorno de programación Eclipse. Índice general I Preliminares 1 1 Introducción 2 1.1 Resumen ............................................... 2 1.2 Contexto...............................................
    [Show full text]
  • A Comparison of Visualisation Techniques for Complex Networks
    DEGREE PROJECT IN COMPUTER SCIENCE AND ENGINEERING, SECOND CYCLE, 30 CREDITS STOCKHOLM, SWEDEN 2016 A comparison of visualisation techniques for complex networks VIKTOR GUMMESSON KTH ROYAL INSTITUTE OF TECHNOLOGY SCHOOL OF COMPUTER SCIENCE AND COMMUNICATION A comparison of visualisation techniques for complex networks En jämförelse av visualiseringsmetoder för komplexa nätverk VIKTOR GUMMESSON [email protected] Master’s Thesis in Computer Science Royal Institute of Technology Supervisor, KTH: Olov Engwall Examiner: Olle Bälter Project commissioned by: Scania Supervisors at Scania: Magnus Kyllegård, Viktor Kaznov Abstract The need to visualise sets of data and networks within a company is a well-known task. In this thesis, research has been done of techniques used to visualize complex networks in order to find out if there is a generalized optimal technique that can visualize complex networks. For this purpose an application was implemented containing three different views, which were selected from the research done on the sub- ject. As it turns out, it points toward that there is no generalized op- timal technique that can be used to default visualize complex networks in a satisfactory way. A definit conclusion could not be given due to the fact that all visualization techniques which could not be evaluated within this thesis timeframe. Referat Behov av att visualisera data inom bolag är ett känt faktum. Denna avhandling har använt olika tekniker för att undersöka om det existe- rar en generell optimal teknik som kan tillämpas vid visualisering av komplexa nätverk. Vid genomförandet implementerades en applikation med tre olika vyer som valdes ut baserat på forskning inom det valda området.
    [Show full text]
  • Grph: List of Algorithms
    Grph: list of algorithms Luc Hogie (CNRS), Aur´elienLancin (INRIA), Issam Tahiri (INRIA), Grgory Morel (INRIA), Nathan Cohen (INRIA), David Coudert (INRIA) September 16, 2013 Contents 1 Traversal 4 1.1 Breadth First Search.................................4 1.2 Depth First Search..................................4 1.3 Random Search....................................4 1.3.1 Single visit..................................4 1.4 Parallelization.....................................4 2 Shortest paths 4 2.1 K-Shortest paths...................................4 2.2 BFS-based.......................................5 2.3 Dijkstra........................................5 2.4 Bellman-Ford.....................................5 2.4.1 David mod..................................5 2.5 Floyd Warshall....................................5 3 Clustering 5 3.1 Kernighan-Lin....................................5 3.2 Number of triangles.................................5 3.2.1 Native.....................................5 3.2.2 Matrix-based.................................5 3.3 List all triangles...................................6 3.4 List all paths.....................................6 3.5 List all cycles.....................................6 3.6 Finding cliques....................................6 4 Distances 6 4.1 Distance matrix....................................6 4.2 Eccentricity......................................6 4.3 Radius.........................................6 4.4 Diameter.......................................6 4.5 Center vertex.....................................6
    [Show full text]
  • Visualizing Three-Dimensional Graph Drawings Sebastian
    VISUALIZING THREE-DIMENSIONAL GRAPH DRAWINGS SEBASTIAN HANLON Bachelor of Science, University of Lethbridge, 2004 A Thesis Submitted to the School of Graduate Studies of the University of Lethbridge in Partial Fulfillmene th f o t Requirements for the Degree MASTE SCIENCF RO E Departmen Mathematicf o t Computed san r Science Universit Lethbridgf yo e LETHBRIDGE, ALBERTA, CANADA © Copyright Sebastian Hanlon, 2006 Abstract The GLuskap system for interactive three-dimensional graph drawing applies techniques of scientific visualizatio interactivd nan e system constructione th o st , display analysid an , f so graph drawings. Important feature systee th f mo s include suppor large-screer fo t n stereo- graphi displaD c3 y with immersive head-trackin motion-tracked gan d interactiv wanD e3 d control. A distributed rendering architecture contributes to the portability of the system, with user control performed on a laptop computer without specialized graphics hardware. An interfac implementinr efo g graph drawing layou analysid an t s algorithm Pythoe th n si n programming language is also provided. This thesis describes comprehensively the work systee author—thie th th n y mo b s work include desige s th implementatio d nan - ma e th f no featurer jo s described above. Further direction continuer sfo d developmen researcd an t n hi cognitive tools for graph drawing research are also suggested. in Acknowledgments Firstly, I would like to thank my advisor, Dr. Stephen Wismath, for encouraging me to pursue graduate studies in computer science—without him, this thesis would not exist. He has furthermore been supportive and enthusiastic throughout the course of my studies; one bettea r fo r k supervisorcoulas t dno alsI .
    [Show full text]
  • Graph Formats
    Graph Formats Contents 1 Graph Formats 1 1.1 Graph Density............................................1 1.2 Graph formats............................................1 1.3 Power laws..............................................5 1.4 Descriptive statistics.........................................9 #install.packages("igraph") #install.packages("ggplot2") library('igraph') library('ggplot2') 1 Graph Formats 1.1 Graph Density Graph algorithms * breadth first search (BFS traversal): O(m) * connected components: O(n + m) * shortest path (Dijkstra): O(m + n log n) * all shortest paths (Floyd-Warshall): O(nˆ3) 1.1.1 Graph characteristics (directed graph): | V |= n, | E |= m Graph Density m r = n(n − 1) Average Degree: 1 X 2m < k >= deg(v ) = n i n i Average Path: 1 X < L >= d(v , v ) n(n − 1) i j i6=j 1.2 Graph formats 1.2.1 GraphML GraphML is XML-base file format for graphs. It has quite clear and flexible format. Along with XML it represents information in hierarchical way: 1 <?xml version="1.0" encoding="UTF-8"?> <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd"> <graph id="G" edgedefault="undirected"> <node id="n0"/> <node id="n1"/> <node id="n2"/> <node id="n3"/> <node id="n4"/> <node id="n5"/> <node id="n6"/> <node id="n7"/> <node id="n8"/> <node id="n9"/> <node id="n10"/> <edge source="n0" target="n2"/> <edge source="n1" target="n2"/> <edge source="n2" target="n3"/> <edge source="n3" target="n5"/> <edge source="n3" target="n4"/> <edge source="n4" target="n6"/> <edge source="n6" target="n5"/> <edge source="n5" target="n7"/> <edge source="n6" target="n8"/> <edge source="n8" target="n7"/> <edge source="n8" target="n9"/> <edge source="n8" target="n10"/> </graph> </graphml> 1.2.2 GML Another flexible format and a bit more readible format is GML (Graph Modelling Language).
    [Show full text]
  • Cnfgen Documentation Release 70E5b68
    CNFgen Documentation Release 70e5b68 Massimo Lauria Apr 17, 2021 Table of contents 1 Exporting formulas to DIMACS3 2 Exporting formulas to LaTeX5 3 Reference 7 4 Testing satisfiability 9 5 Formula families 11 5.1 Included formula families...................................... 11 5.2 Command line invocation...................................... 23 6 Graph based formulas 25 6.1 Directed Acyclic Graphs....................................... 26 6.2 Bipartite Graphs........................................... 26 6.3 Graph I/O............................................... 26 6.4 Graph generators........................................... 29 6.5 References.............................................. 29 7 Post-process a CNF formula 31 7.1 Example: OR substitution...................................... 31 7.2 Using CNF transformations..................................... 31 8 The command line utility 33 9 Adding a formula family to CNFgen 35 10 Welcome to CNFgen’s documentation! 37 10.1 The cnfgen library......................................... 37 10.2 The cnfgen command line tool.................................. 38 10.3 Reference............................................... 38 11 Indices and tables 39 Bibliography 41 Python Module Index 43 Index 45 i ii CNFgen Documentation, Release 70e5b68 The entry point to cnfgen library is cnfgen.CNF, which is the data structure representing CNF formulas. Variables can have text names but in general each variable is an integer from 1 to n, where n is the number of variables. >>> from cnfgen import CNF >>> F= CNF() >>> x=F.new_variable("X") >>> y=F.new_variable("Y") >>> z=F.new_variable("Z") >>> print(x,y,z) 1 2 3 A clause is a list of literals, and each literal is +v or -v where v is the number corresponding to a variable. The user can interleave the addition of variables and clauses. Notice that the method :py:method:‘new_variable‘ return the numeric id of the newly added variable, which can be optionally used to build clauses.
    [Show full text]
  • Network Visualisation with Ggraph
    Network Visualisation with ggraph Hannah Frick @hfcfrick Outline for the Tutorial • Representation of networks with igraph • Visualisation with ggraph • layers • nodes • edges Based on Thomas Lin Pedersen’s series of blog posts on ggraph 2 About me • Statistician by training • Author of psychomix and trackeR packages • A Mango cat since ~ mid 2017 • R-Ladies: co-organiser for London chapter and part of the global Leadership Team • Github: hfrick • Twitter: @hfcfrick 3 Networks are everywhere 4 Representing Networks 5 Terminology Nodes and edges Directed 6 Matrix Representation Code whether each possible edge exists or not. 0, no edge Aij = {1, edge exists For example 0 0 1 1 ⎛ 1 0 0 0 ⎞ A = ⎜ 0 0 0 1 ⎟ ⎜ 0 1 0 0 ⎟ ⎝ ⎠ 7 Matrix Representation in R library(igraph) A <- rbind(c(0, 0, 1, 1), c(1, 0, 0, 0), c(0, 0, 0, 1), c(0, 1, 0, 0)) g <- graph_from_adjacency_matrix(A) plot(g) 8 Edge List Representation It is much more compact to just list the edges. We can use a two-column matrix A B ⎡ B A ⎤ E = ⎢ B C ⎥ ⎢ C A ⎥ ⎣ ⎦ 9 Edge List in R el <- rbind(c("A","B"), c("B","A"), c("B","C"), c("C","A")) g <- graph_from_edgelist(el) plot(g) 10 Creating igraph Objects From an adjacency matrix or edge list g <- graph_from_adjacency_matrix(A) g <- graph_from_edgelist(el) From a textual description g <- graph_from_literal(A--B, B-+C, C-+A) From a data frame df <- as.data.frame(el) g <- graph_from_data_frame(df) 11 Converting back From a graph object we can output just as we read in: Adjacency Matrix Edge List A <- as_adjacency_matrix(g, el <- as_edgelist(g) sparse = FALSE) el A ## [,1] [,2] ## A B C ## [1,] "A" "B" ## A 0 1 0 ## [2,] "B" "A" ## B 1 0 1 ## [3,] "B" "C" ## C 1 0 0 ## [4,] "C" "A" 12 Import/Export 13 Networks from Data Frames Usually we’ll read in edge lists as data.frame objects.
    [Show full text]
  • Cnfgen Documentation Release 0.9.0-12-G561aedd
    CNFgen Documentation Release 0.9.0-12-g561aedd Massimo Lauria Feb 04, 2021 Table of contents 1 Exporting formulas to DIMACS3 2 Exporting formulas to LaTeX5 3 Reference 7 4 Testing satisfiability 9 5 Formula families 11 5.1 Included formula families...................................... 11 5.2 Command line invocation...................................... 22 6 Graph based formulas 25 6.1 Directed Acyclic Graphs and Bipartite Graphs........................... 26 6.2 Graph I/O............................................... 27 6.3 Graph generators........................................... 29 6.4 References.............................................. 29 7 Post-process a CNF formula 31 7.1 Example: OR substitution...................................... 31 7.2 Using CNF transformations..................................... 31 8 The command line utility 33 9 Adding a formula family to CNFgen 35 10 Welcome to CNFgen’s documentation! 37 10.1 The cnfgen library......................................... 37 10.2 The cnfgen command line tool.................................. 38 10.3 Reference............................................... 38 11 Indices and tables 39 Bibliography 41 Python Module Index 43 Index 45 i ii CNFgen Documentation, Release 0.9.0-12-g561aedd The entry point to cnfgen library is cnfgen.CNF, which is the data structure representing CNF formulas. Any string (actually any hashable object) is a valid name for a variable, that can be optionally documented with an additional description. >>> from cnfgen import CNF >>> F= CNF() >>> F.add_variable("X",'this
    [Show full text]
  • A Comparative Study of Social Network Analysis Tools David Combe, Christine Largeron, Elod Egyed-Zsigmond, Mathias Géry
    A comparative study of social network analysis tools David Combe, Christine Largeron, Elod Egyed-Zsigmond, Mathias Géry To cite this version: David Combe, Christine Largeron, Elod Egyed-Zsigmond, Mathias Géry. A comparative study of social network analysis tools. WEB INTELLIGENCE & VIRTUAL ENTERPRISES, Oct 2010, Saint- Etienne, France. hal-00531447 HAL Id: hal-00531447 https://hal.archives-ouvertes.fr/hal-00531447 Submitted on 2 Nov 2010 HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. 1 A comparative study of social network analysis tools David Combe1 ∗, Christine Largeron1, Elod˝ Egyed-Zsigmond2 and Mathias Géry1 Université de Lyon 1 CNRS, UMR 5516, Laboratoire Hubert Curien, F-42000, Saint-Étienne, France Université de Saint-Étienne, Jean-Monnet, F-42000, Saint-Étienne, France Email: {david.combe, christine.largeron, mathias.gery}@univ-st-etienne.fr 2 UMR 5205 CNRS, LIRIS 7 av J. Capelle, F 69100 Villeurbanne, France Email: [email protected] Abstract. Social networks have known an important development since the appearance of web 2.0 platforms. This leads to a growing need for social network mining and social network analysis (SNA) methods and tools in order to provide deeper analysis of the network but also to detect communities in view of various applications.
    [Show full text]