全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 winbugs及其他软件专版
940 0
2021-09-14
各位老师们,请问:在winbugs中,对于正态分布,为什么当精度越来越高的时候,待估参数的标准差越来越大?还有MC error是指什么意思?用来衡量什么?
救救孩纸吧,希望可以帮忙解答一下,谢谢啦!

代码如下:
n <- 25
x <- runif(n = n,min = 0,max = 100)
# Interesting quantile
q <- 0.25
eps <- rnorm(n = n,mean = 0,sd = 1)
y <- 1+2*x+eps
iter <- 10000
burnin <- 5000
#MCMC-Gibbs Sampling
library(coda)
library(lattice)
library(R2WinBUGS)
library(boot)
inits <- function(){list(beta0=1,beta1=2,sigma=3)}
para <- c("beta0","beta1")
data <- list("q","n","y","x")
sim <- bugs(data,inits,para,"ch_2bern.txt",n.chains=1,n.iter=iter,
            n.burnin=burnin,
            n.thin=1,working.directory="H:/bugs",
            bugs.directory="C:/WinBUGS14",
            debug=F,codaPkg=T)
sim.coda <- read.bugs(sim)
summary(sim.coda)
par(mfrow=c(2,2))
plot(sim.coda)
autocorr.plot(sim.coda[[1]][,1],main="beta0",auto.layout=F)   #beta0
autocorr.plot(sim.coda[[1]][,2],main="beta1",auto.layout=F)   #beta1
quantile(eps+1)       #true value

#ch_2bern.txt
model ALD {
beta0~dnorm(0,10)
beta1~dnorm(0,10)
for (i in 1:n) {
h <- 1
u <- y-beta0-beta1*x
p <- exp(log(q*(1-q))-(abs(u)+(2*q-1)*u)/2-600)
h~dbern(p)
}
}
运行结果:
display(log)
check(H:/bugs/ch_2bern.txt)
model is syntactically correct
data(H:/bugs/data.txt)
data loaded
compile(1)
model compiled
inits(1,H:/bugs/inits1.txt)
undefined variable
gen.inits()
initial values generated, model initialized
thin.updater(1)
update(5000)
set(beta0)
set(beta1)
set(deviance)
dic.set()
update(5000)
coda(*,H:/bugs/coda)
stats(*)


Node statistics
        node        mean        sd         MC error        2.5%        median        97.5%        start        sample
        beta0        0.1651        0.2849        0.01243        -0.4006        0.1762        0.7155        5001        5000
        beta1        1.999        0.007563        3.283E-4        1.982        1.999        2.012        5001        5000
        deviance        30100.0        1.904        0.06005        30100.0        30100.0        30110.0        5001        5000
dic.stats()


DIC
Dbar = post.mean of -2logL; Dhat = -2LogL at post.mean of stochastic nodes
        Dbar        Dhat        pD        DIC       
h        30100.300        30099.400        0.965        30101.300       
total        30100.300        30099.400        0.965        30101.300       
history(*,H:/bugs/history.odc)


History


save(H:/bugs/log.odc)
save(H:/bugs/log.txt)






二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

分享

扫码加好友,拉您进群