Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

nbAndGraConversion

Convert nb and gra format into each other


Description

Convert neighborhood structure objects of class "nb" from R-package spdep to graph objects of class "gra" from R-package BayesX and vice versa.

Usage

nb2gra(nbObject)
gra2nb(graObject)

Arguments

nbObject

neighborhood structure object of class "nb"

graObject

graph object of class "gra"

Value

Equivalent object in the other format.

Author(s)

Daniel Sabanes Bove

See Also

sp2bnd, bnd2sp for conversion between the geographical information formats and read.gra, write.gra for the interface to the BayesX files.

Examples

## first nb to gra:
library(spdep)
library(maptools)
columbus <- readShapePoly(system.file("etc/shapes/columbus.shp", package="spdep")[1])
colNb <- poly2nb(columbus)
## ... here manual editing is possible ...
## then export to graph format
colGra <- nb2gra(colNb)

## and save in BayesX file
graFile <- tempfile()
write.gra(colGra, file=graFile)

## now back from gra to nb:
colGra <- read.gra(graFile)
newColNb <- gra2nb(colGra)
newColNb
## compare this with the original
colNb
## only the call attribute does not match (which is OK):
all.equal(newColNb, colNb,
          check.attributes=FALSE)
attr(newColNb, "call")
attr(colNb, "call")

BayesX

R Utilities Accompanying the Software Package BayesX

v0.3-1
GPL-2 | GPL-3
Authors
Nikolaus Umlauf [aut, cre], Thomas Kneib [aut], Nadja Klein [aut], Felix Heinzl [ctb], Andreas Brezger [ctb], Daniel Sabanes Bove [ctb]
Initial release
2019-08-23

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.