使用R2OpenBUGS匹配Weibull

时间:2015-04-25 21:24:15

标签: r weibull

因为使用R2OpenBUGS估计Weibull函数的参数与使用rweibull生成数据集所提供的数量有很大不同吗?我的健康有什么问题?

data<-rweibull(200, 2, 10)

model<-function(){

v ~ dgamma(0.0001,0.0001)
lambda ~ dgamma(0.0001,0.0001)

for(i in 1:n){
   y[i] ~ dweib(v, lambda)
   }
}

y<-data
n<-length(y)
data<-list("y", "n")

inits<-function(){list(v=1, lambda=1)}
params<-c("v", "lambda")
model.file<-file.path(tempdir(), "model.txt")
write.model(model, model.file)
weibull<-bugs(data, inits, params, model.file, n.iter = 3000, n.burnin =  2000, n.chains = 3)
print(weibull, 4)

获得的结果是:

Current: 3 chains, each with 3000 iterations (first 2000 discarded)
Cumulative: n.sims = 3000 iterations saved
          mean     sd       2.5%       25%       50%       75%      97.5%    Rhat     n.eff
v           2.0484 0.1044    1.8450    1.9780    2.0500    2.1180    2.2470 1.0062   780
lambda      0.0097 0.0026    0.0056    0.0078    0.0093    0.0112    0.0159 1.0063   830
deviance 1145.6853 1.8403 1144.0000 1144.0000 1145.0000 1146.0000 1151.0000 1.0047   770

pD = 1.6 and DIC = 1147.0

1 个答案:

答案 0 :(得分:2)

R使用shape(在您的情况下= 2)和scale(= 10)默认情况下对Weibull进行参数化:BUGS使用shapelambda,其中{{ 1}}。所以你应该期望lambda=(1/scale)^shape大约是(1/10)^ 2 = 0.01,这接近你的中位数0.0093。

This question on CrossValidatedthis paper in the R Journal,比较参数化。