Continuous random variables: densities, CDFs, expectation and the uniform, exponential and normal
Ten problems on continuous random variables: normalizing a density and integrating it for a probability, a CDF turned into a density, a median and a mean with an infinite variance, expectation and variance by integration, the uniform distribution and a density above 1, the exponential's CDF, mean, median and memorylessness, standardizing a normal with z-values and a percentile, the density of Y = X² through its CDF, inverse-CDF sampling and the minimum of independent exponentials, with worked solutions and the mistakes of reading a density as a probability, dropping the |dx/dy| in a change of variables, taking the exponential's mean as λ, dividing by σ² and taking the mean as the median.
Before you start
A continuous random variable takes values in an interval: a waiting time, a measurement, the output of a regression model. No single value has positive probability, so its distribution is described by a density ,f(x), and probabilities are areas under it. Everything from the discrete case carries over with sums replaced by integrals: E[X]=∫xf(x)dx instead of .∑xp(x). What does not carry over is reading f(x) as a probability. A density can be larger than ;1; only its integral over an interval is a probability. These ten problems normalize densities, move between the density and the cumulative distribution function, work through the uniform, exponential and normal distributions, and end with the two tools behind sampling: transforming a variable through its CDF, and the inverse CDF that turns a uniform random number into any distribution.
A densityf has f(x)≥0 and ,∫−∞∞f(x)dx=1, and .P(a<X<b)=∫abf(x)dx. In particular ,P(X=a)=0, so < and ≤ give the same probabilities.
The CDF is .F(x)=P(X≤x)=∫−∞xf(t)dt. It rises from 0 to ,1,,P(a<X≤b)=F(b)−F(a), and f=F′ wherever F is differentiable.
Expectation.E[X]=∫xf(x)dx and ;E[g(X)]=∫g(x)f(x)dx;.Var(X)=E[X2]−(E[X])2. The median m solves .F(m)=21.
Uniform:(a,b):f(x)=b−a1 on ,(a,b), mean ,2a+b, variance .12(b−a)2.
Exponential:(λ):f(x)=λe−λx for ,x≥0,,F(x)=1−e−λx,,P(X>x)=e−λx, mean ,λ1, variance .λ21.λ is a rate, events per unit time; λ1 is the average wait.
Normal:(μ,σ2):.f(x)=σ2π1e−(x−μ)2/(2σ2). Standardize with ,Z=σX−μ, which is Normal(0,1) with CDF .Φ. Useful values: ,Φ(1)=0.8413,,Φ(2)=0.9772,,Φ(1.2816)=0.9, and .Φ(−z)=1−Φ(z).
Change of variables. For ,Y=g(X), find FY(y)=P(g(X)≤y) as a probability about ,X, then differentiate. For an increasing g this gives fY(y)=fX(x)dydx with .x=g−1(y).
Problems
·
X has density f(x)=cx2 for 0≤x≤3 and 0 elsewhere. Find ,c, the CDF, and .P(1<X<2).
·
X has CDF F(x)=1−x21 for x≥1 and F(x)=0 for .x<1. Find its density, ,P(2<X<4), the median, E[X] and .E[X2].
··
X has density f(x)=2x on .[0,1]. Find ,E[X],,E[X2],,Var(X), the standard deviation and the median.
·
.X∼Uniform(2,8). Find its density, ,P(3<X<5),E[X] and .Var(X). Then for ,W∼Uniform(0,0.5), find the density and .P(0.3<W<0.31).
··
Requests arrive at a server at a rate of 0.5 per minute, so the wait X for the next one is Exponential.(0.5). Find the mean wait, ,P(X>4), the median wait and .P(X>6∣X>2).
··
Show by integration that an Exponential(λ) variable has E[X]=λ1 and .Var(X)=λ21.
··
Test scores are Normal with mean 100 and standard deviation .15. Find the fraction above ,130, the fraction between 85 and ,115, and the score at the 90th percentile.
··
X∼Uniform(0,1) and .Y=X2. Find the CDF and density of ,Y,P(Y<0.25) and E[Y] two ways.
···
.U∼Uniform(0,1). Show that Y=−λlnU is Exponential,(λ), and find the sample it gives for U=0.3 and .λ=2. Then find the transformation of U that samples the variable of Problem 2, and its value at .U=0.75.
···
Three independent replicas answer a request after Exponential times with rates ,1,2 and 3 per second, and the client takes the first answer. Find the distribution of the response time ,T, its mean, ,P(T>0.5), and the probability that the slowest replica (rate )1) answers first.
Answers
,c=91,F(x)=27x3 on ,[0,3],P(1<X<2)=277≈0.2593
,f(x)=x32,,P(2<X<4)=0.1875, median ,2≈1.414,,E[X]=2,E[X2]=∞
,E[X]=32,,E[X2]=21,,Var(X)=181≈0.0556, standard deviation ,≈0.2357, median 21≈0.7071
X has density f(x)=cx2 for 0≤x≤3 and 0 elsewhere. Find ,c, the CDF, and .P(1<X<2).
,∫03cx2dx=c⋅327=9c=1, so c=91The density must integrate to .1.
F(x)=∫0x9t2dt=27x3 for 0≤x≤3F=0 below 0 and F=1 above ;3;F(3)=1 is a check on .c.
P(1<X<2)=∫129x2dx=278−1From the density.
F(2)−F(1)=278−271=277The same number from the CDF, with no integral left to do.
,c=91,F(x)=27x3 on ,[0,3],P(1<X<2)=277≈0.2593The middle third of the range holds about a quarter of the probability, because the density grows like .x2.
Problem 2
X has CDF F(x)=1−x21 for x≥1 and F(x)=0 for .x<1. Find its density, ,P(2<X<4), the median, E[X] and .E[X2].
f(x)=F′(x)=x32 for x≥1Differentiate the CDF.
P(2<X<4)=F(4)−F(2)=(1−161)−(1−41)=163=0.1875Differences of the CDF.
,1−m21=21, so m2=2 and m=2≈1.4142The median solves .F(m)=21.
E[X]=∫1∞x⋅x32dx=∫1∞x22dx=2An improper integral that converges.
,f(x)=x32,,P(2<X<4)=0.1875, median ,2≈1.414,,E[X]=2,E[X2]=∞E[X2]=∫1∞x2dx diverges, so this heavy-tailed (Pareto) variable has a mean but no finite variance. The mean is pulled above the median by the long right tail.
Problem 3
X has density f(x)=2x on .[0,1]. Find ,E[X],,E[X2],,Var(X), the standard deviation and the median.
∫012xdx=1Check it is a density.
E[X]=∫01x⋅2xdx=32.∫012x2dx=32.
E[X2]=∫01x2⋅2xdx=42=21Square the value, keep the density as the weight.
Var(X)=21−94=181The same shortcut as in the discrete case.
,E[X]=32,,E[X2]=21,,Var(X)=181≈0.0556, standard deviation ,≈0.2357, median 21≈0.7071,F(x)=x2, so F(m)=21 gives .m=21. The density leans right, so the median is above the mean: the long tail is on the left.
Problem 4
.X∼Uniform(2,8). Find its density, ,P(3<X<5),E[X] and .Var(X). Then for ,W∼Uniform(0,0.5), find the density and .P(0.3<W<0.31).
f(x)=8−21=61 on (2,8)Constant height, area .1.
P(3<X<5)=65−3=31For a uniform, probability is length over total length.
E[X]=22+8=5 and Var(X)=12(8−2)2=3From E[X2]=∫286x2dx=18512−8=28 and .28−25=3.
fW(w)=0.51=2 on (0,0.5)A density of 2 is fine: the interval is only 0.5 long, so the area is still .1.
,f=61,,P(3<X<5)=31,,E[X]=5,;Var(X)=3;,fW=2,P(0.3<W<0.31)=0.02:2×0.01=0.02: the density times a short width approximates the probability of a short interval (Mistake 1).
Problem 5
Requests arrive at a server at a rate of 0.5 per minute, so the wait X for the next one is Exponential.(0.5). Find the mean wait, ,P(X>4), the median wait and .P(X>6∣X>2).
E[X]=0.51=2 minutesHalf an arrival per minute is one every two minutes on average.
P(X>4)=e−0.5⋅4=e−2≈0.1353The survival function .e−λx.
,1−e−0.5m=21, so m=0.5ln2=2ln2≈1.3863 minutesThe median solves .F(m)=21.
P(X>6∣X>2)=e−1e−3=e−2≈0.1353X>6 is contained in ,X>2, so the intersection is .X>6.
Mean 2 minutes, ,P(X>4)≈0.1353, median ≈1.386 minutes, P(X>6∣X>2)≈0.1353Memorylessness: after two minutes with nothing, the chance of waiting four more is the same as it was at the start. The continuous version of the geometric distribution.
Problem 6
Show by integration that an Exponential(λ) variable has E[X]=λ1 and .Var(X)=λ21.
E[X]=∫0∞xλe−λxdx=[−xe−λx]0∞+∫0∞e−λxdxParts with u=x and ,dv=λe−λxdx, so .v=−e−λx.
E[X]=0+λ1xe−λx→0 as ,x→∞, and .∫0∞e−λxdx=λ1.
E[X2]=∫0∞x2λe−λxdx=0+∫0∞2xe−λxdx=λ2E[X]=λ22Parts again with ;u=x2; the remaining integral is λ2 times the one in step 1.
Var(X)=λ22−λ21=λ21The shortcut.
E[X]=λ1 and Var(X)=λ21The standard deviation equals the mean. For λ=0.5 in Problem 5, both are 2 minutes.
Problem 7
Test scores are Normal with mean 100 and standard deviation .15. Find the fraction above ,130, the fraction between 85 and ,115, and the score at the 90th percentile.
z=15130−100=2Standardize: subtract the mean, divide by the standard deviation.
P(X>130)=1−Φ(2)=1−0.97725≈0.0228About .2.3%.
P(85<X<115)=Φ(1)−Φ(−1)=2Φ(1)−1≈0.6827;z=±1; by symmetry .Φ(−1)=1−Φ(1).
x=100+15×1.2816≈119.22Solve Φ(z)=0.9 for ,z=1.2816, then undo the standardization: .x=μ+σz.
,P(X>130)≈0.0228,,P(85<X<115)≈0.6827, 90th percentile ≈119.2Within one standard deviation of the mean lies about 68% of a normal distribution, and beyond two standard deviations on one side lies about .2.3%.
Problem 8
X∼Uniform(0,1) and .Y=X2. Find the CDF and density of ,Y,P(Y<0.25) and E[Y] two ways.
FY(y)=P(X2≤y)=P(X≤y)=y for 0≤y≤1,X≥0, so X2≤y exactly when .X≤y.
fY(y)=dydy=2y1 on (0,1)Equivalently .fX(y)dydx=1⋅2y1. It is unbounded near 0 and still integrates to .1.
P(Y<0.25)=FY(0.25)=0.5Y<0.25 exactly when .X<0.5.
E[Y]=∫01y⋅2y1dy=∫012ydy=31From the density of .Y.
,FY(y)=y,fY(y)=2y1 on ,(0,1),,P(Y<0.25)=0.5,E[Y]=31Check without :fY:.E[X2]=∫01x2dx=31. Squaring numbers in (0,1) crowds them toward ,0, which is where the density piles up.
Problem 9
.U∼Uniform(0,1). Show that Y=−λlnU is Exponential,(λ), and find the sample it gives for U=0.3 and .λ=2. Then find the transformation of U that samples the variable of Problem 2, and its value at .U=0.75.
P(Y>y)=P(−lnU>λy)=P(U<e−λy)Multiply by −1 and exponentiate; ex is increasing, so the inequality keeps its direction.
P(Y>y)=e−λy for y≥0For a uniform, .P(U<u)=u. That is the exponential survival function.
,U=0.3,:λ=2:y=−2ln0.3≈0.6020One uniform random number becomes one exponential sample.
In general X=F−1(U) has CDF :F:P(F−1(U)≤x)=P(U≤F(x))=F(x)Inverse-CDF sampling. For the exponential, ,F−1(u)=−λln(1−u), and 1−U is uniform too, which gives the formula above.
Y=−λlnU is Exponential,(λ), with y≈0.602 for ;U=0.3; for Problem 2, ,X=1−U1, which is 2 at U=0.75Solve u=1−x21 for .x. This is how libraries turn a uniform random number generator into samples from other distributions.
Problem 10
Three independent replicas answer a request after Exponential times with rates ,1,2 and 3 per second, and the client takes the first answer. Find the distribution of the response time ,T, its mean, ,P(T>0.5), and the probability that the slowest replica (rate )1) answers first.
P(T>t)=P(X1>t)P(X2>t)P(X3>t)=e−te−2te−3t=e−6tThe minimum is above t only if all three are; independence lets the probabilities multiply.
,T∼Exponential(6), so E[T]=61 secondThe rates add.
P(T>0.5)=e−3≈0.0498The survival function at .0.5.
P(X1=T)=∫0∞e−t⋅e−5tdt=61Replica 1 answers at t (density )e−t) and the other two are still busy (probability ).e−2te−3t).
,T∼Exponential(6),E[T]=61≈0.167 s, ,P(T>0.5)≈0.0498,P(replica 1 first)=61In general each replica wins with probability its rate over the total, ,λ1+λ2+λ3λi, so the others win with 62 and .63.
Where this goes wrong
1. The density read as a probability
In the discrete case ,p(x)=P(X=x), and the density looks like it should mean the same.
W∼Uniform(0,0.5) has density fW(w)=2Right so far: Problem 4.
“The density at 0.3 is the probability of .0.3.”The step that causes the mistake: a density is probability per unit length, not probability.
P(W=0.3)=fW(0.3)=2A probability can never be .2. For a continuous variable ;P(W=0.3)=0; the density only becomes a probability when multiplied by a width, so .P(0.3<W<0.31)≈2×0.01=0.02.
2. Change of variables without |dx/dy|
The density of Y=g(X) is found by substituting the inverse into the density of .X.
,X∼Uniform(0,1),,Y=X2, and x=yRight so far: Problem 8.
“.fY(y)=fX(y)=1.”The step that causes the mistake: it moves the height of the density but not the width of the intervals, which squaring shrinks near .0.
Y is Uniform,(0,1), so P(Y<0.25)=0.25But Y<0.25 is exactly ,X<0.5, which has probability .0.5. The factor dydx=2y1 is what keeps probabilities equal, and going through the CDF, ,FY(y)=y, never loses it.
3. The exponential's mean taken as λ
The rate is the parameter in the formula, and it is read as the average.
Requests arrive at λ=0.5 per minute, and the wait is Exponential(0.5)Right so far: Problem 5.
“The parameter of the distribution is its mean.”True of the Poisson count, not of the exponential wait.
E[X]=λ=0.5 minutesHalf an arrival per minute means a wait of 0.51=2 minutes on average: ,E[X]=λ1, as Problem 6 shows. A check by units: λ is per minute, and a wait has to come out in minutes.
4. Standardizing with the variance
The normal is written Normal,(μ,σ2), and the second parameter goes in the denominator.
Scores are Normal:(100,152):,μ=100,σ2=225Right so far: Problem 7.
“.z=σ2x−μ.”The step that causes the mistake: Z has to be unitless, and x−μ is in points while σ2 is in points squared.
,z=22530≈0.1333, so P(X>130)=1−Φ(0.1333)≈0.4470Nearly half the class above 130 would put 130 barely above average. Divide by the standard deviation: z=1530=2 and .P(X>130)≈0.0228.
5. The mean taken as the median
For a normal, half the probability is below the mean, and the same is assumed of every distribution.
The wait in Problem 5 has mean 2 minutesRight so far.
“Half the waits are shorter than the average wait.”True for a symmetric distribution; the exponential is skewed right.
P(X<2)=0.5:P(X<2)=1−e−1≈0.6321: the long right tail pulls the mean up, so most waits are shorter than average. The median is 2ln2≈1.386 minutes.
More at eulerpad.app. This is one of 102 free practice sets with worked solutions at eulerpad.app/practice, alongside guides to the topics behind them.
EulerPad, the app, reads your handwritten math on iPad, iPhone and Android and checks it line by line. It's free to start.
This set is also Chapter 5 of Probability & Statistics for Machine Learning, a 250-problem workbook with worked solutions: eulerpad.app/workbooks