使用 R2OpenBUGS 拟合 Weibull
Fiting Weibull using R2OpenBUGS
因为使用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
R 默认使用 shape
(在您的情况下为 =2)和 scale
(=10)参数化 Weibull:BUGS 使用 shape
和 lambda
,其中lambda=(1/scale)^shape
。因此,您应该期望 lambda
大约为 (1/10)^2=0.01,这接近于您的中位数 0.0093。
This question on CrossValidated, and this paper in the R Journal,比较参数化。
因为使用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
R 默认使用 shape
(在您的情况下为 =2)和 scale
(=10)参数化 Weibull:BUGS 使用 shape
和 lambda
,其中lambda=(1/scale)^shape
。因此,您应该期望 lambda
大约为 (1/10)^2=0.01,这接近于您的中位数 0.0093。
This question on CrossValidated, and this paper in the R Journal,比较参数化。