Description Usage Arguments Details Value Author(s) References Examples
Put an adjacency object in a ragged array
1 | addSpatial(map, raggedArray, effect = NULL,prefix=NULL)
|
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 |
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.
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 |
NregionSpatial |
where 'region' is replaced by the name of the effect. The number of regions. |
Patrick Brown
Also see the geoBUGS manual
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.