用r2openbug拟合Weibull函数
因为使用R2OpenBUGS对Weibull函数参数的估计与使用rweibull生成数据集所提供的量有很大不同?我的身材怎么了用r2openbug拟合Weibull函数,r,weibull,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(
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)
默认情况下,R使用
shape
(=2)和scale
(=10)参数化Weibull:BUGS使用shape
和lambda
,其中lambda=(1/比例)^shape
。因此,您应该预计lambda
大约为(1/10)^2=0.01,这接近您的中值0.0093
,并比较参数化
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