[R] Question about R graphs

legendy junli at uab.edu
Wed Oct 22 20:34:01 CEST 2008


Hello all,

I have a question about CODA. Using my R code as bellow, I drew two graphs
(the data comes from the example of the speed of light in the Gelman’s book
“Bayesian Data Analysis (Second edition)” (page 77)). My R code is:
 
library(R2WinBUGS)
 
y=c(28, 26, 33, 24, 34, -44, 27, 16, 40, -2, 29, 22, 24, 21, 25, 30, 23, 29,
31,
    19, 24, 20, 36, 32, 36, 28, 25, 21, 28, 29, 37, 25, 28, 26, 30, 32, 36,
26, 
    30, 22, 36, 23, 27, 27, 28, 27, 31, 27, 26, 33, 26, 32, 32, 24, 39, 28,
24, 
    25, 32, 25, 29, 27, 28, 29, 16, 23) 
 
n=length(y)
 
data=list("n","y")
 
inits=function() {list(mu=runif(1,-5,5),tau=runif(1,0.01,10))}
   
parameters=c("mu","sigma")
   
sim=bugs(data,inits,parameters,"U:/my BUGS
code.txt",n.chains=3,n.iter=1000,debug=T)
         
library(coda)
 
y=sim$sims.array
 
x1=mcmc(y[,1,])  #mu,sigma, and deviance from the chain 1
x2=mcmc(y[,2,])  #mu,sigma, and deviance from the chain 2
x3=mcmc(y[,3,])  #mu,sigma, and deviance from the chain 3
 
x=mcmc.list(x1,x2,x3)
 
plot(x)
 
gelman.plot(x)

# my BUGS code is (copy and save as a txt file):

model
{
  for(i in 1:n)
  {
    y[i]~dnorm(mu,tau)			
  }
	
  mu~dnorm(0.0,0.001)	
  tau~dgamma(0.001,0.001) 
  sigma<-1/sqrt(tau)
}

As you see, I set 3 chains and 1000 iterations, so there should be 1500
simulation samples after removed the first 500 samples for each chain (burn
in). But from the density graph, there indicated only N=500. Why N=500? But
not 1500.
 
>From another graph produced by “gelman.plot”, we can see that the x axis is
labeled as “last iteration in chain”. What is the last iteration in chain? I
set 3 chains, which chain was the result calculated based on?

Thank you very much.

Legendy

-- 
View this message in context: http://www.nabble.com/Question-about-R-graphs-tp20117061p20117061.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list