user45367
user45367

Reputation: 161

How can I extract data from mcmc RJAGS

I'm running the following model where I got a measurement for each polling week. Which produce more than 100 alpha vectors for each party. May question is, how could I stockpile them in a way I could draw a line graph?

model{
  ## measurement 
 for(i in 1:NPOLLS){  
      p1[i] ~ dnorm(alpha1[WoY[i]] + pollster1[org[i]], prec1[i])
       p2[i] ~ dnorm(alpha2[WoY[i]] + pollster2[org[i]], prec2[i])
       p3[i] ~ dnorm(alpha3[WoY[i]] + pollster3[org[i]], prec3[i])

}

## transition 
for(i in 2:NPERIODS){    
    alpha1[i] ~ dnorm(alpha1[i-1],phi1)
    alpha2[i] ~ dnorm(alpha2[i-1],phi2)
    alpha3[i] ~ dnorm(alpha3[i-1],phi3)
 }

pollster1[1] <- -sum(pollster1[2:NPOLLSTERS])
pollster2[1] <- -sum(pollster2[2:NPOLLSTERS])
pollster3[1] <- -sum(pollster3[2:NPOLLSTERS])

## priors
phi1 ~ dgamma(5000,1)     
alpha1[1] ~ dunif(.2,.4) 
phi2 ~ dgamma(5000,1)     
alpha2[1] ~ dunif(.2,.4)
phi3 ~ dgamma(10000,1)     
alpha3[1] ~ dunif(.1,.3)
    for(i in 2:NPOLLSTERS){
    pollster1[i] ~ dnorm(0,.01);    
    pollster2[i] ~ dnorm(0,.01);
    pollster3[i] ~ dnorm(0,.01);
 } }

Upvotes: 0

Views: 2521

Answers (1)

Philippe
Philippe

Reputation: 204

jags function provid a mmcm.list object with a summary generic function for this class of object. Use str and name functions on your new object return by the jags function and you need to find something like mcmc. The mcmcsub-object is a matrix of class mcmc.list containing the posteriors with n rowthe number of iterartion and n col the estimated parameters. So you can extract what you want. The length of the mcmc object is equal to the number of chains. They also have a generic plot.mcmmcfuncion to draw the posterior density.

Upvotes: 0

Related Questions