楼主: pipilee
5621 12

求助统计学高手! [推广有奖]

11
epoh 发表于 2011-10-1 14:39:57

我以另一个例子来解释:

以winbugs产生的物件schools.sim

可以经由library(coda),作进一步检验分析.

这个例子需要两个文件school.bug , schools.dat

请将其放进c:\Bugs\school

也请注意你的winbugs安装的位置,

若有不同,请自行更改

所有结果都存在c:\Bugs\school,

包含你说的log.odc,那就是执行结果的文件

school.bug , schools.dat

school.rar (432 Bytes)

# in R command window

library(R2WinBUGS)
schools <- read.table ("c:/Bugs/school/schools.dat", header=TRUE)
J <- nrow(schools)
y <- schools$estimate
sigma.y <- schools$sd
data <- list ("J", "y", "sigma.y")
inits <- function() {list (theta=rnorm(J,0,100), mu.theta=rnorm(1,0,100), sigma.theta=runif(1,0,100))}
parameters <- c("theta", "mu.theta", "sigma.theta")

schools.sim <- bugs(data, inits, parameters.to.save=parameters,"school.bug",n.chains=2,
               n.thin=1,n.iter=10000,n.burnin=5000,debug=TRUE,DIC=TRUE,
               bugs.directory="d:/WinBUGS14/",working.directory = "c:/Bugs/school")
print(schools.sim)

library(coda)
out=as.mcmc.list(schools.sim)
gelman.plot(out)

#########################################################
Inference for Bugs model at "school.bug", fit using WinBUGS,
2 chains, each with 10000 iterations (first 5000 discarded)
n.sims = 10000 iterations saved
            mean  sd  2.5%  25%  50%  75% 97.5% Rhat n.eff
theta[1]    11.9 8.3  -1.8  6.4 10.9 15.8  31.8  1.0 10000
theta[2]     8.1 6.4  -5.2  4.2  8.1 12.3  20.7  1.0   800
theta[3]     6.3 7.9 -12.1  2.2  6.9 11.3  20.9  1.0  1600
theta[4]     7.9 6.6  -5.6  3.9  7.9 12.2  21.1  1.0   780
theta[5]     5.3 6.4  -8.9  1.4  5.7  9.7  16.2  1.0   420
theta[6]     6.3 6.8  -9.0  2.5  6.8 10.8  18.6  1.0  2700
theta[7]    11.1 6.7  -0.8  6.5 10.6 15.0  26.3  1.0  5400
theta[8]     8.8 8.0  -7.3  4.3  8.6 13.1  26.1  1.0 10000
mu.theta     8.2 5.1  -2.0  5.0  8.2 11.5  18.3  1.0  2100
sigma.theta  6.9 5.7   0.2  2.8  5.5  9.5  21.2  1.1    94
deviance    60.2 2.2  56.7 58.8 59.9 61.2  65.6  1.0  3800

For each parameter, n.eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor (at convergence, Rhat=1).

DIC info (using the rule, pD = Dbar-Dhat)
pD = 2.9 and DIC = 63.1
DIC is an estimate of expected predictive error (lower deviance is better).

已有 1 人评分学术水平 热心指数 信用等级 收起 理由
zhangtao + 5 + 5 + 5 向epoh大师致以最最最崇高的敬意!

总评分: 学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

12
zhangtao 发表于 2011-10-1 22:18:17
111.jpeg

epoh老师,您好!
以上R估计的图片,我想问一下:theta[1]、theta[2]、theta[3]这三张图片
跑到哪儿去了?为什么在R中没有显示出来?
非常感谢!






点击图片添加到帖子内容中




数学好就是要天天学

13
love芹菜 发表于 2013-4-29 00:01:12
好难啊

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-5 11:33