Learn R Programming

diseasemapping (version 2.0.6)

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", region.id = attributes(adjMat)$region.id)

Value

A vector of names and indices

Arguments

adjMat

An object of class nb containing the adjacency matrix.

graphFile

name of file to save adjacency matrix to.

region.id

names of regions

Author

Patrick Brown

Details

This function correctly handles regions which have zero neighbours.

See Also

Examples

Run this code

data('kentucky')
kentucky = terra::unwrap(kentucky)
# remove all the neighbours Ballard county
kSub = kentucky[-c(2,20,79),]


adjMat = terra::adjacent(kSub)
attributes(adjMat)$region.id = kSub$County

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

# Ballard is region 3
nbRes['Ballard']
# note that Ballard has no neighbours
table(adjMat[,'from']==3)

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

# \donttest{
# there will be a warning about zero neighbours
junk = bym(poverty ~ 1, data=kSub, family='gaussian', num.threads=3)
# }


Run the code above in your browser using DataLab