plotDist: Plotting of Statistical Distributions

Description Usage Arguments Details Note Author(s) See Also Examples

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 = 2, ...)

Arguments

distA

Character variable naming the first probability density function (starting with "d") or cumulative density function (starting with "p") to be graphed. May be set to "dprop" for a sample proportion, in which case only one distribution (i.e., distA) may be graphed, using the same arguments as dbinom.

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. However, if distA="dprop", then parmA1 should be set to the size in dbinom.

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. However, if distA="dprop", then parmA2 should be set to the prob in dbinom.

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 dissatisfied 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 default 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, shadePhat, plot, and getMinMax

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
par( mfrow=c(2,2) )

# 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, 
          main=expression(paste("Standard Normal,", T[3],", and ", T[paste(3,",",1.4)], sep="")) ) 

plotDist( "dchisq", 15, , "dnorm", 15, sqrt(2*15), col=c("blue", "hotpink"),
   main=expression(paste("Normal approximation to ",chi[~(15)]^{~2})) ) 

# Cumulative distribution functions.
plotDist( "pnorm", 50, 10, "pcauchy", 50, 10, col=c("purple","orange"), 
   main = "Normal and Cauchy CDFs" )

# Plots sample proportion by calling function shadePhat.
plotDist( "dprop", 15, 0.3, col="turquoise", main = "Sample proportion" )

par( mfrow=c(1,1) )

Example output



fastGraph documentation built on July 23, 2019, 5:04 p.m.