The Uniform distribution is an absolute continuous probability distribution where all intervals of the same length within the distribution's support are equally probable. It is defined by two parameters: the lower bound \(a\) and the upper bound \(b\), with \(a < b\).
Usage
Unif(min = 0, max = 1)
# S4 method for class 'Unif,numeric'
d(distr, x, log = FALSE)
# S4 method for class 'Unif,numeric'
p(distr, q, lower.tail = TRUE, log.p = FALSE)
# S4 method for class 'Unif,numeric'
qn(distr, p, lower.tail = TRUE, log.p = FALSE)
# S4 method for class 'Unif,numeric'
r(distr, n)
# S4 method for class 'Unif'
mean(x)
# S4 method for class 'Unif'
median(x)
# S4 method for class 'Unif'
mode(x)
# S4 method for class 'Unif'
var(x)
# S4 method for class 'Unif'
sd(x)
# S4 method for class 'Unif'
skew(x)
# S4 method for class 'Unif'
kurt(x)
# S4 method for class 'Unif'
entro(x)
llunif(x, min, max)
# S4 method for class 'Unif,numeric'
ll(distr, x)
eunif(x, type = "mle", ...)
# S4 method for class 'Unif,numeric'
mle(distr, x, na.rm = FALSE)
# S4 method for class 'Unif,numeric'
me(distr, x, na.rm = FALSE)
Arguments
- min, max
numeric. The distribution parameters.
- distr
an object of class
Unif
.- x
For the density function,
x
is a numeric vector of quantiles. For the moments functions,x
is an object of classUnif
. For the log-likelihood and the estimation functions,x
is the sample of observations.- log, log.p
logical. Should the logarithm of the probability be returned?
- q
numeric. Vector of quantiles.
- lower.tail
logical. If TRUE (default), probabilities are \(P(X \leq x)\), otherwise \(P(X > x)\).
- p
numeric. Vector of probabilities.
- n
number of observations. If
length(n) > 1
, the length is taken to be the number required.- type
character, case ignored. The estimator type (mle or me).
- ...
extra arguments.
- na.rm
logical. Should the
NA
values be removed?
Value
Each type of function returns a different type of object:
Distribution Functions: When supplied with one argument (
distr
), thed()
,p()
,q()
,r()
,ll()
functions return the density, cumulative probability, quantile, random sample generator, and log-likelihood functions, respectively. When supplied with both arguments (distr
andx
), they evaluate the aforementioned functions directly.Moments: Returns a numeric, either vector or matrix depending on the moment and the distribution. The
moments()
function returns a list with all the available methods.Estimation: Returns a list, the estimators of the unknown parameters. Note that in distribution families like the binomial, multinomial, and negative binomial, the size is not returned, since it is considered known.
Variance: Returns a named matrix. The asymptotic covariance matrix of the estimator.
Details
The probability density function (PDF) of the Uniform distribution is: $$ f(x; a, b) = \frac{1}{b - a}, \quad a \le x \le b .$$
Examples
# -----------------------------------------------------
# Uniform Distribution Example
# -----------------------------------------------------
# Create the distribution
a <- 3 ; b <- 5
D <- Unif(a, b)
# ------------------
# dpqr Functions
# ------------------
d(D, c(0.3, 0.8, 0.5)) # density function
#> [1] 0 0 0
p(D, c(0.3, 0.8, 0.5)) # distribution function
#> [1] 0 0 0
qn(D, c(0.4, 0.8)) # inverse distribution function
#> [1] 3.8 4.6
x <- r(D, 100) # random generator function
# alternative way to use the function
df <- d(D) ; df(x) # df is a function itself
#> [1] 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5
#> [19] 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5
#> [37] 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5
#> [55] 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5
#> [73] 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5
#> [91] 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5
# ------------------
# Moments
# ------------------
mean(D) # Expectation
#> [1] 4
var(D) # Variance
#> [1] 0.3333333
sd(D) # Standard Deviation
#> [1] 0.5773503
skew(D) # Skewness
#> [1] 0
kurt(D) # Excess Kurtosis
#> [1] -1.2
entro(D) # Entropy
#> [1] 0.6931472
# List of all available moments
mom <- moments(D)
#> Warning: The mode is any element in the support (or its interior) of
#> a Uniform distribution. The mean is returned by default.
mom$mean # expectation
#> [1] 4
# ------------------
# Point Estimation
# ------------------
ll(D, x)
#> [1] -69.31472
llunif(x, a, b)
#> [1] -69.31472
eunif(x, type = "mle")
#> $min
#> [1] 3.025647
#>
#> $max
#> [1] 4.996425
#>
eunif(x, type = "me")
#> $min
#> [1] 2.9922
#>
#> $max
#> [1] 5.056657
#>
mle(D, x)
#> $min
#> [1] 3.025647
#>
#> $max
#> [1] 4.996425
#>
me(D, x)
#> $min
#> [1] 2.9922
#>
#> $max
#> [1] 5.056657
#>
e(D, x, type = "mle")
#> $min
#> [1] 3.025647
#>
#> $max
#> [1] 4.996425
#>
mle("unif", x) # the distr argument can be a character
#> $min
#> [1] 3.025647
#>
#> $max
#> [1] 4.996425
#>