# Hierarchical Pooling but "same level" ie "sibling pooling"

I am new to the pymc and thinking with probabilities.
I have checked out a few of the basic hierarchical pooling tutorials: radon and rugby.

I am interested in understanding the extended hierarchical pooling found in where they “move up” in the level.
https://docs.pymc.io/pymc-examples/examples/case_studies/multilevel_modeling.html

In this example, after they have modeled the “floor” by “county” relationship, they move on to take into account a “country” level in the example.

I am however interested in a more “sibling approach”. For instance, I surmise (and pretend I have data for the following).

1. Rainfall by county. I believe that rainfall can “wash away” radon in the ground as it trickles through.

While, we could say that this is just an input variable into the Normal distribution, I wish for the relationship between amount of Rainfall and radon to be variable by county, related, but can fluctuate.

In the physical world, I would explain that by saying, the effects of rainwater in loose-soil vs solid granite is different, but would still expect that 5 inches of rain per week to have more of an effect than 1 inches of rain per week.

How can I modify the existing radon example to incorporate such "county level " if I only want to include this type of rainfall data?

Am I even asking the question correctly?
– btw I cannot add soil type as an input, because I don’t have it…which is why I want to let it find it’s own loosely related values.

You’re on the right track, but usually we add the impacts of various inputs and then apply a link function to map it to the 0-1 scale that the `Binomial` likelihood function expects. See here for an example: https://towardsdatascience.com/bayesian-logistic-regression-with-pymc3-8e17c576f31a

[Repost from above, since I was having trouble editting a previous post. unclear why]

# edit notes: change nomenclature of the example to use hair color

As a follow up. I would like to post an example using the example from the Baseball Tutorial.
https://docs.pymc.io/pymc-examples/examples/case_studies/hierarchical_partial_pooling.html

After the intial setup, you can do pooling with:

N = #number of players
with pm.Model() as baseball_model:

``````phi = pm.Uniform("phi", lower=0.0, upper=1.0)
kappa_log = pm.Exponential("kappa_log", lam=1.5)
kappa = pm.Deterministic("kappa", tt.exp(kappa_log))

thetas = pm.Beta("draw_thetas", alpha=phi * kappa, beta=(1.0 - phi) * kappa, shape = N)
y = pm.Binomial("y", n=at_bats, p=thetas, observed = hits)
``````

===========================
I wish to extend this with the following information (examples):
some people played on different ground: turf, other people on mud. (2)
some people are of different hair color: black vs white vs blonde (3)

with pm.Model() as baseball_model:

``````phi = pm.Uniform("phi", lower=0.0, upper=1.0)
kappa_log = pm.Exponential("kappa_log", lam=1.5)
kappa = pm.Deterministic("kappa", tt.exp(kappa_log))

thetas = pm.Beta("thetas", alpha=phi * kappa, beta=(1.0 - phi) * kappa, shape = N)
thetas = draw_thetas[draw_idx]/3

# this to account for "ground type"
phi_ground = pm.Uniform("phi_ground, lower=0.0, upper=1.0)
kappa_log_ground = pm.Exponential("kappa_log_ground", lam=1.5)
kappa_ground= pm.Deterministic("kappa_ground", tt.exp(kappa_log_ground))

ground = pm.Beta("ground", alpha=phi_ground * kappa_ground, beta=(1.0 - phi_ground) * kappa_ground, shape = 2)  # because turf vs mud
grounds = ground[ground_idx]/3

# this to account for "hair color"
phi_hc = pm.Uniform("phi_ground, lower=0.0, upper=1.0)
kappa_log_hc = pm.Exponential("kappa_log_hc", lam=1.5)
kappa_hc= pm.Deterministic("kappa_hc", tt.exp(kappa_log_hce))

hair_color = pm.Beta("race", alpha=phi_race * kappa_hc, beta=(1.0 - phi_race) * kappa_hc, shape = 3)  # black, white, blonde
hair_color = hair_color[hair_color_idx]/3

# then to wrap it all together:
y = pm.Binomial("y", n=at_bats, p=thetas + grounds + hair_color, observed = hits)
``````

Is this the right way of trying to capture this?

thanks! will check that out.