├── .Rbuildignore ├── .gitignore ├── data ├── nycNodes.rda ├── vbdNodes.rda ├── managerEdges.rda ├── managerNodes.rda ├── network1Edges.rda ├── network1Nodes.rda ├── network2Edges.rda ├── network2Nodes.rda ├── network3Edges.rda ├── network3Nodes.rda ├── network4Edges.rda ├── network4Nodes.rda ├── network5Edges.rda ├── network5Nodes.rda ├── nycHypergraph.rda ├── terroristEdges.rda ├── terroristNodes.rda ├── vbdHypergraph.rda ├── florentineEdges.rda ├── florentineNodes.rda ├── hypergraph1Edges.rda ├── hypergraph1Nodes.rda ├── nycAffiliations.rda ├── vbdAffiliations.rda └── hypergraph1Affiliations.rda ├── images ├── middlemen.png ├── erdosRenyi50.png ├── adviceNetwork.png ├── marriageTopology.png ├── terroristNetwork.png ├── weightedInstitutions.png └── victorian-britain-institutions.png ├── networkR.Rproj ├── man ├── filterNetwork.Rd ├── nodeProjection.Rd ├── randomGraph.Rd ├── adjacencyMatrix.Rd ├── degree.Rd ├── density.Rd ├── affiliationProjection.Rd ├── degreeDistribution.Rd ├── adjacencyDF.Rd ├── robustness.Rd ├── averageDegree.Rd ├── affiliationSet.Rd ├── isUndirected.Rd ├── strongWeak.Rd ├── undirectedAdjMatrix.Rd ├── middlemanPower.Rd ├── connectivity.Rd ├── betaMeasure.Rd ├── hypergraphNeighbourhood.Rd ├── affiliationEnviornment.Rd ├── middlemanPowerDetail.Rd ├── predecessorsSuccessors.Rd ├── potentialBrokerage.Rd ├── externalInfluence.Rd ├── criticalCoverage.Rd ├── setPredSucc.Rd ├── elites.Rd ├── affiliationInfluence.Rd ├── nodeCoverage.Rd ├── nodeInfluence.Rd ├── setCoverage.Rd ├── criticalSets.Rd ├── setBrokerage.Rd ├── nodeSetBrokerage.Rd ├── setCriticality.Rd ├── nodeCriticality.Rd ├── blockSNE.Rd └── nodeNormCriticality.Rd ├── DESCRIPTION ├── R ├── adjacencyDF.R ├── isUndirected.R ├── filterNetwork.R ├── undirectedAdjMatrix.R ├── adjacencyMatrix.R ├── degreeDistribution.R ├── averageDegree.R ├── affiliationSet.R ├── potentialBrokerage.R ├── density.R ├── connectivity.R ├── degree.R ├── strongWeak.R ├── betaMeasure.R ├── criticalCoverage.R ├── hypergraphNeighbourhood.R ├── nodeProjection.R ├── middlemanPowerDetail.R ├── affiliationEnvironment.R ├── criticalSets.R ├── predecessorsSuccessors.R ├── middlemanPower.R ├── setCriticality.R ├── affiliationProjection.R ├── nodeCoverage.R ├── elites.R ├── externalInfluence.R ├── nodeCriticality.R ├── nodeInfluence.R ├── nodeSetBrokerage.R ├── nodeNormCriticality.R ├── affiliationInfluence.R ├── robustness.R ├── blockSNE.R ├── setCoverage.R ├── randomGraph.R ├── setBrokerage.R └── setPredSucc.R ├── NAMESPACE ├── LICENSE └── README.md /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | -------------------------------------------------------------------------------- /data/nycNodes.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/nycNodes.rda -------------------------------------------------------------------------------- /data/vbdNodes.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/vbdNodes.rda -------------------------------------------------------------------------------- /data/managerEdges.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/managerEdges.rda -------------------------------------------------------------------------------- /data/managerNodes.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/managerNodes.rda -------------------------------------------------------------------------------- /images/middlemen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/images/middlemen.png -------------------------------------------------------------------------------- /data/network1Edges.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/network1Edges.rda -------------------------------------------------------------------------------- /data/network1Nodes.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/network1Nodes.rda -------------------------------------------------------------------------------- /data/network2Edges.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/network2Edges.rda -------------------------------------------------------------------------------- /data/network2Nodes.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/network2Nodes.rda -------------------------------------------------------------------------------- /data/network3Edges.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/network3Edges.rda -------------------------------------------------------------------------------- /data/network3Nodes.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/network3Nodes.rda -------------------------------------------------------------------------------- /data/network4Edges.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/network4Edges.rda -------------------------------------------------------------------------------- /data/network4Nodes.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/network4Nodes.rda -------------------------------------------------------------------------------- /data/network5Edges.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/network5Edges.rda -------------------------------------------------------------------------------- /data/network5Nodes.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/network5Nodes.rda -------------------------------------------------------------------------------- /data/nycHypergraph.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/nycHypergraph.rda -------------------------------------------------------------------------------- /data/terroristEdges.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/terroristEdges.rda -------------------------------------------------------------------------------- /data/terroristNodes.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/terroristNodes.rda -------------------------------------------------------------------------------- /data/vbdHypergraph.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/vbdHypergraph.rda -------------------------------------------------------------------------------- /images/erdosRenyi50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/images/erdosRenyi50.png -------------------------------------------------------------------------------- /data/florentineEdges.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/florentineEdges.rda -------------------------------------------------------------------------------- /data/florentineNodes.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/florentineNodes.rda -------------------------------------------------------------------------------- /data/hypergraph1Edges.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/hypergraph1Edges.rda -------------------------------------------------------------------------------- /data/hypergraph1Nodes.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/hypergraph1Nodes.rda -------------------------------------------------------------------------------- /data/nycAffiliations.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/nycAffiliations.rda -------------------------------------------------------------------------------- /data/vbdAffiliations.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/vbdAffiliations.rda -------------------------------------------------------------------------------- /images/adviceNetwork.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/images/adviceNetwork.png -------------------------------------------------------------------------------- /images/marriageTopology.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/images/marriageTopology.png -------------------------------------------------------------------------------- /images/terroristNetwork.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/images/terroristNetwork.png -------------------------------------------------------------------------------- /images/weightedInstitutions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/images/weightedInstitutions.png -------------------------------------------------------------------------------- /data/hypergraph1Affiliations.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/data/hypergraph1Affiliations.rda -------------------------------------------------------------------------------- /images/victorian-britain-institutions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/O1sims/networkR/HEAD/images/victorian-britain-institutions.png -------------------------------------------------------------------------------- /networkR.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | -------------------------------------------------------------------------------- /man/filterNetwork.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/filterNetwork.R 3 | \name{filterNetwork} 4 | \alias{filterNetwork} 5 | \title{Filter a networks edges} 6 | \usage{ 7 | filterNetwork(edgeList) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where sources are in the first column and targets are in the second column.} 11 | } 12 | \description{ 13 | This function filters a network such that it removes any duplicated connections, or more specifically arcs, between a pair of nodes. 14 | } 15 | \examples{ 16 | filterNetwork() 17 | } 18 | \keyword{filter} 19 | -------------------------------------------------------------------------------- /man/nodeProjection.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/nodeProjection.R 3 | \name{nodeProjection} 4 | \alias{nodeProjection} 5 | \title{Represent a hypergraph as a network of nodes only} 6 | \usage{ 7 | nodeProjection(edgeList) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to.} 11 | } 12 | \description{ 13 | This function projects a hypergraph into a network of nodes only. 14 | } 15 | \examples{ 16 | nodeProjection 17 | } 18 | \keyword{node} 19 | \keyword{projection} 20 | -------------------------------------------------------------------------------- /man/randomGraph.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/randomGraph.R 3 | \name{randomGraph} 4 | \alias{randomGraph} 5 | \title{Generate a random network} 6 | \usage{ 7 | randomGraph(n, p, undirected) 8 | } 9 | \arguments{ 10 | \item{n}{The number of nodes to be present within the network.} 11 | 12 | \item{p}{The probability that any two nodes are connected together.} 13 | 14 | \item{undirected}{should the randomly generated network be undirected? TRUE or FALSE.} 15 | } 16 | \description{ 17 | The function generates a randomly connected network. 18 | } 19 | \examples{ 20 | randomGraph() 21 | } 22 | \keyword{graph} 23 | \keyword{network} 24 | \keyword{random} 25 | -------------------------------------------------------------------------------- /man/adjacencyMatrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/adjacencyMatrix.R 3 | \name{adjacencyMatrix} 4 | \alias{adjacencyMatrix} 5 | \title{Transform network data into an adjacency matrix} 6 | \usage{ 7 | adjacencyMatrix(edgeList, nodeList) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe where all nodes and their respective names are listed.} 13 | } 14 | \description{ 15 | This function transforms network data into an n-by-n adjacency matrix. 16 | } 17 | \examples{ 18 | adjacencyMatrix() 19 | } 20 | \keyword{adjacency} 21 | \keyword{matrix} 22 | -------------------------------------------------------------------------------- /man/degree.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/degree.R 3 | \name{degree} 4 | \alias{degree} 5 | \title{Calculate node degree} 6 | \usage{ 7 | degree(edgeList, nodeList) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe where all nodes and their respective names are listed.} 13 | } 14 | \description{ 15 | This function calculates the degree of all nodes in the network. This includes counting the in-degree and out-degree of each node. Averages of all degrees are also considered. 16 | } 17 | \examples{ 18 | degree() 19 | } 20 | \keyword{degree} 21 | -------------------------------------------------------------------------------- /man/density.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/density.R 3 | \name{density} 4 | \alias{density} 5 | \title{Density of a network} 6 | \usage{ 7 | density(edgeList, nodeList, undirected = TRUE) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data within which sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe within which all nodes and their respective names are listed.} 13 | 14 | \item{undirected}{Is the network graph undirected? TRUE or FALSE.} 15 | } 16 | \description{ 17 | This function calculates the density of a network graph. 18 | } 19 | \examples{ 20 | density() 21 | } 22 | \keyword{density} 23 | -------------------------------------------------------------------------------- /man/affiliationProjection.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/affiliationProjection.R 3 | \name{affiliationProjection} 4 | \alias{affiliationProjection} 5 | \title{Represent a hypergraph as a network of affiliations} 6 | \usage{ 7 | affiliationProjection(edgeList) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to.} 11 | } 12 | \description{ 13 | This function projects a hypergraph into a network of affiliations. 14 | } 15 | \examples{ 16 | affiliationProjection() 17 | } 18 | \keyword{affiliation} 19 | \keyword{projection} 20 | -------------------------------------------------------------------------------- /man/degreeDistribution.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/degreeDistribution.R 3 | \name{degreeDistribution} 4 | \alias{degreeDistribution} 5 | \title{Plot degree distribution} 6 | \usage{ 7 | degreeDistribution(edgeList, nodeList) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe where all nodes and their respective names are listed.} 13 | } 14 | \description{ 15 | This function plots the degree distribution of a network. Depends on `ggplot2`. 16 | } 17 | \examples{ 18 | degreeDistribution() 19 | } 20 | \keyword{degree} 21 | \keyword{distribution} 22 | -------------------------------------------------------------------------------- /man/adjacencyDF.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/adjacencyDF.R 3 | \name{adjacencyDF} 4 | \alias{adjacencyDF} 5 | \title{Transform network data into a data frame adjacency matrix} 6 | \usage{ 7 | adjacencyDF(edgeList, nodeList) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe where all nodes and their respective names are listed.} 13 | } 14 | \description{ 15 | This function transforms network data into an n-by-n adjacency matrix dressed up as a data frame. 16 | } 17 | \examples{ 18 | adjacencyDF() 19 | } 20 | \keyword{adjacency} 21 | \keyword{matrix} 22 | -------------------------------------------------------------------------------- /man/robustness.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/robustness.R 3 | \name{robustness} 4 | \alias{robustness} 5 | \title{Calculate the robustness of a middleman position} 6 | \usage{ 7 | robustness(edgeList, nodeList) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe where all nodes and their respective names are listed.} 13 | } 14 | \description{ 15 | Robustness of a middleman measured by the number of arcs that need to be removed in order for a middleman to lose its position as a middleman. 16 | } 17 | \examples{ 18 | robustness() 19 | } 20 | \keyword{robustness} 21 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: networkR 2 | Title: A package for analysing social and economic networks 3 | Version: 0.0.0.9000 4 | Authors@R: person("Owen", "Sims", email = "sims.owen@gmail.com", role = c("aut", "cre")) 5 | Maintainer: Owen Sims 6 | Description: This package provides a number of functions to analyse the 7 | structure and statistics of networks and hypergraphs. 8 | URL: https://github.com/O1sims/networkR 9 | BugReports: URL: https://github.com/OwenSims/networkR/issues 10 | License: MIT 11 | Suggests: 12 | testthat 13 | Depends: 14 | R (>= 3.0.0) 15 | Imports: 16 | gtools, 17 | magrittr, 18 | ggplot2, 19 | expm, 20 | data.table, 21 | igraph 22 | Encoding: UTF-8 23 | LazyData: true 24 | RoxygenNote: 6.0.1 25 | -------------------------------------------------------------------------------- /man/averageDegree.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/averageDegree.R 3 | \name{averageDegree} 4 | \alias{averageDegree} 5 | \title{Calculate average node degree in network} 6 | \usage{ 7 | averageDegree(edgeList, nodeList) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe where all nodes and their respective names are listed.} 13 | } 14 | \description{ 15 | This function calculates the degree of all nodes in the network. This includes counting the in-degree and out-degree of each node. Averages of all degrees are also considered. 16 | } 17 | \examples{ 18 | averageDegree() 19 | } 20 | \keyword{degree} 21 | -------------------------------------------------------------------------------- /man/affiliationSet.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/affiliationSet.R 3 | \name{affiliationSet} 4 | \alias{affiliationSet} 5 | \title{List the affiliation memberships of each node} 6 | \usage{ 7 | affiliationSet(edgeList, nodeList) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to.} 11 | 12 | \item{nodeList}{A dataframe where all nodes and their respective names are listed.} 13 | } 14 | \description{ 15 | This function returns a list of the membership of each node in the hypergraph 16 | } 17 | \examples{ 18 | affiliationSet() 19 | } 20 | \keyword{affiliation} 21 | \keyword{projection} 22 | -------------------------------------------------------------------------------- /man/isUndirected.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/isUndirected.R 3 | \name{isUndirected} 4 | \alias{isUndirected} 5 | \title{Query whether a network is undirected} 6 | \usage{ 7 | isUndirected(edgeList, nodeList, adjMatrix) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe where all nodes and their respective names are listed.} 13 | 14 | \item{adjMatrix}{The network represented as an adjacency matrix.} 15 | } 16 | \description{ 17 | A function that queries whether some network data is undirected and returns a TRUE or FALSE value. 18 | } 19 | \examples{ 20 | isUndirected() 21 | } 22 | \keyword{undirected} 23 | -------------------------------------------------------------------------------- /man/strongWeak.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/strongWeak.R 3 | \name{strongWeak} 4 | \alias{strongWeak} 5 | \title{Distinguish strong, weak, and Non-middlemen} 6 | \usage{ 7 | strongWeak(edgeList, nodeList, adjMatrix) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe where all nodes and their respective names are listed.} 13 | 14 | \item{adjMatrix}{The network represented as an adjacency matrix.} 15 | } 16 | \description{ 17 | A function that returns whether individual nodes are strong, weak or non-middlemen 18 | } 19 | \examples{ 20 | strongWeak() 21 | } 22 | \keyword{brokerage} 23 | \keyword{middleman} 24 | -------------------------------------------------------------------------------- /R/adjacencyDF.R: -------------------------------------------------------------------------------- 1 | #' Transform network data into a data frame adjacency matrix 2 | #' 3 | #' This function transforms network data into an n-by-n adjacency matrix dressed up as a data frame. 4 | #' @param edgeList A dataframe of network data where sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe where all nodes and their respective names are listed. 6 | #' @keywords adjacency matrix 7 | #' @export 8 | #' @examples 9 | #' adjacencyDF() 10 | 11 | adjacencyDF <- function(edgeList, nodeList) { 12 | networkDF <- adjacencyMatrix(edgeList = edgeList, 13 | nodeList = nodeList) 14 | networkDF <- as.data.frame.matrix(networkDF) 15 | colnames(networkDF) <- rownames(networkDF) <- nodeList[, 2] 16 | return(networkDF) 17 | } 18 | -------------------------------------------------------------------------------- /man/undirectedAdjMatrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/undirectedAdjMatrix.R 3 | \name{undirectedAdjMatrix} 4 | \alias{undirectedAdjMatrix} 5 | \title{Coerce adjacency matrix to be undirected} 6 | \usage{ 7 | undirectedAdjMatrix(edgeList, nodeList, adjMatrix) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe where all nodes and their respective names are listed.} 13 | 14 | \item{adjMatrix}{The network represented as an adjacency matrix.} 15 | } 16 | \description{ 17 | A function that coerces an adjacency matrix to become undirected. 18 | } 19 | \examples{ 20 | undirectedAdjMatrix() 21 | } 22 | \keyword{undirected} 23 | -------------------------------------------------------------------------------- /R/isUndirected.R: -------------------------------------------------------------------------------- 1 | #' Query whether a network is undirected 2 | #' 3 | #' A function that queries whether some network data is undirected and returns a TRUE or FALSE value. 4 | #' @param edgeList A dataframe of network data where sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe where all nodes and their respective names are listed. 6 | #' @param adjMatrix The network represented as an adjacency matrix. 7 | #' @keywords undirected 8 | #' @export 9 | #' @examples 10 | #' isUndirected() 11 | 12 | isUndirected <- function(edgeList, nodeList, adjMatrix) { 13 | if (missing(adjMatrix)) { 14 | adjMatrix <- adjacencyMatrix(edgeList, 15 | nodeList) 16 | } 17 | return(FALSE %in% (adjMatrix == t(adjMatrix)) == FALSE) 18 | } 19 | -------------------------------------------------------------------------------- /man/middlemanPower.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/middlemanPower.R 3 | \name{middlemanPower} 4 | \alias{middlemanPower} 5 | \title{Calculate Middleman power for all nodes} 6 | \usage{ 7 | middlemanPower(edgeList, nodeList, adjMatrix, normalised) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe where all nodes and their respective names are listed.} 13 | 14 | \item{adjMatrix}{The network represented as an adjacency matrix.} 15 | } 16 | \description{ 17 | A function that calculates the middleman power of each node in a network. 18 | } 19 | \examples{ 20 | middlemanPower() 21 | } 22 | \keyword{brokerage} 23 | \keyword{middleman} 24 | -------------------------------------------------------------------------------- /man/connectivity.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/connectivity.R 3 | \name{connectivity} 4 | \alias{connectivity} 5 | \title{Connectivity of a network} 6 | \usage{ 7 | connectivity(edgeList, nodeList, adjMatrix) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data within which sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe within which all nodes and their respective names are listed.} 13 | 14 | \item{adjMatrix}{The network represented as an adjacency matrix.} 15 | } 16 | \description{ 17 | This function calculates the connectivity of a network by summing the number of unique successors of each node within the network. 18 | } 19 | \examples{ 20 | connectivity() 21 | } 22 | \keyword{connectivity} 23 | -------------------------------------------------------------------------------- /man/betaMeasure.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/betaMeasure.R 3 | \name{betaMeasure} 4 | \alias{betaMeasure} 5 | \title{Generalised beta-measure (Gilles and van den Brink, 2000) applied to each node} 6 | \usage{ 7 | betaMeasure(edgeList, nodeList) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data within which sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe within which all nodes and their respective names are listed.} 13 | } 14 | \description{ 15 | This function calculates the generalised beta-measure, or dominance, of each node as discussed in Gilles and ven den Brink (2000). This will also consider a weighted network. 16 | } 17 | \examples{ 18 | betaMeasure() 19 | } 20 | \keyword{beta-measure} 21 | -------------------------------------------------------------------------------- /man/hypergraphNeighbourhood.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hypergraphNeighbourhood.R 3 | \name{hypergraphNeighbourhood} 4 | \alias{hypergraphNeighbourhood} 5 | \title{Find the neighbourhood of each node} 6 | \usage{ 7 | hypergraphNeighbourhood(edgeList, nodeList) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to.} 11 | 12 | \item{nodeList}{A dataframe where all nodes and their respective names are listed.} 13 | } 14 | \description{ 15 | This function finds the neighbourhood of each node within a given hypergraph. 16 | } 17 | \examples{ 18 | hypergraphNeighbourhood() 19 | } 20 | \keyword{neighbour} 21 | \keyword{neighbourhood} 22 | -------------------------------------------------------------------------------- /R/filterNetwork.R: -------------------------------------------------------------------------------- 1 | #' Filter a networks edges 2 | #' 3 | #' This function filters a network such that it removes any duplicated connections, or more specifically arcs, between a pair of nodes. 4 | #' @param edgeList A dataframe of network data where sources are in the first column and targets are in the second column. 5 | #' @keywords filter 6 | #' @export 7 | #' @examples 8 | #' filterNetwork() 9 | 10 | filterNetwork <- function(edgeList) { 11 | for (i in 1:(nrow(edgeList) - 1)) { 12 | for (j in (i + 1):nrow(edgeList)) { 13 | if (edgeList$targets[i] == edgeList$sources[j] && 14 | edgeList$sources[i] == edgeList$targets[j]) { 15 | edgeList[i, ] <- 0 16 | } 17 | } 18 | } 19 | row_sub <- apply(edgeList, 1, function(row) all(row != 0)) 20 | edgeList <- edgeList[row_sub, ] 21 | return(edgeList) 22 | } 23 | -------------------------------------------------------------------------------- /R/undirectedAdjMatrix.R: -------------------------------------------------------------------------------- 1 | #' Coerce adjacency matrix to be undirected 2 | #' 3 | #' A function that coerces an adjacency matrix to become undirected. 4 | #' @param edgeList A dataframe of network data where sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe where all nodes and their respective names are listed. 6 | #' @param adjMatrix The network represented as an adjacency matrix. 7 | #' @keywords undirected 8 | #' @export 9 | #' @examples 10 | #' undirectedAdjMatrix() 11 | 12 | undirectedAdjMatrix <- function(edgeList, nodeList, adjMatrix) { 13 | if (missing(adjMatrix)) { 14 | adjMatrix <- adjacencyMatrix(edgeList, 15 | nodeList) 16 | } 17 | adjMatrix <- adjMatrix + t(adjMatrix) 18 | adjMatrix[, ] <- !adjMatrix %in% c("0", "FALSE") 19 | return(adjMatrix) 20 | } 21 | -------------------------------------------------------------------------------- /man/affiliationEnviornment.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/affiliationEnvironment.R 3 | \name{affiliationEnviornment} 4 | \alias{affiliationEnviornment} 5 | \title{Find the affiliation neighbourhood of each affiliation} 6 | \usage{ 7 | affiliationEnviornment(edgeList, affiliationList) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to.} 11 | 12 | \item{affiliationList}{A dataframe where all affiliations and their respective names are listed.} 13 | } 14 | \description{ 15 | This function transforms network data into an n-by-n adjacency matrix. 16 | } 17 | \examples{ 18 | affiliationEnviornment() 19 | } 20 | \keyword{affiliation} 21 | \keyword{environment} 22 | -------------------------------------------------------------------------------- /R/adjacencyMatrix.R: -------------------------------------------------------------------------------- 1 | #' Transform network data into an adjacency matrix 2 | #' 3 | #' This function transforms network data into an n-by-n adjacency matrix. 4 | #' @param edgeList A dataframe of network data where sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe where all nodes and their respective names are listed. 6 | #' @keywords adjacency matrix 7 | #' @export 8 | #' @examples 9 | #' adjacencyMatrix() 10 | 11 | adjacencyMatrix <- function(edgeList, nodeList) { 12 | networkMatrix <- matrix(data = 0L, 13 | nrow = nrow(nodeList), 14 | ncol = nrow(nodeList)) 15 | for (i in 1:nrow(edgeList)) { 16 | networkMatrix[edgeList[i, 1], edgeList[i, 2]] <- 17 | networkMatrix[edgeList[i, 1], edgeList[i, 2]] + 1 18 | } 19 | return(networkMatrix) 20 | } 21 | -------------------------------------------------------------------------------- /man/middlemanPowerDetail.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/middlemanPowerDetail.R 3 | \name{middlemanPowerDetail} 4 | \alias{middlemanPowerDetail} 5 | \title{Provide detailed results of middleman power fo all nodes} 6 | \usage{ 7 | middlemanPowerDetail(edgeList, nodeList, adjMatrix) 8 | } 9 | \arguments{ 10 | \item{nodeList}{A dataframe where all nodes and their respective names are listed.} 11 | 12 | \item{adjMatrix}{The network represented as an adjacency matrix.} 13 | 14 | \item{network}{A dataframe of network data where sources are in the first column and targets are in the second column.} 15 | } 16 | \description{ 17 | A function that returns detailed reults on each nodes middleman power in the network. 18 | } 19 | \examples{ 20 | middlemanPowerDetail() 21 | } 22 | \keyword{brokerage} 23 | \keyword{middleman} 24 | -------------------------------------------------------------------------------- /man/predecessorsSuccessors.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/predecessorsSuccessors.R 3 | \name{predecessorsSuccessors} 4 | \alias{predecessorsSuccessors} 5 | \title{Find the predecessors and successors of a node} 6 | \usage{ 7 | predecessorsSuccessors(edgeList, nodeList, adjMatrix) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data within which sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe within which all nodes and their respective names are listed.} 13 | 14 | \item{adjMatrix}{The network represented as an adjacency matrix.} 15 | } 16 | \description{ 17 | This function calculates the predecessors and successors of a node or node set. 18 | } 19 | \examples{ 20 | predecessorsSuccessors() 21 | } 22 | \keyword{node} 23 | \keyword{predecessors} 24 | \keyword{successors} 25 | -------------------------------------------------------------------------------- /R/degreeDistribution.R: -------------------------------------------------------------------------------- 1 | #' Plot degree distribution 2 | #' 3 | #' This function plots the degree distribution of a network. Depends on `ggplot2`. 4 | #' @param edgeList A dataframe of network data where sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe where all nodes and their respective names are listed. 6 | #' @keywords degree distribution 7 | #' @export 8 | #' @examples 9 | #' degreeDistribution() 10 | 11 | degreeDistribution <- function(edgeList, nodeList) { 12 | deg <- degree(edgeList, nodeList) 13 | degDistPlot <- ggplot2::ggplot(deg, 14 | aes(x = deg$degree)) + 15 | geom_histogram(binwidth = 0.5, 16 | alpha = 0.8) + 17 | labs(title = "Degree distribution", 18 | x = "Degree", 19 | y = "Count") + 20 | theme(legend.position = "none") 21 | return(degDistPlot) 22 | } 23 | -------------------------------------------------------------------------------- /man/potentialBrokerage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/potentialBrokerage.R 3 | \name{potentialBrokerage} 4 | \alias{potentialBrokerage} 5 | \title{Potential brokerage of a network} 6 | \usage{ 7 | potentialBrokerage(edgeList, nodeList, adjMatrix) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe where all nodes and their respective names are listed.} 13 | 14 | \item{adjMatrix}{The network represented as an adjacency matrix.} 15 | } 16 | \description{ 17 | A function that calculates the number of indirect relationships that exist, and therefore can be potentially brokered. This acts as a normaliser for `middlemanPower`. 18 | } 19 | \examples{ 20 | potentialBrokerage() 21 | } 22 | \keyword{brokerage} 23 | \keyword{middleman} 24 | -------------------------------------------------------------------------------- /R/averageDegree.R: -------------------------------------------------------------------------------- 1 | #' Calculate average node degree in network 2 | #' 3 | #' This function calculates the degree of all nodes in the network. This includes counting the in-degree and out-degree of each node. Averages of all degrees are also considered. 4 | #' @param edgeList A dataframe of network data where sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe where all nodes and their respective names are listed. 6 | #' @keywords degree 7 | #' @export 8 | #' @examples 9 | #' averageDegree() 10 | 11 | averageDegree <- function(edgeList, nodeList) { 12 | deg <- degree(edgeList, nodeList) 13 | avgDegree <- data.frame(avgInDegree = sum(deg$inDegree)/nrow(nodeList), 14 | avgOutDegree = sum(deg$outDegree)/nrow(nodeList), 15 | avgDegree = sum(deg$degree)/nrow(nodeList)) 16 | return(round(avgDegree, digits = 3)) 17 | } 18 | -------------------------------------------------------------------------------- /man/externalInfluence.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/externalInfluence.R 3 | \name{externalInfluence} 4 | \alias{externalInfluence} 5 | \title{Calculate the external influence of affiliations} 6 | \usage{ 7 | externalInfluence(edgeList, affiliationList, weight) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to.} 11 | 12 | \item{affiliationList}{A dataframe where all affiliations and their respective names are listed.} 13 | 14 | \item{weight}{The weight or value of an affiliation.} 15 | } 16 | \description{ 17 | This function calculates the external influence of affiliations within a hypergraph. Affiliations can have values, and therefore be weighted. 18 | } 19 | \examples{ 20 | externalInfluence() 21 | } 22 | \keyword{influence} 23 | -------------------------------------------------------------------------------- /R/affiliationSet.R: -------------------------------------------------------------------------------- 1 | #' List the affiliation memberships of each node 2 | #' 3 | #' This function returns a list of the membership of each node in the hypergraph 4 | #' @param edgeList A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to. 5 | #' @param nodeList A dataframe where all nodes and their respective names are listed. 6 | #' @keywords affiliation projection 7 | #' @export 8 | #' @examples 9 | #' affiliationSet() 10 | 11 | affiliationSet <- function(edgeList, nodeList) { 12 | for (i in 1:nrow(nodeList)) { 13 | if (i == 1) { 14 | affSet <- list(subset(edgeList$affiliations, 15 | edgeList$nodes == nodeList[i, 1])) 16 | } else { 17 | affSet[nodeList[i, 1]] <- list(subset(edgeList$affiliations, 18 | edgeList$nodes == nodeList[i, 1])) 19 | } 20 | } 21 | return(affSet) 22 | } 23 | -------------------------------------------------------------------------------- /R/potentialBrokerage.R: -------------------------------------------------------------------------------- 1 | #' Potential brokerage of a network 2 | #' 3 | #' A function that calculates the number of indirect relationships that exist, and therefore can be potentially brokered. This acts as a normaliser for `middlemanPower`. 4 | #' @param edgeList A dataframe of network data where sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe where all nodes and their respective names are listed. 6 | #' @param adjMatrix The network represented as an adjacency matrix. 7 | #' @keywords brokerage middleman 8 | #' @export 9 | #' @examples 10 | #' potentialBrokerage() 11 | 12 | potentialBrokerage <- function(edgeList, nodeList, adjMatrix) { 13 | d <- degree(edgeList, nodeList) 14 | PS <- predecessorsSuccessors(edgeList, nodeList, adjMatrix) 15 | potBrokerage <- 0 16 | for (i in 1:nrow(nodeList)) { 17 | potBrokerage <- potBrokerage + (PS$noSucc[i] - d$outDegree[i]) 18 | } 19 | potBrokerage <- max(potBrokerage, 1) 20 | return(potBrokerage) 21 | } 22 | -------------------------------------------------------------------------------- /man/criticalCoverage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/criticalCoverage.R 3 | \name{criticalCoverage} 4 | \alias{criticalCoverage} 5 | \title{Per capita coverage of all critical sets} 6 | \usage{ 7 | criticalCoverage(edgeList, nodeList, s, setPS, approximate) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data within which sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe within which all nodes and their respective names are listed.} 13 | 14 | \item{s}{The maximum size of block that is considered within the block formation game.} 15 | 16 | \item{setPS}{The set of predeccessors and successors for each combination of nodes considered.} 17 | 18 | \item{approximate}{Should the Strong Nash Equilibrium be approximated? TRUE or FALSE.} 19 | } 20 | \description{ 21 | This function calculates per capita coverage of all critical sets in the network. 22 | } 23 | \examples{ 24 | criticalCoverage() 25 | } 26 | \keyword{coverage} 27 | -------------------------------------------------------------------------------- /man/setPredSucc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/setPredSucc.R 3 | \name{setPredSucc} 4 | \alias{setPredSucc} 5 | \title{Find the predecessors and successors of a node set} 6 | \usage{ 7 | setPredSucc(edgeList, nodeList, s, adjMatrix, approximate) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data within which sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe within which all nodes and their respective names are listed.} 13 | 14 | \item{s}{The maximum size of block that is considered within the block formation game.} 15 | 16 | \item{adjMatrix}{The network represented as an adjacency matrix.} 17 | 18 | \item{approximate}{Should the number of sets considered be truncated? TRUE or FALSE.} 19 | } 20 | \description{ 21 | This function calculates the predecessors and successors of a node or node set. 22 | } 23 | \examples{ 24 | setPredSucc() 25 | } 26 | \keyword{node} 27 | \keyword{predecessors} 28 | \keyword{successors} 29 | -------------------------------------------------------------------------------- /R/density.R: -------------------------------------------------------------------------------- 1 | #' Density of a network 2 | #' 3 | #' This function calculates the density of a network graph. 4 | #' @param edgeList A dataframe of network data within which sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe within which all nodes and their respective names are listed. 6 | #' @param undirected Is the network graph undirected? TRUE or FALSE. 7 | #' @keywords density 8 | #' @export 9 | #' @examples 10 | #' density() 11 | 12 | density <- function(edgeList, nodeList, undirected = TRUE) { 13 | edges <- unique(edgeList[, ]) 14 | if (undirected) { 15 | undirectedNet <- rbind( 16 | edges, 17 | data.frame( 18 | sources = edges[, 2], 19 | targets = edges[, 1])) 20 | undirectedNet <- unique(undirectedNet[, ]) 21 | density <- nrow(undirectedNet) / (nrow(nodeList) * (nrow(nodeList) - 1)) 22 | } else { 23 | edges <- unique(edgeList[, ]) 24 | density <- nrow(edges) / (nrow(nodeList) * (nrow(nodeList) - 1)) 25 | } 26 | return(density) 27 | } 28 | -------------------------------------------------------------------------------- /man/elites.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/elites.R 3 | \name{elites} 4 | \alias{elites} 5 | \title{Find all elites in the hypergraph} 6 | \usage{ 7 | elites(edgeList, nodeList, affiliationList, typeList, e) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to.} 11 | 12 | \item{nodeList}{A dataframe where all node numbers and their respective names are listed.} 13 | 14 | \item{affiliationList}{A dataframe where all affiliation numbers and their respective names are listed.} 15 | 16 | \item{typeList}{Each affiliation is assigned a type; must be in order of affiliations.} 17 | 18 | \item{e}{The number of aspects that a node exists in order for it to be determined as an elite.} 19 | } 20 | \description{ 21 | This function lists all elites nodes in a hypergraph determined by some criteria. 22 | } 23 | \examples{ 24 | elites() 25 | } 26 | \keyword{elite} 27 | -------------------------------------------------------------------------------- /man/affiliationInfluence.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/affiliationInfluence.R 3 | \name{affiliationInfluence} 4 | \alias{affiliationInfluence} 5 | \title{Calculate the influence of affiliations within a hypergraph} 6 | \usage{ 7 | affiliationInfluence(edgeList, affiliationList, weights, normalise) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to.} 11 | 12 | \item{affiliationList}{A dataframe where all affiliations and their respective names are listed.} 13 | 14 | \item{normalise}{Should the influence score be normalised? TRUE or FALSE.} 15 | 16 | \item{weight}{The weight or value of an affiliation.} 17 | } 18 | \description{ 19 | The function calculates the influence of nodes and affiliations within a hypergraph. The measure accepts weights, or values, distributed over affiliations. 20 | } 21 | \examples{ 22 | affiliationInfluence() 23 | } 24 | \keyword{influence} 25 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(adjacencyDF) 4 | export(adjacencyMatrix) 5 | export(affiliationEnviornment) 6 | export(affiliationInfluence) 7 | export(affiliationProjection) 8 | export(affiliationSet) 9 | export(averageDegree) 10 | export(betaMeasure) 11 | export(blockSNE) 12 | export(connectivity) 13 | export(criticalCoverage) 14 | export(criticalSets) 15 | export(degree) 16 | export(degreeDistribution) 17 | export(density) 18 | export(elites) 19 | export(externalInfluence) 20 | export(filterNetwork) 21 | export(hypergraphNeighbourhood) 22 | export(isUndirected) 23 | export(middlemanPower) 24 | export(middlemanPowerDetail) 25 | export(nodeCoverage) 26 | export(nodeCriticality) 27 | export(nodeInfluence) 28 | export(nodeNormCriticality) 29 | export(nodeProjection) 30 | export(nodeSetBrokerage) 31 | export(potentialBrokerage) 32 | export(predecessorsSuccessors) 33 | export(randomGraph) 34 | export(robustness) 35 | export(setBrokerage) 36 | export(setCoverage) 37 | export(setCriticality) 38 | export(setPredSucc) 39 | export(strongWeak) 40 | export(undirectedAdjMatrix) 41 | -------------------------------------------------------------------------------- /R/connectivity.R: -------------------------------------------------------------------------------- 1 | #' Connectivity of a network 2 | #' 3 | #' This function calculates the connectivity of a network by summing the number of unique successors of each node within the network. 4 | #' @param edgeList A dataframe of network data within which sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe within which all nodes and their respective names are listed. 6 | #' @param adjMatrix The network represented as an adjacency matrix. 7 | #' @keywords connectivity 8 | #' @export 9 | #' @examples 10 | #' connectivity() 11 | 12 | connectivity <- function(edgeList, nodeList, adjMatrix) { 13 | if (missing(adjMatrix)) { 14 | adjMatrix <- adjacencyMatrix(edgeList, 15 | nodeList) 16 | } 17 | adjMatrix[, ] <- !adjMatrix %in% c("0", "FALSE") 18 | for (i in 1:nrow(adjMatrix)) { 19 | adjMatrix <- adjMatrix + expm::`%^%`(adjMatrix, i) 20 | adjMatrix[, ] <- !adjMatrix %in% c("0", "FALSE") 21 | } 22 | for (i in 1:nrow(adjMatrix)) { 23 | adjMatrix[i, i] <- 0 24 | } 25 | k <- sum(adjMatrix) 26 | return(k) 27 | } 28 | -------------------------------------------------------------------------------- /man/nodeCoverage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/nodeCoverage.R 3 | \name{nodeCoverage} 4 | \alias{nodeCoverage} 5 | \title{Calculate the coverage of each node} 6 | \usage{ 7 | nodeCoverage(edgeList, nodeList, s, adjMatrix, setPS, approximate) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data within which sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe within which all nodes and their respective names are listed.} 13 | 14 | \item{s}{The maximum size of block that is considered within the block formation game.} 15 | 16 | \item{adjMatrix}{The network represented as an adjacency matrix.} 17 | 18 | \item{setPS}{The set of predeccessors and successors for each combination of nodes considered.} 19 | 20 | \item{approximate}{Should the Strong Nash Equilibrium be approximated? TRUE or FALSE.} 21 | } 22 | \description{ 23 | This function calculates the coverage for each node based on their existence within blocks. 24 | } 25 | \examples{ 26 | nodeCoverage() 27 | } 28 | \keyword{coverage} 29 | \keyword{node} 30 | -------------------------------------------------------------------------------- /man/nodeInfluence.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/nodeInfluence.R 3 | \name{nodeInfluence} 4 | \alias{nodeInfluence} 5 | \title{Calculate the influence of nodes within a hypergraph} 6 | \usage{ 7 | nodeInfluence(edgeList, nodeList, affiliationList, weights, normalise) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to.} 11 | 12 | \item{nodeList}{A dataframe where all nodes and their respective names are listed.} 13 | 14 | \item{affiliationList}{A dataframe where all affiliations and their respective names are listed.} 15 | 16 | \item{normalise}{Should the influence score be normalised? TRUE or FALSE.} 17 | 18 | \item{weight}{The weight or value of an affiliation.} 19 | } 20 | \description{ 21 | The function calculates the influence of nodes and affiliations within a hypergraph. The measure accepts weights, or values, distributed over affiliations. 22 | } 23 | \examples{ 24 | nodeInfluence() 25 | } 26 | \keyword{influence} 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Owen Sims 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /man/setCoverage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/setCoverage.R 3 | \name{setCoverage} 4 | \alias{setCoverage} 5 | \title{Calculate the coverage of all sets of nodes} 6 | \usage{ 7 | setCoverage(edgeList, nodeList, s, adjMatrix, setPS, approximate) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data within which sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe within which all nodes and their respective names are listed.} 13 | 14 | \item{s}{The maximum size of block that is considered within the block formation game.} 15 | 16 | \item{adjMatrix}{The network represented as an adjacency matrix.} 17 | 18 | \item{setPS}{The set of predeccessors and successors for each combination of nodes considered.} 19 | 20 | \item{approximate}{Should the Strong Nash Equilibrium be approximated? TRUE or FALSE.} 21 | } 22 | \description{ 23 | This function calculates the coverage, i.e., the number of indirect connections that the node set faciliates, for each set of nodes in the network. 24 | } 25 | \examples{ 26 | setCoverage() 27 | } 28 | \keyword{coverage} 29 | -------------------------------------------------------------------------------- /R/degree.R: -------------------------------------------------------------------------------- 1 | #' Calculate node degree 2 | #' 3 | #' This function calculates the degree of all nodes in the network. This includes counting the in-degree and out-degree of each node. Averages of all degrees are also considered. 4 | #' @param edgeList A dataframe of network data where sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe where all nodes and their respective names are listed. 6 | #' @keywords degree 7 | #' @export 8 | #' @examples 9 | #' degree() 10 | 11 | degree <- function(edgeList, nodeList) { 12 | inDeg <- outDeg <- degree <- 0 13 | for (i in 1:nrow(nodeList)) { 14 | inDeg[i] <- sum(edgeList[, 2] == i) 15 | outDeg[i] <- sum(edgeList[, 1] == i) 16 | neighbours <- c(subset(edgeList[, 2], 17 | edgeList[, 1] == i), 18 | subset(edgeList[, 1], 19 | edgeList[, 2] == i)) 20 | degree[i] <- length(unique(neighbours)) 21 | } 22 | deg <- data.frame(name = nodeList[, 2], 23 | inDegree = inDeg, 24 | outDegree = outDeg, 25 | degree = degree) 26 | return(deg) 27 | } 28 | -------------------------------------------------------------------------------- /R/strongWeak.R: -------------------------------------------------------------------------------- 1 | #' Distinguish strong, weak, and Non-middlemen 2 | #' 3 | #' A function that returns whether individual nodes are strong, weak or non-middlemen 4 | #' @param edgeList A dataframe of network data where sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe where all nodes and their respective names are listed. 6 | #' @param adjMatrix The network represented as an adjacency matrix. 7 | #' @keywords brokerage middleman 8 | #' @export 9 | #' @examples 10 | #' strongWeak() 11 | 12 | strongWeak <- function(edgeList, nodeList, adjMatrix) { 13 | if (missing(adjMatrix)) { 14 | adjMatrix <- adjacencyMatrix(edgeList, nodeList) 15 | } 16 | power <- middlemanPower(edgeList, nodeList, adjMatrix) 17 | unAdjMatrix <- undirectedAdjMatrix(edgeList, nodeList, adjMatrix) 18 | unPower <- middlemanPower(edgeList, nodeList, unAdjMatrix) 19 | middlemanType <- sapply(1:length(power), function(x) { 20 | if (unPower[x] == 0 & power[x] == 0) { 21 | "Non-middleman" 22 | } else if (unPower[x] == 0 & power[x] > 0) { 23 | "Weak middleman" 24 | } else { 25 | "Strong middleman" 26 | } 27 | }) 28 | return(middlemanType) 29 | } 30 | -------------------------------------------------------------------------------- /man/criticalSets.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/criticalSets.R 3 | \name{criticalSets} 4 | \alias{criticalSets} 5 | \title{Find all critical sets in a network} 6 | \usage{ 7 | criticalSets(edgeList, nodeList, s, adjMatrix, setPS, setPower, approximate) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data within which sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe within which all nodes and their respective names are listed.} 13 | 14 | \item{s}{The maximum size of block that is considered within the block formation game.} 15 | 16 | \item{adjMatrix}{The network represented as an adjacency matrix.} 17 | 18 | \item{setPS}{The set of predeccessors and successors for each combination of nodes considered.} 19 | 20 | \item{setPower}{All sets within a network along with their respective brokerage scores.} 21 | 22 | \item{approximate}{Should the Strong Nash Equilibrium be approximated? TRUE or FALSE.} 23 | } 24 | \description{ 25 | This function calculates all critical sets in the network. 26 | } 27 | \examples{ 28 | criticalSets() 29 | } 30 | \keyword{critical} 31 | \keyword{sets} 32 | -------------------------------------------------------------------------------- /man/setBrokerage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/setBrokerage.R 3 | \name{setBrokerage} 4 | \alias{setBrokerage} 5 | \title{Brokerage of each node set within the network} 6 | \usage{ 7 | setBrokerage(edgeList, nodeList, s, adjMatrix, setPS, perCapita, approximate) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data within which sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe within which all nodes and their respective names are listed.} 13 | 14 | \item{s}{The maximum size of block that is considered within the block formation game.} 15 | 16 | \item{adjMatrix}{The network represented as an adjacency matrix.} 17 | 18 | \item{setPS}{The set of predeccessors and successors for each combination of nodes considered.} 19 | 20 | \item{perCapita}{The brokerage power of the node set divided by the number of nodes within the set.} 21 | 22 | \item{approximate}{Should the Strong Nash Equilibrium be approximated? TRUE or FALSE.} 23 | } 24 | \description{ 25 | This function calculates the brokerage of each set of nodes within the network. 26 | } 27 | \examples{ 28 | setBrokerage() 29 | } 30 | \keyword{brokerage} 31 | -------------------------------------------------------------------------------- /man/nodeSetBrokerage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/nodeSetBrokerage.R 3 | \name{nodeSetBrokerage} 4 | \alias{nodeSetBrokerage} 5 | \title{Brokerage of a node given its presence in a node set} 6 | \usage{ 7 | nodeSetBrokerage(edgeList, nodeList, s, perCapita, adjMatrix, setPS, setPower, 8 | approximate) 9 | } 10 | \arguments{ 11 | \item{edgeList}{A dataframe of network data within which sources are in the first column and targets are in the second column.} 12 | 13 | \item{nodeList}{A dataframe within which all nodes and their respective names are listed.} 14 | 15 | \item{s}{The maximum size of block that is considered within the block formation game.} 16 | 17 | \item{perCapita}{The brokerage power of the node set divided by the number of nodes within the set.} 18 | 19 | \item{adjMatrix}{The network represented as an adjacency matrix.} 20 | 21 | \item{setPS}{The set of predeccessors and successors for each combination of nodes considered.} 22 | 23 | \item{approximate}{Should the Strong Nash Equilibrium be approximated? TRUE or FALSE.} 24 | } 25 | \description{ 26 | This function calculates the brokerage of each node given its existence in critical sets. 27 | } 28 | \examples{ 29 | nodeSetBrokerage() 30 | } 31 | \keyword{brokerage} 32 | -------------------------------------------------------------------------------- /man/setCriticality.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/setCriticality.R 3 | \name{setCriticality} 4 | \alias{setCriticality} 5 | \title{Calculate the criticality of all node sets in Strong Nash equilibrium (SNE)} 6 | \usage{ 7 | setCriticality(edgeList, nodeList, c, s, adjMatrix, setPS, setPower, 8 | approximate) 9 | } 10 | \arguments{ 11 | \item{edgeList}{A dataframe of network data within which sources are in the first column and targets are in the second column.} 12 | 13 | \item{nodeList}{A dataframe within which all nodes and their respective names are listed.} 14 | 15 | \item{c}{The cost of signalling to, and adding an, extra node to a block.} 16 | 17 | \item{s}{The maximum size of block that is considered within the block formation game.} 18 | 19 | \item{adjMatrix}{The network represented as an adjacency matrix.} 20 | 21 | \item{setPS}{The set of predeccessors and successors for each combination of nodes considered.} 22 | 23 | \item{approximate}{Should the Strong Nash Equilibrium be approximated? TRUE or FALSE.} 24 | } 25 | \description{ 26 | This function calculates the criticality of all node sets that remain in all resulting SNE configurations of a block formation game. 27 | } 28 | \examples{ 29 | setCriticality() 30 | } 31 | \keyword{criticality} 32 | -------------------------------------------------------------------------------- /R/betaMeasure.R: -------------------------------------------------------------------------------- 1 | #' Generalised beta-measure (Gilles and van den Brink, 2000) applied to each node 2 | #' 3 | #' This function calculates the generalised beta-measure, or dominance, of each node as discussed in Gilles and ven den Brink (2000). This will also consider a weighted network. 4 | #' @param edgeList A dataframe of network data within which sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe within which all nodes and their respective names are listed. 6 | #' @keywords beta-measure 7 | #' @export 8 | #' @examples 9 | #' betaMeasure() 10 | 11 | betaMeasure <- function(edgeList, nodeList) { 12 | inDeg <- Beta <- 0 13 | for (i in 1:nrow(nodeList)) { 14 | inDeg[i] <- sum(edgeList[, 2] == i) 15 | } 16 | for (i in 1:nrow(nodeList)) { 17 | Beta[i] <- 0 18 | successorSet <- subset(edgeList, 19 | edgeList[, 1] == i) 20 | successorSet <- successorSet[, 2] 21 | 22 | if (length(successorSet) > 0) { 23 | for (j in 1:length(successorSet)) { 24 | Beta[i] <- Beta[i] + (1/inDeg[successorSet[j]]) 25 | } 26 | } 27 | } 28 | if (sum(Beta) == sum(inDeg > 0)) { 29 | return(round(Beta, digits = 3)) 30 | } else { 31 | return(print("We made a mistake in the calculation. HALP!")) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /man/nodeCriticality.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/nodeCriticality.R 3 | \name{nodeCriticality} 4 | \alias{nodeCriticality} 5 | \title{Calculate the criticality of each node} 6 | \usage{ 7 | nodeCriticality(edgeList, nodeList, c, s, adjMatrix, setPS, setPower, 8 | approximate) 9 | } 10 | \arguments{ 11 | \item{edgeList}{A dataframe of network data within which sources are in the first column and targets are in the second column.} 12 | 13 | \item{nodeList}{A dataframe within which all nodes and their respective names are listed.} 14 | 15 | \item{c}{The cost of signalling to, and adding an, extra node to a block.} 16 | 17 | \item{s}{The maximum size of block that is considered within the block formation game.} 18 | 19 | \item{adjMatrix}{The network represented as an adjacency matrix.} 20 | 21 | \item{setPS}{The set of predeccessors and successors for each combination of nodes considered.} 22 | 23 | \item{approximate}{Should the Strong Nash Equilibrium be approximated? TRUE or FALSE.} 24 | } 25 | \description{ 26 | This function calculates the criticality of each node in the network. Node criticality is derived from the resulting Strong Nash equilibrium (SNE) configuration from the block formation game. 27 | } 28 | \examples{ 29 | nodeCriticality() 30 | } 31 | \keyword{criticality} 32 | -------------------------------------------------------------------------------- /man/blockSNE.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/blockSNE.R 3 | \name{blockSNE} 4 | \alias{blockSNE} 5 | \title{Strong Nash equilibrium (SNE) configuration of a block formation game} 6 | \usage{ 7 | blockSNE(edgeList, nodeList, c, s, adjMatrix, setPS, setPower, approximate) 8 | } 9 | \arguments{ 10 | \item{edgeList}{A dataframe of network data within which sources are in the first column and targets are in the second column.} 11 | 12 | \item{nodeList}{A dataframe within which all nodes and their respective names are listed.} 13 | 14 | \item{c}{The cost of signalling to, and adding an, extra node to a block.} 15 | 16 | \item{s}{The maximum size of block that is considered within the block formation game.} 17 | 18 | \item{adjMatrix}{The network represented as an adjacency matrix.} 19 | 20 | \item{setPS}{The set of predeccessors and successors for each combination of nodes considered.} 21 | 22 | \item{approximate}{Should the Strong Nash Equilibrium be approximated? TRUE or FALSE.} 23 | 24 | \item{perCapita}{The brokerage power of the node set divided by the number of nodes within the set.} 25 | } 26 | \description{ 27 | This function calculates the resulting SNE configuration of a block formation game along with the brokerage of the restulting sets. 28 | } 29 | \examples{ 30 | blockSNE() 31 | } 32 | \keyword{brokerage} 33 | -------------------------------------------------------------------------------- /man/nodeNormCriticality.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/nodeNormCriticality.R 3 | \name{nodeNormCriticality} 4 | \alias{nodeNormCriticality} 5 | \title{Calculate the normalised criticality of each node} 6 | \usage{ 7 | nodeNormCriticality(edgeList, nodeList, c, s, adjMatrix, setPS, setPower, 8 | approximate) 9 | } 10 | \arguments{ 11 | \item{edgeList}{A dataframe of network data within which sources are in the first column and targets are in the second column.} 12 | 13 | \item{nodeList}{A dataframe within which all nodes and their respective names are listed.} 14 | 15 | \item{c}{The cost of signalling to, and adding an, extra node to a block.} 16 | 17 | \item{s}{The maximum size of block that is considered within the block formation game.} 18 | 19 | \item{adjMatrix}{The network represented as an adjacency matrix.} 20 | 21 | \item{setPS}{The set of predeccessors and successors for each combination of nodes considered.} 22 | 23 | \item{approximate}{Should the Strong Nash Equilibrium be approximated? TRUE or FALSE.} 24 | } 25 | \description{ 26 | This function calculates the normalised criticality of each node in the network. Node criticality is derived from the resulting Strong Nash equilibrium (SNE) configuration from the block formation game. 27 | } 28 | \examples{ 29 | nodeNormCriticality() 30 | } 31 | \keyword{criticality} 32 | -------------------------------------------------------------------------------- /R/criticalCoverage.R: -------------------------------------------------------------------------------- 1 | #' Per capita coverage of all critical sets 2 | #' 3 | #' This function calculates per capita coverage of all critical sets in the network. 4 | #' @param edgeList A dataframe of network data within which sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe within which all nodes and their respective names are listed. 6 | #' @param s The maximum size of block that is considered within the block formation game. 7 | #' @param setPS The set of predeccessors and successors for each combination of nodes considered. 8 | #' @param approximate Should the Strong Nash Equilibrium be approximated? TRUE or FALSE. 9 | #' @keywords coverage 10 | #' @export 11 | #' @examples 12 | #' criticalCoverage() 13 | 14 | criticalCoverage <- function(edgeList, nodeList, s, setPS, approximate) { 15 | if (missing(s)) { s <- nrow(nodeList) - 2 } 16 | if (missing(approximate)) { approximate <- FALSE } 17 | crits <- criticalSets(edgeList, 18 | nodeList, 19 | s, 20 | approximate = approximate) 21 | critsCov <- setCoverage(edgeList, 22 | nodeList, 23 | s, 24 | setPS = crits) 25 | critsCov$coverageMeasure <- round(critsCov$coverage/critsCov$setSize, 26 | digits = 3) 27 | return(critsCov) 28 | } 29 | -------------------------------------------------------------------------------- /R/hypergraphNeighbourhood.R: -------------------------------------------------------------------------------- 1 | #' Find the neighbourhood of each node 2 | #' 3 | #' This function finds the neighbourhood of each node within a given hypergraph. 4 | #' @param edgeList A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to. 5 | #' @param nodeList A dataframe where all nodes and their respective names are listed. 6 | #' @keywords neighbourhood neighbour 7 | #' @export 8 | #' @examples 9 | #' hypergraphNeighbourhood() 10 | 11 | hypergraphNeighbourhood <- function(edgeList, nodeList) { 12 | for (i in 1:nrow(nodeList)) { 13 | affSet <- subset(edgeList$affiliations, 14 | edgeList$nodes == nodeList[i, 1]) 15 | if (length(affSet) > 0) { 16 | for (j in 1:length(affSet)) { 17 | members <- subset(edgeList$nodes, 18 | edgeList$affiliations == affSet[j]) 19 | if (j == 1) { 20 | neighbours <- setdiff(members, 21 | nodeList[i, 1]) 22 | } else { 23 | neighbours <- setdiff(union(neighbours, members), 24 | nodeList[i, 1]) 25 | } 26 | } 27 | } 28 | if (i == 1) { 29 | neighbourhood <- list(neighbours) 30 | } else { 31 | neighbourhood[nodeList[i, 1]] <- list(neighbours) 32 | } 33 | } 34 | return(neighbourhood) 35 | } 36 | -------------------------------------------------------------------------------- /R/nodeProjection.R: -------------------------------------------------------------------------------- 1 | #' Represent a hypergraph as a network of nodes only 2 | #' 3 | #' This function projects a hypergraph into a network of nodes only. 4 | #' @param edgeList A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to. 5 | #' @keywords node projection 6 | #' @export 7 | #' @examples 8 | #' nodeProjection 9 | 10 | nodeProjection <- function(edgeList) { 11 | nodeNetwork <- data.frame(sources = 0, 12 | targets = 0) 13 | activeAffiliations <- unique(edgeList[, 2]) 14 | 15 | if (length(activeAffiliations) > 0) { 16 | for (i in 1:length(activeAffiliations)) { 17 | affiliationSet <- subset(edgeList[, 1], 18 | edgeList[, 2] == activeAffiliations[i]) 19 | connections <- data.frame(t(combn(affiliationSet, 20 | m = 2))) 21 | colnames(connections) <- c("sources", 22 | "targets") 23 | nodeNetwork <- rbind(nodeNetwork, 24 | connections, 25 | data.frame(sources = connections$targets, 26 | targets = connections$sources)) 27 | } 28 | nodeNetwork <- nodeNetwork[-1, ] 29 | return(nodeNetwork) 30 | } else { 31 | return(print("No affiliations to project!")) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /R/middlemanPowerDetail.R: -------------------------------------------------------------------------------- 1 | #' Provide detailed results of middleman power fo all nodes 2 | #' 3 | #' A function that returns detailed reults on each nodes middleman power in the network. 4 | #' @param network A dataframe of network data where sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe where all nodes and their respective names are listed. 6 | #' @param adjMatrix The network represented as an adjacency matrix. 7 | #' @keywords brokerage middleman 8 | #' @export 9 | #' @examples 10 | #' middlemanPowerDetail() 11 | 12 | middlemanPowerDetail <- function(edgeList, nodeList, adjMatrix) { 13 | if (missing(adjMatrix)) { 14 | adjMatrix <- adjacencyMatrix(edgeList, 15 | nodeList) 16 | } 17 | power <- middlemanPower(edgeList, 18 | nodeList, 19 | adjMatrix) 20 | normPower <- round(power/as.integer(potentialBrokerage(edgeList, 21 | nodeList)), 22 | digits = 3) 23 | type <- strongWeak(edgeList, 24 | nodeList, 25 | adjMatrix) 26 | details <- data.frame(number = nodeList[, 1], 27 | name = nodeList[, 2], 28 | power = power, 29 | normPower = normPower, 30 | type = type) 31 | return(details) 32 | } 33 | -------------------------------------------------------------------------------- /R/affiliationEnvironment.R: -------------------------------------------------------------------------------- 1 | #' Find the affiliation neighbourhood of each affiliation 2 | #' 3 | #' This function transforms network data into an n-by-n adjacency matrix. 4 | #' @param edgeList A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to. 5 | #' @param affiliationList A dataframe where all affiliations and their respective names are listed. 6 | #' @keywords affiliation environment 7 | #' @export 8 | #' @examples 9 | #' affiliationEnviornment() 10 | 11 | affiliationEnviornment <- function(edgeList, affiliationList) { 12 | for (i in 1:nrow(affiliationList)) { 13 | members <- subset(edgeList$nodes, 14 | edgeList$affiliations == affiliationList[i, 1]) 15 | if (i == 1) { 16 | membersList <- list(members) 17 | } else { 18 | membersList[affiliationList[i, 1]] <- list(members) 19 | } 20 | } 21 | for (i in 1:nrow(affiliationList)) { 22 | environment <- 0 23 | for (j in setdiff(seq(1, nrow(affiliationList)), i)) { 24 | if (length(intersect(membersList[[i]], membersList[[j]])) > 0) { 25 | environment <- c(environment, 26 | j) 27 | } 28 | } 29 | if (i == 1) { 30 | affEnviornment <- list(setdiff(environment, 0)) 31 | } else { 32 | affEnviornment[affiliationList[i, 1]] <- list(setdiff(environment, 0)) 33 | } 34 | } 35 | return(affEnviornment) 36 | } 37 | -------------------------------------------------------------------------------- /R/criticalSets.R: -------------------------------------------------------------------------------- 1 | #' Find all critical sets in a network 2 | #' 3 | #' This function calculates all critical sets in the network. 4 | #' @param edgeList A dataframe of network data within which sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe within which all nodes and their respective names are listed. 6 | #' @param s The maximum size of block that is considered within the block formation game. 7 | #' @param adjMatrix The network represented as an adjacency matrix. 8 | #' @param setPS The set of predeccessors and successors for each combination of nodes considered. 9 | #' @param setPower All sets within a network along with their respective brokerage scores. 10 | #' @param approximate Should the Strong Nash Equilibrium be approximated? TRUE or FALSE. 11 | #' @keywords critical sets 12 | #' @export 13 | #' @examples 14 | #' criticalSets() 15 | 16 | criticalSets <- function(edgeList, nodeList, s, adjMatrix, setPS, setPower, approximate) { 17 | if (missing(s)) { s <- nrow(nodeList) - 2 } 18 | if (missing(approximate)) { approximate <- FALSE } 19 | if (missing(setPower)) { 20 | setPower <- setBrokerage(edgeList, 21 | nodeList, 22 | s = s, 23 | adjMatrix, 24 | setPS, 25 | perCapita = FALSE, 26 | approximate = approximate) 27 | } 28 | criticalSets <- subset(setPower, 29 | setPower$power > 0) 30 | return(criticalSets) 31 | } 32 | -------------------------------------------------------------------------------- /R/predecessorsSuccessors.R: -------------------------------------------------------------------------------- 1 | #' Find the predecessors and successors of a node 2 | #' 3 | #' This function calculates the predecessors and successors of a node or node set. 4 | #' @param edgeList A dataframe of network data within which sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe within which all nodes and their respective names are listed. 6 | #' @param adjMatrix The network represented as an adjacency matrix. 7 | #' @keywords node predecessors successors 8 | #' @export 9 | #' @examples 10 | #' predecessorsSuccessors() 11 | 12 | predecessorsSuccessors <- function(edgeList, nodeList, adjMatrix) { 13 | if (missing(adjMatrix)) { 14 | adjMatrix <- adjacencyMatrix(edgeList, nodeList) 15 | } 16 | adjMatrix[, ] <- !adjMatrix %in% c("0", "FALSE") 17 | for (i in 1:nrow(adjMatrix)) { 18 | adjMatrix <- adjMatrix + expm::`%^%`(adjMatrix, i) 19 | adjMatrix[, ] <- !adjMatrix %in% c("0", "FALSE") 20 | } 21 | for (i in 1:nrow(adjMatrix)) { 22 | adjMatrix[i, i] <- 0 23 | } 24 | noSuccessors <- noPredecessors <- 0 25 | for (i in 1:nrow(adjMatrix)) { 26 | noSuccessors[i] <- length(which(adjMatrix[i, ] == 1)) 27 | noPredecessors[i] <- length(which(adjMatrix[, i] == 1)) 28 | } 29 | adjMatrix <- adjacencyMatrix(edgeList, nodeList) 30 | noPredecessorsSuccessors <- data.frame(nodeNumber = seq(1, nrow(adjMatrix)), 31 | nodeName = nodeList[, 2], 32 | noPred = noPredecessors, 33 | noSucc = noSuccessors) 34 | return(noPredecessorsSuccessors) 35 | } 36 | -------------------------------------------------------------------------------- /R/middlemanPower.R: -------------------------------------------------------------------------------- 1 | #' Calculate Middleman power for all nodes 2 | #' 3 | #' A function that calculates the middleman power of each node in a network. 4 | #' @param edgeList A dataframe of network data where sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe where all nodes and their respective names are listed. 6 | #' @param adjMatrix The network represented as an adjacency matrix. 7 | #' @keywords brokerage middleman 8 | #' @export 9 | #' @examples 10 | #' middlemanPower() 11 | 12 | middlemanPower <- function(edgeList, nodeList, adjMatrix, normalised) { 13 | if (missing(adjMatrix)) { 14 | originalAdjMatrix <- adjMatrix <- adjacencyMatrix(edgeList, nodeList) 15 | } else { 16 | originalAdjMatrix <- adjMatrix 17 | } 18 | if (missing(normalised)) { normalised <- FALSE } 19 | PS <- predecessorsSuccessors(edgeList = edgeList, 20 | nodeList = nodeList, 21 | adjMatrix = adjMatrix) 22 | K <- connectivity(adjMatrix = originalAdjMatrix) 23 | power <- 0 24 | for (i in 1:nrow(adjMatrix)) { 25 | adjMatrix <- originalAdjMatrix 26 | adjMatrix[i, ] <- adjMatrix[, i] <- 0 27 | kappa <- connectivity(adjMatrix = adjMatrix) 28 | power[i] <- K - kappa - PS$noPred[i] - PS$noSucc[i] 29 | } 30 | if (normalised == TRUE) { 31 | potBroker <- potentialBrokerage(edgeList = edgeList, 32 | nodeList = nodeList, 33 | adjMatrix = originalAdjMatrix) 34 | power <- round(power/as.integer(potBroker), 35 | digits = 3) 36 | } 37 | return(power) 38 | } 39 | -------------------------------------------------------------------------------- /R/setCriticality.R: -------------------------------------------------------------------------------- 1 | #' Calculate the criticality of all node sets in Strong Nash equilibrium (SNE) 2 | #' 3 | #' This function calculates the criticality of all node sets that remain in all resulting SNE configurations of a block formation game. 4 | #' @param edgeList A dataframe of network data within which sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe within which all nodes and their respective names are listed. 6 | #' @param c The cost of signalling to, and adding an, extra node to a block. 7 | #' @param s The maximum size of block that is considered within the block formation game. 8 | #' @param adjMatrix The network represented as an adjacency matrix. 9 | #' @param setPS The set of predeccessors and successors for each combination of nodes considered. 10 | #' @param approximate Should the Strong Nash Equilibrium be approximated? TRUE or FALSE. 11 | #' @keywords criticality 12 | #' @export 13 | #' @examples 14 | #' setCriticality() 15 | 16 | setCriticality <- function(edgeList, nodeList, c, s, adjMatrix, setPS, setPower, approximate) { 17 | if (missing(c)) { c <- 0 } 18 | if (missing(s)) { s <- nrow(nodeList) - 2 } 19 | if (missing(approximate)) { 20 | approximate <- FALSE 21 | } 22 | critMeasure <- blockSNE(edgeList, 23 | nodeList, 24 | c = c, 25 | s = s, 26 | approximate = approximate) 27 | colnames(critMeasure) <- c("set", "setSize", "successors", "predecessors", "noSucc", 28 | "noPred", "criticality", "criticalityMeasure") 29 | return(critMeasure) 30 | } 31 | -------------------------------------------------------------------------------- /R/affiliationProjection.R: -------------------------------------------------------------------------------- 1 | #' Represent a hypergraph as a network of affiliations 2 | #' 3 | #' This function projects a hypergraph into a network of affiliations. 4 | #' @param edgeList A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to. 5 | #' @keywords affiliation projection 6 | #' @export 7 | #' @examples 8 | #' affiliationProjection() 9 | 10 | affiliationProjection <- function(edgeList) { 11 | affiliationNetwork <- data.frame(sources = 0, 12 | targets = 0, 13 | weight = 0) 14 | activeAffiliations <- unique(edgeList[, 2]) 15 | if (length(activeAffiliations) > 0) { 16 | for (i in 1:length(activeAffiliations)) { 17 | members <- subset(edgeList[, 1], 18 | edgeList[, 2] == activeAffiliations[i]) 19 | otherAffiliations <- setdiff(activeAffiliations, 20 | activeAffiliations[i]) 21 | for (j in 1:length(otherAffiliations)) { 22 | overlap <- intersect(members, 23 | subset(edgeList[, 1], 24 | edgeList[, 2] == otherAffiliations[j])) 25 | if (length(overlap) > 0) { 26 | affiliationNetwork <- rbind(affiliationNetwork, 27 | c(activeAffiliations[i], 28 | otherAffiliations[j], 29 | length(overlap))) 30 | } 31 | } 32 | } 33 | } 34 | affiliationNetwork <- affiliationNetwork[-1, ] 35 | return(affiliationNetwork) 36 | } 37 | -------------------------------------------------------------------------------- /R/nodeCoverage.R: -------------------------------------------------------------------------------- 1 | #' Calculate the coverage of each node 2 | #' 3 | #' This function calculates the coverage for each node based on their existence within blocks. 4 | #' @param edgeList A dataframe of network data within which sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe within which all nodes and their respective names are listed. 6 | #' @param s The maximum size of block that is considered within the block formation game. 7 | #' @param adjMatrix The network represented as an adjacency matrix. 8 | #' @param setPS The set of predeccessors and successors for each combination of nodes considered. 9 | #' @param approximate Should the Strong Nash Equilibrium be approximated? TRUE or FALSE. 10 | #' @keywords node coverage 11 | #' @export 12 | #' @examples 13 | #' nodeCoverage() 14 | 15 | nodeCoverage <- function(edgeList, nodeList, s, adjMatrix, setPS, approximate) { 16 | if (missing(s)) { s <- nrow(nodeList) - 2 } 17 | if (missing(approximate)) { approximate <- FALSE } 18 | coverage <- criticalCoverage(edgeList, 19 | nodeList, 20 | s = s, 21 | approximate = approximate) 22 | normaliser <- sum(coverage$coverageMeasure) 23 | nodeNormCoverage <- 0 24 | for (i in 1:nrow(nodeList)) { 25 | r <- coverage 26 | t <- sapply(1:nrow(r), function(x) i %in% r$set[[x]]) 27 | r <- r[t, ] 28 | if (nrow(r) > 0) { 29 | nodeNormCoverage[i] <- sum(r$coverageMeasure) 30 | } else { 31 | nodeNormCoverage[i] <- 0 32 | } 33 | } 34 | nodeNormCoverage <- round(nodeNormCoverage/normaliser, 35 | digits = 3) 36 | return(nodeNormCoverage) 37 | } 38 | -------------------------------------------------------------------------------- /R/elites.R: -------------------------------------------------------------------------------- 1 | #' Find all elites in the hypergraph 2 | #' 3 | #' This function lists all elites nodes in a hypergraph determined by some criteria. 4 | #' @param edgeList A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to. 5 | #' @param nodeList A dataframe where all node numbers and their respective names are listed. 6 | #' @param affiliationList A dataframe where all affiliation numbers and their respective names are listed. 7 | #' @param typeList Each affiliation is assigned a type; must be in order of affiliations. 8 | #' @param e The number of aspects that a node exists in order for it to be determined as an elite. 9 | #' @keywords elite 10 | #' @export 11 | #' @examples 12 | #' elites() 13 | 14 | elites <- function(edgeList, nodeList, affiliationList, typeList, e) { 15 | if (missing(e)) { e <- length(unique(typeList)) } 16 | if (e > length(unique(typeList))) { 17 | return(print("e must be less than or equal to the number of aspects in the hypergraph.")) 18 | } 19 | presence <- 0 20 | for (i in 1:nrow(nodeList)) { 21 | affiliationMembership <- subset(edgeList[, 2], 22 | edgeList[, 1] == nodeList[i, 1]) 23 | if (length(affiliationMembership) > 0) { 24 | for (j in 1:length(affiliationMembership)) { 25 | match <- match(affiliationMembership[j], 26 | affiliationList[, 1]) 27 | t <- typeList[match] 28 | if (j == 1) { 29 | ty <- t 30 | } else { 31 | ty <- unique(c(ty, t)) 32 | } 33 | } 34 | } 35 | presence[i] <- length(ty) 36 | } 37 | elites <- subset(nodeList, 38 | presence >= e) 39 | return(elites) 40 | } 41 | -------------------------------------------------------------------------------- /R/externalInfluence.R: -------------------------------------------------------------------------------- 1 | #' Calculate the external influence of affiliations 2 | #' 3 | #' This function calculates the external influence of affiliations within a hypergraph. Affiliations can have values, and therefore be weighted. 4 | #' @param edgeList A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to. 5 | #' @param affiliationList A dataframe where all affiliations and their respective names are listed. 6 | #' @param weight The weight or value of an affiliation. 7 | #' @keywords influence 8 | #' @export 9 | #' @examples 10 | #' externalInfluence() 11 | 12 | externalInfluence <- function(edgeList, affiliationList, weight) { 13 | if (missing(weight)) { weight <- rep(1, nrow(affiliationList)) } 14 | external <- affiliationMembership <- 0 15 | activeAffiliations <- unique(edgeList[, 2]) 16 | affiliationNetwork <- affiliationProjection(edgeList) 17 | for (i in 1:length(unique(edgeList[, 2]))) { 18 | affiliationMembership[activeAffiliations[i]] <- length(unique(subset(edgeList[, 1], 19 | edgeList[, 2] == activeAffiliations[i]))) 20 | } 21 | for (i in 1:nrow(affiliationList)) { 22 | external[affiliationList[i, 1]] <- 0 23 | subNetwork <- unique(subset(affiliationNetwork, 24 | affiliationNetwork[, 1] == affiliationList[i, 1])) 25 | neighbours <- subNetwork[, 2] 26 | 27 | if (length(neighbours) > 0) { 28 | for (j in 1:length(neighbours)) { 29 | external[affiliationList[i, 1]] <- external[affiliationList[i, 1]] + (weight[neighbours[j]] * (subNetwork[j, 3]/affiliationMembership[neighbours[j]])) 30 | } 31 | } 32 | } 33 | return(external) 34 | } 35 | 36 | -------------------------------------------------------------------------------- /R/nodeCriticality.R: -------------------------------------------------------------------------------- 1 | #' Calculate the criticality of each node 2 | #' 3 | #' This function calculates the criticality of each node in the network. Node criticality is derived from the resulting Strong Nash equilibrium (SNE) configuration from the block formation game. 4 | #' @param edgeList A dataframe of network data within which sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe within which all nodes and their respective names are listed. 6 | #' @param c The cost of signalling to, and adding an, extra node to a block. 7 | #' @param s The maximum size of block that is considered within the block formation game. 8 | #' @param adjMatrix The network represented as an adjacency matrix. 9 | #' @param setPS The set of predeccessors and successors for each combination of nodes considered. 10 | #' @param approximate Should the Strong Nash Equilibrium be approximated? TRUE or FALSE. 11 | #' @keywords criticality 12 | #' @export 13 | #' @examples 14 | #' nodeCriticality() 15 | 16 | nodeCriticality <- function(edgeList, nodeList, c, s, adjMatrix, setPS, setPower, approximate) { 17 | if (missing(s)) { c <- 0 } 18 | if (missing(s)) { s <- nrow(nodeList) - 2 } 19 | if (missing(approximate)) { approximate <- FALSE } 20 | critMeasure <- setCriticality(edgeList, 21 | nodeList, 22 | c = c, 23 | s = s, 24 | approximate = approximate) 25 | nodeCriticality <- 0 26 | for (i in 1:nrow(nodeList)) { 27 | r <- critMeasure 28 | t <- sapply(1:nrow(r), function(x) i %in% r$set[[x]]) 29 | r <- r[t, ] 30 | if (nrow(r) > 0) { 31 | nodeCriticality[i] <- sum(r$criticalityMeasure) 32 | } else { 33 | nodeCriticality[i] <- 0 34 | } 35 | } 36 | return(nodeCriticality) 37 | } 38 | -------------------------------------------------------------------------------- /R/nodeInfluence.R: -------------------------------------------------------------------------------- 1 | #' Calculate the influence of nodes within a hypergraph 2 | #' 3 | #' The function calculates the influence of nodes and affiliations within a hypergraph. The measure accepts weights, or values, distributed over affiliations. 4 | #' @param edgeList A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to. 5 | #' @param nodeList A dataframe where all nodes and their respective names are listed. 6 | #' @param affiliationList A dataframe where all affiliations and their respective names are listed. 7 | #' @param weight The weight or value of an affiliation. 8 | #' @param normalise Should the influence score be normalised? TRUE or FALSE. 9 | #' @keywords influence 10 | #' @export 11 | #' @examples 12 | #' nodeInfluence() 13 | 14 | nodeInfluence <- function(edgeList, nodeList, affiliationList, weights, normalise) { 15 | if (missing(weights)) { weights <- rep(1, nrow(affiliationList)) } 16 | if (missing(normalise)) { normalise <- FALSE } 17 | sigma <- affiliationMembership <- 0 18 | activeAffiliations <- unique(edgeList[, 2]) 19 | for (i in 1:length(unique(edgeList[, 2]))) { 20 | affiliationMembership[activeAffiliations[i]] <- length(unique(subset(edgeList[, 1], 21 | edgeList[, 2] == activeAffiliations[i]))) 22 | } 23 | for (i in 1:nrow(nodeList)) { 24 | sigma[i] <- 0 25 | affiliations <- subset(edgeList[, 2], 26 | edgeList[, 1] == nodeList[i, 1]) 27 | for (j in 1:length(affiliations)) { 28 | sigma[i] <- sigma[i] + (weights[affiliations[j]]/affiliationMembership[affiliations[j]]) 29 | } 30 | } 31 | if (normalise == TRUE) { 32 | sigma <- sigma/sum(weights) 33 | } 34 | return(round(sigma, digits = 3)) 35 | } 36 | -------------------------------------------------------------------------------- /R/nodeSetBrokerage.R: -------------------------------------------------------------------------------- 1 | #' Brokerage of a node given its presence in a node set 2 | #' 3 | #' This function calculates the brokerage of each node given its existence in critical sets. 4 | #' @param edgeList A dataframe of network data within which sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe within which all nodes and their respective names are listed. 6 | #' @param s The maximum size of block that is considered within the block formation game. 7 | #' @param adjMatrix The network represented as an adjacency matrix. 8 | #' @param setPS The set of predeccessors and successors for each combination of nodes considered. 9 | #' @param perCapita The brokerage power of the node set divided by the number of nodes within the set. 10 | #' @param approximate Should the Strong Nash Equilibrium be approximated? TRUE or FALSE. 11 | #' @keywords brokerage 12 | #' @export 13 | #' @examples 14 | #' nodeSetBrokerage() 15 | 16 | nodeSetBrokerage <- function(edgeList, nodeList, s, perCapita, adjMatrix, setPS, setPower, approximate) { 17 | if (missing(s)) { 18 | s <- nrow(nodeList) - 2 19 | } 20 | if (missing(perCapita)) { 21 | perCapita <- TRUE 22 | } 23 | if (missing(approximate)) { 24 | approximate <- FALSE 25 | } 26 | setBrokerage <- setBrokerage(edgeList, 27 | nodeList, 28 | s = s, 29 | perCapita = perCapita, 30 | approximate = approximate) 31 | nodeSetBrokerage <- 0 32 | for (i in 1:nrow(nodeList)) { 33 | r <- setBrokerage 34 | t <- sapply(1:nrow(r), function(x) i %in% r$set[[x]]) 35 | r <- r[t, ] 36 | nodeSetBrokerage[i] <- sum(r$powerCapita) 37 | } 38 | nodeSetBrokerage <- round(nodeSetBrokerage/sum(setBrokerage$powerCapita), 39 | digits = 3) 40 | return(nodeSetBrokerage) 41 | } 42 | -------------------------------------------------------------------------------- /R/nodeNormCriticality.R: -------------------------------------------------------------------------------- 1 | #' Calculate the normalised criticality of each node 2 | #' 3 | #' This function calculates the normalised criticality of each node in the network. Node criticality is derived from the resulting Strong Nash equilibrium (SNE) configuration from the block formation game. 4 | #' @param edgeList A dataframe of network data within which sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe within which all nodes and their respective names are listed. 6 | #' @param c The cost of signalling to, and adding an, extra node to a block. 7 | #' @param s The maximum size of block that is considered within the block formation game. 8 | #' @param adjMatrix The network represented as an adjacency matrix. 9 | #' @param setPS The set of predeccessors and successors for each combination of nodes considered. 10 | #' @param approximate Should the Strong Nash Equilibrium be approximated? TRUE or FALSE. 11 | #' @keywords criticality 12 | #' @export 13 | #' @examples 14 | #' nodeNormCriticality() 15 | 16 | nodeNormCriticality <- function(edgeList, nodeList, c, s, adjMatrix, setPS, setPower, approximate) { 17 | if (missing(c)) { c <- 0 } 18 | if (missing(s)) { s <- nrow(nodeList) - 2 } 19 | if (missing(approximate)) { approximate <- FALSE } 20 | critMeasure <- setCriticality(edgeList, 21 | nodeList, 22 | c = c, 23 | s = s, 24 | approximate = approximate) 25 | normaliser <- sum(critMeasure$criticalityMeasure) 26 | nodeNormCriticality <- 0 27 | for (i in 1:nrow(nodeList)) { 28 | r <- critMeasure 29 | t <- sapply(1:nrow(r), function(x) i %in% r$set[[x]]) 30 | r <- r[t, ] 31 | if (nrow(r) > 0) { 32 | nodeNormCriticality[i] <- sum(r$criticalityMeasure) 33 | } else { 34 | nodeNormCriticality[i] <- 0 35 | } 36 | } 37 | nodeNormCriticality <- round(nodeNormCriticality/normaliser, 38 | digits = 3) 39 | return(nodeNormCriticality) 40 | } 41 | -------------------------------------------------------------------------------- /R/affiliationInfluence.R: -------------------------------------------------------------------------------- 1 | #' Calculate the influence of affiliations within a hypergraph 2 | #' 3 | #' The function calculates the influence of nodes and affiliations within a hypergraph. The measure accepts weights, or values, distributed over affiliations. 4 | #' @param edgeList A dataframe of network data where nodes are in the first column and affiliations are in the second column. Nodes are members of the affiliation that they are next to. 5 | #' @param affiliationList A dataframe where all affiliations and their respective names are listed. 6 | #' @param weight The weight or value of an affiliation. 7 | #' @param normalise Should the influence score be normalised? TRUE or FALSE. 8 | #' @keywords influence 9 | #' @export 10 | #' @examples 11 | #' affiliationInfluence() 12 | 13 | affiliationInfluence <- function(edgeList, affiliationList, weights, normalise) { 14 | if (missing(weights)) { weights <- rep(1, max(affiliationList$number)) } 15 | if (missing(normalise)) { normalise <- FALSE } 16 | sigma <- affiliationMembership <- 0 17 | activeAffiliations <- unique(edgeList[, 2]) 18 | affiliationNetwork <- affiliationProjection(edgeList) 19 | for (i in 1:length(unique(edgeList[, 2]))) { 20 | affiliationMembership[activeAffiliations[i]] <- length(unique(subset(edgeList[, 1], 21 | edgeList[, 2] == activeAffiliations[i]))) 22 | } 23 | for (i in 1:nrow(affiliationList)) { 24 | sigma[affiliationList[i, 1]] <- weights[affiliationList[i, 1]] 25 | subNetwork <- unique(subset(affiliationNetwork, 26 | affiliationNetwork[, 1] == affiliationList[i, 1])) 27 | if (nrow(subNetwork) > 0) { 28 | neighbours <- subNetwork[, 2] 29 | for (j in 1:length(neighbours)) { 30 | sigma[affiliationList[i, 1]] <- 31 | sigma[affiliationList[i, 1]] + (weights[neighbours[j]] * (subNetwork[j, 3]/max(affiliationMembership[neighbours[j]], 1))) 32 | } 33 | } 34 | } 35 | if (normalise == TRUE) { 36 | sigma <- sigma/sum(weights) 37 | } 38 | return(sigma) 39 | } 40 | -------------------------------------------------------------------------------- /R/robustness.R: -------------------------------------------------------------------------------- 1 | #' Calculate the robustness of a middleman position 2 | #' 3 | #' Robustness of a middleman measured by the number of arcs that need to be removed in order for a middleman to lose its position as a middleman. 4 | #' @param edgeList A dataframe of network data where sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe where all nodes and their respective names are listed. 6 | #' @keywords robustness 7 | #' @export 8 | #' @examples 9 | #' robustness() 10 | 11 | robustness <- function(edgeList, nodeList) { 12 | robust <- rep(0, 13 | nrow(nodeList)) 14 | nodeList$power <- middlemanPower(edgeList, nodeList) 15 | middlemen <- middlemanSet <- subset(nodeList[, 1], 16 | nodeList$power > 0) 17 | connections <- as.data.frame(gtools::permutations(n = length(nodeList[, 1]), 18 | r = 2, 19 | v = nodeList[, 1])) 20 | colnames(connections) <- c("sources", 21 | "targets") 22 | for (j in 1:nrow(connections)) { 23 | print(paste0(j)) 24 | combinations <- combn(1:nrow(connections), 25 | m = j) 26 | for (h in 1:ncol(combinations)) { 27 | newEdgeList <- rbind(edgeList, 28 | connections[combinations[, h], ]) 29 | newEdgeList <- unique(newEdgeList[,]) 30 | nodeList$power <- middlemanPower(newEdgeList, 31 | nodeList) 32 | newMiddlemen <- subset(nodeList[, 1], 33 | nodeList$power > 0) 34 | l <- setdiff(middlemanSet, 35 | newMiddlemen) 36 | if (length(l) > 0) { 37 | for (k in 1:length(l)) { robust[l[k]] <- j } 38 | middlemanSet <- setdiff(middlemanSet, l) 39 | print(paste0("New middleman set : ", middlemanSet)) 40 | print(cbind(nodeList[, 1], robust)) 41 | if (length(middlemanSet) == 0) { 42 | return(cbind(nodeList[, 1], robust)) 43 | } 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /R/blockSNE.R: -------------------------------------------------------------------------------- 1 | #' Strong Nash equilibrium (SNE) configuration of a block formation game 2 | #' 3 | #' This function calculates the resulting SNE configuration of a block formation game along with the brokerage of the restulting sets. 4 | #' @param edgeList A dataframe of network data within which sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe within which all nodes and their respective names are listed. 6 | #' @param c The cost of signalling to, and adding an, extra node to a block. 7 | #' @param s The maximum size of block that is considered within the block formation game. 8 | #' @param adjMatrix The network represented as an adjacency matrix. 9 | #' @param setPS The set of predeccessors and successors for each combination of nodes considered. 10 | #' @param perCapita The brokerage power of the node set divided by the number of nodes within the set. 11 | #' @param approximate Should the Strong Nash Equilibrium be approximated? TRUE or FALSE. 12 | #' @keywords brokerage 13 | #' @export 14 | #' @examples 15 | #' blockSNE() 16 | 17 | blockSNE <- function(edgeList, nodeList, c, s, adjMatrix, setPS, setPower, approximate) { 18 | if (missing(s)) { s <- nrow(nodeList) - 2 } 19 | if (missing(approximate)) { approximate <- FALSE } 20 | if (missing(setPower)) { 21 | setPower <- setBrokerage(edgeList, 22 | nodeList, 23 | s = s, 24 | adjMatrix, 25 | setPS, 26 | perCapita = TRUE, 27 | approximate = approximate) 28 | } 29 | if (missing(c)) { c <- 0 } 30 | setPower$powerCapita <- setPower$powerCapita - (c * (setPower$setSize - 1)) 31 | setPower <- subset(setPower, 32 | setPower$powerCapita > 0) 33 | setPower <- setPower[order(-setPower$powerCapita), ] 34 | for (i in 1:(nrow(setPower) - 1)) { 35 | for (j in (i + 1):nrow(setPower)) { 36 | if (setPower$setSize[j] != 0) { 37 | if (TRUE %in% (setPower$set[[i]] %in% setPower$set[[j]])) { 38 | setPower$set[[j]] <- setPower$setSize[j] <- 0 39 | } 40 | } 41 | } 42 | } 43 | SNE <- setPower[!(setPower$setSize == 0), ] 44 | return(SNE) 45 | } 46 | -------------------------------------------------------------------------------- /R/setCoverage.R: -------------------------------------------------------------------------------- 1 | #' Calculate the coverage of all sets of nodes 2 | #' 3 | #' This function calculates the coverage, i.e., the number of indirect connections that the node set faciliates, for each set of nodes in the network. 4 | #' @param edgeList A dataframe of network data within which sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe within which all nodes and their respective names are listed. 6 | #' @param s The maximum size of block that is considered within the block formation game. 7 | #' @param adjMatrix The network represented as an adjacency matrix. 8 | #' @param setPS The set of predeccessors and successors for each combination of nodes considered. 9 | #' @param approximate Should the Strong Nash Equilibrium be approximated? TRUE or FALSE. 10 | #' @keywords coverage 11 | #' @export 12 | #' @examples 13 | #' setCoverage() 14 | 15 | setCoverage <- function(edgeList, nodeList, s, adjMatrix, setPS, approximate) { 16 | if (missing(s)) { s <- nrow(nodeList) - 2 } 17 | if (missing(approximate)) { approximate <- FALSE } 18 | if (missing(adjMatrix)) { 19 | originalAdjMatrix <- adjMatrix <- adjacencyMatrix(edgeList, 20 | nodeList) 21 | } else { 22 | originalAdjMatrix <- adjMatrix 23 | } 24 | if (missing(setPS)) { setPS <- setPredSucc(edgeList, nodeList, s, adjMatrix, approximate = approximate) } 25 | ps <- setPredSucc(edgeList, 26 | nodeList, 27 | s = 1) 28 | coverage <- 0 29 | for (i in 1:nrow(setPS)) { 30 | for (h in 1:length(setPS$set[[i]])) { 31 | if (h == 1) { 32 | cov <- expand.grid(c(setdiff(ps$predecessors[[setPS$set[[i]][h]]], setPS$set[[i]])), 33 | c(setdiff(ps$successors[[setPS$set[[i]][h]]], setPS$set[[i]]))) 34 | } else { 35 | cov <- rbind(cov, 36 | expand.grid(c(setdiff(ps$predecessors[[setPS$set[[i]][h]]], setPS$set[[i]])), 37 | c(setdiff(ps$successors[[setPS$set[[i]][h]]], setPS$set[[i]])))) 38 | } 39 | } 40 | row_sub = apply(cov, 1, function(row) all(row != 0)) 41 | cov <- cov[row_sub, ] 42 | if (nrow(cov) > 0) { 43 | for (j in 1:nrow(cov)) { 44 | if (cov[j, 1] == cov[j, 2]) { 45 | cov[j, 1] <- cov[j, 2] <- 0 46 | } 47 | } 48 | } 49 | row_sub = apply(cov, 1, function(row) all(row != 0)) 50 | cov <- cov[row_sub, ] 51 | coverage[i] <- nrow(unique(cov[, ])) 52 | } 53 | setPS$coverage <- coverage 54 | return(setPS) 55 | } 56 | -------------------------------------------------------------------------------- /R/randomGraph.R: -------------------------------------------------------------------------------- 1 | #' Generate a random network 2 | #' 3 | #' The function generates a randomly connected network. 4 | #' @param n The number of nodes to be present within the network. 5 | #' @param p The probability that any two nodes are connected together. 6 | #' @param undirected should the randomly generated network be undirected? TRUE or FALSE. 7 | #' @keywords random graph network 8 | #' @export 9 | #' @examples 10 | #' randomGraph() 11 | 12 | randomGraph <- function(n, p, undirected) { 13 | if (n < 2) { 14 | return(print("You need a population of more than 1 node...")) 15 | } 16 | if (p < 0 || p > 1) { 17 | return(print("p can't be below zero or greater than 1...")) 18 | } else if (p == 0) { 19 | network <- data.frame(sources = NA, 20 | targets = NA) 21 | return(network) 22 | } else { 23 | m <- max(1, n * round(n * p, 24 | digits = 0)) 25 | } 26 | if (missing(undirected)) { undirected <- FALSE } 27 | network <- data.frame(sources = round(runif(n = m, 28 | min = 1, 29 | max = n), 30 | digits = 0), 31 | targets = round(runif(n = m, 32 | min = 1, 33 | max = n), 34 | digits = 0)) 35 | network <- unique(network[,]) 36 | for (i in 1:nrow(network)) { 37 | if (network$sources[i] == network$targets[i]) { 38 | network[i, ] <- 0 39 | } 40 | } 41 | row_sub <- apply(network, 1, function(row) all(row != 0)) 42 | network <- network[row_sub, ] 43 | if (nrow(network) < m) { 44 | while (nrow(network) < m) { 45 | buffer <- m - nrow(network) 46 | addNetwork <- data.frame(sources = round(runif(n = buffer, 47 | min = 1, 48 | max = n), 49 | digits = 0), 50 | targets = round(runif(n = buffer, 51 | min = 1, 52 | max = n), 53 | digits = 0)) 54 | addNetwork <- unique(addNetwork[,]) 55 | for (i in 1:nrow(addNetwork)) { 56 | if (addNetwork$sources[i] == addNetwork$targets[i]) { 57 | addNetwork[-i, ] <- 0 58 | } 59 | } 60 | if (0 %in% addNetwork$sources) { 61 | row_sub <- apply(addNetwork, 1, function(row) all(row != 0)) 62 | addNetwork <- addNetwork[row_sub, ] 63 | } 64 | network <- rbind(network, addNetwork) 65 | network <- unique(network[,]) 66 | } 67 | } 68 | if (undirected == TRUE) { 69 | unNetwork <- data.frame(sources = network$targets, 70 | targets = network$sources) 71 | network <- rbind(network, unNetwork) 72 | } 73 | return(network) 74 | } 75 | -------------------------------------------------------------------------------- /R/setBrokerage.R: -------------------------------------------------------------------------------- 1 | #' Brokerage of each node set within the network 2 | #' 3 | #' This function calculates the brokerage of each set of nodes within the network. 4 | #' @param edgeList A dataframe of network data within which sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe within which all nodes and their respective names are listed. 6 | #' @param s The maximum size of block that is considered within the block formation game. 7 | #' @param adjMatrix The network represented as an adjacency matrix. 8 | #' @param setPS The set of predeccessors and successors for each combination of nodes considered. 9 | #' @param perCapita The brokerage power of the node set divided by the number of nodes within the set. 10 | #' @param approximate Should the Strong Nash Equilibrium be approximated? TRUE or FALSE. 11 | #' @keywords brokerage 12 | #' @export 13 | #' @examples 14 | #' setBrokerage() 15 | 16 | setBrokerage <- function(edgeList, nodeList, s, adjMatrix, setPS, perCapita, approximate) { 17 | if (missing(adjMatrix)) { 18 | originalAdjMatrix <- adjMatrix <- adjacencyMatrix(edgeList, 19 | nodeList) 20 | } else { 21 | originalAdjMatrix <- adjMatrix 22 | } 23 | if (missing(s)) { 24 | s <- nrow(nodeList) - 2 25 | } 26 | if (missing(approximate)) { 27 | approximate <- FALSE 28 | } 29 | if (missing(perCapita)) { 30 | perCapita <- FALSE 31 | } 32 | if (missing(setPS)) { 33 | setPS <- setPredSucc(edgeList, 34 | nodeList, 35 | s = s, 36 | adjMatrix, 37 | approximate = approximate) 38 | } 39 | K <- connectivity(adjMatrix = originalAdjMatrix) 40 | setPS$power <- 0 41 | for (i in 1:nrow(setPS)) { 42 | adjMatrix <- originalAdjMatrix 43 | K <- allSucc <- 0 44 | for (j in 1:nrow(nodeList)) { 45 | if (!(length(setPS$successors[[j]]) == 0 || setPS$successors[[j]] == 0)) { 46 | if (!(j %in% setPS$set[[i]])) { 47 | inSet <- setPS$set[[i]] %in% setPS$successors[[j]] 48 | noSet <- sum(inSet == TRUE) 49 | if (noSet > 0) { 50 | l <- length(setPS$successors[[j]]) - noSet + 1 51 | K <- K + l 52 | } else { 53 | K <- K + length(unique(setPS$successors[[j]])) 54 | } 55 | } else { 56 | allSucc <- c(allSucc, setPS$successors[[j]]) 57 | } 58 | } 59 | } 60 | K <- K + length(setdiff(unique(allSucc), setPS$set[[i]])) - 1 61 | for (j in 1:length(setPS$set[[i]])) { 62 | adjMatrix[setPS$set[[i]][j], ] <- adjMatrix[, setPS$set[[i]][j]] <- 0 63 | } 64 | kappa <- connectivity(adjMatrix = adjMatrix) 65 | setPS$power[i] <- K - kappa - setPS$noSucc[[i]] - setPS$noPred[[i]] 66 | print(paste0("i = ", i)) 67 | } 68 | potBroker <- potentialBrokerage(edgeList = edgeList, nodeList = nodeList) 69 | setPS$power <- round(setPS$power/1, 70 | digits = 3) 71 | if (perCapita == TRUE) { 72 | setPS$powerCapita <- round(setPS$power/setPS$setSize, 73 | digits = 3) 74 | } else { 75 | setPS$powerCapita <- setPS$power 76 | } 77 | return(setPS) 78 | } 79 | -------------------------------------------------------------------------------- /R/setPredSucc.R: -------------------------------------------------------------------------------- 1 | #' Find the predecessors and successors of a node set 2 | #' 3 | #' This function calculates the predecessors and successors of a node or node set. 4 | #' @param edgeList A dataframe of network data within which sources are in the first column and targets are in the second column. 5 | #' @param nodeList A dataframe within which all nodes and their respective names are listed. 6 | #' @param s The maximum size of block that is considered within the block formation game. 7 | #' @param adjMatrix The network represented as an adjacency matrix. 8 | #' @param approximate Should the number of sets considered be truncated? TRUE or FALSE. 9 | #' @keywords node predecessors successors 10 | #' @export 11 | #' @examples 12 | #' setPredSucc() 13 | 14 | setPredSucc <- function(edgeList, nodeList, s, adjMatrix, approximate) { 15 | if (missing(s)) { s <- nrow(nodeList) - 2 } 16 | if (s > nrow(nodeList) - 2) { 17 | return(print("s must be less than or equal to number of nodes in network minus 2 [s <= nrow(nodeList) - 2]")) 18 | } 19 | if (missing(approximate)) { approximate <- FALSE } 20 | if (missing(adjMatrix)) { 21 | adjMatrix <- adjacencyMatrix(edgeList, 22 | nodeList) 23 | } 24 | adjMatrix[, ] <- !adjMatrix %in% c("0", "FALSE") 25 | for (i in 1:nrow(adjMatrix)) { 26 | adjMatrix <- adjMatrix + expm::`%^%`(adjMatrix, i) 27 | adjMatrix[, ] <- !adjMatrix %in% c("0", "FALSE") 28 | } 29 | for (i in 1:nrow(adjMatrix)) { 30 | adjMatrix[i, i] <- 0 31 | } 32 | time <- Sys.time() 33 | for (i in 1:s) { 34 | sets <- combn(seq(1:nrow(adjMatrix)), 35 | m = i) 36 | if (approximate == TRUE) { 37 | if (ncol(sets) > 500000) { 38 | sets <- sets[, sample(ncol(sets))] 39 | sets <- sets[, sample(1:ncol(sets), 40 | size = 500000, 41 | replace = FALSE)] 42 | } 43 | } 44 | for (j in 1:ncol(sets)) { 45 | set <- sets[, j] 46 | successors <- predecessors <- noSucc <- noPred <- 0 47 | for (k in 1:i) { 48 | successors <- c(successors, 49 | which(adjMatrix[set[k], ] == 1)) 50 | predecessors <- c(predecessors, 51 | which(adjMatrix[, set[k]] == 1)) 52 | } 53 | if (length(successors) > 1) { 54 | successors <- setdiff(unique(successors), 55 | c(set, 0)) 56 | noSucc <- length(successors) 57 | } else { 58 | successors <- noSucc <- 0 59 | } 60 | if (length(predecessors) > 1) { 61 | predecessors <- setdiff(unique(predecessors), 62 | c(set, 0)) 63 | noPred <- length(predecessors) 64 | } else { 65 | predecessors <- noPred <- 0 66 | } 67 | if (i == 1 & j == 1 & k == 1) { 68 | PS <- list(set = list(set), 69 | setSize = i, 70 | successors = list(successors), 71 | predecessors = list(predecessors), 72 | noSucc = list(noSucc), 73 | noPred = list(noPred)) 74 | } else { 75 | a <- list(set = list(set), 76 | setSize = i, 77 | successors = list(successors), 78 | predecessors = list(predecessors), 79 | noSucc = list(noSucc), 80 | noPred = list(noPred)) 81 | PS <- data.table::rbindlist(list(PS, a), 82 | use.names = TRUE, 83 | fill = TRUE) 84 | } 85 | } 86 | } 87 | return(PS) 88 | } 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](http://www.repostatus.org/badges/latest/wip.svg)](http://www.repostatus.org/#wip) 2 | 3 | # `networkR` : An `R` package for analysing social and economic networks 4 | 5 | ## 1 About `networkR` 6 | 7 | The `networkR` package provides a set of functions for the analysis of social and economic networks and hypergraphs. As such, the package provides a range of tools to analyse both the macroscopic and microscopic features of networked systems. The macroscopic analysis include the degree distribution, diameter and density of the network. The microscopic analysis includes the power, influence and centrality of individual nodes. 8 | 9 | The primary use of the package is the analysis of social and economic networks; including directorate networks that are represented as hypergraphs. 10 | 11 | ### 1.1 Versions 12 | 13 | No versions have been officially released yet. Currently we are still beta testing and adding new functionality, however we will post any new versions here when realeased. 14 | 15 | ### 1.2 Installation 16 | 17 | There is no CRAN version available yet. Instead, consider the following installation instructions for `devtools`. 18 | 19 | # install.packages("devtools") 20 | library(devtools) 21 | devtools::install_github("O1sims/networkR") 22 | 23 | ## 2 Data 24 | 25 | The package also contains empirical and synthetic data. This is supplied to allow for testing of the package. As we are dealing with network data we partition the dataset into a `nodeList` and an `edgeList`. If we are dealing with a hypergraph we also include an `affiliationList` to the dataset. The functions typically require these data components. 26 | 27 | ### 2.1 Real-world data 28 | 29 | The package provides four empirical network and hypergraph datasets. 30 | 31 | **Florentine marriages:** The first network dataset is the elite marriage network of Renaissance Florence circa 1435. This dataset has been used in various representations in a number of network-oriented academic articles. The data was originally sourced from Padgett and Ansell (1994). The static network consists of 32 families and 31 arcs, meaning that a number of families are singletons. Arguably these nodes could be disregarded from the analysis. 32 | 33 | * **Marriage Data:** `florentineNodes.rda` and `florentineEdges.rda`. 34 | 35 | ![](images/marriageTopology.png "Elite Florentine marriages") 36 | 37 | 38 | **Manager advice:** The second network dataset is the manager advice network gathered by David Krackhardt (1987). This directed network contains 21 managers from 4 different levels of management and also contains 129 arcs between the managers. 39 | 40 | * **Advice data:** `managerNodes.rda` and `managerEdges.rda`. 41 | 42 | ![](images/adviceNetwork.png "Managerial advice network") 43 | 44 | **9/11 terrorists:** The third dataset refers to four different networks that show the evolution of the interactions between terrorists that coordinated and instigated the 9/11 terrorists attacks. These networks span from December 1999 to August 2001, just before the attack. The size of the network increases over time from 27 terrorists in December 1999 to 32 terrorists in August 2001. The network also becomes more concentrated over time. These networks have been constructed from a number of different sources within academic literature, government reports and journalist articles. 45 | 46 | * **Terrorist data:** `terroristNodes.rda` and `terroristEdges.rda`. 47 | 48 | ![](images/terroristNetwork.png "9/11 terrorist network in December 2000") 49 | 50 | **Directors of New York City:** The final dataset refers to a hypergraph representing the directorate of New York City in 1902. We provide a bipartite network of all railways, insurance, and financial institutions as well as their directors. The purpose of this data is to illustrate the control of directors and firms in New York during this time. This network contains over 250 unique firms and 3000 unique directors. There are 4299 links; each link indicates membership of a director to a firm. Since the number of links is greater than the number of unique directors it is certain that overlapping directorate exists. This network has been constructed from historical *New York Times* articles and the *Directory of Directors of New York City*. Other sources are used to acquire data on the valuation of each of the firms. 51 | 52 | * **Directorate data:** `nycNodes.rda`, `nycAffiliations.rda` and `nycHypergraph.rda`. 53 | 54 | ### 2.2 Synthetic data 55 | 56 | A number of example or test data are provided. These can be used to test the functions within the package. 57 | 58 | Consider the directed network in `network1Nodes.rda` and `network1Edges.rda`. The network contains 7 nodes---one of which is a source and another is a sink---and 8 arcs that can be interpreted as the flow of information, money, or economic goods: node 1 is connected to node 7 through the intermediation of other nodes in the network. The network of relationships is plotted in the Figure below. 59 | 60 | ## 3 Analysing networks 61 | 62 | Let's look at a number of `networkR` functions applied to the first test network (`network1Nodes.rda` and `network1Edges.rda`). Load these files up. 63 | 64 | > library(networkR) 65 | > data(list = c("network1Nodes", "network1Edges")) 66 | 67 | ### 3.1 Middlemen and middleman power 68 | 69 | It is pretty obvious from reviewing this network that nodes 2, 5, and 6 are all middlemen. Furthermore, it is noticeable that node 6 would still remain a middleman regardless of whether the network were transformed into its undirected state. We get the following values when running the `middlemanPowerDetail()` function. 70 | 71 | > middlemanPowerDetail(network1Edges, network1Nodes) 72 | number name power normPower type 73 | 1 1 0 0.0 Non-middleman 74 | 2 2 1 0.1 Weak middleman 75 | 3 3 0 0.0 Non-middleman 76 | 4 4 0 0.0 Non-middleman 77 | 5 5 2 0.2 Weak middleman 78 | 6 6 5 0.5 Strong middleman 79 | 7 7 0 0.0 Non-middleman 80 | 81 | As hypothesised we find that nodes 2 and 5 are both weak middlemen and node 6 is a strong middleman. To add to this we also find : (a) the number of relationships brokered by all middleman, and (b) the normalised middleman power for each node. We can represent middlemen visually with the following R commands: 82 | 83 | > colourMiddlemen <- middlemanPowerDetail(network1Edges, network1Nodes) 84 | > colourMiddlemen$colour <- ifelse(colourMiddlemen$power > 0, "darkred", "lightblue") 85 | > isTrue <- isUndirected(network1Edges, network1Nodes) == FALSE 86 | > plot(graph_from_data_frame(network1Edges, 87 | directed = isTrue), 88 | vertex.color = middle$colour, 89 | vertex.label.dist = 3, 90 | vertex.size = 20, 91 | edge.color = "gray50") 92 | 93 | In this case, the network is plotted such that middlemen are coloured in red and non-middlemen are coloured in blue. This is seen in the Figure below. 94 | 95 | ![](images/middlemen.png "Highlighted middlemen") 96 | 97 | ### 3.2 Coverage, blocks and set middleman power 98 | 99 | The coverage of each node set in the 7 node network is given by: 100 | 101 | > setCoverage(network1Edges, network1Nodes) 102 | set setSize successors predecessors noSucc noPred coverage 103 | 1: 1 1 2,3,4,5,6,7 0 6 0 0 104 | 2: 2 1 4,5,6,7 1 4 1 4 105 | 3: 3 1 5,6,7 1 3 1 3 106 | 4: 4 1 6,7 1,2 2 2 4 107 | 5: 5 1 6,7 1,2,3 2 3 6 108 | --- 109 | 115: 2,3,4,5,7 5 6 1,6 1 2 1 110 | 116: 2,3,4,6,7 5 5 1,5 1 2 1 111 | 117: 2,3,5,6,7 5 4 1,4 1 2 1 112 | 118: 2,4,5,6,7 5 1,3 0 2 0 113 | 119: 3,4,5,6,7 5 1,2 0 2 0 114 | 115 | The brokerage, or middleman power, of each node set can be derived in much the same way. This is done by executing the `setBrokerage()` function. We arrive at the following output: 116 | 117 | > setBrokerage(network1Edges, network1Nodes) 118 | set setSize successors predecessors noSucc noPred power 119 | 1: 1 1 2,3,4,5,6,7 0 6 0 0 120 | 2: 2 1 4,5,6,7 1 4 1 1 121 | 3: 3 1 5,6,7 1 3 1 0 122 | 4: 4 1 6,7 1,2 2 2 0 123 | 5: 5 1 6,7 1,2,3 2 3 2 124 | --- 125 | 115: 2,3,4,5,7 5 6 1,6 1 2 1 126 | 116: 2,3,4,6,7 5 5 1,5 1 2 1 127 | 117: 2,3,5,6,7 5 4 1,4 1 2 1 128 | 118: 2,4,5,6,7 5 1,3 0 2 0 129 | 119: 3,4,5,6,7 5 1,2 0 2 0 130 | 131 | We can see that a positive coverage does not translate to a positive middleman power. More specifically, the middleman power of a node set is defined on the critical sets of the network. All critical sets are provided with the function `criticalSets()`. The output for the 7 node network is as below: 132 | 133 | > criticalSets(network1Edges, network1Nodes) 134 | set setSize successors predecessors noSucc noPred power powerCapita 135 | 1: 2 1 4,5,6,7 1 4 1 1 1.000 136 | 2: 5 1 6,7 1,2,3 2 3 2 2.000 137 | 3: 6 1 7 1,2,3,4,5 1 5 5 5.000 138 | 4: 1,5 2 2,3,4,6,7 2,3 5 2 2 1.000 139 | 5: 1,6 2 2,3,4,5,7 2,3,4,5 5 4 4 2.000 140 | --- 141 | 62: 1,3,4,5,7 5 2,6 2,6 2 2 1 0.200 142 | 63: 2,3,4,5,6 5 7 1 1 1 1 0.200 143 | 64: 2,3,4,5,7 5 6 1,6 1 2 1 0.200 144 | 65: 2,3,4,6,7 5 5 1,5 1 2 1 0.200 145 | 66: 2,3,5,6,7 5 4 1,4 1 2 1 0.200 146 | 147 | This function also provides the middleman power per capita. 148 | 149 | ### 3.3 Criticality 150 | 151 | The criticality of individual or sets of nodes is a measure of their assumed brokerage after they have been allowed the ability to form coalitions and actively broker relations. It is therefore a measure based on the resulting stable sets. We use the notion of Strong Nash equilibrium (SNE) to determine the stability of a coalition within a network. Each coalition also has some cost of formation; this cost function can also be determined within the model itself. 152 | 153 | For example, when considering the network of 7 nodes when there exists no costs in forming blocks we can determine the SNE as follows: 154 | 155 | > blockSNE(network1Edges, network1Nodes) 156 | set setSize successors predecessors noSucc noPred power powerCapita 157 | 1: 6 1 7 1,2,3,4,5 1 5 5 5 158 | 2: 4,5 2 6,7 1,2,3 2 3 6 3 159 | 3: 2,3 2 4,5,6,7 1 4 1 4 2 160 | 161 | Specifically, node 6 remains as a middleman and two blocks are formed: one containing nodes 4 and 5, and another containing nodes 2 and 3. All other nodes do not form a block and therefore earn a payoff of zero. If, however, there is some substantial cost of forming a block, then the SNE degredates to the point where no blocks are formed and middlemen are the only nodes that earn a positive payoff. By setting `c = 2` we get the following Strong Nash equilibrium: 162 | 163 | > blockSNE(network1Edges, network1Nodes, c = 2) 164 | set setSize successors predecessors noSucc noPred power powerCapita 165 | 1: 6 1 7 1,2,3,4,5 1 5 5 5 166 | 2: 5 1 6,7 1,2,3 2 3 2 2 167 | 3: 2 1 4,5,6,7 1 4 1 1 1 168 | 169 | The criticality of individual nodes can be calculated from all potential SNE blocks that are known the emerge. Simply, the criticality of all nodes in the network is calculated as: 170 | 171 | > nodeNormCriticality(network1Edges, network1Nodes) 172 | [1] 0.0 0.2 0.2 0.3 0.3 0.5 0.0 173 | 174 | ## 4 Analysing hypergraphs 175 | 176 | A set of functions for analysing [hypergraphs](https://en.wikipedia.org/wiki/Hypergraph) are provided in the package. These functions revolve around the projection of hypergraphs into different network structures and the measurement of a node or an affiiations "control" within the hypergraph. This notion of control as a centrality measure is represented by the sigma score and beta measures within hypergraphs. Within the realm of socio-economic networks, the best application of hypergraphs come in the form of corporate directorate networks. 177 | 178 | Two such examples are provided in the dataset alongside this package: 179 | 1. New York City (NYC) corporate directors of 1902; and 180 | 2. The corporate directors of Victorian Britain between 1880 and 1900. 181 | 182 | **NYC corporate directors:** Using the NYC Directorate data (1902) we can illustrate an example of an affiliation projection of the directorate hypergraph. Consider the following code. 183 | 184 | > c("nycNodes", "nycAffiliations", "nycHypergraph") %>% data() 185 | > projection <- nycHypergraph %>% 186 | affiliationProjection() %>% 187 | filterNetwork() 188 | > plot(graph_from_data_frame(projection, 189 | directed = FALSE), 190 | vertex.color = nycAffiliations$types, 191 | vertex.label = NA, 192 | vertex.label.dist = 3, 193 | vertex.label.color = "black", 194 | vertex.size = log(nycAffiliations$valuations)/5, 195 | edge.width = projection$weight, 196 | edge.color = "grey50", 197 | edge.arrow.size = 0) 198 | 199 | ![](images/weightedInstitutions.png "Overlapping directorate network of NYC") 200 | 201 | **Victorian Britain directors:** The Victorian Britain directorate data (1880-1900), which can be found in its raw format [here](https://github.com/O1sims/VictorianBritainDirectors), can also be used in much the same way. See the code below: 202 | ``` 203 | > data(list = c("vbdNodes", "vbdAffiliations", "vbdHypergraph")) 204 | > projection <- vbdHypergraph %>% 205 | affiliationProjection() %>% 206 | filterNetwork() 207 | > plot(graph_from_data_frame( 208 | projection, 209 | directed = FALSE), 210 | vertex.label = NA, 211 | vertex.label.dist = 3, 212 | vertex.label.color = "black", 213 | vertex.size = 2, 214 | edge.width = projection$weight, 215 | edge.color = "grey50", 216 | edge.arrow.size = 0) 217 | ``` 218 | This generates the following institutional overlap for firms in 1880. 219 | 220 | ![](images/victorian-britain-institutions.png "Overlapping directorate of firms in Victorian Britain") 221 | 222 | It is important to understand the structure of the hypergraph data that needs to be passed to the functions. Data is structured such that a bipartite network is expressed: `nodes` are connected to `affiliations` by an edge, however a set of nodes nor a set of affiliations are connected to each other directly. 223 | 224 | ### 4.1 Elites in aspectual hypergraphs 225 | 226 | Affiliations within a hypergraph can be associated within an "aspect". As such, an affiliation can be associated with one and only one affiliation. We consider these cases and discuss the analysis and formation of elite networks in aspectual hypergraphs. 227 | 228 | For example, when analysing director networks each firm exists within one industry and therefore one aspect of the economy. An elite director is one who is on the board of companies of every industry under analysis. 229 | 230 | > data(list = c("nycNodes", "nycAffiliations", "nycHypergraph")) 231 | > elites(nycHypergraph, nycNodes, nycAffiliations, nycAffiliations$types) 232 | number nodes 233 | 1: 212 JAMES H. HYDE 234 | 2: 220 E.H. HARRIMAN 235 | 3: 240 SAMUEL D. BABCOCK 236 | 4: 268 GEORGE F. BAKER 237 | 5: 272 JOHN JACOB ASTOR 238 | --- 239 | 31: 1886 GEORGE J. GOULD 240 | 32: 1956 BRAYTON IVES 241 | 33: 2131 STUYVESANT FISH 242 | 34: 2679 N. PARKER SHORTRIDGE 243 | 35: 2907 JACOB H. SCHIFF 244 | 245 | All directors listed were seen as influential during this time period. 246 | 247 | ## 5 Other functions 248 | 249 | A number of other functions are defined in `networkFunctions.R`. For example, the `randomGraph()` function provides an Erdos-Renyi graph where the probability of an arc or link existing between any two nodes is explicitly defined within the argument `0 < p < 1`. 250 | 251 | > erdosRenyi <- randomGraph( 252 | n = 50, 253 | p = 0.05) 254 | > plot(graph_from_data_frame( 255 | erdosRenyi, 256 | directed = FALSE), 257 | vertex.color = "orange", 258 | vertex.label = NA, 259 | vertex.label.dist = 3, 260 | vertex.size = 5, 261 | edge.color = "gray50", 262 | edge.arrow.size = 0) 263 | 264 | 265 | This generates the following graph: 266 | 267 | ![](images/erdosRenyi50.png "Random graph of 50 nodes with p = 0.05") 268 | --------------------------------------------------------------------------------