Today we are going to look at the calculus methods associated with pdf and cdf equations. Many of the distributions we use in statistics don’t have closed form solutions to their integrals. However, the foundational distribution (“The one ring to rule them all”) of the uniform distribution does give us a simple pdf that we can integrate.

This link provides a pretty intuitive explenation of the importance of calculus for probability distributions.

We are going to use the pdf and cdf to address the following items.

By Hand Tasks (In Class)

  • What is the expected value (mean) of the Uniform distribution?
  • What is the variance of the uniform distribution?
  • What is the standard deviation?
  • Use the pdf of the Uniform distribution to derive the cdf and solve for a few points. With your group draw the CDF (on paper or a board).

With R Functions

R has lot’s of probability distributions that come pre-installed with it. With additional packages there are few published density function that are not available in R.

Understing R Help files for distributions

We will use the uniform distribution as an example.

  • ?runif, ?punif, ?qunif, or ?dunify all return the same help page. Notice that we have the uniform distribution unif with one of four letters in the front d,p,q,r
    • r random: signifies the random selection of values that follow functional distribution.
    • q quantile: the inverse cdf, User inputs quantile, y, and qunif ouputs the x of the cdf.
    • d density: the pdf, user inputs (x) and the (y) or height of the pdf is returned.
    • p probability: the cdf, user inputs (x) and the respective quantile (y) is returned

These two links provide additional information on R and available distributions

R Calculation (In Class)

  • Use the dunif function to make a plot of the pdf.
    • Hint: You will need to create the x vector.
  • Use the qunif function to find the 50th percentile.
  • Use the qunif function to find the IQR.
  • Use the qunif function to plot the CDF of the Uniform distribution. See Figure 3-2 in Akritas.
  • Use the punif function to create the same CDF plot.
  • Use the runif function to create 1, 000 random samples and plot the histogram of these random samples.

We could also use the integrate function in R as well.

f = function(x) x
# Finding the mean
integrate(f,lower=0,upper=1)
## 0.5 with absolute error < 5.6e-15
# Finding E(x^2)
f2 = function(x) x^2
integrate(f2,lower=0,upper=1)
## 0.3333333 with absolute error < 3.7e-15
# now find Var(X)
integrate(f2,lower=0,upper=1)$value -integrate(f,lower=0,upper=1)$value^2
## [1] 0.08333333
# and the standard deviation
sqrt(integrate(f2,lower=0,upper=1)$value -integrate(f,lower=0,upper=1)$value^2
)
## [1] 0.2886751