Continuous Distributions compute the probability of a range of values from a given distribution.
Normal Distrbutions
Let's start with the Normal Distributions.
Syntax in R: base distribution: norm()
.
There's 4 prefixes: d
(exactly), p
(cumulative), q
(quartile aka "inverse"), r
(random sample).
The
Normal Distribution,
$$
N(\mu,\sigma),
$$
depends on the mean \(\mu\) and standard deviation \(\sigma\). It's
probability density function (pdf) is given by:
$$
f(x) = \frac{1}{\sqrt{2\pi \sigma}} \exp\left[ -\frac{(x-\mu)^2}{2\sigma^2}\right]
$$
In R, to get the exact value of $f(x)$, use dnorm
.
dnorm(x = #, mean = #, sd = #)
# computes the probability of exactly x successess
# x = exact value of x (any real number),
# mean = mean of normal distribution
# sd = standard deviation of normal distribution
We don't really need to know or use dnorm
unless we want to plot the curve.
To compute probabilities of intervals of a normal distribution, we use the
cumulative distribution. In math notation, if \(X \sim N(\mu,\sigma) \) then to compute
$$
P(X \le b) \qquad \text{(i.e. less than b--left tail)}
$$
we use:
pnorm(b, mean = #, sd = #)
# computes the cumulative probability P(X <= b)
# mean = mean of normal distribution
# sd = standard deviation of normal distribution
# lower value = -oo
# higher value = b
Often, we need other calculations using the normal curve. For example:
$$
P(a \le X \le b) \qquad \text{(i.e. between a and b)}
$$
or
$$
P(X \ge a) \qquad \text{(i.e. greater than a--right tail)}
$$
Thanfully, with a bit of basic geometry (drawing pictures helps!),
we can use the cumulative from above to accomplish the other two probabilities.
# P(a <= X <= b):
pnorm(b, mean = #, sd = #) - dnorm(a, mean = #, sd = #)
# computes the probability under a normal distribution between the values of a and b
# lower value = a
# higher value = b
# P(X >= a):
pnorm(a, mean = #, sd = #, lower.tail = FALSE)
# computes the probability under a normal distribution for the values greater than a
# lower value = a
# higher value = +oo
Examples:
Here are a few examples. Hit the 'Evaluate R Code' button to see the outputs.
Inverse Normal
Inverse:
qnorm(p = #, mean = #, sd = #, lower.tail = FALSE)
# inverse normal: finds z such that P(x <= z) = p (right-tail)
Here are a few examples. Hit the 'Evaluate R Code' button to see the outputs.
Examples:
Here are a few examples. Hit the 'Evaluate R Code' button to see the outputs.
Additional Continuous Distributions
In addition to the normal distribution, R has other distributions programmed.
In the code below, I'll reference a few of the distributions we use in our Intro Statistics course.