Some hazard functions in Julia

Hazard and cumulative hazard functions

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:

Required packages

using Distributions
using Plots
using StatsBase
using HazReg

Examples

LogNormal

#= Hazard function =#
plot(t -> hLogNormal(t, 0.5, 1),
      xlabel = "x", ylabel = "Hazard", title = "LogNormal distribution",
    xlims = (0,10),   xticks = 0:1:10, label = "",
    xtickfont = font(16, "Courier"),  ytickfont = font(16, "Courier"),
    xguidefontsize=18, yguidefontsize=18, linewidth=3,
    linecolor = "blue")
Example block output
#= Cumulative Hazard function =#
plot(t -> chLogNormal(t, 0.5, 1),
      xlabel = "x", ylabel = "Cumulative Hazard", title = "LogNormal distribution",
    xlims = (0,10),   xticks = 0:1:10, label = "",
    xtickfont = font(16, "Courier"),  ytickfont = font(16, "Courier"),
    xguidefontsize=18, yguidefontsize=18, linewidth=3,
    linecolor = "blue")
Example block output

LogLogistic

#= Hazard function =#
plot(t -> hLogLogistic(t, 1, 0.5),
      xlabel = "x", ylabel = "Hazard", title = "LogLogistic distribution",
    xlims = (0,10),   xticks = 0:1:10, label = "",
    xtickfont = font(16, "Courier"),  ytickfont = font(16, "Courier"),
    xguidefontsize=18, yguidefontsize=18, linewidth=3,
    linecolor = "blue")
Example block output
#= Cumulative Hazard function =#
plot(t -> chLogLogistic(t, 1, 0.5),
      xlabel = "x", ylabel = "Cumulative Hazard", title = "LogLogistic distribution",
    xlims = (0,10),   xticks = 0:1:10, label = "",
    xtickfont = font(16, "Courier"),  ytickfont = font(16, "Courier"),
    xguidefontsize=18, yguidefontsize=18, linewidth=3,
    linecolor = "blue")
Example block output

Weibull

#= Weibull function =#
plot(t -> hWeibull(t, 3, 0.5),
      xlabel = "x", ylabel = "Hazard", title = "Weibull distribution",
    xlims = (0,10),   xticks = 0:1:10, label = "",
    xtickfont = font(16, "Courier"),  ytickfont = font(16, "Courier"),
    xguidefontsize=18, yguidefontsize=18, linewidth=3,
    linecolor = "blue")
Example block output
#= Cumulative Hazard function =#
plot(t -> chWeibull(t, 3, 0.5),
      xlabel = "x", ylabel = "Cumulative Hazard", title = "Weibull distribution",
    xlims = (0,10),   xticks = 0:1:10, label = "",
    xtickfont = font(16, "Courier"),  ytickfont = font(16, "Courier"),
    xguidefontsize=18, yguidefontsize=18, linewidth=3,
    linecolor = "blue")
Example block output

Gamma

#= Weibull function =#
plot(t -> hGamma(t, 3, 0.5),
      xlabel = "x", ylabel = "Hazard", title = "Gamma distribution",
    xlims = (0,10),   xticks = 0:1:10, label = "",
    xtickfont = font(16, "Courier"),  ytickfont = font(16, "Courier"),
    xguidefontsize=18, yguidefontsize=18, linewidth=3,
    linecolor = "blue")
Example block output
#= Cumulative Hazard function =#
plot(t -> chGamma(t, 3, 0.5),
      xlabel = "x", ylabel = "Cumulative Hazard", title = "Gamma distribution",
    xlims = (0,10),   xticks = 0:1:10, label = "",
    xtickfont = font(16, "Courier"),  ytickfont = font(16, "Courier"),
    xguidefontsize=18, yguidefontsize=18, linewidth=3,
    linecolor = "blue")
Example block output