knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of netmem
is to make
available different measures to analyse and manipulate complex networks using
matrices.
# Check if the 'devtools' package is installed if (!requireNamespace("devtools", quietly = TRUE)) { install.packages("devtools") } # Check if the 'emo' package is installed via devtools if (!requireNamespace("emo", quietly = TRUE)) { devtools::install_github("hadley/emo") }
r emo::ji("pen")
Author/mantainer: Alejandro
Espinosa-Rada
r emo::ji("school")
Current: Institute of Sociology, Pontificia Universidad Católica de Chile
r emo::ji("school")
Before: Social Networks Lab, ETH Zürich

The package implements different measures to analyse and manipulate complex multilayer networks, from an ego-centric perspective, considering one-mode networks, valued ties (i.e. weighted or multiplex) or with multiple levels.
citation(package = "netmem")
netmem
:Utilities:
matrix_report()
: Matrix report
matrix_adjlist()
: Transform a matrix into an adjacency list
matrix_projection()
: Unipartite projections
matrix_to_edgelist()
: Transform a square matrix into an edge-list
adj_to_matrix()
: Transform an adjacency list into a matrix
adj_to_incidence()
: Transform an adjacency matrix into a incidence matrix
cumulativeSumMatrices()
: Cumulative sum of matrices
edgelist_to_matrix()
: Transform an edgelist into a matrix
expand_matrix()
: Expand matrix
extract_component()
: Extract components
hypergraph()
: Hypergraphs
perm_matrix()
: Permutation matrix
perm_label()
: Permute labels of a matrix
power_function()
: Power of a matrix
meta_matrix()
: Meta matrix for multilevel networks
minmax_overlap()
: Minimum/maximum overlap
mix_matrix()
: Mixing matrix
simplicial_complexes()
: Simplicial complexes
structural_na()
: Structural missing data
ego_net()
: Ego network
zone_sample()
: Zone-2 sampling from second-mode
Ego and personal networks:
eb_constraint()
: Constraint
ei_index()
: Krackhardt and Stern's E-I index
heterogeneity()
: Blau's and IQV index
redundancy()
: Redundancy measures
Path distances:
bfs_ugraph()
: Breath-first algorithm
compound_relation()
: Relational composition
count_geodesics()
: Count geodesic distances
short_path()
: Shortest path
wlocal_distances()
: Dijikstra's algorithm (one actor)
wall_distances()
: Dijikstra's algorithm (all actors)
Signed networks:
posneg_index()
: Positive-negative centrality
struc_balance()
: Structural balance
Structural measures:
gen_density()
: Generalized density
gen_degree()
: Generalized degree
multilevel_degree()
: Degree centrality for multilevel networks
recip_coef()
: Reciprocity
trans_coef()
: Transitivity
trans_matrix()
: Transitivity matrix
components_id()
: Components
k_core()
: Generalized k-core
dyadic_census()
: Dyad census
multiplex_census()
: Multiplex triad census
mixed_census()
: Multilevel triad and quadrilateral census
Cohesive subgroups:
clique_table()
: Clique table
dyad_triad_table()
: Forbidden triad table
percolation_clique()
: Clique percolation
q_analysis()
: Q-analysis
shared_partners()
: Shared partners
Similarity measures:
bonacich_norm()
: Bonacich normalization
co_ocurrence()
: Co‐occurrence
dist_sim_matrix()
: Structural similarities
fractional_approach()
: Fractional approach
jaccard()
: Jaccard similarity
Network inference:
kp_reciprocity()
: Reciprocity of Katz and Powell
z_arctest()
: Z test of the number of arcs
triad_uman()
: Triad census analysis assuming U|MAN
ind_rand_matrix()
: Independent random matrix
Geographic information:
dist_geographic()
: Geographical distances
spatial_cor()
: Spatial autocorrelation
Data currently available:
FIFAego
: Ego FIFA
FIFAex
: Outside FIFA
FIFAin
: Inside FIFA
krackhardt_friends
: Krackhardt friends
lazega_lawfirm
: Lazega Law Firm
Additional data in classicnets: Classic Data of Social
Networks
netmem: Network Measures using Matrices
You can install the development version from GitHub with:
### OPTION 1 # install.packages("devtools") devtools::install_github("anespinosa/netmem") ### OPTION 2 options(repos = c( netmem = "https://anespinosa.r-universe.dev", CRAN = "https://cloud.r-project.org" )) install.packages("netmem")
library(netmem)
Connections between individuals are often embedded in complex structures, which shape actors’ expectations, behaviours and outcomes over time. These structures can themselves be interdependent and exist at different levels. Multilevel networks are a means by which we can represent this complex system by using nodes and edges of different types. Check this book edited by Emmanuel Lazega and Tom A.B. Snijders or this book edited by David Knoke, Mario Diani, James Hollway and Dimitris Christopoulos.
For multilevel structures, we tend to collect the data in different matrices representing the variation of ties within and between levels. Often, we describe the connection between actors as an adjacency matrix and the relations between levels through incidence matrices. The comfortable combination of these matrices into a common structure would represent the multilevel network that could be highly complex.
Create the data
A1 <- matrix(c( 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0 ), byrow = TRUE, ncol = 5) B1 <- matrix(c( 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1 ), byrow = TRUE, ncol = 3) A2 <- matrix(c( 0, 1, 1, 1, 0, 0, 1, 0, 0 ), byrow = TRUE, nrow = 3) B2 <- matrix(c( 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1 ), byrow = TRUE, ncol = 4) A3 <- matrix(c( 0, 1, 3, 1, 1, 0, 0, 0, 3, 0, 0, 5, 1, 0, 5, 0 ), byrow = TRUE, ncol = 4)
We will start with a report of the matrices:
matrix_report(A1) matrix_report(B1) matrix_report(A2) matrix_report(B2) matrix_report(A3)
What is the density of some of the matrices?
matrices <- list(A1, B1, A2, B2) gen_density(matrices, multilayer = TRUE)
How about the degree centrality of the entire structure?
multilevel_degree(A1, B1, A2, B2, complete = TRUE)
Besides, we can perform a k-core analysis of one of the levels using the information of an incidence matrix
k_core(A1, B1, multilevel = TRUE)
This package also allows performing complex census for multilevel networks.
mixed_census(A2, t(B1), B2, quad = TRUE)
When we are interested in one particular actor, we could perform different
network measures. For example, actor e
has connections with all the other
actors in the network. Therefore, we could estimate some of Ronald Burt's
measures.
# First we will assign names to the matrix rownames(A1) <- letters[1:nrow(A1)] colnames(A1) <- letters[1:ncol(A1)] eb_constraint(A1, ego = "e") redundancy(A1, ego = "e")
Also, sometimes we might want to subset a group of actors surrounding an ego.
ego_net(A1, ego = "e")
This package expand some measures for one-mode networks, such as the generalized
degree centrality. Suppose we consider a valued matrix A3
. If alpha=0
then
it would only count the direct connections. But, adding the tuning parameter
alpha=0.5
would determine the relative importance of the number of ties
compared to tie weights.
gen_degree(A3, digraph = FALSE, weighted = TRUE)
Also, we could conduct some exploratory analysis using the normalized degree of an incidence matrix.
gen_degree(B1, bipartite = TRUE, normalized = TRUE)
This package also implements some analysis of dyads.
# dyad census dyadic_census(A1) # Katz and Powell reciprocity kp_reciprocity(A1) # Z test of the number of arcs z_arctest(A1)
We can also check the triad census assuming conditional uniform distribution considering different types of dyads (U|MAN)
triad_uman(A1)
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
# library(todor) # todor::todor_package(c("TODO", "FIXME"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.