nbInlaToGraph: Write a graph file for INLA

nbToInlaGraphR Documentation

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)

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

Details

This function correctly handles regions which have zero neighbours.

Value

A vector of names and indices

Author(s)

Patrick Brown

See Also

adjacent

Examples


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')


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




diseasemapping documentation built on Sept. 22, 2023, 1:07 a.m.