The Uniform distribution is the simplest probability distribution, but it plays an important role in statistics since it is very useful in modeling random variables. The uniform distribution is a continuous probability distribution and is concerned with events that are equally likely to occur. The continuous random variable $X$ is said to be uniformly distributed, or having rectangular distribution on the interval $[a, b]$. We write $X \sim U(a, b)$, if its probability density function equals $f(x) = \frac{1}{b-a}, \; x \in [a,b]$ and $0$ elsewhere (Lovric 2011).
$$f(x) = \begin{cases} \frac{1}{b-a}, & \text{when $a \le x \le b$} \\[2ex] 0, & \text{when $x < a$ or $x > b$} \end{cases}$$The figure below shows a continuous uniform distribution $X \sim U(-2, 0.8)$, thus a distribution where all values of $x$ within the interval [-2,0.8] are $\frac{1}{0.8-(-2)} =\frac{1}{2.8} = 3.25$, whereas all other values of $x$ are 0.
x = np.arange(-5, 5, 0.01)
plt.figure(figsize=(10, 5))
plt.plot(x, stats.uniform.pdf(x, loc=a, scale=b - a), color="darkblue")
plt.title("$X \\sim U(-2, 0.8)$")
plt.ylabel("probability")
plt.show()
The mean and the median are given by $$ \mu = \frac{a+b}{2}\text{.}$$
The cumulative density function is shown below and given be the equation
$$F(x) = \begin{cases} 0, & \text{for $x < a$} \\[2ex] \frac{x-a}{b-a}, & \text{for $x \in [a,b)$} \\[2ex] 1, & \text{for $x \ge b$} \end{cases}$$plt.figure(figsize=(10, 5))
plt.plot(x, stats.uniform.cdf(x, loc=a, scale=b - a), color="darkblue")
plt.title("$X \\sim U(-2, 0.8)$")
plt.ylabel("cummulative probability")
plt.show()
Citation
The E-Learning project SOGA-Py was developed at the Department of Earth Sciences by Annette Rudolph, Joachim Krois and Kai Hartmann. You can reach us via mail by soga[at]zedat.fu-berlin.de.
Please cite as follow: Rudolph, A., Krois, J., Hartmann, K. (2023): Statistics and Geodata Analysis using Python (SOGA-Py). Department of Earth Sciences, Freie Universitaet Berlin.