plotDist {fastGraph} | R Documentation |
Plotting of Statistical Distributions
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
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., |
parmA1 |
The first argument in |
parmA2 |
The second argument in |
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 |
parmB2 |
The second argument in |
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 |
parmC2 |
The second argument in |
xlab |
The label of the |
xmin |
The minimum x-value to be graphed. |
xmax |
The maximum x-value to be graphed. |
col |
A vector specifying the colors of |
is.discrete |
A vector with 1, 2, or 3 logical values, indicating whether or not |
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 |
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
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) )