# Estimating model with moment constraints

**URL:** <https://discourse.mc-stan.org/t/estimating-model-with-moment-constraints/8779>\
**Category:** Modeling\
**Created:** [May 10, 2019, 4:26am UTC](https://discourse.mc-stan.org/t/estimating-model-with-moment-constraints/8779 "2019-05-10T04:26:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JulianK](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@JulianK](https://discourse.mc-stan.org/u/JulianK)\
**Post date:** [May 10, 2019, 4:26am UTC](https://discourse.mc-stan.org/t/estimating-model-with-moment-constraints/8779/1 "2019-05-10T04:26:15Z")

</div>

Hello!

I’m wondering if the following problem is in principle solvable in Stan - it’s not immediately obvious how you might do it.

Suppose that I have a series of variables Y\_i where i \in [1,n]. Suppose that I think that I have the following hierarchical model:

**Problem specification**

- Y\_i \sim \text{Poisson}(\lambda\_i), where \lambda\_i is an unknown parameter
- \lambda\_i \sim \text{Gamma}(\alpha, \beta) for i \in [1,n], ie a hierarchical prior and \alpha and \beta are unknown.

I am trying to understand the posterior distribution of each \lambda\_i.

Suppose that I don’t have any actual Y\_i data but that instead I have some model from elsewhere that gives the following constraints:

- \mathbb{E}(\lambda\_i) = L\_i for i \in [1,n], i.e. I have prior knowledge about what the mean of each of the \lambda\_i variables should be.

Is this problem solvable in Stan directly?

**One approach - maybe incorrect…**

One thing I can think of is assuming an additional prior as follows:

- \lambda\_i \sim \text{Normal}(L\_i, \sigma\_i^2) for i \in [1,n] where {\sigma\_i^2} are treated as unknowns and then allowed to vary to be consistent with the data.

This type of prior could help encode my knowledge about how good my other models are.

But this is a prior mean assumption, whereas I guess what I’m expressing above is the desire for some sort of quasi-posterior mean constraint.

I’m not sure if this problem is adequately/fully specified… any thoughts welcome!

Thanks in advance,  
Julian

---

<div class="post-metadata">

**Author:** ![stijn](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/stijn/32/105_2.png) [@stijn](https://discourse.mc-stan.org/u/stijn)\
**Post date:** [May 10, 2019, 5:00am UTC](https://discourse.mc-stan.org/t/estimating-model-with-moment-constraints/8779/2 "2019-05-10T05:00:55Z")

</div>

The mean of the Gamma distribution is \frac{\alpha}{\beta} according to [wikipedia](https://en.wikipedia.org/wiki/Gamma_distribution). If you set \beta = \frac{\alpha}{L}, then you can use \lambda\_i \sim Gamma(\alpha, \frac{\alpha}{L}) where you estimate \alpha. This is the same approach as you proposed but with the Gamma distribution instead of the normal distribution. You will need some data to estimate \alpha though.

If you want to include the uncertainty in your estimate of L, and you have Y\_i, you could do.

\begin{align} Y\_i \sim Poisson(\lambda\_i) \\ \lambda\_i \sim Gamma(\alpha, \frac{\alpha}{Lhat}) \\ Lhat \sim Normal(L, Lse) \\ \end{align}

Where I assume you know L, and its standard error Lse.
