Overview
Type | Distribution | R Suffix | Comments |
---|---|---|---|
Continuous | Normal | -norm() | |
Lognormal | -lnorm() | Normally distributed in a log scale | |
Uniform | -unif() | ||
Discrete | Binomial | -binom() | |
Multinomial | -multinom() | Similar to binomial but when there are more than 2 outcomes | |
Poisson | -pois() |
Prefix:
- PDF or PMF (
d-
) e.g.dnorm(x)
- CDF
( p-
) e.g.pnorm(x)
- the quantile function (
q-
) - The random deviate function (
-r
)
Normal Distribution
dnorm(x, mean = 0, sd = 1)
: PDFpnorm(x, mean = 0, sd = 1, lower.tail = TRUE)
CDFqnorm(x, mean = 0, sd = 1, lower.tail = TRUE)
: quantile functionrnorm(x, mean = 0, sd = 1)
: generates random deviates
Explanation
pnorm
is the CDF, which is the area under the normal curve below certain threshold. If we set lower.tail = FALSE
, we are essentially compute the area above q
(a.k.a. 1 - pnorm(x, mean, sd)
)
qnorm(p, mean = 0, sd = 1, lower.tail = TRUE)
calculates the value such that the area of the curve below this value is equal to p
.
For example, given a random variable pnorm
finds qnorm
finds
Binomial Distribution
See: Binomial
x
: number of eventsn
: number of trailsp
orprob
: probability of success
The R function family provided by the binomial distribution shares the similar postfixes as the normal distribution.
dbinom(x, n, p)
: PMFpbinom(x, n, p, lower.tail = TRUE)
: CDFqninom(x, n, p, lower.tail = TRUE)
: quantile functionrbinom(x, n, p)
: generates random deviates
Examples
Compute
sum(dbinom(46:54, 100, 0.5))
Alternatively
pbinom(54, 100, 0.5) - pbinom(45, 100, 0.5)