node_positions: Calculate node position vectors

Description Usage Arguments Details Value References Examples

View source: R/node_positions.R

Description

For binary networks, counts the number of times each node appears in each unique node position within motifs; for weighted networks calculates a range of weighted node position measures.

Usage

1
2
3
4
5
6
7
8
node_positions(
  M,
  six_node = FALSE,
  level = "all",
  weights_method,
  weights_combine = "none",
  normalisation = "none"
)

Arguments

M

A numeric matrix representing interactions between two groups of nodes. Each row corresponds to a node in one level and each column corresponds to a node in the other level. Elements of M are positive numbers if nodes do interact, and 0 otherwise. Formally, M is a biadjacency matrix. When nodes i and j interact, m_ij > 0; if they do not interact, m_ij = 0. If interactions are weighted (non-zero matrix elements take values other than 1), the function will automatically convert the matrix to a binary matrix.

six_node

Logical; should six node motifs be counted? Defaults to FALSE.

level

Which node level should positions be calculated for: "rows", "columns" or "all"? Defaults to "all".

weights_method

The method for calculating weighted positions; must be one of 'none', 'mean_motifweights', 'total_motifweights', 'mean_nodeweights', 'total_nodeweights', 'contribution', 'mora' or 'all' (see details).

weights_combine

Method for combining weighted position measures; must be one of 'none', 'mean' or 'sum' (see details). Defaults to 'none'.

normalisation

Which normalisation should be used: "none","sum","sizeclass", "sizeclass_plus1", "sizeclass_NAzero", "position","levelsize","levelsize_plus1","levelsize_NAzero","motif","motif_plus1" or "motif_NAzero" (see details)? Defaults to "none".

Details

For binary networks, counts the number of times each node occurs in each unique position within motifs (to quantify a node's structural role). If networks are weighted, node_positions can also calculate various weighted node position measures.

If a matrix is provided without row or column names, default names will be assigned: the first row will be called called 'r1', the second row will be called 'r2' and so on. Similarly, the first column will be called 'c1', the second column will be called 'c2' and so on.

Six node

If six_node = FALSE, node positions in all motifs containing between 2 and 5 nodes are counted. If six_node = TRUE, node positions in all motifs containing between 2 and 6 nodes are counted. Analyses where six_node = FALSE are substantially faster than when six_node = TRUE, especially for large networks. For large networks, counting six node motifs is also memory intensive. In some cases, R can crash if there is not enough memory.

Level

The level argument controls which level of nodes positions are calculated for: "rows" returns position counts for all nodes in rows, "columns" returns position counts for all nodes in columns, and "all" return counts for all nodes in the network.

Weighted networks

node_positions also supports weighted networks for motifs up to five nodes. Weighted analyses are controlled using two arguments: weights_method and weights_combine. These are described in detail below:

Normalisation

Nodes with more interactions will tend to appear in more positions. Normalisation helps control for this effect. bmotif include six main types of normalisation:

Value

Returns a data frame with one column for each node position: 46 columns if six_node is FALSE, and 148 columns if six_node is TRUE. Columns names are given as "npx" where x is the ID of the position as described in Simmons et al. (2017) (and originally in Appendix 1 of Baker et al. (2015)). To view the 'motif dictionary' showing which node position a given ID corresponds to, enter vignette("bmotif-dictionary").

For a network with A rows and P columns, by default (where level = "all") the data frame has A + P rows, one for each node. If level = "rows", the data frame will have A rows, one for each row node; if level = "columns", it will have P rows, one for each column node.

By default, the elements of this data frame will be the raw binary or weighted position measures (depending on which was requested). If normalisation is set to something other than "none", the elements will be normalised position counts as described above.

If weights_method is set to 'all', node_positions instead returns a list of length five, each containing a data.frame corresponding to one of the five weighting methods described above.

References

Baker, N., Kaartinen, R., Roslin, T., and Stouffer, D. B. (2015). Species’ roles in food webs show fidelity across a highly variable oak forest. Ecography, 38(2):130–139.

Mora, B.B., Cirtwill, A.R. and Stouffer, D.B., 2018. pymfinder: a tool for the motif analysis of binary and quantitative complex networks. bioRxiv, 364703.

Simmons, B. I., Sweering, M. J. M., Dicks, L. V., Sutherland, W. J. and Di Clemente, R. bmotif: a package for counting motifs in bipartite networks. bioRxiv. doi: 10.1101/302356

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
set.seed(123)
row <- 10
col <- 10

# node positions in a binary network
m <- matrix(sample(0:1, row*col, replace=TRUE), row, col)
node_positions(M = m, six_node = TRUE, weights_method = "none", weights_combine = "none")

# node positions in a weighted network
m[m>0] <- stats::runif(sum(m), 0, 100)
node_positions(M = m, six_node = FALSE, weights_method = "all", weights_combine = "sum")

bmotif documentation built on Sept. 13, 2020, 5:10 p.m.