I’d like to use a Poisson distribution and it’s conjugate prior Gamma…
But I’m having problem to understand a basic example.
This is the sampling of ‘mu’ for a Poisson distribution with one observed value = 1.
with pm.Model() as model:
mu = pm.HalfFlat('mu')
p_obs = pm.Poisson('p_obs',mu=mu,observed=[1])
trace = pm.sample()#tune=2000,draws=10000,target_accept=0.9)
pm.traceplot(trace)
This is what I get :
And
trace['mu'].mean() = 1.993718...
First surprise : I expected the mean to be around 1, not 2… !?
Then I try this other way to sample mu with the same data (observed value =1 , seen once) directly with a Gamma which is the Poisson conjugate prior.
with pm.Model() as model:
mu = pm.Gamma('mu',alpha=1,beta=1)
trace = pm.sample() #tune=2000,draws=10000)#,target_accept=0.9)
pm.traceplot(trace)
Which shows this posterior :
This does not correspond to the previous curve !! I don’t understand why…
And when it comes to the mean of the samples:
trace['mu'].mean() = 1.0148405502...
Which is totally different from the previous model !
It’s closer to what I think it should be (regarding the observed data), but I don’t understand why this two models give far different results…
I don’t know which model is wrong, and why.
Any help will be appreciated.