Learn R Programming

ppsbm (version 1.0.0)

convertNodePair: Convert node pair \((i,j)\)

Description

Convert node pair \((i,j)\) into an index in \(\{1,\dots,N\}\) where \(N=n(n-1)\) (directed case) or \(N=n(n-1)/2\) (undirected case).

Usage

convertNodePair(i, j, n, directed)

Value

Index corresponding to the node pair

Arguments

i

Node \(i\) : \(i\in \{1, \ldots, n\} \)

j

Node \(j\) : \(j\in \{1, \ldots, n\} \)

n

Total number of nodes, \(1\le i \le n\)

directed

Boolean for directed (TRUE) or undirected (FALSE) case

Details

Interacting individuals \((i,j)\) must be encoded into integer values in \(\{1,\dots,N\}\) in describing the data.

Directed case :

  • The node pair \((i,j)\) with \((i\neq j)\) is converted into the index \((i-1)*(n-1)+j-(i<j)\)

Undirected case :

  • The node pair \((i,j)\) with \((i\neq j)\) is converted into the index \((2*n-i)*(i-1)/2 +j-i\)

The number of possible node pairs is

  • \(N = n*(n-1)\) for the directed case

  • \(N = n*(n-1)/2\) for the undirected case

which corresponds to the range of values for data$type.seq

Examples

Run this code
# Convert the node pair (3,7) into an index, where the total number of nodes is 10,
# for directed and undirected interactions

i <- 3
j <- 7
n <- 10

directedIndex <- convertNodePair(i,j,n,TRUE)
undirectedIndex <- convertNodePair(i,j,n,FALSE)

Run the code above in your browser using DataLab