from edumath.probability import bernoulli_pmf, binomial_mean, binomial_pmf, binomial_variance
bernoulli_pmf(1, 0.7), binomial_pmf(trials=5, successes=2, probability=0.25)(0.7, 0.263671875)
A distribution describes how probability is spread across possible values of a random variable. Some patterns appear so often that they have names. Learning these names helps you recognize the right model before doing calculations.
After this lesson you should be able to:
edumath, Python, and SymPy to evaluate distribution formulas.A probability distribution tells us which values a random variable can take and how likely those values are.
For a discrete random variable, this may be a table:
x |
0 | 1 |
|---|---|---|
P(X=x) |
0.3 | 0.7 |
For a continuous random variable, a distribution is usually described by a curve or density. Areas under the curve represent probabilities.
A Bernoulli random variable models one trial with two outcomes:
1 = success
0 = failure
If success has probability p, then:
P(X=1) = p
P(X=0) = 1-p
Examples:
A binomial random variable counts the number of successes in a fixed number of independent Bernoulli trials.
A binomial model needs:
n;p is the same each time;The probability of exactly k successes is:
P(X=k) = C(n,k) p^k (1-p)^(n-k)
A uniform distribution gives equal probability to all allowed outcomes.
A fair die is discrete uniform:
P(1)=P(2)=...=P(6)=1/6
A continuous uniform distribution on an interval, such as from 0 to 1, spreads probability evenly across the whole interval.
A normal distribution is the bell-shaped distribution often used for measurement errors, natural variation, and averages of many small independent effects.
It is described by:
Not every bell-looking data set is exactly normal, and not every measurement should be modeled as normal. Always connect the distribution to the story and check assumptions when possible.
Two other common patterns are useful to recognize:
This lesson focuses on Bernoulli, binomial, uniform, and normal, but you will meet geometric and Poisson distributions in many statistics courses.
Ask these questions:
A machine part either passes inspection or fails inspection. Let X=1 if it passes and X=0 if it fails. If the pass probability is 0.92, then:
P(X=1) = 0.92
P(X=0) = 0.08
This is Bernoulli because there is one yes/no trial.
A quiz has 5 multiple-choice questions. Suppose a student guesses randomly and has probability 0.25 of answering each question correctly. What is the probability of exactly 2 correct answers?
n=5.p=0.25.k=2 successes.P(X=2) = C(5,2)(0.25)^2(0.75)^3
= 10(0.0625)(0.421875)
= 0.263671875
Choose a distribution for each story:
P(X=3) for X ~ Binomial(n=4, p=0.5).C(4,3)(0.5)^3(0.5)^1 = 4/16 = 1/4.Distribution problems become easier when you match the story before touching a formula.
Guess first. Is “one coin flip” Bernoulli or binomial?
Guided exercise.
One coin flip has one success/failure trial, so it is Bernoulli. Ten coin flips and the number of heads would be binomial.
Checkpoint. Classify each as Bernoulli or binomial: one free throw made or missed; number of made free throws in 8 attempts.
Guess first. In C(n,k)p^k(1-p)^(n-k), does k count successes or failures?
Guided exercise.
For n=3, k=2, and p=0.5:
P(X=2) = C(3,2)(0.5)^2(0.5)^1
= 3(0.25)(0.5)
= 0.375
Checkpoint. Compute P(X=1) for X ~ Binomial(n=3, p=0.25).
Guess first. Is a loaded die uniform?
Guided exercise.
A fair die is uniform because each face has probability 1/6. A loaded die is not uniform because some faces have different probabilities.
Checkpoint. Give one example of a discrete uniform random variable and one example that is not uniform.
Guess first. If two normal distributions have the same mean but one has a larger standard deviation, which is more spread out?
Guided exercise.
The standard deviation controls spread. A larger standard deviation means values are more spread out from the mean.
Checkpoint. What does the mean control in a normal distribution? What does the standard deviation control?
Guess first. Which distribution fits “number of defective items in a sample of 20 independent items”?
Guided exercise.
This counts successes in a fixed number of independent yes/no trials. If the defect probability is the same for each item, a binomial distribution is reasonable.
Checkpoint. Choose a distribution: waiting time until a bus arrives; whether one message is spam; result of a fair spinner with 5 equal sections.
C(3,1)(0.25)^1(0.75)^2 = 3(0.25)(0.5625) = 0.421875.Use this checkpoint to match stories with common distributions.
Use edumath for Bernoulli and binomial calculations.
(0.7, 0.263671875)
Compute binomial mean and variance.
Use SymPy for exact binomial expressions.