Title: | Methods to Analyse Signed Networks |
---|---|
Description: | Methods for the analysis of signed networks. This includes several measures for structural balance as introduced by Cartwright and Harary (1956) <doi:10.1037/h0046049>, blockmodeling algorithms from Doreian (2008) <doi:10.1016/j.socnet.2008.03.005>, various centrality indices, and projections of signed two-mode networks introduced by Schoch (2020) <doi:10.1080/0022250X.2019.1711376>. |
Authors: | David Schoch [aut, cre] |
Maintainer: | David Schoch <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.4 |
Built: | 2024-11-22 04:38:05 UTC |
Source: | https://github.com/schochastics/signnet |
This function returns the adjacency matrix for a signed graph that contains ambivalent ties
as_adj_complex(g, attr)
as_adj_complex(g, attr)
g |
igraph object |
attr |
edge attribute name that encodes positive ("P"), negative ("N") and ambivalent ("A") ties. |
complex adjacency matrix
This function returns the adjacency matrix for a signed graph
as_adj_signed(g, sparse = FALSE)
as_adj_signed(g, sparse = FALSE)
g |
igraph object. Must have a "sign" edge attribute. |
sparse |
Logical scalar, whether to return the result as a sparse matrix. The Matrix package is required for sparse matrices. |
signed adjacency matrix
Convert Signed Network to Complex
as_complex_edges(g, attr = "type")
as_complex_edges(g, attr = "type")
g |
igraph object. Must have a "sign" edge attribute. |
attr |
new edge attribute name that encodes positive ("P"), negative ("N") and ambivalent ("A") ties. |
igraph object
David Schoch
g <- sample_islands_signed(2, 10, 1, 10) as_complex_edges(g)
g <- sample_islands_signed(2, 10, 1, 10) as_complex_edges(g)
The complex incidence matrix of a signed graph containing ambivalent ties.
as_incidence_complex(g, attr)
as_incidence_complex(g, attr)
g |
igraph object. |
attr |
edge attribute name that encodes positive ("P"), negative ("N") and ambivalent ("A") ties. |
This function is slightly different than as_incidence_matrix since it is defined for bipartite graphs.
The incidence matrix here is defined as a , where n is the number of vertices and m the number of edges. Edges (i,j) are oriented such that i<j and entries are defined as
a complex matrix
David Schoch
laplacian_matrix_complex,as_adj_complex
This function returns the incidence matrix for a signed two-mode network.
as_incidence_signed(g, sparse = FALSE)
as_incidence_signed(g, sparse = FALSE)
g |
igraph object (bipartite). Must have a "sign" edge attribute. |
sparse |
Logical scalar, whether to return the result as a sparse matrix. The Matrix package is required for sparse matrices. |
signed incidence matrix
convert unsigned projection to signed
as_signed_proj(g)
as_signed_proj(g)
g |
igraph object |
igraph object
David Schoch
library(igraph) # create a simple signed two mode network el <- matrix(c(1, "a", 1, "b", 1, "c", 2, "a", 2, "b"), ncol = 2, byrow = TRUE) g <- graph_from_edgelist(el, directed = FALSE) E(g)$sign <- c(1, 1, -1, 1, -1) V(g)$type <- c(FALSE, TRUE, TRUE, TRUE, FALSE) # convert to unsigned two-mode network and project l <- as_unsigned_2mode(g, primary = TRUE) p <- bipartite_projection(l, which = "true") # turn the unsigned projection back to a signed network as_signed_proj(p)
library(igraph) # create a simple signed two mode network el <- matrix(c(1, "a", 1, "b", 1, "c", 2, "a", 2, "b"), ncol = 2, byrow = TRUE) g <- graph_from_edgelist(el, directed = FALSE) E(g)$sign <- c(1, 1, -1, 1, -1) V(g)$type <- c(FALSE, TRUE, TRUE, TRUE, FALSE) # convert to unsigned two-mode network and project l <- as_unsigned_2mode(g, primary = TRUE) p <- bipartite_projection(l, which = "true") # turn the unsigned projection back to a signed network as_signed_proj(p)
convert signed two-mode network to unsigned
as_unsigned_2mode(g, primary = TRUE)
as_unsigned_2mode(g, primary = TRUE)
g |
igraph object. Two-mode network, must have a "sign" edge attribute. |
primary |
logical. Which mode to transform |
igraph object
David Schoch
library(igraph) # create a simple signed two mode network el <- matrix(c(1, "a", 1, "b", 1, "c", 2, "a", 2, "b"), ncol = 2, byrow = TRUE) g <- graph_from_edgelist(el, directed = FALSE) E(g)$sign <- c(1, 1, -1, 1, -1) V(g)$type <- c(FALSE, TRUE, TRUE, TRUE, FALSE) # convert to unsigned two-mode network and project l <- as_unsigned_2mode(g, primary = TRUE) p <- bipartite_projection(l, which = "true") # turn the unsigned projection back to a signed network as_signed_proj(p)
library(igraph) # create a simple signed two mode network el <- matrix(c(1, "a", 1, "b", 1, "c", 2, "a", 2, "b"), ncol = 2, byrow = TRUE) g <- graph_from_edgelist(el, directed = FALSE) E(g)$sign <- c(1, 1, -1, 1, -1) V(g)$type <- c(FALSE, TRUE, TRUE, TRUE, FALSE) # convert to unsigned two-mode network and project l <- as_unsigned_2mode(g, primary = TRUE) p <- bipartite_projection(l, which = "true") # turn the unsigned projection back to a signed network as_signed_proj(p)
Allies/Enemy relations from Avatar: The Last Airbender
avatar
avatar
igraph object
scraped from Avatar Wiki (https://avatar.fandom.com/wiki/Category:Characters)
Implements several indices to assess the balancedness of a network.
balance_score(g, method = "triangles")
balance_score(g, method = "triangles")
g |
igraph object with a sign edge attribute. |
method |
string indicating the method to be used. See details for options |
The method parameter can be one of
Fraction of balanced triangles. Maximal (=1) if all triangles are balanced.
where are the eigenvalues of the
signed adjacency matrix and
of the unsigned adjacency matrix. Maximal (=1) if all walks are balanced.
The frustration index assumes that the network can be partitioned into two groups, where intra group edges are positive and inter group edges are negative. The index is defined as the sum of intra group negative and inter group positive edges. Note that the problem is NP complete and only an upper bound is returned (based on simulated annealing). Exact methods can be found in the work of Aref. The index is normalized such that it is maximal (=1) if the network is balanced.
numeric balancedness score between 0 and 1
David Schoch
Estrada, E. (2019). Rethinking structural balance in signed social networks. Discrete Applied Mathematics.
Samin Aref, Mark C Wilson (2018). Measuring partial balance in signed networks. Journal of Complex Networks, 6(4): 566–595, https://doi.org/10.1093/comnet/cnx044
library(igraph) g <- graph.full(4) E(g)$sign <- c(-1, 1, 1, -1, -1, 1) balance_score(g, method = "triangles") balance_score(g, method = "walk")
library(igraph) g <- graph.full(4) E(g)$sign <- c(-1, 1, 1, -1, -1, 1) balance_score(g, method = "triangles") balance_score(g, method = "walk")
Count Walks in complex signed network
complex_walks(g, attr, k)
complex_walks(g, attr, k)
g |
igraph object. |
attr |
edge attribute that encodes positive ("P"), negative ("N") and ambivalent ("A") ties. |
k |
integer. length of walks |
igraph object
David Schoch
g <- sample_islands_signed(2, 10, 1, 10) g <- as_complex_edges(g, attr = "type") complex_walks(g, attr = "type", k = 3)
g <- sample_islands_signed(2, 10, 1, 10) g <- as_complex_edges(g, attr = "type") complex_walks(g, attr = "type", k = 3)
Counts the number of all possible signed triangles (+++),(++-), (+–) and (—)
count_complex_triangles(g, attr)
count_complex_triangles(g, attr)
g |
igraph object. |
attr |
edge attribute name that encodes positive ("P"), negative ("N") and ambivalent ("A") ties. |
counts for all complex triangle types
David Schoch
library(igraph) g <- graph.full(4) E(g)$type <- c("P", "N", "A", "A", "P", "N") count_complex_triangles(g, attr = "type")
library(igraph) g <- graph.full(4) E(g)$type <- c("P", "N", "A", "A", "P", "N") count_complex_triangles(g, attr = "type")
Counts the number of all possible signed triangles (+++),(++-), (+–) and (—)
count_signed_triangles(g)
count_signed_triangles(g)
g |
igraph object with a sign edge attribute. |
counts for all 4 signed triangle types
David Schoch
library(igraph) g <- graph.full(4) E(g)$sign <- c(-1, 1, 1, -1, -1, 1) count_signed_triangles(g)
library(igraph) g <- graph.full(4) E(g)$sign <- c(-1, 1, 1, -1, -1, 1) count_signed_triangles(g)
51 signed networks of inter state relations
cowList
cowList
List of igraph objects
http://mrvar.fdv.uni-lj.si/pajek/SVG/CoW/default.htm
Doreian, P. and Mrvar, A. (2015). "Structural Balance and Signed International Relations". Journal of Social Structure, 16(2)
several options to calculate the signed degree of vertices
degree_signed( g, mode = c("all", "in", "out"), type = c("pos", "neg", "ratio", "net") )
degree_signed( g, mode = c("all", "in", "out"), type = c("pos", "neg", "ratio", "net") )
g |
igraph object with a sign edge attribute. |
mode |
character string, “out” for out-degree, “in” for in-degree or “all” for undirected networks. |
type |
character string, “pos” or “neg” for counting positive or negative neighbors only, "ratio" for pos/(pos+neg), or "net" for pos-neg. |
centrality scores as numeric vector.
David Schoch
returns the eigenvector associated with the dominant eigenvalue from the adjacency matrix.
eigen_centrality_signed(g, scale = TRUE)
eigen_centrality_signed(g, scale = TRUE)
g |
igraph object with a sign edge attribute. |
scale |
Logical scalar, whether to scale the result to have a maximum score of one. If no scaling is used then the result vector is the same as returned by |
Note that, with negative values, the adjacency matrix may not have a dominant eigenvalue. This means it is not clear which eigenvector should be used. In addition it is possible for the adjacency matrix to have repeated eigenvalues and hence multiple linearly independent eigenvectors. In this case certain centralities can be arbitrarily assigned. The function returns an error if this is the case.
centrality scores as numeric vector.
David Schoch
Bonacich, P. and Lloyd, P. (2004). "Calculating Status with Negative Relations." Social Networks 26 (4): 331–38.
Everett, M. and Borgatti, S.P. (2014). "Networks Containing Negative Ties." Social Networks 38: 111–20.
library(igraph) data("tribes") eigen_centrality_signed(tribes)
library(igraph) data("tribes") eigen_centrality_signed(tribes)
Computes the exact frustration index of a signed network using linear programming
frustration_exact(g, ...)
frustration_exact(g, ...)
g |
signed network |
... |
additional parameters for the ompr solver |
The frustration index indicates the minimum number of edges whose removal results in a balance
network. The function needs the following packages to be installed: ompr
, ompr.roi
,ROI
, and ROI.plugin.glpk
.
The function Implements the AND model in Aref et al., 2020
list containing the frustration index and the bipartition of nodes
David Schoch
Aref, Samin, Andrew J. Mason, and Mark C. Wilson. "Computing the line index of balance using linear programming optimisation." Optimization problems in graph theory. Springer, Cham, 2018. 65-84.
Aref, Samin, Andrew J. Mason, and Mark C. Wilson. "A modeling and computational study of the frustration index in signed networks." Networks 75.1 (2020): 95-110.
Plot Blockmodel matrix
ggblock( g, blocks = NULL, cols = NULL, show_blocks = FALSE, show_labels = FALSE )
ggblock( g, blocks = NULL, cols = NULL, show_blocks = FALSE, show_labels = FALSE )
g |
igraph object with a sign edge attribute. |
blocks |
vector of block membership as obtained, e.g. from signed_blockmodel |
cols |
colors used for negative and positive ties |
show_blocks |
logical. Should block borders be displayed? (Default: FALSE) |
show_labels |
logical. Should node labels be displayed? (Default: FALSE) |
ggplot2 object
David Schoch
## Not run: library(igraph) data("tribes") clu <- signed_blockmodel(tribes, k = 3, alpha = 0.5, annealing = TRUE) ggblock(tribes, clu$membership, show_blocks = TRUE, show_labels = TRUE) ## End(Not run)
## Not run: library(igraph) data("tribes") clu <- signed_blockmodel(tribes, k = 3, alpha = 0.5, annealing = TRUE) ggblock(tribes, clu$membership, show_blocks = TRUE, show_labels = TRUE) ## End(Not run)
Plot a signed or complex network
ggsigned(g, type = "signed", attr = NULL, edge_cols = NULL, weights = FALSE)
ggsigned(g, type = "signed", attr = NULL, edge_cols = NULL, weights = FALSE)
g |
igraph object. Must have a "sign" edge attribute or an attribute containing "P", "N", "A" |
type |
character string. either "signed" or "complex" |
attr |
character string. edge attribute that containing "P", "N", "A" if type="complex" |
edge_cols |
colors used for negative and positive (and ambivalent) ties |
weights |
logical. If TRUE, weights are computed based on sign. Defaults to FALSE |
This is a very rudimentary visualization of a signed network. If you are fluent in 'ggraph', you can probably cook up something more sophisticated. The function is thus mostly meant to give a quick overview of the network.
ggplot2 object
David Schoch
circular graph with positive and negative edges.
graph_circular_signed(n, r = 1, pos = 0.1, neg = 0.1)
graph_circular_signed(n, r = 1, pos = 0.1, neg = 0.1)
n |
number of nodes |
r |
radius |
pos |
distance fraction between positive edges |
neg |
distance fraction between negative edges |
igraph graph
David Schoch
library(igraph) graph_circular_signed(n = 50)
library(igraph) graph_circular_signed(n = 50)
Create signed graphs from adjacency matrices
graph_from_adjacency_matrix_signed(A, mode = "undirected", ...)
graph_from_adjacency_matrix_signed(A, mode = "undirected", ...)
A |
square adjacency matrix of a signed graph |
mode |
Character scalar, specifies how to interpret the supplied matrix. Possible values are: directed, undirected |
... |
additional parameters for |
a signed network as igraph object
A <- matrix(c(0, 1, -1, 1, 0, 1, -1, 1, 0), 3, 3) graph_from_adjacency_matrix_signed(A)
A <- matrix(c(0, 1, -1, 1, 0, 1, -1, 1, 0), 3, 3) graph_from_adjacency_matrix_signed(A)
Create a signed graph from an edgelist matrix
graph_from_edgelist_signed(el, signs, directed = FALSE)
graph_from_edgelist_signed(el, signs, directed = FALSE)
el |
The edgelist, a two column matrix, character or numeric. |
signs |
vector indicating the sign of edges. Entries must be 1 or -1. |
directed |
whether to create a directed graph. |
a signed network as igraph object
el <- matrix(c("foo", "bar", "bar", "foobar"), ncol = 2, byrow = TRUE) signs <- c(-1, 1) graph_from_edgelist_signed(el, signs)
el <- matrix(c("foo", "bar", "bar", "foobar"), ncol = 2, byrow = TRUE) signs <- c(-1, 1) graph_from_edgelist_signed(el, signs)
Check if network is a signed network
is_signed(g)
is_signed(g)
g |
igraph object |
logical scalar
g <- sample_islands_signed(2, 5, 1, 5) is_signed(g)
g <- sample_islands_signed(2, 5, 1, 5) is_signed(g)
The Laplacian of a signed graph containing ambivalent ties.
laplacian_matrix_complex(g, attr, norm = FALSE)
laplacian_matrix_complex(g, attr, norm = FALSE)
g |
igraph object. |
attr |
edge attribute name that encodes positive ("P"), negative ("N") and ambivalent ("A") ties. |
norm |
Whether to calculate the normalized Laplacian. See definitions below. |
See laplacian_matrix of igraph for more details. In the complex case, D is a diagonal matrix containing the absolute values of row sums of the complex adjacency matrix.
a complex matrix
David Schoch
The Laplacian of a signed graph.
laplacian_matrix_signed(g, norm = FALSE, sparse = FALSE)
laplacian_matrix_signed(g, norm = FALSE, sparse = FALSE)
g |
igraph object with a sign edge attribute. |
norm |
Whether to calculate the normalized Laplacian. See definitions below. |
sparse |
Logical scalar, whether to return the result as a sparse matrix. The Matrix package is required for sparse matrices. |
See laplacian_matrix of igraph for more details. In the signed case, D is a diagonal matrix containing the absolute values of row sums of the signed adjacency matrix.
a numeric matrix
David Schoch
library(igraph) g <- sample_islands_signed(3, 10, 5 / 10, 1) laplacian_matrix_signed(g) laplacian_matrix_signed(g, norm = TRUE)
library(igraph) g <- sample_islands_signed(3, 10, 5 / 10, 1) laplacian_matrix_signed(g) laplacian_matrix_signed(g, norm = TRUE)
centrality index for signed networks by Everett and Borgatti
pn_index(g, mode = c("all", "in", "out"))
pn_index(g, mode = c("all", "in", "out"))
g |
igraph object with a sign edge attribute. |
mode |
character string, “out” for out-pn, “in” for in-pn or “all” for undirected networks. |
centrality scores as numeric vector.
David Schoch
Everett, M. and Borgatti, S. (2014) Networks containing negative ties. Social Networks 38 111-120
A <- matrix(c( 0, 1, 0, 1, 0, 0, 0, -1, -1, 0, 1, 0, 1, -1, 1, -1, -1, 0, 0, 0, 0, 1, 0, 1, -1, 0, 0, 0, -1, 0, 1, -1, 1, 0, 1, -1, -1, 0, 0, 0, 0, 1, -1, 1, 0, 1, 0, -1, 0, -1, 0, -1, 0, -1, 1, 0, 1, 0, 1, -1, 0, -1, 0, -1, 0, 1, 0, 1, -1, 1, -1, 0, 0, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, 0, 1, -1, 1, 0, 1, 0, 0, 0, 0, -1, -1, 1, 0, 1, 0 ), 10, 10) g <- graph_from_adjacency_matrix_signed(A,"undirected") pn_index(g)
A <- matrix(c( 0, 1, 0, 1, 0, 0, 0, -1, -1, 0, 1, 0, 1, -1, 1, -1, -1, 0, 0, 0, 0, 1, 0, 1, -1, 0, 0, 0, -1, 0, 1, -1, 1, 0, 1, -1, -1, 0, 0, 0, 0, 1, -1, 1, 0, 1, 0, -1, 0, -1, 0, -1, 0, -1, 1, 0, 1, 0, 1, -1, 0, -1, 0, -1, 0, 1, 0, 1, -1, 1, -1, 0, 0, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, 0, 1, -1, 1, 0, 1, 0, 0, 0, 0, -1, -1, 1, 0, 1, 0 ), 10, 10) g <- graph_from_adjacency_matrix_signed(A,"undirected") pn_index(g)
Bipartite random signed graphs
sample_bipartite_signed( n1, n2, p, p_neg, directed = FALSE, mode = c("out", "in", "all") )
sample_bipartite_signed( n1, n2, p, p_neg, directed = FALSE, mode = c("out", "in", "all") )
n1 |
Integer scalar, the number of bottom vertices. |
n2 |
Integer scalar, the number of top vertices. |
p |
The probability for drawing an edge between two arbitrary vertices. |
p_neg |
The probability of a drawn edge to be a negative tie |
directed |
logical, whether the graph will be directed. defaults to FALSE. |
mode |
Character scalar, specifies how to direct the edges in directed graphs. If it is ‘out’, then directed edges point from bottom vertices to top vertices. If it is ‘in’, edges point from top vertices to bottom vertices. ‘out’ and ‘in’ do not generate mutual edges. If this argument is ‘all’, then each edge direction is considered independently and mutual edges might be generated. This argument is ignored for undirected graphs. |
A signed bipartite igraph graph.
sample_bipartite_signed(10, 10, 0.5, 0.5)
sample_bipartite_signed(10, 10, 0.5, 0.5)
Generate random signed graphs according to the G(n,p) Erdos-Renyi model
sample_gnp_signed(n, p, p_neg, directed = FALSE, loops = FALSE)
sample_gnp_signed(n, p, p_neg, directed = FALSE, loops = FALSE)
n |
The number of vertices in the graph. |
p |
The probability for drawing an edge between two arbitrary vertices. |
p_neg |
The probability of a drawn edge to be a negative tie |
directed |
logical, whether the graph will be directed. defaults to FALSE. |
loops |
logical, whether to add loop edges, defaults to FALSE. |
a signed igraph graph object
Erdos, P. and Renyi, A., On random graphs, Publicationes Mathematicae 6, 290–297 (1959).
sample_gnp_signed(10, 0.4, 0.5)
sample_gnp_signed(10, 0.4, 0.5)
Create a number of Erdos-Renyi random graphs with identical parameters, and connect them with the specified number of negative ties.
sample_islands_signed(islands.n, islands.size, islands.pin, n.inter)
sample_islands_signed(islands.n, islands.size, islands.pin, n.inter)
islands.n |
The number of islands in the graph. |
islands.size |
The size of the islands in the graph. |
islands.pin |
The probability of intra-island edges. |
n.inter |
number of negative edges between two islands. |
a signed igraph graph
David Schoch
library(igraph) sample_islands_signed(3, 10, 0.5, 1)
library(igraph) sample_islands_signed(3, 10, 0.5, 1)
Finds blocks of nodes with intra-positive and inter-negative edges
signed_blockmodel(g, k, alpha = 0.5, annealing = FALSE)
signed_blockmodel(g, k, alpha = 0.5, annealing = FALSE)
g |
igraph object with a sign edge attribute. |
k |
number of blocks |
alpha |
see details |
annealing |
logical. if TRUE, use simulated annealing (Default: FALSE) |
The function minimizes P(C)=N+(1-
)P,
where N is the total number of negative ties within plus-sets and P be the total number of
positive ties between plus-sets. This function implements the structural balance model. That is,
all diagonal blocks are positive and off-diagonal blocks negative.
For the generalized version see signed_blockmodel_general.
numeric vector of block assignments and the associated criterion value
David Schoch
Doreian, Patrick and Andrej Mrvar (2009). Partitioning signed social networks. Social Networks 31(1) 1-11
library(igraph) g <- sample_islands_signed(10, 10, 1, 20) clu <- signed_blockmodel(g, k = 10, alpha = 0.5) table(clu$membership) clu$criterion # Using simulated annealing (less change of getting trapped in local optima) data("tribes") clu <- signed_blockmodel(tribes, k = 3, alpha = 0.5, annealing = TRUE) table(clu$membership) clu$criterion
library(igraph) g <- sample_islands_signed(10, 10, 1, 20) clu <- signed_blockmodel(g, k = 10, alpha = 0.5) table(clu$membership) clu$criterion # Using simulated annealing (less change of getting trapped in local optima) data("tribes") clu <- signed_blockmodel(tribes, k = 3, alpha = 0.5, annealing = TRUE) table(clu$membership) clu$criterion
Finds blocks of nodes with specified inter/intra group ties
signed_blockmodel_general(g, blockmat, alpha = 0.5)
signed_blockmodel_general(g, blockmat, alpha = 0.5)
g |
igraph object with a sign edge attribute. |
blockmat |
Integer Matrix. Specifies the inter/intra group patterns of ties |
alpha |
see details |
The function minimizes P(C)=N+(1-
)P,
where N is the total number of negative ties within plus-sets and P be the total number of
positive ties between plus-sets. This function implements the generalized model. For the structural balance
version see signed_blockmodel.
numeric vector of block assignments and the associated criterion value
David Schoch
Doreian, Patrick and Andrej Mrvar (2009). Partitioning signed social networks. Social Networks 31(1) 1-11
library(igraph) # create a signed network with three groups and different inter/intra group ties g1 <- g2 <- g3 <- graph.full(5) V(g1)$name <- as.character(1:5) V(g2)$name <- as.character(6:10) V(g3)$name <- as.character(11:15) g <- Reduce("%u%", list(g1, g2, g3)) E(g)$sign <- 1 E(g)$sign[1:10] <- -1 g <- add.edges(g, c(rbind(1:5, 6:10)), attr = list(sign = -1)) g <- add.edges(g, c(rbind(1:5, 11:15)), attr = list(sign = -1)) g <- add.edges(g, c(rbind(11:15, 6:10)), attr = list(sign = 1)) # specify the link patterns between groups blockmat <- matrix(c(1, -1, -1, -1, 1, 1, -1, 1, -1), 3, 3, byrow = TRUE) signed_blockmodel_general(g, blockmat, 0.5)
library(igraph) # create a signed network with three groups and different inter/intra group ties g1 <- g2 <- g3 <- graph.full(5) V(g1)$name <- as.character(1:5) V(g2)$name <- as.character(6:10) V(g3)$name <- as.character(11:15) g <- Reduce("%u%", list(g1, g2, g3)) E(g)$sign <- 1 E(g)$sign[1:10] <- -1 g <- add.edges(g, c(rbind(1:5, 6:10)), attr = list(sign = -1)) g <- add.edges(g, c(rbind(1:5, 11:15)), attr = list(sign = -1)) g <- add.edges(g, c(rbind(11:15, 6:10)), attr = list(sign = 1)) # specify the link patterns between groups blockmat <- matrix(c(1, -1, -1, -1, 1, 1, -1, 1, -1), 3, 3, byrow = TRUE) signed_blockmodel_general(g, blockmat, 0.5)
lists all possible signed triangles
signed_triangles(g)
signed_triangles(g)
g |
igraph object with a sign edge attribute. |
matrix of vertex ids and the number of positive ties per triangle
David Schoch
library(igraph) g <- graph.full(4) E(g)$sign <- c(-1, 1, 1, -1, -1, 1) signed_triangles(g)
library(igraph) g <- graph.full(4) E(g)$sign <- c(-1, 1, 1, -1, -1, 1) signed_triangles(g)
triad census for signed graphs
triad_census_signed(g)
triad_census_signed(g)
g |
igraph object with a sign edge attribute. |
counts for all 139 signed directed triangle types
David Schoch
library(igraph) g <- graph.full(4, directed = TRUE) E(g)$sign <- rep(c(-1, 1, 1, -1, -1, 1), 2) triad_census_signed(g)
library(igraph) g <- graph.full(4, directed = TRUE) E(g)$sign <- rep(c(-1, 1, 1, -1, -1, 1), 2) triad_census_signed(g)
Signed social network of tribes of the Gahuku–Gama alliance structure of the Eastern Central Highlands of New Guinea, from Kenneth Read. The network contains sixteen tribes connected by friendship ("rova") and enmity ("hina").
tribes
tribes
An igraph object
http://vlado.fmf.uni-lj.si/pub/networks/data/ucinet/gama.dat
Read, K. E. (1954) Cultures of the central highlands, New Guinea. Southwestern Journal of Anthropology, 1–43.