# NOT RUN {
#simulate the data
ns=100; nr=2; nlr <- c(20, 20)
mu0 <- c(0, 0)
sigma2 <- c(1., 1.)
Gamma <- matrix(c(3, 0, 0, 3), nrow=2)
sample <- matrix(0, nrow=sum(nlr), ncol=ns)
for(i in 1:ns){
alpha <- mvrnorm(1, rep(0, nr), Gamma)
sampleR <- NULL
for(g in 1:nr){
beta <- rnorm(nlr[g], mean=alpha[g] + mu0[g], sd=sqrt(sigma2[g]))
sampleR <- c(sampleR, beta)
}
sample[,i] <- sampleR
}
#run mcmc
mcmc.result <- spatial.lme.mcmc(sample, nlr, 10000)
#check the results
Gamma <- mcmc.result$Gamma.save
sigma2 <- mcmc.result$sigma2.save
mu <- mcmc.result$mu.save
matrix(rowMeans(Gamma), nr, nr)
apply(sigma2, 1, function(x) quantile(x, prob=c(0.025, 0.5, 0.975)))
summary(rowMeans(mu[1:nlr[1],]))
summary(rowMeans(mu[(nlr[1]+1):sum(nlr),]))
# }
Run the code above in your browser using DataLab