Learn R Programming

bmotif (version 2.0.2)

node_positions: Calculate node position vectors

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

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".

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.

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:

  • 'weights_combine': determines how weighted position measures are combined across motif occurrences to give an overall measure for a each node in a each position.

    • 'none': weights are ignored and node_positions returns the frequency with which each node occurs in each unique positions within motifs. 'weights_method' must also be 'none'.

    • 'sum': weighted measures are summed across occurrences.

    • 'mean': the mean of the weighted measure across occurrences is calculated.

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:

  • "none": performs no normalisation and will return the raw position measure

  • "sum": divides the position measure for each node by the total number of times that node appears in any position (divides each element in a row by the row sum).

  • "position": divides the position measure for each node by the total number of times any node occurs in that node position (divides each element in a column by the column sum). This gives a measure of how often a node occurs in a position relative to the other nodes in the network.

  • Size class normalisation

    • "sizeclass": divides the position measure for each node by the total number of times that node appears in any position within the same motif size class (the number of nodes a motif contains).

    • "sizeclass_plus1": same as 'sizeclass' but adds one to all position measures If a species does not occur in any motifs in a given size class, 'sizeclass' normalisation will return NAs. 'sizeclass_plus1' avoids this by adding one to all counts.

    • "sizeclass_NAzero": same as 'sizeclass' but replaces all NA values with 0. If a species does not occur in any motifs in a given size class, 'sizeclass' normalisation will return NAs. 'sizeclass_NAzero' avoids this by replacing NAs with zero.

  • Levelsize normalisation

    • "levelsize": divides the position measure for each node by the total number of times that node appears in any position within a motif with a given number of nodes in the top level and the bottom level. For example, the relative frequencies of all position measures in motifs with three nodes in the top level and two nodes in the bottom level will sum to one, as will the relative frequency of all position counts in motifs with 2 nodes in the top level and two nodes in the bottom level, and so on.

    • "levelsize_plus1": same as 'levelsize' but adds one to all position measures If a species does not occur in any motifs with a given number of nodes in the top level and the bottom level, 'levelsize' normalisation will return NAs. 'levelsize_plus1' avoids this by adding one to all counts.

    • "levelsize_NAzero": same as 'levelsize' but replaces all NA values with 0. If a species does not occur in any motifs with a given number of nodes in the top level and the bottom level, 'levelsize' normalisation will return NAs. 'levelsize_NAzero' avoids this by replacing NAs with zero.

  • Motif normalisation

    • "motif": divides the position measure for each node by the total number of times that node appears in any position within the same motif. For example, the relative frequencies of all position measures in motif 5 will sum to one, as will the relative frequency of all position counts in motif 10, and so on.

    • "motif_plus1": same as 'motif' but adds one to all position measures. If a species does not occur in a particular motif, 'motif' normalisation will return NAs. 'motif_plus1' avoids this by adding one to all counts.

    • "motif_NAzero": same as 'motif' but replaces all NA values with 0. If a species does not occur in a particular motif, 'levelsize' normalisation will return NAs. 'motif_NAzero' avoids this by replacing NAs with zero.

References

Baker, N., Kaartinen, R., Roslin, T., and Stouffer, D. B. (2015). Species<U+2019> roles in food webs show fidelity across a highly variable oak forest. Ecography, 38(2):130<U+2013>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

Run this code
# NOT RUN {
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")
# }

Run the code above in your browser using DataLab