read.graph: Read and write a graph-object

Description Usage Arguments Value Author(s) See Also Examples

Description

Reads a graph-object to a file and write graph-object to file

Usage

1
2
3
4
5
6
7
8
9
inla.read.graph(..., size.only = FALSE)
inla.write.graph(graph, filename = "graph.dat", mode = c("binary", "ascii"), ...)

## S3 method for class 'inla.graph'
summary(object, ...)
## S3 method for class 'inla.graph'
plot(x, y, ...)
## S3 method for class 'inla.graph.summary'
print(x, ...)

Arguments

filename

The filename of the graph.

graph

An inla.graph-object, a (sparse) symmetric matrix, a filename containing the graph, or a list or collection of characters and/or numbers defining the graph.

mode

The mode of the file; ascii-file or a (gzip-compressed) binary. Default value depends on the inla.option internal.binary.mode which is default TRUE; see inla.setOption.

object

An inla.graph -object

x

An inla.graph -object

y

Not used

size.only

Only read the size of the graph

...

Additional arguments. In inla.read.graph, then it is the graph definition (object, character, filename), plus extra arguments. In inla.write.graph it is extra arguments to inla.read.graph.

Value

The output of inla.read.graph, is an inla.graph object, with elements

n

is the size of the graph

nnbs

is a vector with the number of neigbours

nbs

is a list-list with the neigbours

cc

list with connected component information (this entry can be auto-generated; see below)

  • idis a vector with the connected component id for each node (starting from 1)

  • nis the number of connected components

  • nodesis a list-list of nodes belonging to each connected component

The connected component information, can be generated from the rest of the graph-structure, using graph = inla.add.graph.cc(graph) if you manually construct the inla.graph-object. Methods implemented for inla.graph are summary and plot. The method plot require the libraries Rgraphviz and graph from the Bioconductor-project, see http://www.bioconductor.org.

Author(s)

Havard Rue hrue@math.ntnu.no

See Also

inla.spy

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## a graph on a file
cat("3 1 1 2 2 1 1 3 0\n", file="g.dat")
g = inla.read.graph("g.dat")
## writing an inla.graph-object to file
g.file = inla.write.graph(g, mode="binary")
## re-reading it from that file
gg = inla.read.graph(g.file)
summary(g)
plot(g)
inla.spy(g)
## when defining the graph directly in the call, we can use a mix of character and numbers
g = inla.read.graph(c(3, 1, "1 2 2 1 1 3", 0))
inla.spy(c(3, 1, "1 2 2 1 1 3 0"))
inla.spy(c(3, 1, "1 2 2 1 1 3 0"),  reordering=3:1)
inla.write.graph(c(3, 1, "1 2 2 1 1 3 0"))

andrewzm/INLA documentation built on May 10, 2019, 11:12 a.m.