4 Discrete Distributions
4.1 Uniform distributions
Consider the uniform distribution on \(\{0, \dots, n\}\) with
= 20 n
Its mass function (when defined on the integers) is given by
= function(k, n) (n+1)^{-1}*(0 <= k)*(k <= n) dunid
Here is a graph of this function
= -3:(n+3)
k plot(k, dunid(k, n), type = "h", lwd = 2, xlab = "", ylab = "")
Its distribution function (when defined on the reals) is given by
= function(x, n) pmin(1, pmax(0, floor(x+1))/(n+1)) punid
Here is a graph of this function
curve(punid(x, n), -3, n+3, 1e3, lwd = 2, xlab = "", ylab = "")
abline(h = c(0, 1), lty = 2)
4.2 Binomial distributions
Consider the binomial distribution with the following parameters
= 20
n = 0.2 p
Here is a plot of its mass function
= -3:(n+3)
k plot(k, dbinom(k, n, p), type = "h", lwd = 2, xlab = "", ylab = "")
Here is a plot of its (cumulative) distribution function
curve(pbinom(x, n, p), -3, n+3, 1e3, lwd = 2, xlab = "", ylab = "")
abline(h = c(0, 1), lty = 2)
4.3 Geometric distributions
Consider the geometric distribution with the following parameter
= 0.2 p
Here is a plot of its mass function
= -3:30
k plot(k, dgeom(k, p), type = "h", lwd = 2, xlab = "", ylab = "")
Here is a plot of its (cumulative) distribution function
curve(pgeom(x, p), -1, 30, 1e3, lwd = 2, xlab = "", ylab = "")
abline(h = c(0, 1), lty = 2)
4.4 Poisson distributions
Consider the Poisson distribution with the following parameter
= 5 lambda
Here is a plot of its mass function
= -3:30
k plot(k, dpois(k, lambda), type = "h", lwd = 2, xlab = "", ylab = "")
Here is a plot of its (cumulative) distribution function
curve(ppois(x, lambda), -1, 30, 1e3, lwd = 2, xlab = "", ylab = "")
abline(h = c(0, 1), lty = 2)
Let’s check the validity of the Law of Small Numbers. We work with the following parameters
= 100
n = 2/n
p = n*p
lambda = 0:10 # focusing on the interesting area k
We first compare the mass functions (the horizontal offset is for plotting purposes only)
plot(c(k, k+0.1), c(dbinom(k, n, p), dpois(k, lambda)), type = "h", lwd = 2, xlab = "", ylab = "", col = c(rep("darkgreen", length(k)), rep("darkblue", length(k))))
legend("topright", c("binomial", "Poisson"), lty = 1, lwd = 2, col = c("darkgreen", "darkblue"))
Better yet, we plot the difference in absolute value (notice the range on the vertical axis)
plot(k, dbinom(k, n, p) - dpois(k, lambda), type = "h", lwd = 2, xlab = "", ylab = "")
abline(h = 0, lty = 2)
We now compare the (cumulative) distribution functions
curve(pbinom(x, n, p), -1, 10, 1e3, lwd = 2, xlab = "", ylab = "", col = "darkgreen")
curve(ppois(x, lambda), -1, 10, 1e3, lwd = 2, add = TRUE, col = "darkblue")
abline(h = c(0, 1), lty = 2)
legend("bottomright", c("binomial", "Poisson"), lty = 1, lwd = 2, col = c("darkgreen", "darkblue"))
As these curves are almost indistinguishable (second confirmation that the approximation is very good), we plot the difference
curve(pbinom(x, n, p) - ppois(x, lambda), -1, 10, 1e3, lwd = 2, xlab = "", ylab = "")
abline(h = 0, lty = 2)