Code
using Distributions
using Random
using Plots
using StatsBase
using HazReg
The Power Generalised Weibull (PGW) distribution (Nikulin and Haghighi 2009) is a three-parameter distribution with support on \({\mathbb R}_+\). The corresponding hazard function can accommodate bathtub, unimodal and monotone (increasing and decreasing) hazard shapes. The PGW distribution has become popular in survival analysis given the tractability of its hazard and survival functions. Other flexible distributions that can account for these hazard shapes are discussed in Rubio et al. (2021) and Jones and Noufaily (2015).
The pdf of the PGW distribution is
\[f(t;\sigma,\nu,\gamma) = \dfrac{\nu}{\gamma \sigma^\nu}t^{\nu-1} \left[ 1 + \left(\dfrac{t}{\sigma}\right)^\nu\right]^{\left(\frac{1}{\gamma}-1\right)} \exp\left\{ 1- \left[ 1 + \left(\dfrac{t}{\sigma}\right)^\nu\right]^{\frac{1}{\gamma}} \right\},\]
where \(\sigma>0\) is a scale parameter, and \(\nu,\gamma >0\) are shape parameters.
The survival function of the PGW distribution is
\[S(t;\sigma,\nu,\gamma) = \exp\left\{ 1- \left[ 1 + \left(\dfrac{t}{\sigma}\right)^\nu\right]^{\frac{1}{\gamma}} \right\}.\]
The hazard function of the PGW distribution is
\[h(t;\sigma,\nu,\gamma) = \dfrac{\nu}{\gamma \sigma^\nu}t^{\nu-1} \left[ 1 + \left(\dfrac{t}{\sigma}\right)^\nu\right]^{\left(\frac{1}{\gamma}-1\right)}.\] The cdf can be obtained as \(F(t;\sigma,\nu,\gamma)=1-S(t;\sigma,\nu,\gamma)\), and the cumulative hazard function as \(H(t;\sigma,\nu,\gamma) = -\log S(t;\sigma,\nu,\gamma)\), as usual.
The quantile function of the PGW distribution is
\[Q(p;\sigma,\nu,\gamma) = \sigma \left[ \left( 1 - \log(1-p) \right)^{\gamma} - 1 \right]^{\frac{1}{\nu}},\]
where \(p\in(0,1)\).
The following Julia code shows the implementation of the pdf, survival function, hazard function, cumulative hazard function, quantile function, and random number generation associated to the PGW distribution using the 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 =#
= randPGW(1000, sigma0, nu0, gamma0); sim
#= Histogram and probability density function =#
histogram(sim, normalize=:pdf, color=:gray,
= range(0, 5, length=30), label = "")
bins plot!(t -> pdfPGW(t, sigma0, nu0, gamma0),
= "x", ylabel = "Density", title = "PGW distribution",
xlabel = (0,5), xticks = 0:1:5, 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
#= ad hoc CDF =#
function cdfPGW(t, sigma, nu, gamma)
= 1 .- ccdfPGW.(t, sigma, nu, gamma)
val return val
end
plot(x -> ecdfsim(x), 0, 5, label = "ECDF", linecolor = "gray", linewidth=3)
plot!(t -> cdfPGW(t, sigma0, nu0, gamma0),
= "x", ylabel = "CDF vs. ECDF", title = "PGW distribution",
xlabel = (0,5), xticks = 0:1:5, label = "CDF",
xlims = font(16, "Courier"), ytickfont = font(16, "Courier"),
xtickfont =18, yguidefontsize=18, linewidth=3,
xguidefontsize= "blue") linecolor
#= Hazard function =#
plot(t -> hPGW(t, 0.5, 2, 5),
= "x", ylabel = "Hazard", title = "PGW 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