# PVE calculation

**URL:** <https://discuss.hail.is/t/pve-calculation/2464>\
**Category:** Hail Query & hailctl\
**Created:** [February 4, 2022, 9:10pm UTC](https://discuss.hail.is/t/pve-calculation/2464 "2022-02-04T21:10:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![esebesty](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@esebesty](https://discuss.hail.is/u/esebesty)\
**Post date:** [February 4, 2022, 9:10pm UTC](https://discuss.hail.is/t/pve-calculation/2464/1 "2022-02-04T21:10:22Z")

</div>

Hi all, is there a quick way to calculate PVE (percent variance explained) and include it in the result table, besides locus, alleles, beta, p-value, etc?

---

<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:** [February 4, 2022, 9:14pm UTC](https://discuss.hail.is/t/pve-calculation/2464/2 "2022-02-04T21:14:06Z")

</div>

Should be able to write a `result.annotate` statement to compute it from the existing statistics:

`2*(beta^2)*MAF*(1-MAF)]/[2*(beta^2)*MAF(1-MAF)+((se(beta))^2)*2*N*MAF*(1-MAF)]`

[source](https://www.researchgate.net/post/How_to_determine_the_percent_phenotypic_variation_explained_PVE_by_a_selected_SNP)

---

<div class="post-metadata">

**Author:** ![esebesty](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@esebesty](https://discuss.hail.is/u/esebesty)\
**Post date:** [March 2, 2022, 9:22pm UTC](https://discuss.hail.is/t/pve-calculation/2464/3 "2022-03-02T21:22:28Z")

</div>

Finally did stg like:

```auto
result_lm1 = hl.linear_mixed_regression_rows(data_model1.GT.n_alt_alleles(), lm1)
maf_table = data_model1.annotate_rows(MAF = hl.min(data_model1.variant_qc.AF)).rows()
result_lm1_ann = result_lm1.annotate(MAF = maf_table[result_lm1_ann.locus result_lm1_ann.alleles].MAF)

```

etc, but looks like it takes ages to annotate results with the MAF. Am I missing something here?

---

<div class="post-metadata">

**Author:** ![danking](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/danking/32/43_2.png) [@danking](https://discuss.hail.is/u/danking)\
**Post date:** [March 2, 2022, 10:34pm UTC](https://discuss.hail.is/t/pve-calculation/2464/4 "2022-03-02T22:34:50Z")

</div>

Hail is lazy which means that we build a list of the operations and do not execute it until you “observe” the value. You can observe values with `count`, `write`, `hl.export_vcf`, `aggregate`, etc.

Because of that, it’s hard to comment on the performance without seeing the full script. Can you share it?

This also means that if you split a matrix table like:

```auto
mt1 = mt.anntoate(...)
mt2 = mt.annotate(...)

```

And then try to join them:

```auto
mt1 = mt1.annotate_rows(... mt2.rows()[mt1.row_key])

```

You’ll do all the work to produce `mt` twice. It looks like you might have this pattern. `hl.linear_mixed_regression_rows` has the `pass_through` argument to help address this issue.

Finally, Hail’s `hl.linear_mixed_regression_rows` is not as fast as other LMM methods like BOLTLMM or SAIGE. Have you tried using those instead?

---

<div class="post-metadata">

**Author:** ![esebesty](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@esebesty](https://discuss.hail.is/u/esebesty)\
**Post date:** [March 3, 2022, 4:50pm UTC](https://discuss.hail.is/t/pve-calculation/2464/5 "2022-03-03T16:50:58Z")

</div>

Thanks, I think the `pass_through` argument is all I need, did not notice that! I can calculate MAF at the start, use the argument to include it in the result table, and then use `annotate_rows`. Also, I’m impatient, it did not take ages, after all.
