Learn R Programming

diseasemapping (version 1.5.1)

nbToInlaGraph: Write a graph file for INLA

Description

Writes a graph file from an adjacency matrix suitable for use with INLA.

Usage

nbToInlaGraph(adjMat, graphFile="graph.dat")

Arguments

adjMat

An object of class nb containing the adjacency matrix.

graphFile

name of file to save adjacency matrix to.

Value

A vector of names and indices

Details

This function correctly handles regions which have zero neighbours.

See Also

poly2nb, nb2INLA

Examples

Run this code
# NOT RUN {
data('kentucky')
# remove all the neighbours Ballard county
kSub = kentucky[-c(2,20,79),]

if( require("spdep", quietly=TRUE)) {


adjMat = poly2nb(
	kSub, 
	row.names=kSub$County,
	queen=FALSE
)

nFile = tempfile()
nbRes = nbToInlaGraph(adjMat, nFile)

# Ballard is region 3
nbRes['Ballard']
# note that Ballard has no neighbours
adjMat[[3]]

cat(readLines(nFile, n=5), sep='\n')

# }
# NOT RUN {
# there will be a warning about zero neighbours
junk = bym(poverty ~ 1, data=kSub, family='gaussian')
# }
# NOT RUN {
}

# }

Run the code above in your browser using DataLab