Uniform
The Uniform Distribution
Description
Calculates density, cumulative probability, quantile, and
generates a random sample for the uniform distribution (continuous).
Usage
dunif(x, min = 0, max = 1, log = FALSE) # density
punif(q, min = 0, max = 1, lower.tail = TRUE, log.p = FALSE) # probability
qunif(p, min = 0, max = 1, lower.tail = TRUE, log.p = FALSE) # quantile
runif(n, min = 0, max = 1) # random
Arguments
x, q |
numeric vectors in the range [min, max] that specify
the quantiles.
|
p |
a numeric vector in the range [0, 1] that specifies the
probabilities.
|
n |
an integer in the range [0, Inf) that specifies the number of
random samples requested.
If the input value is not an integer, it is truncated.
If length(n) is greater than 1,
the random function returns length(n) random samples.
|
min |
a numeric vector in the range (-Inf, Inf) that specifies lower
limits. In the case of runif, min to max
is an open interval unless min = max. That is,
if min = 0 and max = 1, then no random numbers
will ever be exactly 0 or 1.
|
max |
a numeric vector in the range (-Inf, Inf) that specifies upper
limits, which are greater than or equal to lower limits
specified in min. In the case of runif,
min to max is an open interval unless min
= max. That is, if min = 0 and max = 1,
then no random numbers will ever be exactly 0 or
1.
|
log |
a logical value. If FALSE (default), the density
function returns the density itself. If TRUE, it
returns the log of the density.
|
lower.tail |
a logical value. If TRUE (default), the probability
supplied to the quantile function or returned by the
probability function is P[X <= x]. If FALSE, it
is P[X > x].
|
log.p |
a logical value. If FALSE (default), the probability
supplied to the quantile function or returned by the
probability function is the probability itself. If
TRUE, it is the log of the probability.
|
Details
The distribution parameter(s) are replicated cyclically to be the
same length as the input x, q, p, or the
number of random samples requested.
Missing values (NAs) in the input or the distribution
parameter(s) will cause the corresponding elements of the result
to be missing.
Value
returns returns density (dunif),
cumulative probability (punif),
quantile (qunif), or
random sample (runif)
for the uniform distribution with parameters min and max.
Side Effects
If the .Random.seed dataset exists, the random sample
function updates its value.
The random sample function creates the .Random.seed dataset
if it does not exist.
Background
The uniform distribution is a family of continuous probability
distributions defined on the interval [min, max] and
parameterized by two parameters, min and max.
The uniform (or rectangular) distribution takes values equally
likely from min to max. The uniform distribution has
several uses but it is commonly used to model round-off errors.
References
Johnson, N. L. and Kotz, S. (1970).
Continuous Univariate Distributions, vol. 2.
Houghton-Mifflin, Boston.
Differences between Spotfire Enterprise Runtime for R and Open-source R
- In open-source R, min = max is allowed for {p,q,r}unif but dunif(2, 2, 2) returns NaN and generates a warning.
- In Spotfire Enterprise Runtime for R, min = max is allowed for all {d,p,q,r}unif and dunif(2, 2, 2) returns Inf.
See Also
set.seed, To generate a uniform sample on integers or populations use
sample.
Examples
x <- 1:10
x + runif(x) # jitter the x data $
runif(100, -1, 1) # 100 numbers uniform on -1 to 1