[Stable]

Generalization of the gamma distribution. Often used in survival and time-to-event analyses.

dist_weibull(shape, scale)

Arguments

shape, scale

shape and scale parameters, the latter defaulting to 1.

Details

We recommend reading this documentation on pkgdown which renders math nicely. https://pkg.mitchelloharawild.com/distributional/reference/dist_weibull.html

In the following, let \(X\) be a Weibull random variable with shape parameter shape = \(k\) and scale parameter scale = \(\lambda\).

Support: \([0, \infty)\)

Mean:

$$ E(X) = \lambda \Gamma\left(1 + \frac{1}{k}\right) $$

where \(\Gamma\) is the gamma function.

Variance:

$$ \text{Var}(X) = \lambda^2 \left[\Gamma\left(1 + \frac{2}{k}\right) - \left(\Gamma\left(1 + \frac{1}{k}\right)\right)^2\right] $$

Probability density function (p.d.f):

$$ f(x) = \frac{k}{\lambda}\left(\frac{x}{\lambda}\right)^{k-1}e^{-(x/\lambda)^k}, \quad x \ge 0 $$

Cumulative distribution function (c.d.f):

$$ F(x) = 1 - e^{-(x/\lambda)^k}, \quad x \ge 0 $$

Moment generating function (m.g.f):

$$ E(e^{tX}) = \sum_{n=0}^\infty \frac{t^n\lambda^n}{n!} \Gamma\left(1+\frac{n}{k}\right) $$

Skewness:

$$ \gamma_1 = \frac{\mu^3 - 3\mu\sigma^2 - \mu^3}{\sigma^3} $$

where \(\mu = E(X)\), \(\sigma^2 = \text{Var}(X)\), and the third raw moment is

$$ \mu^3 = \lambda^3 \Gamma\left(1 + \frac{3}{k}\right) $$

Excess Kurtosis:

$$ \gamma_2 = \frac{\mu^4 - 4\gamma_1\mu\sigma^3 - 6\mu^2\sigma^2 - \mu^4}{\sigma^4} - 3 $$

where the fourth raw moment is

$$ \mu^4 = \lambda^4 \Gamma\left(1 + \frac{4}{k}\right) $$

See also

Examples

dist <- dist_weibull(shape = c(0.5, 1, 1.5, 5), scale = rep(1, 4))

dist
#> <distribution[4]>
#> [1] Weibull(0.5, 1) Weibull(1, 1)   Weibull(1.5, 1) Weibull(5, 1)  
mean(dist)
#> [1] 2.0000000 1.0000000 0.9027453 0.9181687
variance(dist)
#> [1] 20.00000000  1.00000000  0.37569028  0.04422998
skewness(dist)
#> [1]  6.6187612  2.0000000  1.0719866 -0.2541096
kurtosis(dist)
#> [1] 84.7200000  6.0000000  1.3904036 -0.1197099

generate(dist, 10)
#> [[1]]
#>  [1] 1.12985326 2.79840475 0.82237508 2.28172454 0.08071613 0.15435895
#>  [7] 0.04662277 2.03797278 0.52734513 3.11475146
#> 
#> [[2]]
#>  [1] 0.21724873 1.94406276 2.09893558 1.67297842 0.47080664 0.29018893
#>  [7] 2.18420845 3.94555377 0.57654543 0.04616827
#> 
#> [[3]]
#>  [1] 1.3896612 0.9017225 1.0083867 0.5520320 1.1774084 1.2346541 1.3792851
#>  [8] 1.2343888 0.4730064 0.7167316
#> 
#> [[4]]
#>  [1] 0.7811030 0.7172108 0.6794230 1.1696433 1.1575174 0.9394019 1.0234917
#>  [8] 0.9699172 0.4173383 0.7891443
#> 

density(dist, 2)
#> [1] 8.595475e-02 1.353353e-01 1.253822e-01 1.013133e-12
density(dist, 2, log = TRUE)
#> [1]  -2.453934  -2.000000  -2.076388 -27.617973

cdf(dist, 4)
#> [1] 0.8646647 0.9816844 0.9996645 1.0000000

quantile(dist, 0.7)
#> [1] 1.449551 1.203973 1.131734 1.037823