# \`NaN\` in Statistical Hypothesis Testing

**URL:** <https://discourse.julialang.org/t/nan-in-statistical-hypothesis-testing/104380>\
**Category:** New to Julia\
**Created:** [September 29, 2023, 8:44am UTC](https://discourse.julialang.org/t/nan-in-statistical-hypothesis-testing/104380 "2023-09-29T08:44:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sahil\_Khan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sahil_khan/32/47573_2.png) [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Post date:** [September 29, 2023, 8:44am UTC](https://discourse.julialang.org/t/nan-in-statistical-hypothesis-testing/104380/1 "2023-09-29T08:44:51Z")

</div>

How can we ignore missing values or NaN during testing?

```julia
A = [0.1, NaN, 0.16]
B = [1.0, 0.9, 0.82]

EqualVarianceTTest(A, B)

```

output:

```julia
Two sample t-test (equal variance)
----------------------------------
Population details:
    parameter of interest: Mean difference
    value under h_0: 0
    point estimate: NaN
    95% confidence interval: (NaN, NaN)

Test summary:
    outcome with 95% confidence: reject h_0
    two-sided p-value: NaN

Details:
    number of observations: [3,3]
    t-statistic: NaN
    degrees of freedom: 4
    empirical standard error: NaN

```

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [September 29, 2023, 11:55am UTC](https://discourse.julialang.org/t/nan-in-statistical-hypothesis-testing/104380/2 "2023-09-29T11:55:08Z")

</div>

(I don’t know the answer to your question, but I adjusted the title a bit to make it clear to others that this is a question about statistical testing, not unit testing!)

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [September 29, 2023, 1:15pm UTC](https://discourse.julialang.org/t/nan-in-statistical-hypothesis-testing/104380/3 "2023-09-29T13:15:20Z")

</div>

Easy to ignore whatever values you don’t want to use: `EqualVarianceTTest(filter(!isnan, A), B)`.

If your observations in `A` and `B` are paired and you want to ignore corresponding elements from both (not only remove `A[2]` that is `NaN` but also remove `B[2]`), then it’s most convenient to put these arrays into a single columnar table. In Julia, it’s effectively free, and you retain the same familiar array interface:

```julia
using StructArrays
# best to keep both A and B together from the beginning, if they are paired
data = StructArray(; A, B)

data = filter(x -> !any(isnan, x), data)
EqualVarianceTest(data.A, data.B)

```
