Title: | Methods to Analyze One-mode Projections of Two-mode Networks |
---|---|
Description: | Methods to analyze one-mode projections of two-mode networks. Focus lies on methods to determine significant edges. |
Authors: | David Schoch [aut, cre] |
Maintainer: | David Schoch <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.5.0 |
Built: | 2024-11-20 03:49:34 UTC |
Source: | https://github.com/schochastics/levelnet |
Create a two-mode network from a data.frame
bipartite_from_data_frame(df, type1, type2)
bipartite_from_data_frame(df, type1, type2)
df |
data.frame |
type1 |
column name of mode 1 |
type2 |
column name of mode 2 |
two mode network as igraph object
David Schoch
Bill cosponsorship data for the 115th Senate
cosponsor_senate_15
cosponsor_senate_15
a data frame of bill cosponsorships
govtrack.us
Extract significant edges of a weighted network or one-mode projection with the disparsity filter.
disparsity_filter(g, proj = "true", alpha = 0.05, cut_mode = "or")
disparsity_filter(g, proj = "true", alpha = 0.05, cut_mode = "or")
g |
igraph object. either two-mode or weighted network |
proj |
string. Which mode to project on ("true"/"false") |
alpha |
significant level |
cut_mode |
'and' (retain edge if both directions are significant) or 'or' (retain edge if one direction is significant) |
backbone of weighted network as igraph object
David Schoch
Serrano et al. (2009). Extracting the multiscale backbone of complex weighted networks
Returns the permutation induced by sorting the Fiedler vector of the Laplacian matrix of a graph
fiedler_order(g, mode = "cols")
fiedler_order(g, mode = "cols")
g |
an igraph object or a (0,1)-matrix |
mode |
one of "mcl" (clique vertex matrix), "cols" (Lazarus count of columns) "rows" (Lazarus count of rows) or "sym" (Lazarus count of both columns and rows). |
numeric vector
David Schoch
Create a random indifference graph. An indifference graph is an interval graph where intervals have length 1.
graph_indifference(n, r = 2)
graph_indifference(n, r = 2)
n |
number of nodes |
r |
radius |
'n' points (x) are sampled uniformly at random between 0 and 'r'. The interval is then given by (x,x+1)
indifference graph as igraph object and interval representation (a,b)
David Schoch
[graph_interval,graph_tolerance]
graph_indifference(n = 10)
graph_indifference(n = 10)
Create a random interval graph. In an interval graph, each node is characterized by an interval on the real line. Two nodes are connected, if their intervals overlap.
graph_interval(n, r = 2, sd = 0.5)
graph_interval(n, r = 2, sd = 0.5)
n |
number of nodes |
r |
radius (see details) |
sd |
standard deviation (see details) |
Interval graphs are created as follows. First, n random points x are created uniformly at random between 0 and 'r'. For each point, a value Y is created from a normal distribution with mean X and standard deviation is 'sd'. In this way, it is possible to control the density of the network. The larger 'r' and the larger 'sd' the more likely do intervals overlap.
interval graph as igraph object and interval representation as node attribute (a,b)
David Schoch
[graph_indifference,graph_tolerance]
graph_interval(n = 10)
graph_interval(n = 10)
generate random roll-call votes based on ideology space
graph_random_vote( M = 101, D = 1, p = 4, pd = 2, beta = 1, r = 9, noprob = 0.05, Nrand = 1000, N = 525 )
graph_random_vote( M = 101, D = 1, p = 4, pd = 2, beta = 1, r = 9, noprob = 0.05, Nrand = 1000, N = 525 )
M |
number of members |
D |
distance between means |
p |
dimension of space |
pd |
dimensioms where distributions are separated |
beta |
scaling parameter for probabilistic voting |
r |
radius of hypersphere for random generation |
noprob |
probabilit of non voting |
Nrand |
number of randomly generated votes |
N |
number of votes to sample from randomly generated votes |
list with random votes and ideologies
David Schoch
Aldrich, John H., and Montgomery, Jacob M., and Sparks, David B. (2014). Polarization and Ideology: Partisan Sources of Low Dimensionality in Scaled Roll Call Analyses. Political Analysis 22:435-456
Create a random graph with boxicity 2.
graph_rectangle(n, r = 2, sd = 0.5)
graph_rectangle(n, r = 2, sd = 0.5)
n |
number of nodes |
r |
radius |
sd |
standard deviation |
Boxicity 2 graph as igraph object
David Schoch
Create a random tolerance graph. A tolerance graph is an interval graph, where nodes are only connected if the overlap is larger than a nodes tolerance level. These graphs are directed.
graph_tolerance(n, r = 2, sd = 0.5, tol = 0.5)
graph_tolerance(n, r = 2, sd = 0.5, tol = 0.5)
n |
number of nodes |
r |
radius (see details) |
sd |
standard deviation (see details) |
tol |
tolerance |
Tolerance graphs are created as follows. First, n random points x are created uniformly at random between 0 and 'r'. For each point, a value Y is created from a normal distribution with mean X and standard deviation is 'sd'. In this way, it is possible to control the density of the network. The larger 'r' and the larger 'sd' the more likely do intervals overlap. When overlaps are calculated, it is checked whether the overlap is larger than the tolerance of the node. If so, the edge is included.
tolerance graph as igraph object and interval representation and tolerance as node attributes
David Schoch
[graph_interval,graph_indifference]
graph_tolerance(n = 10)
graph_tolerance(n = 10)
small helper functions
clique_vertex_mat(g) is_bipartite1(g)
clique_vertex_mat(g) is_bipartite1(g)
g |
igraph object. |
igraph object
David Schoch
Check whether graph is interval graph.
is_interval(g)
is_interval(g)
g |
igraph object |
This function is not very efficient since it relies on the clique vertex matrix. More efficient linear time algorithms will be implemented in the future.
Logical scalar, whether graph is an interval graph
David Schoch
Returns Laplacian eigenvectors associated with the k smallest positive eigenvalues
laplacian_vectors(g, k = 2)
laplacian_vectors(g, k = 2)
g |
igraph object |
k |
number of vectors to return |
data.frame of vectors
David Schoch
Calculates the Lazarus count of a matrx/graph.
lazarus_count(g, perm = NULL, mode = "cols")
lazarus_count(g, perm = NULL, mode = "cols")
g |
either an igraph object or a (0,1)-matrix |
perm |
permutation or NULL |
mode |
one of "mcl" (clique vertex matrix), "cols" (Lazarus count of columns) "rows" (Lazarus count of rows) or "sym" (Lazarus count of both columns and rows). |
The Lazarus count of a matrix is the number of "holes" in each column. A hole is a number of zero entries surrounded by ones. For an interval graph, this count is zero for the [clique_vertex_mat]. If 'perm' is NULL, a row permutation based on the Fiedler vector of the Laplacian is calculated.
Lazarus count of g
David Schoch
set.seed(10) #the lazarus count of an interval graph is zero g <- graph_interval(n = 10,r = 1) lazarus_count(g, mode = "mcl")
set.seed(10) #the lazarus count of an interval graph is zero g <- graph_interval(n = 10,r = 1) lazarus_count(g, mode = "mcl")
Multisweep lexicograpical BFS
multiLexBFS(g, k = 4)
multiLexBFS(g, k = 4)
g |
igraph object |
k |
number of sweeps |
LexBFS is used to recognize interval graphs. Not fully implemented yet.
permutation
David Schoch
Create a box representation from permutations
perm2box(g, perm, dim)
perm2box(g, perm, dim)
g |
igraph object. |
perm |
integer vector of length n times dim |
dim |
integer. dimensionality of boxes |
coordinates
Chandran, L. S., Francis, M. C. & Sivadasan, N. Geometric representation of graphs in low dimension using axis parallel boxes. Algorithmica 56, 129.
Flexible Stochastic Degree Sequence Model.
fsdsm( g, row_constr, proj = "true", model = "logit", max_iter = 1000, alpha = 0.05, params = list(b0 = 0.1, b1 = 5e-05, b2 = 5e-05, b3 = 5e-05, a = 0.01), verbose = FALSE ) sdsm_prob( g, proj = "true", model = "logit", max_iter = 1000, params = list(b0 = 0.1, b1 = 5e-05, b2 = 5e-05, b3 = 5e-05, a = 0.01), verbose = FALSE )
fsdsm( g, row_constr, proj = "true", model = "logit", max_iter = 1000, alpha = 0.05, params = list(b0 = 0.1, b1 = 5e-05, b2 = 5e-05, b3 = 5e-05, a = 0.01), verbose = FALSE ) sdsm_prob( g, proj = "true", model = "logit", max_iter = 1000, params = list(b0 = 0.1, b1 = 5e-05, b2 = 5e-05, b3 = 5e-05, a = 0.01), verbose = FALSE )
g |
igraph object. The two-mode network |
row_constr |
constraint matrix |
proj |
string. Which mode to project on ("true"/"false") |
model |
string. which link to be used ('logit','probit','cloglog' or 'scobit') |
max_iter |
number of randomly sampled networks |
alpha |
significance level |
params |
named parameter list for scobit model |
verbose |
print status during execution |
a flexible implementation of the stochastic degree sequence model, allowing for the addition of constraints (use sdsm from the backbone package for the regular model)
backbone of one-mode projection
David Schoch
Neal, Zachary (2014). The backbone of bipartite projections: Inferring relationships from co-authorship, co-sponsorship, co-attendance and other co-behaviors
check which binary outcome model fits the data best
sdsm_diagnostic( g, proj = "true", iter = 10, verbose = FALSE, params = list(b0 = 0.1, b1 = 5e-05, b2 = 5e-05, b3 = 5e-05, a = 0.01) )
sdsm_diagnostic( g, proj = "true", iter = 10, verbose = FALSE, params = list(b0 = 0.1, b1 = 5e-05, b2 = 5e-05, b3 = 5e-05, a = 0.01) )
g |
igraph object. The two-mode network |
proj |
string. Which mode to project on |
iter |
number of fits per model |
verbose |
logical. print additional information (default: FALSE) |
params |
named parameter list for scobit model |
rmse and runtime of various models
David Schoch
Create a supergraph with given boxicity using simulated annealing (SA)
superbox_graph( l, dim = 1, perm = NULL, iter = 15000, temp = 10, tmax = 5, verbose = FALSE )
superbox_graph( l, dim = 1, perm = NULL, iter = 15000, temp = 10, tmax = 5, verbose = FALSE )
dim |
integer. target boxicity |
perm |
starting permutation for SA. If NULL, a random permutation is created |
iter |
integer. number of iterations for SA |
temp |
integer. starting temperature for SA |
tmax |
integer. number of function evaluations at each temperature for SA |
verbose |
logical. print report during SA (defaults to FALSE) |
g |
igraph object |
a list with entries
perm |
permutation vector. All permutations are concatenated to one long vector |
ged |
graph edit distance from original graph |
A |
adjacency matrix of supergraph with given boxicity |
Chandran, L. S., Francis, M. C. & Sivadasan, N. Geometric representation of graphs in low dimension using axis parallel boxes. Algorithmica 56, 129.