I’m defining my negative binomial like this currently:

dispersion = pm.HalfNormal(‘dispersion’, 1)

sigma = mean_rate * (1 + mean_rate / dispersion)

counts = pm.NegativeBinomial(“counts”, mu=rates, alpha=sigma, observed=event_count)

So the dispersion is moderating the over-dispersion of the negative binomial. However, I’d like to reparameterize the prior on dispersion so that 1/sqrt(dispersion) is from a half-normal, rather than just dispersion. In Stan I’d just do this:

`1/sqrt(dispersion) ~ half-N(0, 1)`

But I can’t work out how to do it in PYMC. Any help would be gratefully received.

PyMC does not allow for that kind of syntax. In the future it would allow for something defined in terms of dispersion, that is:

```
with pm.Model() as m:
dispersion = 1 / HalfNormal.dist()**2
m.register_rv(dispersion, name="dispersion")
```

But that relies on Aeppl, where we are implementing this sort of functionality, and we dont yet have support for squaring transformations. You can follow progres in GitHub - aesara-devs/aeppl: Tools for an Aesara-based PPL.

Seems like the easiest solution would be to use a deterministic?

```
disp_base = pm.HalfNormal("disp_base", 0, 1)
dispersion = pm.Deterministic("dispersion", pm.math.sqr(1 / disp_base))
```

That’s the easiest but it’s not exactly the same. You are not putting a prior directly on the transformation. It can be perfectly adequate though.

Thanks for the replies - much appreciated.