# BinGraph: Compute a distance bin matrix from a distance matrix In SANTA: Spatial Analysis of Network Associations

## Description

In order for the `Knet` or `Knode` functions to be run on a network, it is necessary to place the raw distances between each vertex pair into discreet distance bins, as the functions are unable to handle continuous distributions of distances. This is done automatically within the `Knet` and `Knode` functions, but can also be done separately using `BinGraph`.

## Usage

 `1` ```BinGraph(D, nsteps=1000, equal.bin.fill=TRUE, verbose=TRUE) ```

## Arguments

 `D` Numeric matrix, a distance matrix output by `DistGraph`. `nsteps` Integer value, the desired number of bins across which the distances are to be split. If there are too few unique distances to fill each bin, then fewer bins are returned. `equal.bin.fill` Logical, if `TRUE` then the function attempts to fill each bin with an equal number of vertex pairs. `verbose` Logical, if `TRUE` messages about the progress of the function are displayed.

## Details

In order for the `Knet` or `Knode` functions to be run, the vertex pair distances (as computed by `DistGraph`) but be split into bins. This is done as part of the `Knet` or `Knode`. However, this step is often slow for large networks and therefore the `BinGraph` function is provided separately, in order to avoid repeat computation.

Each vertex pair is placed into a bin, either ranging from 1 to `nsteps`, or from 1 to the number of unique distances.

If `equal.bin.fill` is `FALSE`, then the bin each vertex pair is placed into is directly proportional to the largest vertex pair distance. For example, if the distance between the pair is 25% of the largest distance and `nsteps` equals `100`, then the vertex pair will be placed into bin `25`. However, this can create problems when there are a small number of edges with especially large distances, as this can result in the majority of vertex pairs being placed into a small number of bins. This can reduce the effectiveness of the `Knet` and `Knode` functions. Therefore, when `equal.bin.fill` is `TRUE`, the function attempts to fill each bin with an equal number of vertex pairs. If there are a large number of tied distances, then the bins may not be filled equally.

## Value

Integer matrix with the same dimensions as `D`.

## Author(s)

Alex J. Cornish [email protected]

`DistGraph`

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14``` ```# create network and calculate the distance matrix using the shortest paths measure g1 <- barabasi.game(6, directed=FALSE) plot(g1, layout=layout.fruchterman.reingold) D1 <- DistGraph(g1, dist.method="shortest.paths") # place the distances into distance bins BinGraph(D1, nsteps=100) # create network and calculate the distance matrix using diffusion kernel-based measure g2 <- erdos.renyi.game(6, p.or.m=0.5, directed=FALSE) g2 <- set.edge.attribute(g2, name="distance", value=runif(ecount(g2))) plot(g2, layout=layout.fruchterman.reingold) # place the distances into distance bins D2 <- DistGraph(g2, dist.method="diffusion", edge.attr="distance") BinGraph(D2, nsteps=100) ```

### Example output

```Loading required package: igraph

Attaching package: 'igraph'

The following objects are masked from 'package:stats':

decompose, spectrum

The following object is masked from 'package:base':

union

computing graph distance matrix... done
computing graph distance bins... done
[,1] [,2] [,3] [,4] [,5] [,6]
[1,]    1    2    2    2    2    3
[2,]    2    1    3    3    3    4
[3,]    2    3    1    3    3    4
[4,]    2    3    3    1    3    2
[5,]    2    3    3    3    1    4
[6,]    3    4    4    2    4    1
computing graph distance matrix... done
computing graph distance bins... done
[,1] [,2] [,3] [,4] [,5] [,6]
[1,]    1   13   15   14   16   12
[2,]   13    1    4    3    9    2
[3,]   15    4    1    6   10    6
[4,]   14    3    5    1    8    7
[5,]   16    9   10    8    1   11
[6,]   12    2    6    7   11    1
```

SANTA documentation built on Nov. 1, 2018, 3:46 a.m.