Learn R Programming

nettools (version 1.0.1)

netdist: Distances between network

Description

This function computes the distance between two adjacency matrix given as matrices or igraph objects.

Usage

netdist(x,...)
"netdist"(x, h, d = "HIM", ga = NULL, components=TRUE, ...)
"netdist"(x, h, d = "HIM", ga = NULL, components=TRUE, ...)
"netdist"(x, d = "HIM", ga = NULL, components=TRUE, ...)
"netdist"(x, h, d = "HIM", ga = NULL, components=TRUE,...)

Arguments

x
Adjacency matrix, igraph object or list of adjacency matrices/igraph objects
h
Adjacency matrix or igraph object. Only when x is a matrix object.
d
HIM (default), character string containing a valid method. Accepted values are: "IM", "ipsen", "Ipsen", "IpsenMikhailov", or "Ipsen-Mikhailov", for Ipsen-Mikhailov distance and "H", "hamming", or "Hamming" for Hamming distance.
ga
NULL (default), a numeric value for the gamma parameter used only if method ipsen is called. If ga=NULL an optimal value based on the number of nodes in the adjacency matrix is computed.
components
TRUE (default), to obtain the components (Hamming and Ipsen-Mikhailov) for method=HIM; otherwise the function returns only the HIM value. If method is set to hamming or ipsen it will be ignored.
...
Additional arguments to be passed to the downstream functions. Normally the argument passed through ... are processed by the functions which compute the distance. Not all parameters are used by all functions.
n.cores
NULL (default), an integer number of available cores to run run the computation. This parameter used only when method is ipsen or HIM. If method list is called, each core take care of the computation of eigenvalues for a matrix in the input list. If n.cores is bigger than the number of available cores on the specific machine, than n.cores is set to the number of available cores - 1.

verbose
FALSE (default), print information about the state of the computation

Value

components set to FALSE the distance between the input networks is returned. If components is TRUE and method is HIM a named vector with 3 values is returned, respectively the Hamming(H) distance, the Ipsen-Mikhailov IM distance and the HIM distance. If a list object is provided as input a distance matrix with all the possible pairwise comparison is returned

Details

netdist is a high level function which provide an interface to different network distance methods. Distance can be computed for weighted and unweighted networks either directed or undirected. Each network must have the same number of nodes, otherwise no computation will be performed and an errore message will be output. Parallel computation is provided automatically through the parallel package included by default from R 2.15, only for methods "ipsen" and "HIM". The computation can be automatically parallelized on a multi-cpu computer using the parameter n.cores.

Input can be either an adjacency matrix, a graph object from igraph package or a list of adjacency matrix or graph objects. If the 'weight' attribute is given within the graph object it will be used as edge weight, otherwise binary representation of the network will be considered. In case edge weights are provided through the adjacency matrix, they should be scaled between 0-1. If some of the weights are outside the interval a scaling function is automatically applied. The parameter ga is used only in the Ipsen and HIM distance. We suggest not to change it and use the automatic computation of the parameter based on the number of nodes in the network.

References

G. Jurman, R. Visintainer, M. Filosi, S. Riccadonna, C. Furlanello The HIM glocal metric and kernel for network comparison and classification arXiv 2013, arXiv:1201.2931v3

Examples

Run this code
a <- matrix(rnorm(200), nrow=20)
b <- matrix(rnorm(200), nrow=20)

aa <- mat2adj(a, method="cor", n.cores=1)
bb <- mat2adj(b, method="cor", n.cores=1)

dd <- netdist(aa,bb, d="HIM", n.cores=1)
print(dd)

## Use a different gamma parameter for HIM distance
dd <- netdist(aa,bb, d="HIM", ga=0.5, n.cores=1)
print(dd)

## The function can accept also list of adjacency matrices as input
alist <- list(aa,bb)
ddist <- netdist(alist, d="HIM", n.cores=1)

## Use of multiple cores
## Not run: 
# dd <- netdist(aa,bb,n.cores=4)
# ## End(Not run)

Run the code above in your browser using DataLab