# load data
data(iowaSW06)
# construct random walk 2 structure matrix for each dimension
Q1<- makeRW2Q(33) # for rows
Q2<- makeRW2Q(24) # for columns
# dimensions of Q1, Q2, in that order
na<- nrow(Q1)
nb<- nrow(Q2)
Q <- list( list(type="Gen",content=Q1), list(type="Gen",content=Q2) )
# construct the design matrix with with as many columns as there are
# in null space of kronecker prod of Q's
X2 <- cbind( rep(1,nb), 1:nb)
X1 <- cbind( rep(1,na), 1:na)
X <- kronecker( X2, X1)
# parameters of gamma prior densities on tausqy, tausqphi[1], tausqphi[2]
alpha2 = beta2 <- c(.1, .1, .1)
# number of samples
nsamp = 100
#random seed
myseed = 314
output <- CARrampsOcl.fit(alpha=alpha2,
beta=beta2, Q=Q, y=iowaSW06, nsamp=nsamp,
seed=myseed,
fixed = FALSE, randeffs=TRUE, coefs=TRUE,designMat=X,
mult= 50)
# summarize marginal posterior densities of precision parameters
library(coda)
summary(as.mcmc( output$params ))
# summarize marginal posterior densities of regression coefficients
# intercept, slope within rows (west-to-east linear trend),
# slope for columns (north to south linear trend),
# interaction between rows and columns
summary(as.mcmc( output$regcoefs))
# summary statistics for site-specific random effects at first 10 sites
print( cbind( output$phi$phimean, output$phi$phisd)[1:10,] )
# plot the raw data and the posterior means of the site-specific random effects
plot2Q( output, numcols=32, col = rev(terrain.colors(32)),
rev.inds = c(FALSE, TRUE))
Run the code above in your browser using DataLab