Probability Distributions
R provides every common probability distribution through one consistent system: a distribution name (norm, binom, pois…) prefixed by d, p, q, or r to ask for a density, a cumulative probability, a quantile, or random draws.
Learn Probability Distributions in our free R course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick reference.
Part of the free R course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
In this lesson you'll master the d/p/q/r prefix system with the normal distribution, branch out to runif / rbinom / rpois , lock down reproducibility with set.seed() , and draw from explicit sets with sample() .
What You'll Learn in This Lesson
1️⃣ The d / p / q / r System
Learn one distribution's four functions and you've learned them all. For the normal distribution, the suffix is norm , and the prefix selects the question. The three deterministic ones below give the same answer on every machine.
Add mean and sd to describe any normal. Here's a worked "heights" example that answers real probability questions exactly.
2️⃣ Beyond the Normal
The same four-letter pattern covers the binomial, Poisson, uniform, exponential, t, chi-squared, and more — just change the suffix and supply that distribution's parameters. These density/probability calls are exact, so their output is stable across machines.
Reading them: dbinom(3, 10, 0.5) is the probability of exactly 3 successes; ppois(2, 4) is the probability of at most 2 events. Use d for "exactly," p for "at most / less than."
3️⃣ Random Draws & set.seed()
The r* functions simulate data. Because they use R's pseudo-random generator, every run differs — until you fix the starting state with set.seed() . We omit the printed numbers here because exact draws depend on your R version, but the code is reproducible on a given machine.
sample() is different: it draws from a set you provide — perfect for dice, cards, shuffling, and bootstrapping. Set replace = TRUE to allow repeats.
Your turn. Fill in the # TODO blank and run it — the deterministic p / q answers are shown.
Compare simulation against exact theory — the heart of Monte Carlo thinking. Simulate thousands of games, measure the empirical win rate, and check it against the 8/36 truth.
📋 Quick Reference — Distributions
Practice quiz
In R's distribution naming, what does the p prefix compute?
- The density at a point
- A random draw
- The cumulative probability (area to the left)
- The quantile
Answer: The cumulative probability (area to the left). p gives P(X <= x), the cumulative probability up to a value.
What does the q prefix (as in qnorm) return?
- The value at a given percentile
- A probability
- A density height
- A random number
Answer: The value at a given percentile. q is the inverse of p: give it a probability, it returns the value.
What does dnorm() give you?
- A cumulative probability
- A random draw
- A percentile rank
- The density (curve height) at a point
Answer: The density (curve height) at a point. d gives density, not a probability; it can even exceed 1.
Which function draws random numbers from a normal distribution?
- pnorm()
- rnorm()
- qnorm()
- dnorm()
Answer: rnorm(). The r prefix generates random draws from the distribution.
What does set.seed(123) accomplish?
- Makes subsequent random draws reproducible
- Speeds up the r* functions
- Sets the mean to 123
- Draws 123 numbers
Answer: Makes subsequent random draws reproducible. Fixing the RNG seed reproduces the same draws on the same R version.
pnorm and qnorm are related how?
- They are unrelated
- They both return densities
- They are exact inverses of each other
- qnorm always doubles pnorm
Answer: They are exact inverses of each other. qnorm(pnorm(x)) == x; one maps value->prob, the other prob->value.
What does dbinom(3, size = 10, prob = 0.5) compute?
- P(at most 3 successes)
- P(exactly 3 successes in 10 trials)
- The mean number of successes
- A random number of successes
Answer: P(exactly 3 successes in 10 trials). d on a discrete distribution gives the probability of exactly that count.
What does ppois(2, lambda = 4) give?
- P(exactly 2 events)
- The mean 4
- A random Poisson count
- P(at most 2 events) when the mean rate is 4
Answer: P(at most 2 events) when the mean rate is 4. p is cumulative: probability of 2 or fewer events.
Why does sample(1:6, 10) without replace = TRUE error?
- 10 is too large a number
- You can't draw 10 distinct values from only 6
- 1:6 is not a vector
- sample needs a probability
Answer: You can't draw 10 distinct values from only 6. Without replacement you can draw at most 6; add replace = TRUE for repeats.
qnorm() expects its first argument to be...
- A raw data value like 95
- A count of trials
- A probability between 0 and 1
- A standard deviation
Answer: A probability between 0 and 1.