# What does the pymc3.Binomial function do when the parameter n receives a list of values?

When I define a pm.Binomial and the parameter n receives a list of values, does metropolis define n as a constant or a random variable? How does he behave? Because from my understanding, if n is a random variable, the space to be covered can be very large according to the problem. I couldn’t find this information anywhere.

For example :
observation = pm.Binomial(“obs”, p = p, n = list_blue_balls, observed= list_all_balls)
trace = pm.sample(18000,step=pm.Metropolis())

1 Like

Though are certainly other uses, I think the primary intention is so that you can model data that consist of multiple sequences, each of which has can (but doesn’t necessarily need) its own `n`, it’s own `p`, and in the case of an observed variable, it’s own `k` (number of successes).

``````flips = [0, 3, 6, 600]
successes = np.multiply(2/3, flips)

coords = {
"coin": list(range(len(successes)))
}
with pm.Model(coords=coords) as model:
ps = pm.Beta('ps',
alpha=1,
beta=1,
dims='coin')
observation = pm.Binomial('like',
p=ps,
n=flips,
observed=successes)
idata = pm.sample(return_inferencedata=True)

print(idata.posterior.mean(dim=['chain','draw']))
``````

This yields:

``````<xarray.Dataset>
Dimensions:  (coin: 4)
Coordinates:
* coin     (coin) int64 0 1 2 3
Data variables:
ps       (coin) float64 0.4996 0.5985 0.627 0.6666
``````
2 Likes

Note that You can also assign a random variable to `n` - it behaves just as any random variable that the Binomial likelihood will conditioned on `n` (sample/proposal in the context of MCMC). There are some demonstrations in All-that-likelihood-with-PyMC3/Likelihood_visual_demo.ipynb at master · junpenglao/All-that-likelihood-with-PyMC3 · GitHub