Learn R Programming

mosaic (version 1.9.1)

cdist: Central portion of a distribution

Description

This function determines the critical values for isolating a central portion of a distribution with a specified probability. This is designed to work especially well for symmetric distributions, but it can be used with any distribution.

Usage

cdist(
  dist = "norm",
  p,
  plot = TRUE,
  verbose = FALSE,
  invisible = FALSE,
  digits = 3L,
  xlim = NULL,
  ylim = NULL,
  resolution = 500L,
  return = c("values", "plot"),
  pattern = c("rings", "stripes"),
  ...,
  refinements = list()
)

xcgamma( p, shape, rate = 1, scale = 1/rate, lower.tail = TRUE, log.p = FALSE, ... )

xct(p, df, ncp, lower.tail = TRUE, log.p = FALSE, ...)

xcchisq(p, df, ncp = 0, lower.tail = TRUE, log.p = FALSE, ...)

xcf(p, df1, df2, lower.tail = TRUE, log.p = FALSE, ...)

xcbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE, ...)

xcpois(p, lambda, lower.tail = TRUE, log.p = FALSE, ...)

xcgeom(p, prob, lower.tail = TRUE, log.p = FALSE, ...)

xcnbinom(p, size, prob, mu, lower.tail = TRUE, log.p = FALSE, ...)

xcbeta(p, shape1, shape2, ncp = 0, lower.tail = TRUE, log.p = FALSE, ...)

Value

a pair of numbers indicating the upper and lower bounds, unless verbose is TRUE, in which case a 1-row data frame is returned containing these bounds, the central probability, the tail probabilities, and the name of the distribution.

Arguments

dist

a character string naming a distribution family (e.g., "norm"). This will work for any family for which the usual d/p/q functions exist.

p

the proportion to be in the central region, with equal proportions in either "tail".

plot

a logical indicating whether a plot should be created

verbose

a logical indicating whether a more verbose output value should be returned.

invisible

a logical

digits

the number of digits desired

xlim

x limits. By default, these are chosen to show the central 99.8\ of the distribution.

ylim

y limits

resolution

number of points used for detecting discreteness and generating plots. The default value of 5000 should work well except for discrete distributions that have many distinct values, especially if these values are not evenly spaced.

return

If "plot", return a plot. If "values", return a vector of numerical values.

pattern

One of "stripes" or "rings". In the latter case, pairs of regions (from the outside to the inside) are grouped together for coloring and probability calculation.

...

additional arguments passed to the distribution functions. Typically these specify the parameters of the particular distribution desired. See the examples.

refinements

A list of refinements to the plot. See ggformula::gf_refine().

shape, scale

shape and scale parameters. Must be positive, scale strictly.

rate

an alternative way to specify the scale.

lower.tail

logical; if TRUE (default), probabilities are \(P[X \le x]\), otherwise, \(P[X > x]\).

log.p

A logical indicating whether probabilities should be returned on the log scale.

df

degrees of freedom (\(> 0\), maybe non-integer). df = Inf is allowed.

ncp

non-centrality parameter \(\delta\); currently except for rt(), only for abs(ncp) <= 37.62. If omitted, use the central t distribution.

df1, df2

degrees of freedom. Inf is allowed.

size

number of trials (zero or more).

prob

probability of success on each trial.

lambda

vector of (non-negative) means.

mu

alternative parametrization via mean: see ‘Details’.

shape1, shape2

non-negative parameters of the Beta distribution.

Examples

Run this code
cdist( "norm", .95)
cdist( "t", c(.90, .95, .99), df=5)
cdist( "t", c(.90, .95, .99), df=50)
# plotting doesn't work well when the parameters are not constant
cdist( "t", .95, df=c(3,5,10,20), plot = FALSE)
cdist( "norm", .95, mean=500, sd=100 )
cdist( "chisq", c(.90, .95), df=3 )
# CI
x <- rnorm(23, mean = 10, sd = 2)
cdist("t", p = 0.95, df=22)
mean(x) + cdist("t", p = 0.95, df=22) * sd(x) / sqrt(23)
confint(t.test(x))
cdist("t", p = 0.95, df=22, verbose = TRUE)

Run the code above in your browser using DataLab