我真的希望这不是一个愚蠢的问题,但我正在尝试模拟一个非常简单的空间贝叶斯模型,并且在 WinBUGS 窗口上不断收到某种“无法复制”的消息。
我正在模拟数据:
library(MASS)
library(spBayes)
library(fields)
library(MBA)
library(MASS)
library(R2WinBUGS)
set.seed(137)
n<-20
coords <- cbind(runif(n, 0, 1), runif(n, 0, 1))
phi<-0.25/0.5
sigma.sq<-0.0008
R<-exp(-phi*iDist(coords))
w<-mvrnorm(1,rep(0,n),sigma.sq*R)
x=coords[,1]
y=coords[,2]
z=0.031+w
data<-list("n","x","y","z")
vars2keep<-list("phi","tau","beta0","beta1")
inits<-function(){list(tau=0.001, phi=0.1, beta0=0.1,beta1=0.01)}
output<-bugs(
model.file="spatialexp_sim.txt",
data=data,
inits = inits,
parameters.to.save = vars2keep,
n.chains=2,
n.iter=1000,
n.burnin=500,
n.thin=10,
debug=TRUE,
DIC=TRUE
)
这是模型:
cat("
model{
rho[1:n] ~ spatial.exp(mu[], x[], y[], tau, phi, 1)
for (i in 1:n){mu[i]<-beta0}
for (i in 1:n) {
z[i] ~ nu[i]
nu[i] <- rho[i] + beta1
}
beta0 ~ dflat()
beta1 ~ dflat() # Flat prior for the intercept
tau ~ dgamma(0.001, 0.001) # Conjugate inverse gamma on the precision
phi ~ dunif(0.001, 0.8) # Uniform prior on phi
}",file="spatialexp_sim.txt"
)
任何线索为什么这件事不起作用?如果这真的很简单,我很抱歉。非常感谢!