hrg.fit (graph, hrg = NULL, start = FALSE, steps = 0)
hrg.consensus (graph, hrg = NULL, start = FALSE, num.samples = 10000)hrg.create (graph, prob)
hrg.dendrogram (hrg)
hrg.game (hrg)
hrg.predict (graph, hrg = NULL, start = FALSE, num.samples = 10000,
num.bins = 25)
## S3 method for class 'igraphHRG':
print(x, type=c("auto", "tree", "plain"),
level = 3, ...)
## S3 method for class 'igraphHRGConsensus':
print(x, \dots)
igraphHRG
object. hrg.fit
allows this to be
NULL
, in which case a random starting point is used for the
fitting. hrg.consensus
and h
igraphHRG
object, or from a random starting point.igraphHRG
or igraphHRGConsensus
object to
print.hrg.fit
returns an igraphHRG
object. This is a list with
the following members:left
vector.hrg.consensus
returns a list of two objects. The first is an
igraphHRGConsensus
object, the second is an igraphHRG
object. The igraphHRGConsensus
object has the following
members:parents
vector.hrg.create
returns an igraphHRG
object. hrg.dendrogram
returns an igraph graph.
hrg.game
returns an igraph graph.
igraphHRG
objects can be printed to the screen in two forms: as
a tree or as a list, depending on the type
argument of the
print function. By default the auto
type is used, which selects
tree
for small graphs and simple
(=list) for bigger
ones. The tree
format looks like
this: Hierarchical random graph, at level 3:
g1 p= 0
'- g15 p=0.33 1
'- g13 p=0.88 6 3 9 4 2 10 7 5 8
'- g8 p= 0.5
'- g16 p= 0.2 20 14 17 19 11 15 16 13
'- g5 p= 0 12 18
This is a graph with 20 vertices, and the
top three levels of the fitted hierarchical random graph are
printed. The root node of the HRG is always vertex group #1
(g1
g1
connect to vertices in the right subtree with
probability zero, according to the fitted model. g1
has two
subgroups, g15
and g8
. g15
has a subgroup of a
single vertex (vertex 1), and another larger subgroup that contains
vertices 6, 3, etc. on lower levels, etc. The plain
printing is simpler and faster to produce, but less
visual: Hierarchical random graph:
g1 p=0.0 -> g12 g10 g2 p=1.0 -> 7 10 g3 p=1.0 -> g18 14
g4 p=1.0 -> g17 15 g5 p=0.4 -> g15 17 g6 p=0.0 -> 1 4
g7 p=1.0 -> 11 16 g8 p=0.1 -> g9 3 g9 p=0.3 -> g11 g16
g10 p=0.2 -> g4 g5 g11 p=1.0 -> g6 5 g12 p=0.8 -> g8 8
g13 p=0.0 -> g14 9 g14 p=1.0 -> 2 6 g15 p=0.2 -> g19 18
g16 p=1.0 -> g13 g2 g17 p=0.5 -> g7 13 g18 p=1.0 -> 12 19
g19 p=0.7 -> g3 20
It lists the two subgroups of each internal node, in
as many columns as the screen width allows.
Consensus dendrograms (igraphHRGConsensus
objects) are printed
simply by listing the children of each internal node of the
dendrogram: HRG consensus tree:
g1 -> 11 12 13 14 15 16 17 18 19 20
g2 -> 1 2 3 4 5 6 7 8 9 10
g3 -> g1 g2
The root of the dendrogram is g3
(because it has no incoming
edges), and it has two subgroups, g1
and g2
.
Please see references below for more about hierarchical random graphs.
igraph contains functions for fitting HRG models to a given network
(hrg.fit
, for generating networks from a given HRG
ensemble (hrg.game
), converting an igraph graph to a
HRG and back (hrg.create
, hrg.dendrogram
),
for calculating a consensus tree from a set of sampled HRGs
(hrg.consensus
) and for predicting missing edges in a
network based on its HRG models (hrg.predict
).
The igraph HRG implementation is heavily based on the code
published by Aaron Clauset, at his website,
hrg.fit
fits a HRG to a given graph. It takes the specified
steps
number of MCMC steps to perform the fitting, or a
convergence criteria if the specified number of steps is
zero. hrg.fit
can start from a given HRG, if this is given in
the hrg
argument and the start
argument is TRUE
.
hrg.consensus
creates a consensus tree from several fitted
hierarchical random graph models, using phylogeny methods. If the
hrg
argument is given and start
is set to TRUE
,
then it starts sampling from the given HRG. Otherwise it optimizes the
HRG log-likelihood first, and then samples starting from the optimum.
hrg.create
creates a HRG from an igraph graph. The igraph graph
must be a directed binary tree, with $n-1$ internal and $n$
leaf vertices. The prob
argument contains the HRG probability
labels for each vertex; these are ignored for leaf vertices.
hrg.dendrogram
creates the corresponsing igraph tree of a
hierarchical random graph model.
hrg.game
samples a graph from a given hierarchical random graph
model.
hrg.predict
uses a hierarchical random graph model to predict
missing edges from a network. This is done by sampling hierarchical
models around the optimum model, proportionally to their
likelihood. The MCMC sampling is stated from hrg
, if it is given
and the start
argument is set to TRUE
. Otherwise a HRG is
fitted to the graph first.
A. Clauset, C. Moore, and M.E.J. Newman. Structural Inference of Hierarchies in Networks. In E. M. Airoldi et al. (Eds.): ICML 2006 Ws, Lecture Notes in Computer Science 4503, 1--13. Springer-Verlag, Berlin Heidelberg (2007).
## A graph with two dense groups
g <- erdos.renyi.game(10, p=1/2) + erdos.renyi.game(10, p=1/2)
hrg <- hrg.fit(g)
hrg
## The consensus tree for it
hrg.consensus(g, hrg=hrg, start=TRUE)
## Prediction of missing edges
g2 <- graph.full(4) + (graph.full(4) - path(1,2))
hrg.predict(g2)
Run the code above in your browser using DataCamp Workspace