Plotting of Statistical Distributions

Share:

Description

This function plots as many as three probability density functions and cumulative distribution functions on the same graph using just one command, where the domain of the graph need not be specified by the user.

Usage

1
2
3
4
plotDist(distA = "dnorm", parmA1 = NULL, parmA2 = NULL, distB = NULL, parmB1 = NULL, 
         parmB2 = NULL, distC = NULL, parmC1 = NULL, parmC2 = NULL, xlab = NULL, 
         xmin = NULL, xmax = NULL, col = c("black", "red", "darkgreen"), 
         is.discrete = NULL, additional.x.range = NULL, lwd = 5, ...)

Arguments

distA

Character variable naming the first probability density function (starting with "d") or cumulative density function (starting with "p") to be graphed.

parmA1

The first argument in distA, excluding the dummy argument. For example, if distA="dnorm", then parmA1 is the mean from "dnorm". Alternatively, parmA1 may be set to be a vector of arguments, excluding the dummy argument.

parmA2

The second argument in distA, excluding the dummy argument. For example, if distA="dnorm", then parmA2 is the sd from "dnorm". Alternatively, parmA2 may be set to be a vector of arguments, excluding both the dummy argument and parmA1.

distB

Character variable naming the second probability density function (starting with "d") or cumulative density function (starting with "p") to be graphed.

parmB1

The first argument in distB, excluding the dummy argument. Alternatively, parmB1 may be set to be a vector of arguments, excluding the dummy argument.

parmB2

The second argument in distB, excluding the dummy argument. Alternatively, parmB1 may be set to be a vector of arguments, excluding both the dummy argument and parmB1.

distC

Character variable naming the third probability density function (starting with "d") or cumulative density function (starting with "p") to be graphed.

parmC1

The first argument in distC, excluding the dummy argument. Alternatively, parmC1 may be set to be a vector of arguments, excluding the dummy argument.

parmC2

The second argument in distC, excluding the dummy argument. Alternatively, parmC2 may be set to be a vector of arguments, excluding both the dummy argument and parmC1.

xlab

The label of the x variable.

xmin

The minimum x-value to be graphed.

xmax

The maximum x-value to be graphed.

col

A vector specifying the colors of distA, distB, and distC, respectively.

is.discrete

A vector with 1, 2, or 3 logical values, indicating whether or not distA, distB, and distC are discrete. For built-in density functions, such as dbinom, pbinom, dgeom, pgeom, dhyper, phyper, dpois, ppois, dnbinom, and pnbinom, this argument is.discrete can be set to NULL, which is the default.

additional.x.range

A vector of two additional x-values for evaluating the function. This argument would be needed only if the user is dissatified with the domain determined by the function.

lwd

The line width for discrete distributions.

...

Optional arguments to be passed to the plot function (see par).

Details

If only one graph is to be plotted, then use distA. If only two graphs are to be plotted, then use distA and distB.

The arguments in plotDist are typically entered as first distribution plus two parameters, second distribution plus two parameters, and third distribution plus two parameters. If only one parameter of the distribution is needed, then the second parameter can be left as the default of NULL. If three or more parameters of the distribution are needed, then the first parameter can be assigned to be a vector consisting of all of the parameters.

The defaul value of distA is "dnorm"; i.e., for plotting the normal distribution.

The default values of all of the arguments following parmC2 usually are sufficient.

Note

This function plotDist calls functions getMinMax, plot, and curve.

Author(s)

Steven T. Garren, James Madison University, Harrisonburg, Virginia, USA

See Also

shadeDist, plot, and getMinMax

Examples

1
2
3
4
5
6
7
8
9
# Plots standard normal density in black, t density with 3 d.f. in red, and
# non-central t density with 3 d.f. and non-centrality parameter=1.4 in green.
plotDist( "dnorm", 0, 1, "dt", 3, 0, "dt", 3, 1.4 ) 

# Plots normal approximation to Binomial(n=100, p=0.4).
plotDist( , 40, sqrt(100*0.4*0.6), "dbinom", 100, 0.4, col=c("blue", "hotpink") )

# Plots cumulative normal and Cauchy distribution functions.
plotDist( "pnorm", 50, 10, "pcauchy", 50, 10, col=c("purple","orange") )