# NOT RUN {
# Simulate data and fit copCAR to them.
# Use the 20 x 20 square lattice as the underlying graph.
m = 20
A = adjacency.matrix(m)
# Create a design matrix by assigning coordinates to each vertex
# such that the coordinates are restricted to the unit square.
x = rep(0:(m - 1) / (m - 1), times = m)
y = rep(0:(m - 1) / (m - 1), each = m)
X = cbind(x, y)
# Set the dependence parameter, regression coefficients, and dispersion parameter.
rho = 0.995 # strong dependence
beta = c(1, 1) # the mean surface increases in the direction of (1, 1)
theta = 2 # dispersion parameter
# Simulate negative binomial data from the model.
z = rcopCAR(rho, beta, X, A, family = negbinomial(theta))
# Fit the copCAR model using the continous extension, and compute 95% (default)
# asymptotic confidence intervals. Give theta the initial value of 1. Use m equal to 100.
fit.ce = copCAR(z ~ X - 1, A = A, family = negbinomial(1), method = "CE", confint = "asymptotic",
control = list(m = 100))
summary(fit.ce)
# Fit the copCAR model using the DT approximation, and compute 90% confidence
# intervals. Bootstrap the intervals, based on a bootstrap sample of size 100.
# Do the bootstrap in parallel, using ten nodes.
fit.dt = copCAR(z ~ X - 1, A = A, family = negbinomial(1), method = "DT", confint = "bootstrap",
control = list(bootit = 100, nodes = 10))
summary(fit.dt, alpha = 0.9)
# Fit the copCAR model using the composite marginal likelihood approach.
# Do not compute confidence intervals.
fit.cml = copCAR(z ~ X - 1, A = A, family = negbinomial(1), method = "CML", confint = "none")
summary(fit.cml)
# }
Run the code above in your browser using DataLab