Quantile in Julia
In Statistics field, when we do the hypothesis testing, we have to get the quantile of a specific distribution so we go to find its value in the table. This method is out of dated, we should embrace the modern technology and exploit it.
Julia is a powerful programming language designed for technical computing. As it own saying that Julia: A fresh approach to technical computing
.
Today, we are going to teach you how to get the quantile of a specific distribution in short time with only line of code.
Preparation
- You should have Julia installed on your device.
- Install the package
Distribution
using Pkg Pkg.add("Distribution")
- Import the package
Distribution
using Distribution
Common Distribution
First of all, we should get the Distribution
object.
For example, if we need to use Standard Normal Distribution
,
N = Normal(0,1)
then you get it.
Common Distribution you may use.
# N(μ,σ): the Normal distribution
Normal(μ,σ)
# χ²(n): the ChiSquare distribution
Chisq(n)
# t(n): the T distribution
TDist(n)
Calculate Quantile
Now, we discuss how to get the Quantile
in Julia.
It is so easy as you only need to call function quantile
to approach your goal.
quantile(d::UnivariateDistribution, q::Real)
Above, it is the basic grammar of the function quantile
.
Maybe it seem abstract to you, so let see some simple example to help you understand it.
- $u_{0.975}$: The $0.975$ quantile of Standard Normal Distribution $N(0,1)$
U=Normal() quantile(U,0.975) # return 1.9599639845400576
- $t_{0.95}(15)$ :The $0.95$ quantile of $t(15)$: T Distribution with $15$ freedom
T₍₁₅₎=TDist(15) quantile(T₍₁₅₎,0.95) # return 1.7530503556925727
- $\chi_{0.025}^2(24)$: The $0.025$ quantile of $\chi^2(24)$ :
ChiSquare
Distribution with $24$ freedomχ²₍₂₄₎=Chisq(24) quantile(χ²₍₂₄₎,0.025) # return 12.401150217444433