Code
using Distributions
using Random
using Plots
using StatsBase
using HazReg
The Exponentiated Weibull distribution is a generalisation of the Weibull distribution which is obtained by exponentiating the Weibull cumulative distribution function. This simple transformation adds a second shape parameter that, interestingly, induces a lot of flexibility on the hazard function. The hazard function of the Exponentiated Weibull distribution can capture the basic shapes: constant, increasing, decreasing, bathtub, and unimodal, making it appealing for survival models.
The probability density function and cumulative distribution function of the Exponentiated Weibull distribution are respectively given by:
\[ \begin{split} f_{EW}(t) &= \alpha \dfrac{\kappa}{\lambda} \left(\dfrac{t}{\lambda}\right)^{\kappa-1} \left[1-\exp\left\{-\left(\dfrac{t}{\lambda}\right)^{\kappa}\right\}\right]^{\alpha-1} \exp\left\{-\left(\dfrac{t}{\lambda}\right)^{\kappa}\right\}, \\ F_{EW}(t) &= \left[1-\exp\left\{-\left(\dfrac{t}{\lambda}\right)^{\kappa}\right\}\right]^{\alpha}, \end{split} \]
where \(t>0\), \(\alpha>0\), \(\lambda>0\), and \(\kappa>0\). The parameter \(\lambda\) is a scale parameter, \(\kappa\) is a shape parameter, and \(\alpha\) is the power (shape) parameter.
The following Julia code contains an implementation of the probability density function, cumulative distribution function, quantile function, random number generation, hazard function, and cumulative hazard function of the Exponentiated Weibull distribution using the corresponding Julia package HazReg.jl
. Some illustrative examples are also presented.
See also:
using Distributions
using Random
using Plots
using StatsBase
using HazReg
#= Fix the seed =#
Random.seed!(123)
#= True values of the parameters =#
= 1
sigma0 = 3
nu0 = 2
gamma0 #= Simulation =#
= randEW(1000, sigma0, nu0, gamma0); sim
#= Histogram and probability density function =#
histogram(sim, normalize=:pdf, color=:gray,
= range(0, 3, length=30), label = "")
bins plot!(t -> pdfEW(t, sigma0, nu0, gamma0),
= "x", ylabel = "Density", title = "EW distribution",
xlabel = (0,3), xticks = 0:1:3, label = "",
xlims = font(16, "Courier"), ytickfont = font(16, "Courier"),
xtickfont =18, yguidefontsize=18, linewidth=3,
xguidefontsize= "blue") linecolor
#= Empirical CDF and CDF =#
#= Empirical CDF=#
= ecdf(sim)
ecdfsim
plot(x -> ecdfsim(x), 0, 3, label = "ECDF", linecolor = "gray", linewidth=3)
plot!(t -> cdfEW(t, sigma0, nu0, gamma0),
= "x", ylabel = "CDF vs. ECDF", title = "EW distribution",
xlabel = (0,3), xticks = 0:1:3, label = "CDF",
xlims = font(16, "Courier"), ytickfont = font(16, "Courier"),
xtickfont =18, yguidefontsize=18, linewidth=3,
xguidefontsize= "blue") linecolor
#= Hazard function =#
plot(t -> hEW(t, 0.25, 0.5, 5),
= "x", ylabel = "Hazard", title = "EW distribution",
xlabel = (0,10), xticks = 0:1:10, label = "",
xlims = font(16, "Courier"), ytickfont = font(16, "Courier"),
xtickfont =18, yguidefontsize=18, linewidth=3,
xguidefontsize= "blue") linecolor