distdata: Explore a probability distribution and calculate...

View source: R/distdata.R

distdataR Documentation

Explore a probability distribution and calculate probabilities

Description

distdata() is the command-line probability-distribution calculator for R4VN. It combines distribution properties, point probabilities/densities, tail probabilities, interval probabilities, quantiles, simulation, and a Viewer-ready plot. distlearn() provides the interactive Shiny companion.

Usage

distdata(
  distribution,
  ...,
  x = NULL,
  lower = NULL,
  upper = NULL,
  probs = NULL,
  nsim = 0L,
  seed = NULL,
  plot = TRUE,
  digits = 6L,
  show = TRUE,
  console = FALSE
)

Arguments

distribution

Distribution name. Common abbreviations are accepted, for example "normal", "binomial", "poisson", "t", "chisq", "weibull", "betabinom", and "zip".

...

Named parameters of the selected distribution. For example, n and p for binomial, mean and sd for normal, or lambda for Poisson. Defaults are teaching-friendly and are shown by distlearn().

x

Optional value(s). For discrete distributions R4VN reports P(X=x), <, <=, >, and >=. For continuous distributions it reports density f(x) and the corresponding tail probabilities.

lower, upper

Optional interval bounds for an interval probability.

probs

Optional cumulative probabilities for which quantiles are requested, for example probs = c(.025, .5, .975).

nsim

Optional number of random observations to simulate. 0 (the default) does not simulate.

seed

Optional user-supplied random seed for simulation. The default NULL does not set a seed.

plot

Logical; retain plot data and display the probability function in the R4VN Viewer.

digits

Number of significant digits in numerical probability output.

show

Logical; open the R4VN Viewer result.

console

Logical; also print the tabular result to the console.

Details

A particularly useful teaching call is distdata("binomial", n = 10, x = 3, p = .2). With only these inputs R4VN reports P(X=3), P(X<3), P(X<=3), P(X>3), and P(X>=3), together with the distribution's mean, variance, standard deviation, parameters, support, and plot. Supplying lower and upper adds the probability inside and outside an interval; supplying probs adds quantiles.

The beta-binomial accepts either shape1/shape2 or the more interpretable pair p/rho. The negative binomial accepts size with either p or mu. Gamma accepts rate or scale.

Value

Invisibly returns an object of classes r4vn_distdata and r4vn_stat. Its raw component contains the distribution specification, parameters, point/range probabilities, quantiles, simulation, and plot grid.

Examples

distdata("binomial", n = 10, x = 3, p = .2, show = FALSE)
distdata("binomial", n = 20, p = .35, lower = 5, upper = 10, show = FALSE)
distdata("normal", mean = 100, sd = 15, x = 130, show = FALSE)
distdata("normal", mean = 100, sd = 15, probs = c(.025, .5, .975), show = FALSE)
distdata("poisson", lambda = 2.5, x = 0:4, show = FALSE)
distdata("nbinom", size = 2, mu = 5, x = 0:4, show = FALSE)
distdata("betabinom", n = 20, p = .3, rho = .1, x = 0:5, show = FALSE)

R4VN documentation built on Sept. 30, 2026, 5:13 p.m.