# Linear regression per column with entry fields

**URL:** <https://discuss.hail.is/t/linear-regression-per-column-with-entry-fields/2207>\
**Category:** Hail Query & hailctl\
**Created:** [August 27, 2021, 3:41pm UTC](https://discuss.hail.is/t/linear-regression-per-column-with-entry-fields/2207 "2021-08-27T15:41:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![djw](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@djw](https://discuss.hail.is/u/djw)\
**Post date:** [August 27, 2021, 3:41pm UTC](https://discuss.hail.is/t/linear-regression-per-column-with-entry-fields/2207/1 "2021-08-27T15:41:22Z")

</div>

Hi all – I have a MatrixTable with genes as row key, phenotype as column key, and two entry fields, called X and Y. For each phenotype, I would like to regress Y on X (for example, if I have 100 genes and 2 phenotypes, then I would run 2 regressions, each with 100 (x,y) pairs).

I’m getting stuck on how to use _linear\_regression\_rows_ on my particular MatrixTable for my analysis. I see _linear\_regression\_rows_ looks for a column keyed response variable, and more generally a transposed-ish version of my MatrixTable. Since I understand transposition to be tricky with MatrixTables, any suggestions on how to implement this regression in Hail given the structure of my data described above?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![johnc1231](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/johnc1231/32/286_2.png) [@johnc1231](https://discuss.hail.is/u/johnc1231)\
**Post date:** [August 27, 2021, 4:23pm UTC](https://discuss.hail.is/t/linear-regression-per-column-with-entry-fields/2207/2 "2021-08-27T16:23:26Z")

</div>

It’s true that you can’t use `linear_regression_rows` in this scenario without doing some sort of transpose. However, you can use the linear regression aggregator: [Hail | Aggregators](https://hail.is/docs/0.2/aggregators.html#hail.expr.aggregators.linreg)

---

<div class="post-metadata">

**Author:** ![djw](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@djw](https://discuss.hail.is/u/djw)\
**Post date:** [August 28, 2021, 12:01am UTC](https://discuss.hail.is/t/linear-regression-per-column-with-entry-fields/2207/3 "2021-08-28T00:01:35Z")

</div>

Thank you!
