Learn R Programming

CARBayes (version 1.3)

binomial.dissimilarityCAR: Fit a localised conditional autoregressive (CAR) model based on dissimilarity metrics with binary neighbourhood relations to spatial binomial data

Description

The function fits a Binomial logistic random effects models to spatial data, where the random effects are modelled by a localised conditional autoregressive (CAR) model, which is a generalisation of that proposed by Lee and Mitchell (2012). The random effects in neighbouring areas (e.g. those that share a common border) are modelled as correlated or conditionally independent, depending on whether the populations living in the two areas are similar (correlated random effects) or very different (conditionally independent). The model represents the logit of the mean function for the set of binomial responses by a combination of covariates and a set of random effects. Inference is based on Markov Chain Monte Carlo (MCMC) simulation, using a combination of Gibbs sampling and Metropolis steps.

Usage

binomial.dissimilarityCAR(formula, beta = NULL, phi = NULL, tau2 = NULL, 
rho = NULL, fix.rho = FALSE, alpha = NULL, trials, W, Z, burnin = 0, 
n.sample = 1000, thin=1, blocksize.beta = 5, blocksize.phi = 10, 
prior.mean.beta = NULL, prior.var.beta = NULL,  prior.max.tau2 = NULL, 
prior.max.alpha = 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.
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.
rho
A starting value for the global spatial correlation parameter rho. If this argument is not specified the function will randomly generate a starting value unless fix.rho=TRUE, in which case it is required.
fix.rho
Logical, whether the global correlation parameter is fixed or estimated in the MCMC algorithm.
alpha
A vector of starting values for the regression parameters that control the identification of localised spatial structure in the random effects surface. If this argument is not specified the function will randomly generate starting values.
trials
A vector the same length as the response containing the total number of trials for each area.
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.
Z
A list, where each element is an n by n matrix of non-negative dissimilarity metrics. For details of their construction see the main help page for CARBayes.
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.
blocksize.phi
The size of the blocks in which to update the random effects in the MCMC algorithm. Defaults to 10.
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.max.tau2
The maximum allowable value for the random effects variance tau2 (a Uniform(0,M) prior is assumed). Defaults to M=1000.
prior.max.alpha
A vector of maximum allowable values for the regression parameters that control the correlation structure amongst the random effects (Uniform(0,M) priors are assumed). Default values are specified if this argument is not included.

Value

  • formulaThe formula for the covariate and offset part of the model.
  • samples.betaA matrix of MCMC samples for the regression parameters beta.
  • samples.phiA matrix of MCMC samples for the random effects phi.
  • samples.tau2A matrix of MCMC samples for the random effects variance tau2.
  • samples.rhoA matrix of MCMC samples for the global spatial correlation parameter rho. Only included if fix.rho=FALSE.
  • samples.alphaA matrix of MCMC samples for the regression parameters that control the identification of localised spatial structure in the random effects surface.
  • 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.
  • W.posteriorA matrix of posterior medians for each element wkj of the n by n neighbourhood matrix W. Elements of this matrix which correspond to two non-neighbouring areas have NA values.
  • W.border.probA matrix showing the posterior probability that each wkj element of the n by n neighbourhood matrix W equals zero. This corresponds to the posterior probability of a boundary in the random effects surface. Elements of this matrix which correspond to two non-neighbouring areas have NA values.
  • residualsA summary matrix of the posterior distributions of the residuals for each area. The summaries include: Mean, Sd, Median, and credible interval.
  • DICThe Deviance Information Criterion.
  • p.dThe effective number of parameters in the model.
  • summary.resultsA summary table of the parameters.

Details

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

References

Lee, D. and R. Mitchell (2012). Boundary detection in disease mapping studies. Biostatistics, 13, 415-426.

Examples

Run this code
###########################################################
#### Run the model on simulated data - localised CAR model
###########################################################

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

#### Split the area into two groups between which there will be a boundary.
groups <-rep(1, n) 
groups[Grid$Var1>5] <- 2

#### 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 response data
phi <- mvrnorm(n=1, mu=groups, Sigma=0.2 * exp(-0.1 * distance))
logit <- phi
prob <- exp(logit) / (1 + exp(logit))
trials <- rep(50,n)
Y <- rbinom(n=n, size=trials, prob=prob)


#### Generate a dissimilarity metric
dissimilarity <- cbind(groups) + rnorm(n, sd=0.2)
dissimilarity.matrix <- as.matrix(dist(cbind(dissimilarity, dissimilarity), 
method="manhattan", diag=TRUE, upper=TRUE)) * W/2

Z <- list(dissimilarity.matrix=dissimilarity.matrix)

#### Run the localised smoothing 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 ~ 1
model <- binomial.dissimilarityCAR(formula=formula, rho=0.99, fix.rho=TRUE, 
trials=trials, W=W, Z=Z, burnin=5000, n.sample=10000)
model <- binomial.dissimilarityCAR(formula=formula, rho=0.99, fix.rho=TRUE, 
trials=trials, W=W, Z=Z, burnin=20, n.sample=50)

Run the code above in your browser using DataLab