Hello,

I’m trying to build an abundance and detection probability model in PyMC3 and have gotten stuck in the PyMC3 syntax - I hope someone can help me out. Thanks in advance!

Here’s a toy problem to demonstrate the issue:

I want to model the number of birds in my yard on any given day. I’ve counted the birds in my yard every day for 100 days, but I’m not a perfect birder, meaning that there could be birds present that I didn’t see. There are two parts to the model - the first is a Poisson model for the counts of birds present (abundance, b). The second is a Binomial model for the detection probability, which is the probability that I see a bird, given that it’s present in my yard (detection probability, p). Using my counts of birds over 100 days, I want to simultaneously estimate the abundance (b) and the detection probability (p).

obsbirds_{d} \sim Binomial(birds_{d},p)

birds_{d} \sim Poisson(b)

```
import pymc3 as pm
import scipy.stats as stats
#generate data
b = 1 #Poisson rate parameter (average number of birds per day in my yard)
p = 0.3 # detection probability (probability that I see a bird, given that it's present)
d = 100 # number of days that I watched birds
birds = stats.poisson.rvs(b, size = d)
obsbirds = stats.binom.rvs(birds, p)
```

I now want to build a model in PyMC3 that estimates b and p simulataneously. Here’s my attempt, but the chains are failing and I can’t figure out what’s wrong.

```
# instantiate pymc3 model
mymodel = pm.Model()
# set up
with mymodel:
##priors
#for poisson part of model
bfit = pm.HalfNormal('b', sigma = 10, shape = 1) #prior for b (must be positive)
#for binomial part of model
pfit = pm.Uniform('p', lower = 0, upper = 1, shape = 1) #prior for p (must be between 0 and 1)
##likelihoods
birdsfit = pm.Poisson('birds', mu = bfit, shape = len(obsbirds))
countsobs = pm.Binomial('obscounts',
n = birdsfit,
p = pfit,
observed=obsbirds)
```

I’d appreciate help with the PyMC3 syntax, or pointers in the right direction. Thanks!