Learn R Programming

CARBayesST (version 2.1)

ST.CARsepspatial: Fit a spatio-temporal generalised linear mixed model to data, with a temporal main effect and separate spatial surfaces with individual variances.

Description

Fit a spatio-temporal generalised linear mixed model to areal unit data, where the response variable can be binomial or Poisson. The linear predictor is modelled by known covariates and two sets of random effects. The latter include a common temporal main effect modelled by a first order random walk and separate spatial effects with a common spatial dependence parameter but separate variance parameters. Each spatial effect is modelled by the conditional autoregressive (CAR) prior proposed by Leroux et al. (1999). Further details are given in the vignette accompanying this package. Inference is conducted in a Bayesian setting using Markov chain Monte Carlo (McMC) simulation.

Usage

ST.CARsepspatial(formula, family, data=NULL,  trials=NULL, W, burnin, n.sample,
    thin=1, prior.mean.beta=NULL, prior.var.beta=NULL, prior.tau2=NULL, 
    prior.sigma2=NULL, verbose=TRUE)

Arguments

formula
A formula for the covariate part of the model using the syntax of the lm() function. Offsets can be included here using the offset() function. The response and each covariate should be vectors of length (KT)*1, where K is the numb
family
One of either `binomial' or `poisson', which respectively specify a binomial likelihood model with a logistic link function or a Poisson likelihood model with a log link function.
data
An optional data.frame containing the variables in the formula.
trials
A vector the same length as the response containing the total number of trials for each area and time period. Only used if family=`binomial'.
W
A K by K neighbourhood matrix (where K is the number of spatial units). Typically a binary specification is used, where the jkth element equals one if areas (j, k) are spatially close (e.g. share a common border) and is zero othe
burnin
The number of McMC samples to discard as the burnin period.
n.sample
The number of McMC samples to generate.
thin
The level of thinning to apply to the McMC samples to reduce their temporal autocorrelation. Defaults to 1.
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 the random effect variances tau2. Defaults to c(0.001, 0.001).
prior.sigma2
The prior shape and scale in the form of c(shape, scale) for an Inverse-Gamma(shape, scale) prior for the temporal trend variance sigma2. Defaults to c(0.001, 0.001).
verbose
Logical, should the function update the user on its progress.

Value

  • summary.resultsA summary table of the parameters.
  • samplesA list containing the McMC samples from the model. The `tau2' element of this list has columns (tau2.phi, tau2.delta, tau2.gamma) (the latter if interaction=TRUE). Similarly, the `rho' element of this list has columns (rho.phi, rho.delta).
  • fitted.valuesA vector of fitted values for each area and time period.
  • residualsA vector of residuals for each area and time period.
  • modelfitModel fit criteria including the Deviance Information Criterion (DIC), the effective number of parameters in the model (p.d), and the Log Marginal Predictive Likelihood (LMPL).
  • acceptThe acceptance probabilities for the parameters.
  • localised.structureNULL, for compatability with the other models.
  • formulaThe formula for the covariate and offset part of the model.
  • modelA text string describing the model fit.
  • XThe design matrix of covariates.

References

Leroux, B., X. Lei, and N. Breslow (1999). Estimation of disease rates in small areas: A new mixed model for spatial dependence, Chapter Statistical Models in Epidemiology, the Environment and Clinical Trials, Halloran, M and Berry, D (eds), pp. 135-178. Springer-Verlag, New York.

Examples

Run this code
##################################################
#### Run the model on simulated data on a lattice
##################################################
#### set up the regular lattice    
x.easting <- 1:10
x.northing <- 1:10
Grid <- expand.grid(x.easting, x.northing)
K <- nrow(Grid)
T <- 5
N.all <- T * K
        
#### set up spatial (W) and temporal (D) neighbourhood matrices
W <-array(0, c(K,K))
    for(i in 1:K)
    {
        for(j in 1:K)
        {
        temp <- (Grid[i,1] - Grid[j,1])^2 + (Grid[i,2] - Grid[j,2])^2
        if(temp==1)  W[i,j] <- 1 
        }    
    }
        
#### Create the spatial covariance matrix
Q.W <- 0.99 * (diag(apply(W, 2, sum)) - W) + 0.01 * diag(rep(1,K))
Q.W.inv <- solve(Q.W)
           
#### Simulate the elements in the linear predictor and the data
x <- rnorm(n=N.all, mean=0, sd=1)
beta <- 0.1

phi1 <- mvrnorm(n=1, mu=rep(0,K), Sigma=(0.01 * Q.W.inv))
phi2 <- mvrnorm(n=1, mu=rep(0,K), Sigma=(0.01 * Q.W.inv))
phi3 <- mvrnorm(n=1, mu=rep(0,K), Sigma=(0.01 * Q.W.inv))
phi4 <- mvrnorm(n=1, mu=rep(0,K), Sigma=(0.05 * Q.W.inv))
phi5 <- mvrnorm(n=1, mu=rep(0,K), Sigma=(0.05 * Q.W.inv))
  
delta <- c(0, 0.5, 0, 0.5, 0)
phi.long <- c(phi1, phi2, phi3, phi4, phi5)
delta.long <- kronecker(delta, rep(1,K))
LP <- 4 +  x * beta + phi.long +  delta.long
mean <- exp(LP)
Y <- rpois(n=N.all, lambda=mean)
                
#### Run the model
model <- ST.CARsepspatial(formula=Y~x, family="poisson", W=W, burnin=10000, 
n.sample=50000)

Run the code above in your browser using DataLab