Running examples in 'CARBayes-Ex.R' failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: MVS.CARleroux
> ### Title: Fit a multivariate spatial generalised linear mixed model to
> ###   data, where the random effects are modelled by a multivariate
> ###   conditional autoregressive model.
> ### Aliases: MVS.CARleroux
> 
> ### ** Examples
> 
> #################################################
> #### 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 
> K <- nrow(W)
> 
> #### Generate the correlation structures
> Q.W <- 0.99 * (diag(apply(W, 2, sum)) - W) + 0.01 * diag(rep(1,K))
> Q.W.inv <- solve(Q.W)
> 
> Sigma <- matrix(c(1,0.5,0, 0.5,1,0.3, 0, 0.3, 1), nrow=3)
> Sigma.inv <- solve(Sigma)
> J <- nrow(Sigma)
> N.all <- K * J
> 
> precision.phi <- kronecker(Q.W, Sigma.inv)
> var.phi <- solve(precision.phi)
> 
> #### Generate the covariate component
> x1 <- rnorm(K)
> x2 <- rnorm(K)
> XB <- cbind(0.1 * x1 - 0.1*x2, -0.1 * x1 + 0.1*x2, 0.1 * x1 - 0.1*x2)
> 
> #### Generate the random effects
> phi <- mvrnorm(n=1, mu=rep(0,N.all), Sigma=var.phi)
> 
> 
> #### Generate the response data
> lp <-as.numeric(t(XB)) + phi
> prob <- exp(lp) / (1 + exp(lp))
> trials.vec <- rep(100,N.all)
> Y.vec <- rbinom(n=N.all, size=trials.vec, prob=prob)
> 
> #### Turn the data and trials into matrices where each row is an area.
> Y <- matrix(Y.vec, nrow=K, ncol=J, byrow=TRUE)
> trials <- matrix(trials.vec, nrow=K, ncol=J, byrow=TRUE)
> 
> #### Run the Leroux model
> formula <- Y ~ x1 + x2
> ## Not run: 
> ##D model <- MVS.CARleroux(formula=formula, family="binomial", 
> ##D trials=trials, W=W, burnin=20000, n.sample=100000)
> ## End(Not run)
> 
> #### Toy example for checking
> model <- MVS.CARleroux(formula=formula, family="binomial", 
+ trials=trials, W=W, burnin=10, n.sample=50)
Setting up the model.
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
CARBayes
 --- call from context --- 
common.frame(formula, data, "binomial")
 --- call from argument --- 
if (class(X) == "try-error") stop("the covariate matrix contains inappropriate values.", 
    call. = FALSE)
 --- R stacktrace ---
where 1: common.frame(formula, data, "binomial")
where 2: binomial.MVlerouxCAR(formula = formula, data = data, trials = trials, 
    W = W, burnin = burnin, n.sample = n.sample, thin = thin, 
    prior.mean.beta = prior.mean.beta, prior.var.beta = prior.var.beta, 
    prior.Sigma.df = prior.Sigma.df, prior.Sigma.scale = prior.Sigma.scale, 
    rho = rho, MALA = MALA, verbose = verbose)
where 3: MVS.CARleroux(formula = formula, family = "binomial", trials = trials, 
    W = W, burnin = 10, n.sample = 50)

 --- value of length: 2 type: logical ---
[1] FALSE FALSE
 --- function from context --- 
