Login
📚 Python for Introductory Statistics
Chapters ▾

9.1 Uniform Distribution

The uniform probability distribution with minimum min and maximum max is given by:

f(x)=1maxmin for min<x<max

The syntax for cumulative probability, P(X<x), inverse, mean and standard deviation:

from scipy import stats
stats.uniform.cdf(x,min,max-min)  # cumulative prob P(X<x)
stats.uniform.ppf(p,min,max-min)  # inverse of cdf or percentiles
stats.uniform.mean(min,max-min)   # mean of X
stats.uniform.std(min,max-min)    # std of X

Example: The amount of time, in minutes, that a person waits for a bus, in a bus station, is uniformly distributed between zero and 15 minutes, inclusive.

P ( X < 12.5 ) = stats.uniform.cdf ( 12.5 , 0 , 15 )

from scipy import stats
stats.uniform.cdf(12.5,0,15)
Show expected output
0.8333333333333334

Interpretation: The probability of waiting less than 12.5 minutes is 0.8333333333333334

Example: The amount of time, in minutes, that a person waits for a bus, in a bus station, is uniformly distributed between zero and 15 minutes, inclusive.

stats.uniform.mean(0,15)   # mean
Show expected output
7.5

Interpretation: The mean waiting time is 7.5

stats.uniform.std(0,15)  # std
Show expected output
4.330127018922194

Interpretation: The mean waiting time is 7.5 with a standard deviation of 4.33.

Example: The amount of time, in minutes, that a person waits for a bus is uniformly distributed between zero and 15 minutes, inclusive.

90 t h  percentile = stats.uniform.ppf ( .9 , 0 , 15 )

stats.uniform.ppf(.9,0,15)    
Show expected output
13.5

Interpretation: Ninety percent of the waiting time is less than or equal to 13.5

Adapted from Python for Introductory Statistics, by Simon Aman (Truman College, City Colleges of Chicago), licensed under CC BY 4.0. Changes were made: reformatted as an accessible XYZ web edition with live in-browser code cells. License: CC-BY-4.0.