# Rewrite R glm in hail

**URL:** <https://discuss.hail.is/t/rewrite-r-glm-in-hail/2569>\
**Category:** Hail Query & hailctl\
**Created:** [March 29, 2022, 2:00pm UTC](https://discuss.hail.is/t/rewrite-r-glm-in-hail/2569 "2022-03-29T14:00:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ch-kr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/ch-kr/32/317_2.png) [@ch-kr](https://discuss.hail.is/u/ch-kr)\
**Post date:** [March 29, 2022, 2:00pm UTC](https://discuss.hail.is/t/rewrite-r-glm-in-hail/2569/1 "2022-03-29T14:00:19Z")

</div>

Hi hail team!

I have a very basic question. I’m trying to rewrite the following R code (from Kaitlin’s MPC code) using hail:

```auto
glm(pop_v_path ~ obs_exp + mis_badness3 + obs_exp:mis_badness3 + polyphen2 + obs_exp:polyphen2, data=cleaned_joint_exac_clinvar.scores, family=binomial)

```

Is there an easy way to write this formula?

Thanks!

---

<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 29, 2022, 2:06pm UTC](https://discuss.hail.is/t/rewrite-r-glm-in-hail/2569/2 "2022-03-29T14:06:16Z")

</div>

My R reading isn’t great: is this a linear regression? Or is this more complicated than that?

---

<div class="post-metadata">

**Author:** ![ch-kr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/ch-kr/32/317_2.png) [@ch-kr](https://discuss.hail.is/u/ch-kr)\
**Post date:** [March 29, 2022, 2:09pm UTC](https://discuss.hail.is/t/rewrite-r-glm-in-hail/2569/3 "2022-03-29T14:09:10Z")

</div>

I think this is a logistic regression. I saw in the R docs that the `:` operator has a specific definition for `glm`:

```auto
A specification of the form first:second indicates the set of terms obtained by taking the interactions of all terms in first with all terms in second.

```

do you know if there is an equivalent for this in python?

---

<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 29, 2022, 8:10pm UTC](https://discuss.hail.is/t/rewrite-r-glm-in-hail/2569/4 "2022-03-29T20:10:53Z")

</div>

Ok, so I think `obs_exp:mis_badness3` in R is the same as `obs_exp * mis_badness3` in Python. In an R formula, `obs_exp * mis_badness3` would translate to the Python `obs_exp + mis_badness3 + obs_exp * mis_badness3`.

---

<div class="post-metadata">

**Author:** ![ch-kr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/ch-kr/32/317_2.png) [@ch-kr](https://discuss.hail.is/u/ch-kr)\
**Post date:** [April 6, 2022, 2:25pm UTC](https://discuss.hail.is/t/rewrite-r-glm-in-hail/2569/5 "2022-04-06T14:25:19Z")

</div>

thank you!!

---

<div class="post-metadata">

**Author:** ![ch-kr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/ch-kr/32/317_2.png) [@ch-kr](https://discuss.hail.is/u/ch-kr)\
**Post date:** [May 5, 2022, 3:37pm UTC](https://discuss.hail.is/t/rewrite-r-glm-in-hail/2569/6 "2022-05-05T15:37:46Z")

</div>

hello! circling back to this, is there a way to do a logistic regression in hail? I think these two functions are the most relevant: [Hail | Aggregators](https://hail.is/docs/0.2/aggregators.html#hail.expr.aggregators.linreg) and [Hail | Statistics](https://hail.is/docs/0.2/methods/stats.html#hail.methods.logistic_regression_rows).

I’m hoping to run a logistic regression in an aggregation (ideally something like `hl.agg.logreg`), is that possible with the existing functionality? Maybe I’ve missed something in the docs?

I’d appreciate any tips – thanks in advance!

---

<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:** [May 5, 2022, 3:53pm UTC](https://discuss.hail.is/t/rewrite-r-glm-in-hail/2569/7 "2022-05-05T15:53:06Z")

</div>

This isn’t possible right now. Fitting a logistic regression a convex optimization problem, and there are no good options for doing this in a single pass over the data (which is what Hail aggregators require). We intend to support doing this on a table, but don’t have a timeline right now.

---

<div class="post-metadata">

**Author:** ![ch-kr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/ch-kr/32/317_2.png) [@ch-kr](https://discuss.hail.is/u/ch-kr)\
**Post date:** [May 5, 2022, 3:54pm UTC](https://discuss.hail.is/t/rewrite-r-glm-in-hail/2569/8 "2022-05-05T15:54:05Z")

</div>

gotcha, thank you for letting me know!
