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.
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 functionsdxxxandpxxxin thestats-packageare used. The abbreviationsxxxare also recognised. Ifdistn = "negative binomial"then the(size, prob)parameterisation is used, unless a value formuis provided via the argumentparamswhen the(size, mu)parameterisation is used.Valid functions are set up like a standard distributional function
dxxx, with first argumentx, last argumentlogand 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, unlessvar_supportis set to the contrary.If
distnis not supplied thendistn = "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_supportis set then it overridesp_vec(see below).- params
A named list of initial parameter values with which to start the movie. If
distnis 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
distnis a function thenparamsmust set any required parameters.If parameter value is outside the corresponding range specified by
param_rangethen it is set to the closest limit of the range.- param_step
A named list of the amounts by which the respective parameters in
paramsare increased/decreased after one click of the +/- button. Ifdistnis a function then the default is 0.1 for all parameters. Ifdistnis 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
paramsare 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. UseNAto impose no limit. Ifdistnis 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 100p_vec[2]% quantiles of the distribution. Ifp_vecis not supplied then a sensible distribution-specific default is used. Ifdistnis a function then the default isp_vec = c(0.001, 0.999).- smallest
A positive numeric scalar. The smallest value to be used for any strictly positive parameters when
distnis a string.- plot_par
A named list of graphical parameters (see
par) to be passed toplot. 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_valueis 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 includingpanel,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.
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)