# How to deal with numerical error in tiedrank

**URL:** <https://discourse.julialang.org/t/how-to-deal-with-numerical-error-in-tiedrank/110263>\
**Category:** General Usage\
**Tags:** question\
**Created:** [February 15, 2024, 4:13pm UTC](https://discourse.julialang.org/t/how-to-deal-with-numerical-error-in-tiedrank/110263 "2024-02-15T16:13:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [February 15, 2024, 4:13pm UTC](https://discourse.julialang.org/t/how-to-deal-with-numerical-error-in-tiedrank/110263/1 "2024-02-15T16:13:25Z")

</div>

Hi all,

I would like to account for numerical error in `tiedrank` from StatsBase. For example,

```julia
julia> tiedrank([1,1+eps(),3])
3-element Vector{Float64}:
 1.0
 2.0
 3.0

```

I would like the first two elements to be treated as equal. I saw that it has a keyword `ls`. I tried passing various functions to `ls` but nothing worked. Is there a way to account for the numerical error?

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [February 15, 2024, 4:22pm UTC](https://discourse.julialang.org/t/how-to-deal-with-numerical-error-in-tiedrank/110263/2 "2024-02-15T16:22:04Z")

</div>

Rounding sounds like a good idea:

```julia
julia> tiedrank(round.([1,1+eps(),3]; digits=1))
3-element Vector{Float64}:
 1.5
 1.5
 3.0

```

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [February 15, 2024, 4:34pm UTC](https://discourse.julialang.org/t/how-to-deal-with-numerical-error-in-tiedrank/110263/3 "2024-02-15T16:34:50Z")

</div>

Yeah. I think that is the best approach when the size of the vector is small. I think `round` will be OK for my use case, but I think I need to use 15 instead of 1 for digits. I don’t know if there is a solution which avoids copying which might be a problem with large vectors. I don’t need that at the moment, but I want to acknowledge the potential performance impact scale.
