# discrete: Univariate Discrete Distributions: p.m.f and c.d.f. In smovie: Some Movies to Illustrate Concepts in Statistics

 discrete R Documentation

## Univariate Discrete Distributions: p.m.f and c.d.f.

### Description

A movie to illustrate how the probability mass function (p.m.f.) and cumulative distribution function (c.d.f.) of a discrete random variable depend on the values of its parameters.

### Usage

``````discrete(
distn,
var_support = NULL,
params = list(),
param_step = list(),
param_range = list(),
p_vec = NULL,
smallest = 0.01,
plot_par = list(),
panel_plot = TRUE,
hscale = NA,
vscale = hscale,
observed_value = NA,
...
)
``````

### Arguments

 `distn` Either a character string or a function to choose the discrete random variable. Strings `"binomial"`, `"geometric"`, `"hypergeometric"`, `"negative binomial"` and `"poisson"` are recognised, case being ignored. The relevant distributional functions `dxxx` and `pxxx` in the `stats-package` are used. The abbreviations `xxx` are also recognised. If `distn = "negative binomial"` then the `(size, prob)` parameterisation is used, unless a value for `mu` is provided via the argument `params` when the `(size, mu)` parameterisation is used. Valid functions are set up like a standard distributional function `dxxx`, with first argument `x`, last argument `log` and with arguments to set the parameters of the distribution in between. See the CRAN task view on distributions. It is assumed that the support of the random variable is a subset of the integers, unless `var_support` is set to the contrary. If `distn` is not supplied then `distn = "binomial"` is used. `var_support` A numeric vector. Can be used to set a fixed set of values for which to plot the p.m.f. and c.d.f., in order better to see the effects of changing the parameter values or to set a support that isn't a subset of the integers. If `var_support` is set then it overrides `p_vec` (see below). `params` A named list of initial parameter values with which to start the movie. If `distn` is a string and a particular parameter value is not supplied then the following values are used. `"binomial"`: `size = 10, prob = 0.5`; `"geometric"`: `prob = 0.5`; `"hypergeometric"`: `m = 10, n = 7, k = 8`; `"negative binomial"`: `size = 10, prob = 0.5`; `"poisson"`: `lambda = 5`. If `distn` is a function then `params` must set any required parameters. If parameter value is outside the corresponding range specified by `param_range` then it is set to the closest limit of the range. `param_step` A named list of the amounts by which the respective parameters in `params` are increased/decreased after one click of the +/- button. If `distn` is a function then the default is 0.1 for all parameters. If `distn` is a string then a sensible distribution-specific default is set internally. `param_range` A named list of the ranges over which the respective parameters in `params` are allowed to vary. Each element of the list should be a vector of length 2: the first element gives the lower limit of the range, the second element the upper limit. Use `NA` to impose no limit. If `distn` is a function then all parameters are unconstrained. `p_vec` A numeric vector of length 2. The p.d.f. and c.d.f. are plotted between the 100`p_vec[1]`% and 100`p_vec[2]`% quantiles of the distribution. If `p_vec` is not supplied then a sensible distribution-specific default is used. If `distn` is a function then the default is `p_vec = c(0.001, 0.999)`. `smallest` A positive numeric scalar. The smallest value to be used for any strictly positive parameters when `distn` is a string. `plot_par` A named list of graphical parameters (see `par`) to be passed to `plot`. This may be used to alter the appearance of the plots of the p.m.f. and c.d.f. `panel_plot` A logical parameter that determines whether the plot is placed inside the panel (`TRUE`) or in the standard graphics window (`FALSE`). If the plot is to be placed inside the panel then the tkrplot library is required. `hscale`, `vscale` Numeric scalars. Scaling parameters for the size of the plot when `panel_plot = TRUE`. The default values are 1.4 on Unix platforms and 2 on Windows platforms. `observed_value` A non-negative integer. If `observed_value` is supplied then the corresponding line in the plot of the p.m.f. is coloured in red. `...` Additional arguments to be passed to `rp.doublebutton`, not including `panel`, `variable`, `title`, `step`, `action`, `initval`, `range`.

### Details

The movie starts with a plot of the p.m.f. of the distribution for the initial values of the parameters. Buttons increase (+) or decrease (-) each parameter. There are radio buttons to switch the plot from the p.m.f. to the c.d.f. and back.

If `distn == "geometric"` then there are radio buttons to switch between the version of the the geometric distribution based on the number of trials up to including the first success and the number of failures until the first success.

Owing to a conflict with the argument `size` of the function `rp.control` the parameter `size` of, for example, the binomial and negative binomial distributions, is labelled as `n`.

### Value

Nothing is returned, only the animation is produced.

`movies`: a user-friendly menu panel.

`smovie`: general information about smovie.

### Examples

``````# Binomial example
discrete()

# The same example, but using a user-supplied function and setting manually
# the initial parameters, parameter step size and range
discrete(distn = dbinom, params = list(size = 10, prob = 0.5),
param_step = list(size = 1),
param_range = list(size = c(1, NA), prob = c(0, 1)))

# Poisson distribution. Show the use of var_support
discrete(distn = "poisson", var_support = 0:20)
``````

smovie documentation built on May 29, 2024, 10:28 a.m.