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.
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.
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 returnedThese two links provide additional information on R and available distributions
dunif
function to make a plot of the pdf.
qunif
function to find the 50th percentile.qunif
function to find the IQR.qunif
function to plot the CDF of the Uniform distribution. See Figure 3-2 in Akritas.punif
function to create the same CDF plot.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