Code
using Distributions
using Plots
using StatsBase
using HazReg
The hazard and the cumulative hazard functions play a crucial role in survival analysis. These functions define the likelihood function in the presence of censored observations. Thus, they are important in many context. For more information about these functions, see Short course on Parametric Survival Analysis.
This tutorial contains the implementation of the hazard and cumulative hazard functions for some popular distributions using the Julia package HazReg.jl
, such as the LogNormal, LogLogistic, Weibull, and Gamma distributions.
The Julia implementation of other, less common, distributions that are of interest in survival analysis can be found in the Julia package HazReg.jl
: HazReg.jl
.
See also:
using Distributions
using Plots
using StatsBase
using HazReg
#= Hazard function =#
plot(t -> hLogNormal(t, 0.5, 1),
= "x", ylabel = "Hazard", title = "LogNormal 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
#= Cumulative Hazard function =#
plot(t -> chLogNormal(t, 0.5, 1),
= "x", ylabel = "Cumulative Hazard", title = "LogNormal 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
#= Hazard function =#
plot(t -> hLogLogistic(t, 1, 0.5),
= "x", ylabel = "Hazard", title = "LogLogistic 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
#= Cumulative Hazard function =#
plot(t -> chLogLogistic(t, 1, 0.5),
= "x", ylabel = "Cumulative Hazard", title = "LogLogistic 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
#= Weibull function =#
plot(t -> hWeibull(t, 3, 0.5),
= "x", ylabel = "Hazard", title = "Weibull 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
#= Cumulative Hazard function =#
plot(t -> chWeibull(t, 3, 0.5),
= "x", ylabel = "Cumulative Hazard", title = "Weibull 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
#= Weibull function =#
plot(t -> hGamma(t, 3, 0.5),
= "x", ylabel = "Hazard", title = "Gamma 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
#= Cumulative Hazard function =#
plot(t -> chGamma(t, 3, 0.5),
= "x", ylabel = "Cumulative Hazard", title = "Gamma 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