Skip to contents

The Weibull distribution is an absolute continuous probability distribution, parameterized by a shape parameter \(k > 0\) and a scale parameter \(\lambda > 0\).

Usage

Weib(shape = 1, scale = 1)

# S4 method for class 'Weib,numeric'
d(distr, x, log = FALSE)

# S4 method for class 'Weib,numeric'
p(distr, q, lower.tail = TRUE, log.p = FALSE)

# S4 method for class 'Weib,numeric'
qn(distr, p, lower.tail = TRUE, log.p = FALSE)

# S4 method for class 'Weib,numeric'
r(distr, n)

# S4 method for class 'Weib'
mean(x)

# S4 method for class 'Weib'
median(x)

# S4 method for class 'Weib'
mode(x)

# S4 method for class 'Weib'
var(x)

# S4 method for class 'Weib'
sd(x)

# S4 method for class 'Weib'
skew(x)

# S4 method for class 'Weib'
kurt(x)

# S4 method for class 'Weib'
entro(x)

llweibull(x, shape, scale)

# S4 method for class 'Weib,numeric'
ll(distr, x)

eweibull(x, type = "mle", ...)

# S4 method for class 'Weib,numeric'
mle(
  distr,
  x,
  par0 = "lme",
  method = "L-BFGS-B",
  lower = 1e-05,
  upper = Inf,
  na.rm = FALSE
)

# S4 method for class 'Weib,numeric'
me(distr, x, par0 = "lme", lower = 0.5, upper = Inf, na.rm = FALSE)

Arguments

shape, scale

numeric. The non-negative distribution parameters.

distr

an object of class Weib.

x

For the density function, x is a numeric vector of quantiles. For the moments functions, x is an object of class Weib. 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, me or lme).

...

extra arguments.

par0, method, lower, upper

arguments passed to optim for the mle and me optimization. See Details.

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), the d(), 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 and x), 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 Weibull distribution is: $$ f(x; k, \lambda) = \frac{k}{\lambda}\left(\frac{x}{\lambda} \right)^{k - 1} \exp\left[-\left(\frac{x}{\lambda}\right)^k\right], \quad x \geq 0 .$$

For the parameter estimation, both the MLE and the ME cannot be explicitly derived. However, the L-moment estimator (type = "lme") is available, and is used as initialization for the numerical approximation of the MLE and the ME.

The MLE and ME of the Weibull distribution parameters is not available in closed form and has to be approximated numerically. The optimization can be performed on the shape parameter \(k\in(0,+\infty)\).

For the MLE, this is done with optim(). The default method used is the L-BFGS-B method with lower bound 1e-5 and upper bound Inf. The par0 argument can either be a numeric (satisfying lower <= par0 <= upper) or a character specifying the closed-form estimator to be used as initialization for the algorithm ("lme" - the default value).

For the ME, this is done with uniroot(). Again, the par0 argument can either be a numeric (satisfying lower <= par0 <= upper) or a character specifying the closed-form estimator to be used as initialization for the algorithm ("mle" or "lme" - the default value). The lower and upper bounds are set by default to 0.5 and Inf, respectively. Note that the ME equations involve the \(\Gamma(1 + 1 \ k)\), which can become unreliable for small values of k, hence the 0.5 lower bound. Specifying a lower bound below 0.5 will result in a warning and be ignored.

References

Kim, H. M., Jang, Y. H., Arnold, B. C., & Zhao, J. (2024). New efficient estimators for the Weibull distribution. Communications in Statistics-Theory and Methods, 53(13), 4576-4601.

See also

Functions from the stats package: dweibull(), pweibull(), qweibull(), rweibull()

Examples

# -----------------------------------------------------
# Weibull Distribution Example
# -----------------------------------------------------

# Create the distribution
a <- 3 ; b <- 5
D <- Weib(a, b)

# ------------------
# dpqr Functions
# ------------------

d(D, c(0.3, 2, 10)) # density function
#> [1] 0.0021595335 0.0900484800 0.0008051103
p(D, c(0.3, 2, 10)) # distribution function
#> [1] 0.0002159767 0.0619950005 0.9996645374
qn(D, c(0.4, 0.8)) # inverse distribution function
#> [1] 3.996939 5.859512
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.213216484 0.189095707 0.223099907 0.171570313 0.183506911 0.235044754
#>   [7] 0.230584643 0.176772122 0.230333687 0.207085245 0.167936595 0.198665143
#>  [13] 0.161516267 0.227530990 0.214915556 0.207129065 0.124968588 0.203969106
#>  [19] 0.200518032 0.056385202 0.209026726 0.218628586 0.228204805 0.233139174
#>  [25] 0.144983652 0.213969519 0.133126941 0.145349466 0.233569584 0.176998852
#>  [31] 0.233913242 0.233568640 0.011617491 0.183448743 0.141567297 0.191559224
#>  [37] 0.222189145 0.233343469 0.186499957 0.117952698 0.141628034 0.133815768
#>  [43] 0.156439565 0.219399362 0.234203286 0.209956745 0.190507331 0.165846503
#>  [49] 0.205451427 0.118625567 0.183711919 0.160501655 0.233070706 0.165627489
#>  [55] 0.048790685 0.226325065 0.076753493 0.190647485 0.045573016 0.231022590
#>  [61] 0.201478393 0.035674815 0.232670668 0.229377728 0.210088231 0.192001303
#>  [67] 0.234201175 0.217805481 0.235080104 0.002620994 0.234898813 0.185030856
#>  [73] 0.146714918 0.154330941 0.159883015 0.218050643 0.072927834 0.234298139
#>  [79] 0.234894547 0.089766721 0.146003765 0.219905987 0.231509449 0.160623031
#>  [85] 0.149186864 0.235034641 0.218020589 0.147624730 0.119072433 0.234959975
#>  [91] 0.170872230 0.170564649 0.122234950 0.217872452 0.101972743 0.094784734
#>  [97] 0.057743329 0.211975329 0.207145840 0.232091664

# ------------------
# Moments
# ------------------

mean(D) # Expectation
#> [1] 4.464898
median(D) # Median
#> [1] 4.424985
mode(D) # Mode
#> [1] 4.367902
var(D) # Variance
#> [1] 2.633322
sd(D) # Standard Deviation
#> [1] 1.622751
skew(D) # Skewness
#> [1] 0.1681028
kurt(D) # Excess Kurtosis
#> [1] -0.2705364
entro(D) # Entropy
#> [1] 4.844159

# List of all available moments
mom <- moments(D)
mom$mean # expectation
#> [1] 4.464898

# ------------------
# Point Estimation
# ------------------

ll(D, x)
#> [1] -183.4598
llweibull(x, a, b)
#> [1] -183.4598

eweibull(x, type = "mle")
#> $shape
#> [1] 3.231992
#> 
#> $scale
#> [1] 5.006414
#> 
eweibull(x, type = "me")
#> $shape
#> [1] 3.193606
#> 
#> $scale
#> [1] 4.972298
#> 
eweibull(x, type = "lme")
#> $shape
#> [1] 3.231992
#> 
#> $scale
#> [1] 4.969405
#> 

mle(D, x)
#> $shape
#> [1] 3.231992
#> 
#> $scale
#> [1] 5.006414
#> 
me(D, x)
#> $shape
#> [1] 3.193606
#> 
#> $scale
#> [1] 4.972298
#> 
e(D, x, type = "mle")
#> $shape
#> [1] 3.231992
#> 
#> $scale
#> [1] 5.006414
#> 

mle("weib", x) # the distr argument can be a character
#> $shape
#> [1] 3.231992
#> 
#> $scale
#> [1] 5.006414
#>