Chapter 17: Probability Distributions
Shih Chien University
2026-07-20
Many statistical tests compute a test statistic, then compare it to a value from a theoretical distribution — exactly what Chapter 18 will do. R supplies, for every common distribution, functions to calculate densities, distribution functions (cumulative probabilities), quantiles, and random draws. This chapter walks through the normal distribution in detail, then catalogs the whole family.
\[f(x) = \frac{1}{\sigma\sqrt{2\pi}}\, e^{-\frac{(x-\mu)^2}{2\sigma^2}}\]
dnorm(x, mean=0, sd=1, log=FALSE) evaluates the density at x (log=TRUE returns its logarithm). Plotting it is one line:
pnorm(q, mean=0, sd=1, lower.tail=TRUE, log.p=FALSE) returns \(p = \Pr(x \le q)\) — the probability that a random value falls at or below q. lower.tail=FALSE flips to \(\Pr(x > q)\); log.p=TRUE returns \(\log(p)\):
[1] 0.5
[1] 0.1586553
[1] 0.9500042
qnorm(p, mean=0, sd=1, lower.tail=TRUE, log.p=FALSE) is pnorm’s inverse: it returns the q for which \(p = \Pr(x \le q)\):
rnorm(n, mean=0, sd=1) generates n random values — for testing functions, simulations, sampling methods:
Nearly every distribution follows one convention:
d — probability density function (for discrete distributions, technically the probability mass function);p — distribution function;q — quantile function;r — random number generator.And shared arguments by type: density functions take x, log; distribution functions take q, lower.tail, log.p; quantile functions take p, lower.tail, log.p; random generators take n (renamed nn for the hypergeometric, whose parameters claimed the letter). Knowing the system, you can usually guess the function you need.
| Family | R functions | Family arguments |
|---|---|---|
| Beta | dbeta pbeta qbeta rbeta |
shape1, shape2, ncp=0 |
| Cauchy | dcauchy pcauchy qcauchy rcauchy |
location, scale |
| Chi-squared | dchisq pchisq qchisq rchisq |
df, ncp=0 |
| Exponential | dexp pexp qexp rexp |
rate |
| F | df pf qf rf |
df1, df2, ncp |
| Gamma | dgamma pgamma qgamma rgamma |
shape, rate=1, scale=1/rate |
| Log-normal | dlnorm plnorm qlnorm rlnorm |
meanlog, sdlog |
| Logistic | dlogis plogis qlogis rlogis |
location, scale |
| Normal | dnorm pnorm qnorm rnorm |
mean, sd |
| Student’s t | dt pt qt rt |
df, ncp |
| Uniform | dunif punif qunif runif |
min, max |
| Weibull | dweibull pweibull qweibull rweibull |
shape, scale |
| Family | R functions | Family arguments |
|---|---|---|
| Binomial | dbinom pbinom qbinom rbinom |
size, prob |
| Birthday (coincidences) | pbirthday qbirthday |
classes, coincident |
| Geometric | dgeom pgeom qgeom rgeom |
prob |
| Hypergeometric | dhyper phyper qhyper rhyper |
m, n, k (random’s count is nn!) |
| Multinomial | dmultinom rmultinom |
size, prob |
| Negative binomial | dnbinom pnbinom qnbinom rnbinom |
size, prob, mu |
| Poisson | dpois ppois qpois rpois |
lambda |
| Studentized range | ptukey qtukey |
nmeans, df, nranges |
| Wilcoxon rank sum | dwilcox pwilcox qwilcox rwilcox |
m, n |
| Wilcoxon signed rank | dsignrank psignrank qsignrank rsignrank |
n |
[1] 0.1171875
[1] 0.2381033
[1] 23
Tip
The d-p-q-r grid is your map. Test statistics (Chapter 18) live in pt/pf/pchisq; confidence intervals in qt/qnorm; simulations in r*. Whenever a formula says “compare to the χ² distribution with k degrees of freedom,” the R translation is one pchisq call.
Copyright. These slides are adapted from R in a Nutshell: A Desktop Quick Reference (2nd ed.) by Joseph Adler, O’Reilly Media. All rights reserved by the original author and publisher.
Non-commercial use only. These materials are strictly for educational purposes and may not be used for commercial gain.
Attribution. Any reproduction, distribution, or use of these materials must properly credit the original source.
R in a Nutshell: A Desktop Quick Reference