addSpatial: Calculate adjacency values for WinBUGS

Description Usage Arguments Details Value Author(s) References Examples

Description

Put an adjacency object in a ragged array

Usage

1
addSpatial(map, raggedArray, effect = NULL,prefix=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

prefix

Character string to be appended to variable 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
## Not run: 

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

forBugs = glmmBUGS(formula=observed + logExpected ~ 1,
  effects="CSDUID",   family="poisson",
  data=data.frame(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
library(diseasemapping)
data(popdata)
popDataAdjMat = poly2nb(popdata,row.names=as.character(popdata[["CSDUID"]]) )

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

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)

glmmBUGS documentation built on May 2, 2019, 6:08 p.m.