# Polygenic risk score calculation

**URL:** <https://discuss.hail.is/t/polygenic-risk-score-calculation/1762>\
**Category:** Hail Query & hailctl\
**Created:** [November 2, 2020, 2:36pm UTC](https://discuss.hail.is/t/polygenic-risk-score-calculation/1762 "2020-11-02T14:36:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rost](https://avatars.discourse-cdn.com/v4/letter/r/6de8d8/32.png) [@Rost](https://discuss.hail.is/u/Rost)\
**Post date:** [November 2, 2020, 2:36pm UTC](https://discuss.hail.is/t/polygenic-risk-score-calculation/1762/1 "2020-11-02T14:36:56Z")

</div>

Hello there!  
I already did linear regression, and get a corresponded matrix table for further polygenic score calculation per individual. My MatrixTable has the next structure:

```auto
mt.describe()

```

```auto
----------------------------------------
Global fields:
    None
----------------------------------------
Column fields:
    's': str
----------------------------------------
Row fields:
    'locus': locus<GRCh37>
    'cvas': struct {
        beta: str, 
        pval: str
    }
----------------------------------------
Entry fields:
 'GT': call

```

Then I want to sum over all variants and calculate (n\_non\_ref\_counts \* beta) for each individual.

```auto
mt = mt.annotate_rows(whole_dataset = 1)
mts = mt.group_rows_by(summary_stat = mt.whole_dataset)\
   .aggregate(risk_score = mt.GT.n_alt_alleles()*hl.float(mt.cvas.beta))

```

but I get next to an error:

```auto
ExpressionException: scope violation: 'GroupedMatrixTable.aggregate_entries' expects an expression indexed by ['column']
    Found indices ['column', 'row'], with unexpected indices ['row']. Invalid fields:
        'GT' (indices ['column', 'row'])
        'cvas' (indices ['row'])
    'GroupedMatrixTable.aggregate_entries' supports aggregation over axes ['column', 'row'], so these fields may appear inside an aggregator function.

```

---

<div class="post-metadata">

**Author:** ![tpoterba](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/tpoterba/32/61_2.png) [@tpoterba](https://discuss.hail.is/u/tpoterba)\
**Post date:** [November 2, 2020, 2:38pm UTC](https://discuss.hail.is/t/polygenic-risk-score-calculation/1762/2 "2020-11-02T14:38:32Z")

</div>

I think this:

```auto
   .aggregate(risk_score = mt.GT.n_alt_alleles()*hl.float(mt.cvas.beta))

```

should be:

```auto
   .aggregate(risk_score = hl.agg.sum(mt.GT.n_alt_alleles()*hl.float(mt.cvas.beta)))

```

Does that seem right?

---

<div class="post-metadata">

**Author:** ![Rost](https://avatars.discourse-cdn.com/v4/letter/r/6de8d8/32.png) [@Rost](https://discuss.hail.is/u/Rost)\
**Post date:** [November 2, 2020, 2:46pm UTC](https://discuss.hail.is/t/polygenic-risk-score-calculation/1762/3 "2020-11-02T14:46:10Z")

</div>

That’s worked. Thank you!
