Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

pdfPlot

Plot Probability Density Function


Description

Produce a probability density function (pdf) plot for a user-specified distribution.

Usage

pdfPlot(distribution = "norm", param.list = list(mean = 0, sd = 1), 
    left.tail.cutoff = ifelse(is.finite(supp.min), 0, 0.001), 
    right.tail.cutoff = ifelse(is.finite(supp.max), 0, 0.001), 
    plot.it = TRUE, add = FALSE, n.points = 1000, pdf.col = "black", 
    pdf.lwd = 3 * par("cex"), pdf.lty = 1, curve.fill = !add, 
    curve.fill.col = "cyan", x.ticks.at.all.x.max = 15, 
    hist.col = ifelse(add, "black", "cyan"), density = 5, 
    digits = .Options$digits, ..., type = "l", main = NULL, xlab = NULL, 
    ylab = NULL, xlim = NULL, ylim = NULL)

Arguments

distribution

a character string denoting the distribution abbreviation. The default value is distribution="norm". See the help file for Distribution.df for a list of possible distribution abbreviations.

param.list

a list with values for the parameters of the distribution. The default value is param.list=list(mean=0, sd=1). See the help file for Distribution.df for the names and possible values of the parameters associated with each distribution.

left.tail.cutoff

a numeric scalar indicating what proportion of the left-tail of the probability distribution to omit from the plot. For densities with a finite support minimum (e.g., Lognormal) the default value is 0; for all other densities the default value is 0.001.

right.tail.cutoff

a scalar indicating what proportion of the right-tail of the probability distribution to omit from the plot. For densities with a finite support maximum (e.g., Binomial) the default value is 0; for all other densities the default value is 0.001.

plot.it

a logical scalar indicating whether to create a plot or add to the existing plot (see add) on the current graphics device. If plot.it=FALSE, no plot is produced, but a list of (x, y) values is returned (see the section VALUE below). The default value is plot.it=TRUE.

add

a logical scalar indicating whether to add the probability density curve to the existing plot (add=TRUE), or to create a new plot (add=FALSE; the default). This argument is ignored if plot.it=FALSE.

n.points

a numeric scalar specifying at how many evenly-spaced points the probability density function will be evaluated. The default value is n.points=1000.

pdf.col

for continuous distributions, a numeric scalar or character string determining the color of the pdf line in the plot. The default value is pdf.col="black". See the entry for col in the help file for par for more information.

pdf.lwd

for continuous distributions, a numeric scalar determining the width of the pdf line in the plot. The default value is pdf.lwd=3*par("cex"). See the entry for lwd in the help file for par for more information.

pdf.lty

for continuous distributions, a numeric scalar determining the line type of the pdf line in the plot. The default value is pdf.lty=1. See the entry for lty in the help file for par for more information.

curve.fill

for continuous distributions, a logical value indicating whether to fill in the area below the probability density curve with the color specified by curve.fill.col. The default value is TRUE unless add=TRUE.

curve.fill.col

for continuous distributions, when curve.fill=TRUE, a numeric scalar or character string indicating what color to use to fill in the area below the probability density curve. The default value is curve.fill.col="cyan". See the entry for col in the help file for par for more information.

x.ticks.at.all.x.max

a numeric scalar indicating the maximum number of ticks marks on the x-axis. The default value is x.ticks.at.all.x.max=15.

hist.col

for discrete distributions, a numeric scalar or character string indicating what color to use to fill in the histogram if add=FALSE, or the color of the shading lines if add=TRUE. The default is "cyan" if add=FALSE and "black" if add=TRUE. See the entry for col in the help file for par for more information.

density

for discrete distributions, a scalar indicting the density of line shading for the histogram when add=TRUE. This argument is ignored if add=FALSE.

digits

a scalar indicating how many significant digits to print for the distribution parameters. The default value is digits=.Options$digits.

type, main, xlab, ylab, xlim, ylim, ...

additional graphical parameters. See plot.default and par).

Details

The probability density function (pdf) of a random variable X, usually denoted f, is defined as:

f(x) = \frac{dF(x)}{dx} \;\;\;\;\;\; (1)

where F is the cumulative distribution function (cdf) of X. That is, f(x) is the derivative of the cdf F with respect to x (where this derivative exists).

For discrete distributions, the probability density function is simply:

f(x) = Pr(X = x) \;\;\;\;\;\; (2)

In this case, f is sometimes called the probability function or probability mass function.

The probability that the random variable X takes on a value in the interval [a, b] is simply the (Lebesgue) integral of the pdf evaluated between a and b. That is,

Pr(a ≤ X ≤ b) = \int_a^b f(x) dx \;\;\;\;\;\; (3)

For discrete distributions, Equation (3) translates to summing up the probabilities of all values in this interval:

Pr(a ≤ X ≤ b) = ∑_{x \in [a,b]} f(x) = ∑_{x \in [a,b]} Pr(X = x) \;\;\;\;\;\; (4)

A probability density function (pdf) plot plots the values of the pdf against quantiles of the specified distribution. Theoretical pdf plots are sometimes plotted along with empirical pdf plots (density plots), histograms or bar graphs to visually assess whether data have a particular distribution.

Value

pdfPlot invisibly returns a list giving coordinates of the points that have been or would have been plotted:

Quantiles

The quantiles used for the plot.

Probability.Densities

The values of the pdf associated with the quantiles.

Author(s)

Steven P. Millard (EnvStats@ProbStatInfo.com)

References

Forbes, C., M. Evans, N. Hastings, and B. Peacock. (2011). Statistical Distributions. Fourth Edition. John Wiley and Sons, Hoboken, NJ.

Johnson, N. L., S. Kotz, and A.W. Kemp. (1992). Univariate Discrete Distributions, Second Edition. John Wiley and Sons, New York.

Johnson, N. L., S. Kotz, and N. Balakrishnan. (1994). Continuous Univariate Distributions, Volume 1. Second Edition. John Wiley and Sons, New York.

Johnson, N. L., S. Kotz, and N. Balakrishnan. (1995). Continuous Univariate Distributions, Volume 2. Second Edition. John Wiley and Sons, New York.

See Also

Examples

# Plot the pdf of the standard normal distribution 
  #-------------------------------------------------
  dev.new()
  pdfPlot()

  #==========

  # Plot the pdf of the standard normal distribution
  # and a N(2, 2) distribution on the sample plot. 
  #-------------------------------------------------
  dev.new()
  pdfPlot(param.list = list(mean=2, sd=2), 
    curve.fill = FALSE, ylim = c(0, dnorm(0)), main = "") 

  pdfPlot(add = TRUE, pdf.col = "red") 

  legend("topright", legend = c("N(2,2)", "N(0,1)"), 
    col = c("black", "red"), lwd = 3 * par("cex")) 

  title("PDF Plots for Two Normal Distributions")
 
  #==========

  # Clean up
  #---------
  graphics.off()

EnvStats

Package for Environmental Statistics, Including US EPA Guidance

v2.4.0
GPL (>= 3)
Authors
Steven P. Millard [aut], Alexander Kowarik [ctb, cre] (<https://orcid.org/0000-0001-8598-4130>)
Initial release
2020-10-20

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.