Description Usage Arguments Value Author(s) References Examples

Fit a spatial generalised linear mixed model to areal unit data, where the response variable can be binomial, Gaussian or Poisson. The linear predictor is modelled by known covariates and a vector of random effects. The latter are modelled by the conditional autoregressive prior proposed by Leroux et al. (1999), and further details are given in the vignette accompanying this package. Independent random effects can be obtained by setting (fix.rho=TRUE, rho=0) similar to the old function S.independent(), in which case the neighbourhood matrix W is not part of the model. In this case enter a fake W matrix that is a K by K matrix of zeros, where K is the number of data points. Similarly, the intrinsic CAR model can be obtained by setting (fix.rho=TRUE, rho=1) similar to the old function S.CARiar(). Inference is conducted in a Bayesian setting using Markov chain Monte Carlo (MCMC) simulation. Missing (NA) values are allowed in the response, and posterior predictive distributions are created for the missing values for predictive purposes. These are saved in the‘samples’ argument in the output of the function and are denoted by ‘Y’.

1 2 3 |

`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 can contain missing (NA) values. |

`family` |
One of either ‘binomial’, ‘gaussian’ or ‘poisson’, which respectively specify a binomial likelihood model with a logistic link function, a Gaussian likelihood model with an identity 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. Only used if family=‘binomial’. |

`W` |
A non-negative 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 otherwise. The matrix can be non-binary, but each row must contain at least one non-zero entry. Note, if fix.rho=TRUE and rho=0 then the W matrix is not actually used by the model so a K by K matrix of zeros could be entered instead if a real W matrix is cannot be obtained. |

`burnin` |
The number of MCMC samples to discard as the burn-in 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 (no thinning). |

`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 100000. |

`prior.nu2` |
The prior shape and scale in the form of c(shape, scale) for an Inverse-Gamma(shape, scale) prior for nu2. Defaults to c(1, 0.01) and only used if family=‘Gaussian’. |

`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(1, 0.01). |

`fix.rho` |
Logical, should the spatial dependence parameter rho be fixed rather than being estimated in the model. |

`rho` |
The value that the spatial dependence parameter is set to if fix.rho=TRUE. Must be in the interval [0, 1], where 0 corresponds to independence while 1 corresponds to fitting the intrinsic CAR prior. |

`MALA` |
Logical, should the function use MALA (TRUE, default) or simple random walk (FALSE) updates for the random effects. Not applicable if family=‘gaussian’. |

`verbose` |
Logical, should the function update the user on its progress. |

`summary.results ` |
A summary table of the parameters. |

`samples ` |
A list containing the MCMC samples from the model. |

`fitted.values ` |
A vector of fitted values for each area. |

`residuals ` |
A matrix with 3 columns where each column is a type of residual and each row relates to an area. The types are "response" (raw), "pearson", and "deviance". |

`modelfit ` |
Model fit criteria including the Deviance Information Criterion (DIC) and its corresponding estimated effective number of parameters (p.d), the Log Marginal Predictive Likelihood (LMPL), the Watanabe-Akaike Information Criterion (WAIC) and its corresponding estimated number of effective parameters (p.w), the loglikelihood, and the percentage deviance explained. |

`accept ` |
The acceptance probabilities for the parameters. |

`localised.structure ` |
NULL, for compatability with the other models. |

`formula ` |
The formula for the covariate and offset part of the model. |

`model ` |
A text string describing the model fit. |

`X ` |
The design matrix of covariates. |

Duncan Lee

Leroux, B., X. Lei, and N. Breslow (2000). 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.

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 | ```
##################################################
#### Run the model on simulated data on a lattice
##################################################
#### Load other libraries required
library(MASS)
#### Set up a square lattice region
x.easting <- 1:10
x.northing <- 1:10
Grid <- expand.grid(x.easting, x.northing)
K <- nrow(Grid)
#### set up distance and neighbourhood (W, based on sharing a common border) matrices
distance <- as.matrix(dist(Grid))
W <-array(0, c(K,K))
W[distance==1] <-1
#### Generate the covariates and response data
x1 <- rnorm(K)
x2 <- rnorm(K)
theta <- rnorm(K, sd=0.05)
phi <- mvrnorm(n=1, mu=rep(0,K), Sigma=0.4 * exp(-0.1 * distance))
logit <- x1 + x2 + theta + phi
prob <- exp(logit) / (1 + exp(logit))
trials <- rep(50,K)
Y <- rbinom(n=K, size=trials, prob=prob)
#### Run the Leroux model
formula <- Y ~ x1 + x2
## Not run: model <- S.CARleroux(formula=formula, family="binomial",
trials=trials, W=W, burnin=20000, n.sample=100000)
## End(Not run)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.