bym-methods {diseasemapping} | R Documentation |
Fit the BYM model
Description
Uses inla to fit a Besag, York and Mollie disease mapping model
Usage
## S4 method for signature 'formula,ANY,ANY,missing'
bym(formula,data,adjMat,region.id,...)
## S4 method for signature 'formula,ANY,missing,missing'
bym(formula,data,adjMat,region.id,...)
## S4 method for signature 'formula,SpatVector,NULL,character'
bym(formula, data, adjMat, region.id, ...)
## S4 method for signature 'formula,SpatVector,missing,character'
bym(formula, data, adjMat, region.id, ...)
## S4 method for signature 'formula,SpatVector,matrix,character'
bym(formula,data,adjMat,region.id,...)
## S4 method for signature 'formula,data.frame,matrix,character'
bym(
formula,data,adjMat,region.id,
prior=list(sd=c(0.1,0.5),propSpatial=c(0.5,0.5)),
family="poisson",formula.fitted=formula,...)
Arguments
formula |
model formula, defaults to intercept-only model suitable for
output from |
data |
The observations and covariates for the model, can be output from
|
adjMat |
An object of class |
region.id |
Variable in |
prior |
named list of vectors specifying priors, see Details |
family |
distribution of the observations, defaults to |
formula.fitted |
formula to use to compute the fitted values, defaults to the model formula but may, for example, exclude individual-level covariates. |
... |
Additional arguments passed to
|
Details
The Besag, York and Mollie model for Poisson distributed case counts is:
is the response variable for region
, on the left side of the
formula
argument.is the 'baseline' expected count, which is specified in
formula
on the log scale withan
offset
variable.are covariates, on the right side of
formula
is a spatial random effect, with a spatially structured variance parameter
and a spatially independent variance
.
The prior
has elements named sd
and propSpatial
, which
specifies model="bym2"
should be used with penalized complexity priors.
The sd
element gives a prior for the marginal standard deviation
.
This prior is approximately exponential, and
prior$sd = c(1, 0.01)
specifies a
prior probability .
The
propSpatial
element gives the prior for the ratio
. Having
prior$propSpatial = c(0.5, 0.9)
implies
.
Value
A list containing
inla |
results from the call to
|
data |
A |
parameters |
Prior and posterior distributions of the two covariance parameters, and a table summary with posterior quantiles of all model parameters. |
Author(s)
Patrick Brown
See Also
Examples
data('kentucky')
kentucky = terra::unwrap(kentucky)
# get rid of under 10s
larynxRates = larynxRates[-grep("_(0|5)$",names(larynxRates))]
kentucky = getSMR(kentucky, larynxRates, larynx, regionCode="County")
if(requireNamespace('INLA')) {
INLA::inla.setOption(num.threads=2)
# not all versions of INLA support blas.num.threads
try(INLA::inla.setOption(blas.num.threads=2), silent=TRUE)
}
kBYM <- try(
bym(
observed ~ offset(logExpected) + poverty, kentucky,
prior= list(sd=c(0.1, 0.5), propSpatial=c(0.5, 0.5))
), silent=TRUE)
if(length(grep("parameters", names(kBYM)))) {
kBYM$parameters$summary
}
if( require("mapmisc", quietly=TRUE) && length(grep("parameters", names(kBYM))) ) {
thecol = colourScale(kBYM$data$fitted.exp, breaks=5, dec=1, style="equal")
terra::plot(kBYM$data, col=thecol$plot)
legendBreaks("topleft", thecol)
}