0

I'm struggling with a problem of binomial and pymc I have a sample divided in groups and I would like to evaluate using MCMC the transition rate from the status Susceptible to Infected and plot the results in a way similar to here

when I compile the script I get this message:

Traceback (most recent call last):
  File "statisticMCMC_bin.py", line 23, in <module>
    plot(mc.finalhcc.stats()['mean'],color='red',linewidth=2)
  File "/Library/Python/2.7/site-packages/pymc-2.3a-py2.7-macosx-10.8-intel.egg/pymc/Node.py", line 265, in stats
    return self.trace.stats(alpha=alpha, start=start, batches=batches,
AttributeError: 'Binomial' object has no attribute 'trace'

and no plot is produced.....How can I fix it?

Here's the model and the launching script:

import sys
import pickle

import pykov 
import random
import scipy.integrate as spi
import numpy as np
import pylab as pl
import math as mt
import scipy.linalg as linear
import decimal
from pymc import *
import numpy as np

n = np.array([647,1814,8838,9949,1920])###initial population
originalHCC=np.array([0,197,302,776,927], dtype=float)
beta=Uniform('beta',0.001,1.0)####death rate
vectorp=np.array([beta,beta,beta,beta,beta]);   


finalhcc = pymc.Binomial('finalhcc', n=n, p=vectorp, value=originalHCC, observed=True)
#
import numpy as np
from pymc import *
from pylab import *
import scipy as sc
#from pymc.Matplot import plot
from scipy.stats.mstats import mquantiles


import MCMC_bin as mod
reload(mod)
mc=MCMC(mod)

mc.use_step_method(AdaptiveMetropolis, [mod.beta])
mc.sample(iter=500000,burn=5000, thin=20,verbose=1)

n = np.array([647,1814,8838,9949,1920,39])



figure(1)
title('HCC with uncertainty')
plot(mc.originalHCC, 's', mec='black', color='black',alpha=0.9)
plot(mc.finalhcc.stats()['mean'],color='red',linewidth=2)
plot(mc.finalhcc.stats()['95% HPD interval'],color='red',linewidth=1,linestyle='dotted')
axis(0,6,0.9*min(mc.originalHCC),1.2*max(mc.originalHCC))
savefig('HCC.png')

1 Answers1

0

This is because, in your model, the Binomial node finalhcc is observed (a data likelihood). Therefore, it has no trace because it is not being sampled. Its value is fixed (the data). Only non-data stochastics and deterministic nodes have traces.

Chris Fonnesbeck
  • 4,143
  • 4
  • 29
  • 30