# Regressing through Latent Variables

**URL:** <https://discourse.pymc.io/t/regressing-through-latent-variables/16189>\
**Category:** version agnostic\
**Tags:** modeling\
**Created:** [November 27, 2024, 4:23pm UTC](https://discourse.pymc.io/t/regressing-through-latent-variables/16189 "2024-11-27T16:23:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreycenfoiles](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/dreycenfoiles/32/8448_2.png) [@dreycenfoiles](https://discourse.pymc.io/u/dreycenfoiles)\
**Post date:** [November 27, 2024, 4:23pm UTC](https://discourse.pymc.io/t/regressing-through-latent-variables/16189/1 "2024-11-27T16:23:51Z")

</div>

Hello,

I’m still fairly new to Bayesian modeling, so I think I have a naive question. I am doing growth curve modeling and trying to determine the existence of an effect coming from input variables. I have some data from group i and observation j that I am modeling as coming from an exponential function:

y\_{ij} \sim \mathcal{N}(A\_ie^{B\_it\_j}, \sigma)

In my model right now, each A\_i and B\_i are separate groups, but I would like to determine if there is a relationship between the components of the exponential and the input data x.

A\_i = f\_1(x\_i) \\ B\_i = f\_2(x\_i)

I suspect that the relationship, if it exists, is nonlinear, but I don’t think I have enough data to fully realize it. For now, I would just like to determine if there is a simple linear effect. My question is how would I go about modeling this in PyMC? Would I include another hierarchy level in the same model? Something to the effect of

A\_i = f\_1(x\_i) \approx A\_m x\_i + A\_b

Like I mentioned above, I believe that this function is, in reality, nonlinear. Would including this bias the model away from the “true” value of A\_i? Are there alternative ways to do this that I am not seeing?

Thank you very much for your time.

---

<div class="post-metadata">

**Author:** ![Martin\_Ingram](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/martin_ingram/32/3535_2.png) [@Martin\_Ingram](https://discourse.pymc.io/u/Martin_Ingram)\
**Post date:** [February 3, 2025, 8:45pm UTC](https://discourse.pymc.io/t/regressing-through-latent-variables/16189/2 "2025-02-03T20:45:23Z")

</div>

Hi dreycenfoiles,

so if I understand you correctly, you’re currently estimating the A\_i and B\_i as constants, but you think they might be functions of some covariates x\_i that you have, right? I think making A\_i and B\_i functions of x\_i makes sense. The only potential issue I see (and perhaps this is what is bothering you) is that currently, you are allowing A\_i and B\_i to have a separate value for each group, but if you impose your function

A\_i \approx A\_m x\_i + A\_b

you force the values to lie on this line. What I might try in your position would be to model

A\_i \sim \mathcal{N}(A\_m x\_i + A\_b, \sigma\_A^2)

i.e. draw the value A\_i from a hyperprior, and infer \sigma\_A^2 from the data. If your covariates x\_i are very informative and the linear relationship is good, \sigma\_A^2 will be very small, but if it’s not very good, \sigma\_A^2 will be large and you’ll be close to your original model. In that case, maybe you could experiment with more non-linear functions – a Gaussian Process or a spline, maybe.

I hope I understood you correctly and this is helpful, let me know! 🙂
