Learn R Programming

cograph (version 2.7.2)

project_bipartite: Project Bipartite Network to One-Mode

Description

Projects a two-mode (bipartite/incidence) network into a one-mode adjacency matrix. Row-mode projection yields a matrix of shared-column connections among row nodes; column-mode projection does the converse.

Usage

project_bipartite(x, mode = "rows", method = "sum", ...)

Value

A square adjacency matrix, one row and column per node of the projected mode: n_rows x n_rows named by rownames(x) for mode = "rows", n_cols x n_cols named by colnames(x)

for mode = "columns". The diagonal is set to 0 (no self-loops).

Arguments

x

An incidence matrix (rows = type 1 nodes, columns = type 2 nodes) where non-zero entries indicate connections. Can also be a data.frame with columns type1, type2, and optionally weight.

mode

Character. "rows" (default) projects onto row nodes (result: n_rows x n_rows). "columns" projects onto column nodes (result: n_cols x n_cols).

method

Character. Projection method:

"sum"

Weighted projection: A %*% t(A) (rows) or t(A) %*% A (columns). Edge weight equals sum of shared connection-weight products.

"binary"

Co-occurrence count: binarize A first, then compute overlap. Edge weight equals number of shared connections.

"jaccard"

Jaccard similarity: shared / (total_i + total_j - shared) for each pair.

"cosine"

Cosine similarity: dot product of row (or column) vectors divided by the product of their norms.

"newman"

Newman's weighted projection (Newman 2001): each shared affiliation contributes 1 / (d_k - 1) where d_k is the degree of the shared node. Gives more weight to connections through exclusive affiliations.

...

Additional arguments (currently unused).

Details

Only method = "sum" and method = "cosine" use the incidence values themselves. "binary", "jaccard" and "newman" first binarize the incidence matrix (x > 0), so any weights are discarded for those three.

For the Newman projection, affiliations shared with only one node of the focal type (d_k = 1) are skipped, since 1 / (d_k - 1) is undefined. This follows the convention in Newman (2001).

References

Newman, M. E. J. (2001). Scientific collaboration networks. II. Shortest paths, weighted networks, and centrality. Physical Review E, 64(1), 016132.

See Also

is_bipartite, plot_heatmap

Examples

Run this code
# Incidence matrix: 4 students x 3 courses
inc <- matrix(c(1, 1, 0,
                1, 0, 1,
                0, 1, 1,
                1, 1, 1), 4, 3, byrow = TRUE)
rownames(inc) <- paste0("S", 1:4)
colnames(inc) <- paste0("C", 1:3)

# Student co-enrollment (weighted)
cograph::project_bipartite(inc, mode = "rows", method = "sum")

# Course overlap (Jaccard similarity)
cograph::project_bipartite(inc, mode = "columns", method = "jaccard")

# Newman's weighted projection
cograph::project_bipartite(inc, mode = "rows", method = "newman")

Run the code above in your browser using DataLab