Processing math: 100%

11 Continuous Random Variables

11.1 Objectives

  1. Define and properly use in context all new terminology, to include: probability density function (pdf) and cumulative distribution function (cdf) for continuous random variables.

  2. Given a continuous random variable, find probabilities using the pdf and/or the cdf.

  3. 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 kXk. Also, let f(x)=x218.

  1. Assume that f(x) is a valid pdf. Find the value of k.

Because f is a valid pdf, we know that kkx218dx=1. So, kkx218dx=x354|kk=k354k354=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 k3 from the plot.

uniroot(function(x)my_pdf(x)-1,c(-10,10))$root
## [1] 2.999997
  1. 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")
  1. Find and plot the cdf of X. FX(x)=P(Xx)=x3t218dt=t354|x3=x354+12

FX(x)={0,x<3x354+12,3x31,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())
  1. 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
  1. Find P(1.5<X2.5). P(1.5<X2.5)=F(2.5)F(1.5)=2.5354+121.535412=0.227
integrate(function(x)x^2/18,1.5,2.5)
## 0.2268519 with absolute error < 2.5e-15
  1. 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.

uniroot(function(x)x^3/54+.5-.8,c(-3,3))
## $root
## [1] 2.530293
## 
## $f.root
## [1] -1.854422e-06
## 
## $iter
## [1] 6
## 
## $init.it
## [1] NA
## 
## $estim.prec
## [1] 6.103516e-05
  1. Find the value x such that P(xXx)=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.

  1. Find the mean and variance of X. E(X)=33xx218dx=x472|33=81728172=0

E(X2)=33x2x218dx=x590|33=2439024390=5.4

Var(X)=E(X2)E(X)2=5.402=5.4

  1. 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.

cuberoot <- function(x) {
  sign(x) * abs(x)^(1/3)}
set.seed(4)
results <- do(10000)*cuberoot((runif(1)-.5)*54)
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(Xa) and FX(b)=P(Xb). Since a<b, we can partition P(Xb) as P(Xa)+P(a<Xb). One of the axioms of probability is that a probability must be non-negative, so I know that P(a<Xb)0. Thus, P(Xb)=P(Xa)+P(a<Xb)P(Xa)

So, we have shown that FX(a)FX(b). Thus, FX(x) is a non-decreasing function.