nbToInlaGraph | R Documentation |
Writes a graph file from an adjacency matrix suitable for use with INLA.
nbToInlaGraph(adjMat, graphFile="graph.dat", region.id = attributes(adjMat)$region.id)
adjMat |
An object of class |
graphFile |
name of file to save adjacency matrix to. |
region.id |
names of regions |
This function correctly handles regions which have zero neighbours.
A vector of names and indices
Patrick Brown
adjacent
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.