Learn R Programming

CARBayes (version 2.0)

poisson.iarCAR: Fit the intrinsic conditional autoregressive (IAR) model to spatial Poisson data

Description

The function fits a Poisson log-normal random effects models to spatial count data, where the random effects are modelled by the intrinsic conditional autoregressive (IAR) model (Besag et. al. 1991). The model represents the natural log of the mean function for the set of Poisson responses by a combination of covariates and a set of random effects. The latter are spatially correlated and come from the IAR model. A set of offsets can also be included on the linear predictor scale. Inference is based on Markov Chain Monte Carlo (MCMC) simulation, using a combination of Gibbs sampling and Metropolis steps.

Usage

poisson.iarCAR(formula, data=NULL, beta=NULL, phi=NULL, tau2=NULL, W, burnin=0, 
n.sample=1000, thin=1, blocksize.beta=5, prior.mean.beta=NULL, 
prior.var.beta=NULL, prior.tau2=NULL)

Arguments

formula
A formula for the covariate part of the model, using the same notation as for the lm() function. The offsets should also be included here using the offset() function.
data
A data.frame containing the variables in the formula.
beta
A vector of starting values for the regression parameters (including the intercept term). If this argument is not specified the function will randomly generate starting values.
phi
A vector of starting values for the random effects. If this argument is not specified the function will randomly generate starting values.
tau2
A starting value for the variance parameter of the random effects. If this argument is not specified the function will randomly generate a starting value.
W
A binary n by n neighbourhood matrix (where n is the number of spatial units). The jkth element equals one if areas (j, k) are spatially close (e.g. share a common border) and is zero otherwise.
burnin
The number of MCMC samples to discard as the burnin period. Defaults to 0.
n.sample
The number of MCMC samples to generate. Defaults to 1,000.
thin
The level of thinning to apply to the MCMC samples to reduce their temporal autocorrelation. Defaults to 1.
blocksize.beta
The size of the blocks in which to update the regression parameters in the MCMC algorithm. Defaults to 5.
prior.mean.beta
A vector of prior means for the regression parameters beta (Gaussian priors are assumed). Defaults to a vector of zeros.
prior.var.beta
A vector of prior variances for the regression parameters beta (Gaussian priors are assumed). Defaults to a vector with values 1000.
prior.tau2
The prior shape and scale in the form of c(shape, scale) for an Inverse-Gamma(shape, scale) prior for tau2. Defaults to c(0.001, 0.001).

Value

  • formulaThe formula for the covariate and offset part of the model.
  • samplesA list containing the MCMC samples from the model.
  • fitted.valuesA summary matrix of the posterior distributions of the fitted values for each area. The summaries include: Mean, Sd, Median, and credible interval.
  • random.effectsA summary matrix of the posterior distributions of the random effects for each area. The summaries include: Mean, Sd, Median, and credible interval.
  • residualsA summary matrix of the posterior distributions of the residuals for each area. The summaries include: Mean, Sd, Median, and credible interval.
  • W.summaryThe neighbourhood matrix W from the model.
  • DICThe Deviance Information Criterion.
  • p.dThe effective number of parameters in the model.
  • MPLThe Marginal Predictive Likelihood of the model.
  • summary.resultsA summary table of the parameters.
  • modelA text string describing the model fit.
  • acceptThe acceptance probabilities for the parameters.

Details

For further details about how to apply the function see the examples below and in the main CARBayes helpfile.

References

Besag, J., J. York, and A. Mollie (1991). Bayesian image restoration with two applications in spatial statistics. Annals of the Institute of Statistics and Mathematics 43, 1-59.

Examples

Run this code
##################################################
#### Run the model on simulated data on a lattice
##################################################

#### Set up a square lattice region
x.easting <- 1:10
x.northing <- 1:10
Grid <- expand.grid(x.easting, x.northing)
n <- nrow(Grid)

#### set up distance and neighbourhood (W, based on sharing a common border) matrices
distance <-array(0, c(n,n))
W <-array(0, c(n,n))
	for(i in 1:n)
	{
		for(j in 1:n)
		{
		temp <- (Grid[i,1] - Grid[j,1])^2 + (Grid[i,2] - Grid[j,2])^2
		distance[i,j] <- sqrt(temp)
			if(temp==1)  W[i,j] <- 1 
		}	
	}
	
	
#### Generate the covariates and response data
x1 <- rnorm(n)
x2 <- rnorm(n)
E <- rep(40,n)
theta <- rnorm(n, sd=0.05)
phi <- mvrnorm(n=1, mu=rep(0,n), Sigma=0.4 * exp(-0.1 * distance))
risk <- exp(-0.2 +  0.1 * x1 + 0.1*x2 + theta + phi)
fitted <- E * risk
Y <- rpois(n=n, lambda=fitted)



#### Run the IAR model
#### Let the function randomly generate starting values for the parameters
#### Use the default priors specified by the function (for details see the help files)
formula <- Y ~ x1 + x2 + offset(log(E))
model <- poisson.iarCAR(formula=formula, W=W, burnin=5000, n.sample=10000)
model <- poisson.iarCAR(formula=formula, W=W, burnin=20, n.sample=50)

Run the code above in your browser using DataLab