# How to intrepret the results from the 'cdf()\` and \`quantile()\` function?

**URL:** <https://discourse.julialang.org/t/how-to-intrepret-the-results-from-the-cdf-and-quantile-function/99354>\
**Category:** General Usage\
**Tags:** distributions, probability, cdf\
**Created:** [May 24, 2023, 9:44pm UTC](https://discourse.julialang.org/t/how-to-intrepret-the-results-from-the-cdf-and-quantile-function/99354 "2023-05-24T21:44:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hugo](https://avatars.discourse-cdn.com/v4/letter/h/b38774/32.png) [@Hugo](https://discourse.julialang.org/u/Hugo)\
**Post date:** [May 24, 2023, 9:44pm UTC](https://discourse.julialang.org/t/how-to-intrepret-the-results-from-the-cdf-and-quantile-function/99354/1 "2023-05-24T21:44:34Z")

</div>

Hey, folks  
I’d like some help understanding the `cdf` and `quantile` functions.

Let x \in \mathbb{R}^n be a data vector.

```julia
using Random
Random.seed!(12345)

x = rand(Uniform(100, 500), 10000)

```

Now, I want to calculate the cumulative distribution function of x, F\_X(x).

```julia
Fx = cdf.(Uniform(100, 500), x)

```

From my understanding given what I read in the [Distributions.jl webpage for function `cdf`](https://juliastats.org/Distributions.jl/stable/univariate/#Distributions.cdf-Tuple%7BUnivariateDistribution,%20Real%7D), to get the F\_X(x'), we provide x'. And that’s what I did. I provided the vector `x` and used the broadcasting `cdf` to get calculate the CDF for every element in `x`. Given I know what distribution the data came from, I knew what distribution to use in the call of `cdf()`.

Now, I want to apply the quantile function to the CDF. Basically, I had a data vector x to which I applied the F\_X(x) to obtain a vector `Fx` \in [0,1]. Then, I will leave the the [0,1] domain back to the “data” domain using the quantile function, \Phi^{-1}(X) \xrightarrow{}{} X. So I did

```julia
y = rand(Uniform(0,1), 100);
quantile(y, Fx)
%
% 10000-element Vector{Float64}:
% 0.8007446939133416
% 0.1224036949634858
% 0.33105528548750984
% 0.8317826664840936
% ⋮
% 0.10683772281267323
% 0.5217773901084406
% 0.7523328558208143

```

where `y` is the `itr` and `Fx` is the `p` vector of probabilities, as explained [here](https://docs.julialang.org/en/v1/stdlib/Statistics/#Statistics.quantile).

This answer was not what I expected. I gave a vector `y` of 100 elements to `quantile()`, and I expected to get a vector of the same length. Likewise, `Fx` was built on a Uniform distribution defined as \mathcal{f}: U[100, 500]. Therefore, I expected to see values from that range as my range.

If I have a U[100, 500], I expect the \Phi^{-1}(0.5) \ \tilde{=} \ \mathbb{E}(\mathcal{f}) = 300. What I got was a 10000-element vector being all elements equal to 0.5.

```julia
quantile(.5, Fx)
%10000-element Vector{Float64}:
% 0.5
% 0.5
% 0.5
% 0.5
% ⋮
% 0.5
% 0.5
% 0.5

```

This has been sufficient to show me I don’t fully understand how these functions work, even though I thought I understood it from the documents. Can anyone point out what my mistake/misconception is? Thank you for your help.

---

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [May 24, 2023, 11:12pm UTC](https://discourse.julialang.org/t/how-to-intrepret-the-results-from-the-cdf-and-quantile-function/99354/2 "2023-05-24T23:12:55Z")

</div>

I’m not sure what the documentation suggests should work, but there’s really just one principle:

1. Functions take two arguments: (a) distribution and (b) data.

Things therefore look like:

```julia
using Distributions
d = Uniform(2, 3)
n = 100
x = rand(d, n)
p = cdf.(d, x)
x′ = quantile.(d, p)

```

In your examples, you seem to be using multiple different values of `d` and swapping the distribution and data arguments order.
