addSpatial {glmmBUGS}R Documentation

Calculate adjacency values for WinBUGS

Description

Put an adjacency object in a ragged array

Usage

addSpatial(map, raggedArray, effect = NULL)

Arguments

map a spatialPolygonsDataFrame object, or an nb object or a list of two vectors, adj and num
raggedArray the result from winBugsRaggedArray
effect a character vector listing the effect names

Details

Computes the values need by the car.normal distribution in WinBUGS. This function is called by glmmBUGS when a spatial argument is provided, addSpatial is usually not called by a user.

Value

The ragged array is returned, with the following additional elements

num a vector of the number of neighbours of each region
adj a vector containing the neighbours
weights a vector of ones, the same length as adj
NregionSpatial where 'region' is replaced by the name of the effect. The number of regions.

Author(s)

Patrick Brown

References

Also see the geoBUGS manual

Examples


# get a winbugs model and data ready, without a spatial effect
data(ontario)

forBugs = glmmBUGS(formula=Observed + logExpected ~ 1,
  effects="CSDUID",   family="poisson",
  data=ontario)

# now add a spatial effect.  
# first, compute the adjacency matrix 
# if region ID's are stored as factors, make sure to convert
# them to characters rather than the default of converting them
# to integers
## Not run: 
#library(spdep)
#library(diseasemapping)
#data(popdata)
popDataAdjMat = poly2nb(popdata,row.names=as.character(popdata[["CSDUID"]]) )
## End(Not run)
data(popDataAdjMat)

# add the adjacency matrix to the ragged array  
raggedWithSpatial = addSpatial(popDataAdjMat, forBugs$ragged, "CSDUID")

# write a new bugs model with a spatial effect
writeBugsModel("model.bug", "CSDUID", NULL, c("count", "expected"), "poisson", spatial="CSDUID")
startingValues = forBugs$startingValues
source("getInits.R")
## Not run: 
library(R2WinBUGS)
popResult = bugs(raggedWithSpatial, getInits, parameters.to.save = names(getInits()), model.file="model.bug", n.chain=3, n.iter=1000, n.burnin=100, n.thin=10, program="winbugs")   
## End(Not run)

[Package glmmBUGS version 1.5 Index]