# Why are missing values not ignored by default?

**URL:** <https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756>\
**Category:** Internals & Design\
**Tags:** data, missing-values\
**Created:** [November 26, 2023, 1:45am UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756 "2023-11-26T01:45:36Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [November 27, 2023, 6:39pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/63 "2023-11-27T18:39:21Z")

</div>

> [@pdeffebach](#):
>
> I’m discussing a scenario where `x < y` should imply “We are absolutely sure that `x` is less than `y`”. This obviously has some costs, I admit.

And I’m saying that this is as dangerous as `missing`s vanishing in any other scalar operation. If you prefer, the example could’ve been about a comparison `<5.5` instead of a units conversion, and the mean would describe the proportion of the team shorter than 5 1/2 feet. The mean _needs_ `[true, missing, false, missing]` to divide by the 2 people that showed up; `[true, false, false, false]` looks the exact same as if all 4 were present. If I really need the latter, I can replace `missing` with `false` myself (destroying information), but I can’t possibly do the inverse (creating information). If you really want to skip missings, propagate those missings in scalar operations so there’s something to skip in folding operations.

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [November 27, 2023, 6:43pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/64 "2023-11-27T18:43:39Z")

</div>

there has to be somewhere to [draw the line](https://jle.aals.org/cgi/viewcontent.cgi?article=1715&context=home) ; not _every_ function can propagate `missing`, but you raise good arguments as to why some of them should

with that being said, I think my ideal world would be:

- binary operators propagate,
- statistical moments and quantiles (and `cor` and `cov`) skip,
- everything else `MethodError`,

so `mean(heights .> 5.5)` would work just fine

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [November 27, 2023, 6:45pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/65 "2023-11-27T18:45:45Z")

</div>

We should just use some unicode. This seems appropriate:

```julia
julia> mean(🙈([1.0, missing, 2.0]))
1.5

```

(sorry)

---

<div class="post-metadata">

**Author:** ![ParadaCarleton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paradacarleton/32/20005_2.png) [@ParadaCarleton](https://discourse.julialang.org/u/ParadaCarleton)\
**Post date:** [November 27, 2023, 6:48pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/66 "2023-11-27T18:48:39Z")

</div>

> [@pdeffebach](#):
>
> [DataFramesMeta.jl](https://github.com/JuliaData/DataFramesMeta.jl) provides some features to make this easier, such as dropping missing values in `@subset`, adding the `@passmissing` macro-flag, and hopefully more in the future.

I do think this is the most likely solution to actually happen, because there’s a tradeoff here between correctness/explicitness and conciseness. A macro gives us most of the conciseness (just apply the macro wherever you need) without the problem of making it easier for users to write incorrect code.

Personally I’m not sure we even want a macro for this, because it encourages absentmindedly dropping missings instead of careful modeling, but I think it’s a reasonable compromise most people can live with (even if it’s not their first choice).

By the way, I’d like to point out [MICE.jl](https://github.com/tom-metherell/Mice.jl) could make this a lot easier by giving a good default method for imputation, especially if you combined it with MonteCarloMeasurements.jl (so you can use any imputed values like normal numbers).

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [November 27, 2023, 6:53pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/67 "2023-11-27T18:53:56Z")

</div>

> [@ParadaCarleton](#):
>
> because it encourages absentmindedly skipping over every missing value instead of carefully considering the data

I would encourage you, as other commenters sharing similar sentiments have been previously encouraged in this thread, to try not to assume that a desire to make `skipmissing` easier to use is born only out of sloppiness, recklessness, ignorance, or laziness

I have carefully considered my data, and I very intentionally want to skip the missings. and I need to do it frequently. and the verbosity that requires makes me painfully _more_ present-minded than I would otherwise want to have to be

---

<div class="post-metadata">

**Author:** ![ParadaCarleton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paradacarleton/32/20005_2.png) [@ParadaCarleton](https://discourse.julialang.org/u/ParadaCarleton)\
**Post date:** [November 27, 2023, 6:59pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/68 "2023-11-27T18:59:30Z")

</div>

> [@adienes](#):
>
> I would encourage you, as other commenters sharing similar sentiments have been previously encouraged in this thread, to try not to assume that a desire to make `skipmissing` easier to use is born only out of sloppiness, recklessness, ignorance, or laziness

I’m not assuming that every case is like that; dropping missings can be a perfectly reasonable choice when you think your data is missing completely at random. But there’s definitely going to be _some_ users who would drop missings accidentally, if it were done automatically (I’ve done this myself!).

This is why I think we should go with the compromise option of making it easy, but still explicit; explicit is better than implicit.

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [November 27, 2023, 7:02pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/69 "2023-11-27T19:02:23Z")

</div>

> [@ParadaCarleton](#):
>
> think your data is missing completely at random.

in many cases where `missing` values arise, they do not represent actual “missing observations.” sometimes they are just placeholders in a table where no observation is possible (e.g. in some diagonal joins)

---

<div class="post-metadata">

**Author:** ![ParadaCarleton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paradacarleton/32/20005_2.png) [@ParadaCarleton](https://discourse.julialang.org/u/ParadaCarleton)\
**Post date:** [November 27, 2023, 7:05pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/70 "2023-11-27T19:05:03Z")

</div>

> [@adienes](#):
>
> in many cases where `missing` values arise, they do not represent actual “missing observations.” sometimes they are just placeholders in a table where no observation is possible (e.g. in some diagonal joins)

I think that falls under missing completely at random (if the populations for each table are identical). (And if they’re not, you’d need to be explicit about what you’re modeling/estimating.)

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [November 27, 2023, 7:05pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/71 "2023-11-27T19:05:41Z")

</div>

If removing the name `skipmissing` entirely was unpopular because it inherently removes the description, we _could_ alias it so what we write is shorter but it prints the same, like `const sm = skipmissing` or `import Base: skipmissing as sm`. Probably still not as short as one would like.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 27, 2023, 7:07pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/72 "2023-11-27T19:07:14Z")

</div>

I’m sure there is a use-case for MICE.jl, but I wouldn’t use it in analysis.

1. It’s far simpler to simply say “here are the results of the population for which I have data” and then assess reasons for missing data and plausible assumptions.
2. What is the limiting distribution of `sigma(x, N)` as `N` approaches infinity? We would like this to converge to a normal distribution and use standard statistical tests. If we impose `sigma(f(x), N)` where `f` is some multiple-imputation method, what is the limiting distribution then?

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [November 27, 2023, 7:29pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/73 "2023-11-27T19:29:36Z")

</div>

More of an FYI, in [Query.jl](https://github.com/queryverse/Query.jl) I’m using [DataValues.jl](https://github.com/queryverse/DataValues.jl) to represent missing values. The original reason was a technical one unrelated to the semantics of how missings propogate, but they also happen to have slightly different semantics. In particular, they (mostly) propagate missings, but not through predicates. So, one is way less likely to end up in 3VL world. At least for me that has worked pretty well.

A pattern I use _a lot_ and that I think works quite well in [Query.jl](https://github.com/queryverse/Query.jl) is to drop missing values early on in a query:

```julia
data |>
  @dropna(:colA, :colC) |>
  @filter(_.colB==3) |>
  ...

```

This will drop rows that have a missing in either `colA`, or `colC`. Because these queries are all functional and non-mutating, one can do this pretty easily on a per-query basis, and at least for me in practice the syntax is concise enough to not be too painful.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 27, 2023, 7:31pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/74 "2023-11-27T19:31:49Z")

</div>

This is a good idea, and emulates Stata’s `gen y if x == 1` syntax quite closely. DataFramesMeta.jl has explored providing a convenient syntax for it but I have not gotten around to a fully-formed PR.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [November 27, 2023, 7:38pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/75 "2023-11-27T19:38:23Z")

</div>

The idea behind `SkipMissingByDefault` is pure convenience for those who want to opt into that behavior. Under the hood it uses `skipmissing`. The package is meant to cover the superficial convenience case for programmer ergonomics. It is not meant as a deep engineering solution. Rather it is a consumer of such solutions. Overall, it provides a one line solution to chnage the default behavior at the end-user level.

> [@alfaromartino](#):
>
> Overall, I would have preferred `skipmissing` to be the default approach. Ultimately, it’s a matter of preference. However, if you’re like me, handling missing values feels like a drag after two hours of serious work, deviating your attention all the time from the actual analysis.

This is a superficial request that the original poster acknowledges is one of preference. Instead of answering a superficial request with a complex engineering solution, let’s meet it with a superficial solution. In no way, I am using “superficial” here in a disparaging connotation.

Moreover, my example points out that the Julia Language is flexible enough to accommodate this request for better or for worse. My example should also inspire a question whether such a package is necessary. The user can change the default behavior of `Main.mean`.

```julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.9.3 (2023-08-24)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> using Statistics

julia> mean(x) = Statistics.mean(skipmissing(x))
mean (generic function with 1 method)

julia> @which mean
Main

julia> mean([1.5 2.0 missing])
1.75

```

We can override a function name with our own function (as opposed to overloading a method) by making sure to state the new definition in the current module before using it.

If we use it before redefining it, we get an error.

```julia-repl
# julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.9.3 (2023-08-24)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> using Statistics

julia> mean([1.5 2.0 missing])
missing

julia> mean(x) = Statistics.mean(skipmissing(x))
ERROR: error in method definition: function Statistics.mean must be explicitly imported to be extended
Stacktrace:
 [1] top-level scope
   @ none:0
 [2] top-level scope
   @ REPL[3]:1

```

Note that we do not want to `import Statistics.mean` as the error suggests since this will change the behavior for all packages. Rather we just want to change the behavior of `mean` in the current module.

It would probably make sense to contain methods using this altered definition in a module to limit its scope.

```julia-repl
module MyProject
    module SkipMissingByDefault
        using Statistics: Statistics # only import Statistics and not mean
        mean(x) = Statistics.mean(skipmissing(x))
        mean_plus_one(x) = mean(x) + 1
    end
    using .SkipMissingByDefault: mean_plus_one
end

```

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [November 27, 2023, 8:10pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/76 "2023-11-27T20:10:35Z")

</div>

> [@adienes](#):
>
> in many cases where `missing` values arise, they do not represent actual “missing observations.” sometimes they are just placeholders in a table where no observation is possible (e.g. in some diagonal joins)

This is more evidence for the point that `missing` should be split into different types, not both `Missing`. Values with different interpretations and desired behavior probably shouldn’t have the same type.

---

<div class="post-metadata">

**Author:** ![mihalybaci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mihalybaci/32/13528_2.png) [@mihalybaci](https://discourse.julialang.org/u/mihalybaci)\
**Post date:** [November 27, 2023, 8:19pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/77 "2023-11-27T20:19:46Z")

</div>

FWIW from a non-regular user of `DataFrames`, I strongly prefer the full `skipmissing`. To me, seeing `mskip` in code would be no more clear than `sm`. I could guess that something is getting skipped, but since I don’t do a lot of data science I would not guess off-hand that it would skip missing values.

I wouldn’t make that grain of salt too big when thinking about the poll results.

And while I’m here, again as a casual user only, I want the default behavior to be the most correct statistically. If I have column of data with 100 values and 10 `missing`s, then I want all my calculations to take place on the valid 90 data points only and do not want the package/function to make assumptions about values. Using the cnonical example here. If I do `x < 100`, then I either want a missing back or an error. I definitely do not want a boolean back.

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [November 27, 2023, 8:21pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/78 "2023-11-27T20:21:15Z")

</div>

missing is hard to work with (Union{}…), so I believe a fair number of us (who do stats) still rely on NaN. Anyhow, dropping NaNs/missings is almost trivial in basic stats. It only becomes a challenge when you need to drop whole cases `(y_i,x_i)` because there’s a missing somewhere in `x_i`.

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [November 27, 2023, 8:51pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/79 "2023-11-27T20:51:40Z")

</div>

> [@mihalybaci](#):
>
> If I do `x < 100`, then I either want a missing back or an error. I definitely do not want a boolean back.

this does not preclude `mean` giving you a float back

like I suggested above, I think it would make a lot of sense for operators e.g. `<` to continue to propagate as they do currently

---

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [November 27, 2023, 9:07pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/80 "2023-11-27T21:07:00Z")

</div>

As someone that rarely deals with missing values I found this topic interesting. Out of curiousity I thought I would do some basis stats (by hand) on this thread and categorize them as wanting current behaviour, skipmissing by default, or Listen and Learn without expressing a strong preference.

Total number of contributors (before mine) 26  
Number wanting skipmissing by default 2  
Number wanting current behaviour 12  
Number listening and contributing 12

Number of contributors with \>= 10 posts 2  
Number of contributors with \>= 5 but \< 10 posts 2

Conclusion: The development team did a good job listening to what users want, but there is always room for improvement, with some very thoughtful suggestions on what that may look like.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 27, 2023, 9:17pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/81 "2023-11-27T21:17:37Z")

</div>

I think this actually highlights some of the biases that lead to the current difficult-to-use behavior. The average data analyst who is most annoyed by the verbosity of dealing with missing data probably is not on Discourse.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [November 27, 2023, 9:47pm UTC](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756/82 "2023-11-27T21:47:22Z")

</div>

Until now I was missing…

[Previous page](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756.md?page=3)

[Next page](https://discourse.julialang.org/t/why-are-missing-values-not-ignored-by-default/106756.md?page=5)