function (formula, data, family) 
{
    frame <- try(suppressWarnings(model.frame(formula, data = data, 
        na.action = na.pass)), silent = TRUE)
    if (class(frame) == "try-error") 
        stop("the formula inputted contains an error, e.g the variables may be different lengths.", 
            call. = FALSE)
    X <- try(suppressWarnings(model.matrix(object = attr(frame, 
        "terms"), data = frame)), silent = TRUE)
    if (class(X) == "try-error") 
        stop("the covariate matrix contains inappropriate values.", 
            call. = FALSE)
    if (sum(is.na(X)) > 0) 
        stop("the covariate matrix contains missing 'NA' values.", 
            call. = FALSE)
    n <- nrow(X)
    p <- ncol(X)
    cor.X <- suppressWarnings(cor(X))
    diag(cor.X) <- 0
    if (max(cor.X, na.rm = TRUE) == 1) 
        stop("the covariate matrix has two exactly linearly related columns.", 
            call. = FALSE)
    if (min(cor.X, na.rm = TRUE) == -1) 
        stop("the covariate matrix has two exactly linearly related columns.", 
            call. = FALSE)
    if (p > 1) {
        if (sort(apply(X, 2, sd))[2] == 0) 
            stop("the covariate matrix has two intercept terms.", 
                call. = FALSE)
    }
    else {
    }
    X.standardised <- X
    X.sd <- apply(X, 2, sd)
    X.mean <- apply(X, 2, mean)
    X.indicator <- rep(NA, p)
    for (j in 1:p) {
        if (length(table(X[, j])) > 2) {
            X.indicator[j] <- 1
            X.standardised[, j] <- (X[, j] - mean(X[, j]))/sd(X[, 
                j])
        }
        else if (length(table(X[, j])) == 1) {
            X.indicator[j] <- 2
        }
        else {
            X.indicator[j] <- 0
        }
    }
    Y <- model.response(frame)
    J <- length(Y)/n
    which.miss <- matrix(as.numeric(!is.na(Y)), nrow = n, ncol = J)
    if (J == 1) 
        which.miss <- as.numeric(which.miss)
    n.miss <- n * J - sum(which.miss)
    if (family == "binomial") {
        if (!is.numeric(Y)) 
            stop("the response variable has non-numeric values.", 
                call. = FALSE)
        int.check <- n * J - n.miss - sum(ceiling(Y) == floor(Y), 
            na.rm = TRUE)
        if (int.check > 0) 
            stop("the response variable has non-integer values.", 
                call. = FALSE)
        if (min(Y, na.rm = TRUE) < 0) 
            stop("the response variable has negative values.", 
                call. = FALSE)
    }
    else if (family == "gaussian") {
        if (!is.numeric(Y)) 
            stop("the response variable has non-numeric values.", 
                call. = FALSE)
    }
    else if (family == "poisson") {
        if (!is.numeric(Y)) 
            stop("the response variable has non-numeric values.", 
                call. = FALSE)
        int.check <- n * J - n.miss - sum(ceiling(Y) == floor(Y), 
            na.rm = TRUE)
        if (int.check > 0) 
            stop("the response variable has non-integer values.", 
                call. = FALSE)
        if (min(Y, na.rm = TRUE) < 0) 
            stop("the response variable has negative values.", 
                call. = FALSE)
    }
    else if (family == "multinomial") {
        if (!is.numeric(Y)) 
            stop("the response variable has non-numeric values.", 
                call. = FALSE)
        int.check <- n * J - n.miss - sum(ceiling(Y) == floor(Y), 
            na.rm = TRUE)
        if (int.check > 0) 
            stop("the response variable has non-integer values.", 
                call. = FALSE)
        if (min(Y, na.rm = TRUE) < 0) 
            stop("the response variable has negative values.", 
                call. = FALSE)
    }
    else {
    }
    offset <- try(model.offset(frame), silent = TRUE)
    if (class(offset) == "try-error") 
        stop("the offset is not numeric.", call. = FALSE)
    if (family == "multinomial") {
        if (is.null(offset)) 
            offset <- array(0, c(n, (J - 1)))
    }
    else {
        if (is.null(offset)) 
            offset <- array(0, c(n, J))
    }
    if (sum(is.na(offset)) > 0) 
        stop("the offset has missing 'NA' values.", call. = FALSE)
    if (!is.numeric(offset)) 
        stop("the offset variable has non-numeric values.", call. = FALSE)
    results <- list(n = n, p = p, X = X, X.standardised = X.standardised, 
        X.sd = X.sd, X.mean = X.mean, X.indicator = X.indicator, 
        offset = offset, Y = Y, which.miss = which.miss, n.miss = n.miss)
    return(results)
}
<bytecode: 0x1ab3180>
<environment: namespace:CARBayes>
 --- function search by body ---
Function common.frame in namespace CARBayes has this body.
 ----------- END OF FAILURE REPORT -------------- 
Fatal error: the condition has length > 1