Statistics 2Week 4 · Continuous Random Variables, Density Functions and Expectations
Week 4 Notes
Statistics for Data Science 1
Continuous random variables: discrete versus continuous, the CDF and its jumps, density functions, probability and percentiles from a PDF, conditional probability, the uniform and exponential distributions, and expectations, with every worked question solved.
A discrete variable takes countable values and has a PMF.
Continuous
When a quantity takes many distinct values, we model it as continuous and ask about intervals.
Figure 1. The shape of the CDF tells the type: steps are discrete, a smooth curve is continuous, a jump plus a smooth part is mixed
1.1CDF and interval probability
Definition: CDFThe cumulative distribution function (CDF) adds up all the probability up to x:
FX(x)=P(X≤x)
Between two values
P(a<X≤b)=F(b)−F(a)
Above a value
P(X>a)=1−F(a)
The CDF never decreases, starts from 0 and ends at 1.
1.2Worked questions
Question 1: daily rainfall
The CDF of the daily rainfall X (in mm) is F(x)=1−e−0.5x for x≥0. Find the probability that the rainfall exceeds 10 mm.
P(X>10)=1−F(10)=1−(1−e−0.5(10))=e−5≈0.0067
Question 2: a piecewise CDF with an unknown k
The CDF of a random variable X is below. If P(X≤4)=43, find P(1≤X≤5).
F(x)=⎩⎨⎧04kx2k+8x−21x<00≤x<22≤x<6x≥6
Pick the right piece.x=4 lies in 2≤x<6, so F(4)=k+84−2=k+41.
Use the given value.k+41=43, so k=43−41=21.
Interval probability.P(1≤X≤5)=F(5)−F(1). Here F(5)=k+85−2=21+83=87 and F(1)=4k=81.
So P(1≤X≤5)=87−81=86=43.
Figure 2. The CDF of Question 2 with k = 1/2: it never decreases, starts at 0 and ends at 1. P(1 ≤ X ≤ 5) is the rise from F(1) = 1/8 to F(5) = 7/8
The fill-in-the-blanks versionThe original question asks for the blanks A to F with option numbers: A = k+41, B = 21, C = X≤5, D = 87, E = 81, F = 43. That is exactly the working above.
1.3Going deeper
Check the pieces join up. At x=2: 4kx2=k and k+82−2=k. At x=6: k+84=1 also gives k=21. Two different conditions give the same k.
Which piece? Always find which interval x falls in before substituting.
Less than and at most.P(X>a)=1−F(a) because the whole probability is 1 and F(a) is the part up to a.
Exam tips
Write which piece of the CDF you use before substituting.
For a continuous random variable P(X=x) is 0, so we use a density functionf(x). Probability is the area under f over an interval, and a high density means X takes values around there more often.
CDF: accumulated density
FX(x0)=∫−∞x0fX(x)dx
PDF: slope of the CDF
fX(x)=FX′(x)
The PDF is easier for probability calculations and shows the shape of the distribution.
4.1A valid PDF and finding k
Never negative
f(x)≥0
Total area 1
∫−∞∞f(x)dx=1
The density must never be negative and must enclose total area 1. Using this we find k.
Figure 5. The density f(x) = x/2 on [0, 2]. Probability is area: the shaded area up to √3 is 0.75, and the whole area under the curve is 1
Worked question: find k
A random variable has PDF fX(x)=ke−x for x≥0 and 0 otherwise. Find k.
∫0∞ke−xdx=1⇒k[−1e−x]0∞=1⇒k[0−(−11)]=1⇒k⋅1=1
Answer
k=1
The upper limit gives e−∞=0, and the lower limit gives −1e0=−1, so the bracket is 0−(−1)=1.
4.2Going deeper
The PDF can be bigger than 1. It is a density, not a probability; only areas are probabilities. A PDF equal to 5 on a very narrow interval is fine (extra remark).
CDF and PDF are two views of one thing. The CDF accumulates the PDF; the PDF is the slope of the CDF. For F(x)=1−e−0.5x the PDF is f(x)=0.5e−0.5x.
Always integrate over where the PDF is non-zero. Here that is x≥0; outside it f=0.
Exam tips
To find a constant: set the total area to 1 and solve.
Check that the final PDF is non-negative.
Common mistakes
Integrating from −∞ when the PDF is 0 there (it adds nothing, but write the right limits).
Definition: probability from a PDFProbability from a PDF is the area under it between the two limits:
∫abf(x)dx=P(a≤X≤b)=F(b)−F(a)
5.1Worked question: how much petrol to stock
At a petrol station the daily petrol demand X (in thousands of litres) has PDF fX(x)=k(1−x)4 for 0≤x≤1, and 0 otherwise. What should be the minimum supply s (in thousands of litres) so that the probability of the petrol running out on any given day is only 1%? (a) 0.4321 (b) 0.3981 (c) 0.6019 (d) 0.9903
Find k.∫01k(1−x)4dx=k[5−(1−x)5]01=5k=1, so k=5 and f(x)=5(1−x)4.
Running out means demand above supply. We need P(X>s)=0.01, that is ∫s15(1−x)4dx=0.01.
Integrate.5[−5(1−x)5]s1=(1−s)5, so (1−s)5=0.01.
Solve.1−s=(0.01)1/5≈0.3981, so s=1−(0.01)1/5≈0.6019.
Answer
The minimum supply is about 0.6019 thousand litres: option (c).
Figure 6. The petrol demand density 5(1 − x)⁴. The tiny shaded tail beyond s = 0.6019 has area 0.01: that is the chance of running out
5.2Percentiles
Definition: percentileThe value k with P(X≤k)=p is the 100p-th percentile.
P(X≤k)=p
Worked question: the 75th percentile
A random variable has PDF fX(x)=kx for 0≤x<2, and 0 otherwise. Find the 75th percentile of X. (Hint: the value k such that P(X≤k)=0.75.) Note that the letter k is used twice: first as the constant in the PDF, then as the percentile.
Find the constant.∫02kxdx=2k=1, so the constant is 21 and f(x)=2x.
Set up the percentile.P(X≤k)=∫0k2xdx=[4x2]0k=4k2=0.75.
Solve.k2=3, so k=3≈1.732 (the positive root, since 0≤X<2).
Answer
The 75th percentile is 3≈1.732; the shaded area in Figure 5 is exactly 0.75.
5.3Going deeper
Tail probabilities are what safety margins ask for. “Running out only 1% of days” means choosing s so the upper tail has area 0.01, i.e. s is the 99th percentile of the demand.
The median is the 50th percentile. For f(x)=2x it solves 4k2=0.5, so k=2 (extra remark).
Check the numbers.(0.3981)5≈0.0100, and 4(3)2=0.75.
Exam tips
For a percentile, integrate the PDF from its left end up to k and set it equal to p.
The handwritten notes stop at the set-upThe notes write the two integrals and stop. The final numbers 0.0609 and 0.4626 are worked out here from ∫5x4dx=x5.
A package delivery time T (in hours) is uniformly distributed over the interval [a,b]. The probability that the delivery takes less than 5 hours is equal to the probability that it takes more than 11 hours. If the value of b is 14, find P(5<T<11∣T>7).
Find a.P(T<5)=b−a5−a and P(T>11)=b−ab−11. Equal, so 5−a=b−11, hence a+b=16 and, with b=14, a=2.
Conditional probability.P(5<T<11∣T>7)=P(T>7)P(7<T<11), because inside T>7 the event 5<T<11 means 7<T<11.
Lengths. The numerator has length 11−7=4 and the denominator 14−7=7 (the common width b−a=12 cancels).
Answer
74
Figure 7. T is uniform on [2, 14] with density 1/12. The shaded area P(7 < T < 11) = 4/12, and P(T > 7) = 7/12, so the ratio is 4/7
Question 4: finding a (Statistics 2 Quiz 1, 23 Feb 2025)
The PDF of a random variable X is fX(x)=ae−3x for x≥0, and 0 otherwise. Find the value of a.
∫0∞ae−3xdx=a[−3e−3x]0∞=a(0−−31)=3a=1⇒a=3
6.3Going deeper
Conditioning shrinks the sample space. Given T>7, only [7,14] is left, of length 7; the uniform density on it is 71, and the answer 74 is the length 4 over 7.
The exponent rule.∫0∞ce−λxdx=λc; setting it to 1 gives c=λ, which is why the exponential density is λe−λx. In Question 4, λ=3 so a=3.
Uniform probabilities are length ratios.P(c<T<d)=b−ad−c for a≤c<d≤b (extra remark).
Exam tips
For a conditional probability, first rewrite the numerator as one interval.
Common mistakes
Dividing by b−a again after the condition (the new width is b−7).
A discrepancy in the handwritten notesIn the handwritten page the last step reads 722×0.4, and a scribbled “1.5” and “0.45” sit next to the variance. The working on the same page gives E[X]=34 and E[X2]=2, which lead to Var(X)=92, not 0.4. These notes use 92, so Var(Y)=1152.
7.2Uniform [a, b]
Mean
E[X]=2a+b
Variance
Var(X)=12(b−a)2
Question 7: the value of a + b (Statistics 2 Quiz 1, 13 Jul 2025)
A package delivery time T (in hours) is uniformly distributed over [a,b]. The probability that the delivery takes less than 5 hours is equal to the probability that it takes more than 11 hours. Find a+b.
P(T<5)=b−a5−a,P(T>11)=b−ab−11⇒5−a=b−11⇒a+b=16
Why this works
The two cut-off points 5 and 11 are the same distance from the two ends of [a,b], so the interval is symmetric about their midpoint: 2a+b=25+11=8, i.e. a+b=16.
During an IPL cricket match, the amount of time (in minutes) Jadeja bats follows the exponential distribution with an expected time of 50 minutes. What is the probability that Jadeja will bat for more than 40 minutes?
Find λ.E[X]=λ1=50, so λ=501 and f(x)=501e−x/50.
Question 9: the service center (Statistics 2 Quiz 1, 13 Jul 2025)
The time (in minutes) a customer spends inside a service center follows an exponential distribution with an average of 10 minutes. What is the probability that a customer has to wait at least 12 more minutes in the center, given that he has already spent 10 minutes in the center?
Set up. The notes write P(X>12∣X>10), reading “12 more” loosely as the interval from the start; the question asks for 12 more minutes after 10, which is P(X>22∣X>10).
Rate.λ=101, so P(X>t)=e−t/10.
Conditional probability.P(X>22∣X>10)=P(X>10)P(X>22)=e−1e−2.2=e−1.2≈0.301. For comparison the notes' set-up P(X>12∣X>10)=e−0.2≈0.819.
The handwritten notes stop at the set-upThe page writes P(x>12∣x>10) and leaves the working blank, so both the set-up and the final numbers here are worked out from the formulas. The exponential distribution is memoryless (an extra remark): P(X>s+t∣X>s)=P(X>t), so already waiting 10 minutes changes nothing: the chance of 12 more minutes is P(X>12)=e−1.2≈0.301. If the question meant 12 minutes in total, the answer would be e−0.2≈0.819.
7.4Normal (μ, σ²)
Mean
E[X]=μ
Variance
Var(X)=σ2
The notes end here with the mean and variance of the normal distribution, written in terms of its two parameters.
7.5Going deeper
Same formulas as discrete, with integrals. The sum ∑xP(X=x) of Week 3 becomes ∫xf(x)dx.
Linear change of variance.Var(aX+b)=a2Var(X): the shift b does nothing, the scale a is squared (as in Statistics 1, Week 3).
Check against the formulas. For f(x)=2x on [0,2] the mean 34 lies to the right of the middle 1, as the density is larger on the right.
Uniform check. For U[2,14]: mean 22+14=8 (the midpoint) and variance 12122=12.
Exam tips
Compute E[X] and E[X2] separately, then subtract.
For exponential problems, find λ from the mean first.