# Prevent GLM from dropping rows with missings

**URL:** <https://discourse.julialang.org/t/prevent-glm-from-dropping-rows-with-missings/92569>\
**Category:** Statistics\
**Created:** [January 5, 2023, 7:16pm UTC](https://discourse.julialang.org/t/prevent-glm-from-dropping-rows-with-missings/92569 "2023-01-05T19:16:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![croberts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/croberts/32/9465_2.png) [@croberts](https://discourse.julialang.org/u/croberts)\
**Post date:** [January 5, 2023, 7:16pm UTC](https://discourse.julialang.org/t/prevent-glm-from-dropping-rows-with-missings/92569/1 "2023-01-05T19:16:30Z")

</div>

The @formula macro allows the construction of variables when creating a model matrix.

This is great! I don’t have to add various transformations of variables to a DataFrame simply because I want to try alternative regression specifications. I can write:  
`@formula(y/x ~ w) `  
or  
`@formula(y - z ~ w + w^2) `

But what if I want to run the regression:

`GLM.lm( @formula(ismissing(y) ~ x + z) , df)`

Uh oh. It doesn’t matter that ismissing(y) is never missing, GLM recognizes that y itself has missing values and drops these rows from the model matrix.

Obviously, I could construct a new variable outside the formula macro:

`df[!, :y_is_missing] = ismissing.(df.y)`

and run my regression using this. But I don’t want to. Is there any way to turn off the feature that drops missings from the model matrix? A long-term solution would probably have GLM.jl check if the transformed variables are missing, rather than if the variables themselves are missing. In the interim…

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [January 5, 2023, 7:25pm UTC](https://discourse.julialang.org/t/prevent-glm-from-dropping-rows-with-missings/92569/2 "2023-01-05T19:25:26Z")

</div>

> [@croberts](#):
>
> Is there any way to turn off the feature that drops missings from the model matrix?

This seems unlikely to fly based on prior discussions. But

> [@croberts](#):
>
> have GLM.jl check if the transformed variables are missing, rather than if the variables themselves are missing

maybe that could work?
