11 Continuous Random Variables
11.1 Objectives
Define and properly use in context all new terminology, to include: probability density function (pdf) and cumulative distribution function (cdf) for continuous random variables.
Given a continuous random variable, find probabilities using the pdf and/or the cdf.
Find the mean and variance of a continuous random variable.
11.2 Homework
11.2.1 Problem 1
Let X be a continuous random variable on the domain −k≤X≤k. Also, let f(x)=x218.
- Assume that f(x) is a valid pdf. Find the value of k.
Because f is a valid pdf, we know that ∫k−kx218dx=1. So, ∫k−kx218dx=x354|k−k=k354−−k354=k327=1
Thus, k=3.
Using R
, see if you can follow the code.
my_pdf <- function(x)integrate(function(y)y^2/18,-x,x)$value
my_pdf<-Vectorize(my_pdf)
domain <- seq(.01,5,.1)
gf_line(my_pdf(domain)~domain) %>%
gf_theme(theme_classic()) %>%
gf_labs(title="Cumulative probability for different values of k",x="k",y="Cummulative Probability") %>%
gf_hline(yintercept = 1,color = "blue")

Looks like k≈3 from the plot.
## [1] 2.999997
- Plot the pdf of X.
x<-seq(-3,3,0.001)
fx<-x^2/18
gf_line(fx~x,ylab="f(x)",title="pdf of X") %>%
gf_theme(theme_classic())

ggplot(data.frame(x=c(-3, 3)), aes(x)) +
stat_function(fun=function(x) x^2/18) +
theme_classic() +
labs(y="f(x)",title="pdf of X")

curve(x^2/18,from=-3,to=3,ylab="f(x)",main="pdf of X")

- Find and plot the cdf of X. FX(x)=P(X≤x)=∫x−3t218dt=t354|x−3=x354+12
FX(x)={0,x<−3x354+12,−3≤x≤31,x>3
x<-seq(-3.5,3.5,0.001)
fx<-pmin(1,(1*(x>=-3)*(x^3/54+1/2)))
gf_line(fx~x,ylab="F(x)",title="cdf of X") %>%
gf_theme(theme_classic())

- Find P(X<1). P(X<1)=F(1)=154+12=0.519
integrate(function(x)x^2/18,-3,1)
## 0.5185185 with absolute error < 5.8e-15
- Find P(1.5<X≤2.5). P(1.5<X≤2.5)=F(2.5)−F(1.5)=2.5354+12−1.5354−12=0.227
integrate(function(x)x^2/18,1.5,2.5)
## 0.2268519 with absolute error < 2.5e-15
- Find the 80th percentile of X (the value x for which 80% of the distribution is to the left of that value).
Need x such that F(x)=0.8. Solving x354+12=0.8 for x yields x=2.530.
## $root
## [1] 2.530293
##
## $f.root
## [1] -1.854422e-06
##
## $iter
## [1] 6
##
## $init.it
## [1] NA
##
## $estim.prec
## [1] 6.103516e-05
- Find the value x such that P(−x≤X≤x)=0.4.
Because this distribution is symmetric, finding x is equivalent to finding x such that P(X>x)=0.3. (It helps to draw a picture). Thus, we need x such that F(x)=0.7. Solving x354+12=0.7 for x yields x=2.210.

- Find the mean and variance of X. E(X)=∫3−3x⋅x218dx=x472|3−3=8172−8172=0
E(X2)=∫3−3x2⋅x218dx=x590|3−3=24390−−24390=5.4
Var(X)=E(X2)−E(X)2=5.4−02=5.4
- Simulate 10000 values from this distribution and plot the density.
This is tricky since we need a cube root function. Just raising to the one-third power won’t work. Let’s write our own function.
results %>%
gf_dens(~cuberoot) %>%
gf_theme(theme_classic()) %>%
gf_labs(title="pdf from simulation",x="x",y="f(x)")

Notice that the smoothing operation goes past the support of X and thus shows a concave down curve. We could clean up by limiting the x-axis to the interval [-3,3].
inspect(results)
##
## quantitative variables:
## name class min Q1 median Q3 max
## 1 cuberoot numeric -2.999981 -2.382864 -0.1574198 2.376346 2.999347
## mean sd n missing
## 1 -0.002416475 2.322639 10000 0
11.2.2 Problem 2
Let X be a continuous random variable. Prove that the cdf of X, FX(x) is a non-decreasing function. (Hint: show that for any a<b, FX(a)≤FX(b).)
Let a<b, where a and b are both in the domain of X. Note that FX(a)=P(X≤a) and FX(b)=P(X≤b). Since a<b, we can partition P(X≤b) as P(X≤a)+P(a<X≤b). One of the axioms of probability is that a probability must be non-negative, so I know that P(a<X≤b)≥0. Thus, P(X≤b)=P(X≤a)+P(a<X≤b)≥P(X≤a)
So, we have shown that FX(a)≤FX(b). Thus, FX(x) is a non-decreasing function.