Description Usage Arguments Details Value Note See Also Examples
Plots calculated areas or values from normal, Student's t, F, chi-square, beta, exponential, and gamma continuous density functions and binomial, geometric, negative binomial, Poisson, and hypergeometric discrete distribution functions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | distrib(
val,
distrib = c("norm", "t", "chisq", "f", "beta", "exp", "gamma", "pois", "binom",
"geom", "hypergeom", "nbinom"),
type = c("p", "q", "d", "forward", "reverse"),
digits = getOption("digits"),
mean = 0,
sd = se,
se = 1,
df = 1,
df1 = df,
df2 = 1,
shape1 = 1,
shape2 = 1,
shape = 1,
rate = 1,
scale = 1/rate,
size = 10,
prob = 0.5,
mu = NULL,
lambda = 1,
m = NULL,
n = NULL,
k = NULL,
lower.tail = TRUE,
plot = TRUE,
show.ans = TRUE,
show.alt = FALSE,
main = NULL,
xlab = NULL,
ylab = NULL,
yaxt = "n",
smoothness = 1000,
shade.col = "red",
shade.trans = 1,
lbl.col = "red",
...
)
|
val |
a single-length numeric containing a value or probability/quantile. |
distrib |
a string indicating the type of distribution to use. See details. |
type |
a string indicating the type of calculation to make – |
digits |
A numeric indicating the number of decimals to round the returned result when |
mean |
a single-length numeric for the mean of the normal distribution. |
sd |
a single-length numeric for the standard deviation of the normal distribution. |
se |
a single-length numeric for the standard error of the normal distribution (see details) |
df |
a single-length numeric for the degrees-of-freedom for the t and chi-square distributions. |
df1 |
a single-length numeric for the numerator degrees-of-freedom for the F distribution. |
df2 |
a single-length numeric for the denominator degrees-of-freedom for the F distribution. |
shape1 |
a single-length numeric for the first shape parameter in the beta distribution. |
shape2 |
a single-length numeric for the first shape parameter in the beta distribution. |
shape |
a single-length numeric for the shape parameter in the gamma distribution. |
rate |
a single-length numeric for the rate parameter in the gamma and exponential distributions. See details. |
scale |
a single-length numeric for the scale parameter in the gamma distribution. |
size |
a single-length numeric for the number of trials in the binomial distribution. |
prob |
a single-length numeric for the probability of success on each trial in the binomial, geometric, and negative binomial distributions. |
mu |
a single-length numeric for the mean of negative binomial distribution. see details |
lambda |
a single-length numeric for the mean of the Poisson distribution. |
m |
a single-length numeric for the number of white balls in the urn of a hypergeometric distribution. |
n |
a single-length numeric for the number of black balls in the urn of a hypergeometric distribution. |
k |
a single-length numeric for the number of balls drawn from the urn of a hypergeometric distribution. |
lower.tail |
a logical indicating if the probabilities are P[X<=x] ( |
plot |
a logical indicating if a plot should be shown ( |
show.ans |
a logical indicating if the computational results should be shown on the plot ( |
show.alt |
a logical indicating if a message showing alternaive (i.e,. traditional) code for obtaining the answer should be shown ( |
main |
a character string for the plot's main label. If null an appropriate string will be created. |
xlab |
character string for plot's x-axis label. If null an appropriate string will be created. |
ylab |
character string for plot's y-axis label. If null an appropriate string will be created. |
yaxt |
a character which specifies the y axis type. Specifying |
smoothness |
a single-length numeric indicating the number of points for which to construct the plot. The larger the number the smoother the plot will appear. |
shade.col |
a string indicating the color to use for the shaded area. |
shade.trans |
Value between 0 and 1 indicating the transparency to use for the shaded area. |
lbl.col |
a string indicating the color to use for labeling the shaded area. |
... |
optional parameters to send to the internal |
This function computes the same values as the pXXX
and qXXX
functions for both continuous density and discrete probability distributions and as the dXXX
functions for the discrete probability distributions. This function is used primarily to include a plot with the calculation. The original functions in the stats package should be consulted for more details on each distribution. For example, use ?dbinom
to get help for computing the probability of a value in the binomial distribution, ?ppois
to get help for computing the cumulative probability of a value on the Poisson distribution, and ?qnorm
to get help for computing the quantile value of a normal distribution.
The strings in the distrib
argument are the same as the abbreviated function names in the stats package. For example, the normal distribution is "norm"
, the chi-square distribution is "chisq"
, and the hypergeometric distribution is "hyper"
The strings in the type
argument at the same as the prefixes to the abbreviated function names in the stats package. For example, the density is computed with "d"
, the cumulative probability with "p"
, and the quantiles with "q"
. The "forward"
and "reverse"
types correspond to "p"
and "q"
, respectively, and are used to match terminology used in the Introductory Statistics course at Northland College.
Other visualizations of the distribution can be seen with functions that are named with the s
prefix (for simulation) on the abbreviated function name. For example, try sbinom()
to show a simulation of the binomial distribution.
Note that for a normal distribution the se=
argument is supplied for convenience only. Whatever is supplied to se=
is then applied to the sd=
argument. Use of se=
may be somewhat simpler for students learning to distinguish between normal distribution calculations on a sampling versus a population distribution.
A numeric answer is returned. If plot=TRUE
then a plot is constructed and a note on how to use one of the functions in stats is printed if show.alt=TRUE
.
Students often need to “look up” values or probabilities from statistical tables in textbooks. These values can be easily found in R with the pXXX
, qXXX
, or dXXX
distributional functions. However, these functions do not provide a visual representation of the computation. This function also replaces the tables of distributional values found in texts but also provides a graph of the computation.
I had hoped to add a plot=
argument to any of the pXXX
, qXXX
, or dXXX
distributional functions but this required replacing the base R functions. A compromise was to create this new function, using the type=
argument with p
, q
, and d
and printing a direction on how to use the base R function if show.alt=TRUE
.
The type=
and distrib=
arguments can be concatenated to provide the typical function in base R. For example, for the examples below see dbinom
, dpois
, pexp
, and qnorm
.
1 2 3 4 5 6 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.