# \[CLOSED\] Help sharing dimension between location and scale in a simple hierarchical model

**URL:** <https://discourse.pymc.io/t/closed-help-sharing-dimension-between-location-and-scale-in-a-simple-hierarchical-model/10134>\
**Category:** version agnostic\
**Tags:** development, shape\_issue, modeling\
**Created:** [August 11, 2022, 1:57pm UTC](https://discourse.pymc.io/t/closed-help-sharing-dimension-between-location-and-scale-in-a-simple-hierarchical-model/10134 "2022-08-11T13:57:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![omrihar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/omrihar/32/3731_2.png) [@omrihar](https://discourse.pymc.io/u/omrihar)\
**Post date:** [August 11, 2022, 1:57pm UTC](https://discourse.pymc.io/t/closed-help-sharing-dimension-between-location-and-scale-in-a-simple-hierarchical-model/10134/1 "2022-08-11T13:57:15Z")

</div>

Hello,

first of all, congratulations on the new and shiny version 4!

I’m trying to define a simple hierarchical model, and have a problem in understanding how to use implicit dimensions. My (simplified) code is here:

```python
coords = {
  "dim1": ["one", "two", "three"],
  "dim2": list(range(50)),
}

with pm.Model(coords=coords) as m:
  # Define priors
  γ = pm.Normal("γ", -2.8, 0.3, dims=("dim1",))
  τ = pm.HalfNormal("τ", 1, dims=("dim1",))
  α = pm.Normal("α", γ, τ, dims=("dim2", "dim1"))
  
  # Define the log-link function
  linear_part = α[dim2_idx, dim1_idx] + at.log(exposure)
  μ = at.exp(linear_part)  
  
  # The likelihood
  y = pm.Poisson("y", μ, observed=claims)

```

When I try to sample from the prior I get an error `IndexError: index 22 is out of bounds for axis 0 with size 3` and I know this is related to having both γ and τ as hyperpriors in the definition of α. This code works if I replace τ with a constant, so I suspect this has something to do with broadcasting, but I’m not really sure how to communicate to pymc that I want both γ and τ to be indexed by the same `dim1_idx` in the linear part of the GLM.

Here `dim1_idx` and `dim2_idx` are coming from categorical columns in a pandas DataFrame, and `exposure` and `claims` are pandas series with the same length as `dim1_idx` and `dim2_idx`.

Any help would be greatly appreciated!  
Cheers,  
Omri

---

<div class="post-metadata">

**Author:** ![omrihar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/omrihar/32/3731_2.png) [@omrihar](https://discourse.pymc.io/u/omrihar)\
**Post date:** [August 11, 2022, 2:59pm UTC](https://discourse.pymc.io/t/closed-help-sharing-dimension-between-location-and-scale-in-a-simple-hierarchical-model/10134/2 "2022-08-11T14:59:48Z")

</div>

OK, I realized I actuallly had a bug somewhere else in the code, the snippet I shared actually works!

Sorry for the trouble 🙂
