# P-value differ from R for linear regression

**URL:** <https://discuss.hail.is/t/p-value-differ-from-r-for-linear-regression/1964>\
**Category:** Development\
**Created:** [March 16, 2021, 2:28pm UTC](https://discuss.hail.is/t/p-value-differ-from-r-for-linear-regression/1964 "2021-03-16T14:28:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mocksu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/mocksu/32/558_2.png) [@mocksu](https://discuss.hail.is/u/mocksu)\
**Post date:** [March 16, 2021, 2:28pm UTC](https://discuss.hail.is/t/p-value-differ-from-r-for-linear-regression/1964/1 "2021-03-16T14:28:01Z")

</div>

It’s a big surprise that I got different p-values from hail and from R. The input data as I manually checked is identical. The hail code is as follows:

mt = mt.annotate\_rows(gwas = hl.agg.linreg(hl.float(mt.phenos.height),  
[1,  
hl.float(mt.phenos.age),  
hl.float(mt.phenos.gender),  
hl.float(mt.anc0dos.x),  
hl.float(mt.anc1dos.x),  
hl.float(mt.anc2dos.x),  
hl.float(mt.hapcounts0.x),  
hl.float(mt.hapcounts1.x)]))

The R code is as follows:

summary(glm(HEIGHT ~ AGE + GENDER + ANC0DOS + ANC1DOS + ANC2DOS + HC0 + HC1)

For one row, the p-value from hail is 0.0995 (beta = -2.19, se = 1.23, t = -1.79), while the p-value from R is 0.086 (beta = -2.19150, se = 1.17954, t = -1.858). I used python statsmodels.api.OLS with constant and got the same p-value as R (0.086).

The fact that the beta values agree with each other suggests there is no input data difference. Not sure why the SE differs from each other.

Thanks for any hope.

---

<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:** [March 17, 2021, 3:14pm UTC](https://discuss.hail.is/t/p-value-differ-from-r-for-linear-regression/1964/2 "2021-03-17T15:14:32Z")

</div>

Can you try using `linear_regression_rows` and seeing what you get? Docs here: [Hail | Statistics](https://hail.is/docs/0.2/methods/stats.html#hail.methods.linear_regression_rows)

---

<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:** [March 18, 2021, 5:13pm UTC](https://discuss.hail.is/t/p-value-differ-from-r-for-linear-regression/1964/3 "2021-03-18T17:13:55Z")

</div>

It will help us understand what’s going on here. It may be that our linreg aggregator has some numerical instability that we need to address.

---

<div class="post-metadata">

**Author:** ![mocksu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/mocksu/32/558_2.png) [@mocksu](https://discuss.hail.is/u/mocksu)\
**Post date:** [March 18, 2021, 7:35pm UTC](https://discuss.hail.is/t/p-value-differ-from-r-for-linear-regression/1964/4 "2021-03-18T19:35:08Z")

</div>

cannot make `linear\_regression\_rows work for the error:

scope vialation: ‘linear\_regression\_rows/covariates’ expects an expression indexed by [‘column’]  
Found indices[‘row’, ‘column’], iwth unexpected indices [‘row’]. Invalid fields:  
‘anc1dos’ (indices [‘row’, ‘column’])

---

<div class="post-metadata">

**Author:** ![mocksu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/mocksu/32/558_2.png) [@mocksu](https://discuss.hail.is/u/mocksu)\
**Post date:** [March 18, 2021, 7:36pm UTC](https://discuss.hail.is/t/p-value-differ-from-r-for-linear-regression/1964/5 "2021-03-18T19:36:43Z")

</div>

Forgot to say, the discrepancy occurs when I use 20 samples. If I use 25,000 samples, the p-values are identical to each other if ignoring precision point.

---

<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:** [March 26, 2021, 7:20pm UTC](https://discuss.hail.is/t/p-value-differ-from-r-for-linear-regression/1964/6 "2021-03-26T19:20:03Z")

</div>

You can’t have entrywise covariates with `linear_regression_rows`. Just include them as x values.

---

<div class="post-metadata">

**Author:** ![mocksu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/mocksu/32/558_2.png) [@mocksu](https://discuss.hail.is/u/mocksu)\
**Post date:** [March 31, 2021, 12:49am UTC](https://discuss.hail.is/t/p-value-differ-from-r-for-linear-regression/1964/7 "2021-03-31T00:49:26Z")

</div>

Could you elaborate a little bit more on “entry wise”? The only difference between the 20 samples & 25k samples is the sample size, all data structures are the same.
