# How to plot a hazard function?

I would like to plot a hazard function when the CDF and PDF are not in the closed form. The PDF and CDF are given below

pdf[μ_, σ_, λ_, α_, β_] := ProbabilityDistribution[
(1/(E^(y^2/2)*(σ*Sqrt[2*Pi]*(α + 2))))*(2 + (α*Integrate[
1/(E^(u^2/2)*Sqrt[2*Pi])/E^(u^2/2)
, {u, -Infinity, λ*y + β*Sqrt[1 + λ^2]}])/Integrate[
E^(-(v^2/2))
, {v, -Infinity, β}
]
)
, {y, -Infinity, Infinity}
]


CDF has the form of

cdf[μ_, σ_, λ_, α_, β_] := (1/(E^(y^2/2)*(Sqrt[2*Pi]*(α + 2))))*(2 + α/2/((1/Sqrt[2*Pi])*Integrate[
E^(-(v^2/2))
, {v, -Infinity, β}
])) - ((α/(α + 2))*Integrate[
(1/(E^(u^2/2)*Sqrt[2*Pi]))*(1/(E^(v^2/2)*Sqrt[2*Pi]))
, {u, x, Infinity}
, {v, 0, λ*y + β*Sqrt[1 + λ^2]}])/ ((1/Sqrt[2*Pi])*Integrate[E^(-(v^2/2))
, {v, -Infinity, β}
]
)

• Next time ask: Did you give us enough to work on your problem? For which values for all these parameters do you want to plot? What is the problem you are facing? Why don you evaluate your integrals? For example Integrate[E^(-(v^2/2)), {v, -Infinity, β}] can be replaced with Sqrt[Pi/2] (1 + Erf[β/Sqrt[2]]) ? Jan 31, 2023 at 12:08

You need to use HazardFunction.

Do not confuse a PDF with a ProbabilityDistribution

pdf[μ_, σ_, λ_, α_, β_, y_] = FullSimplify[
(1/(E^(y^2/2)*(σ*Sqrt[2*Pi]*(α + 2))))*(2 + (α*Integrate[
1/(E^(u^2/2)*Sqrt[2*Pi])/E^(u^2/2)
, {u, -Infinity, λ*y + β*Sqrt[1 + λ^2]}])/Integrate[
E^(-(v^2/2))
, {v, -Infinity, β}
]
)
]


Build you Hazard Function nesting HazardFunction and ProbabilityDistribution on you PDF.

myHazard[μ_, σ_, λ_, α_, β_][z_?NumericQ] := N[
HazardFunction[
ProbabilityDistribution[
pdf[μ, σ, λ, α, β, y]
, {y, -Infinity, Infinity}
]
, z
]
]


Now you need to provide parameters and Evaluate your Plot

\$PlotTheme = {"Scientific", "VibrantColor", "BoldScheme", "LargeLabels"};
Plot[
Evaluate@Flatten@Table[
myHazard[μ, σ, λ, α, β][z]
, {μ, {1}}
, {σ, {1}}
, {λ, {-1, 1}}
, {α, {1}}
, {β, {-5}}
]
, {z, -10,50}
, PlotLegends-> Automatic
]


• NIntegrate[pdf[1, 1, 1, 1, -5, y], {y, -Infinity, Infinity}] does not equal 1. The pdf has not been normalized. Jan 31, 2023 at 15:04
• @BobHanlon Yeah, you are right I noticed, but that wasn't the core of the question, I think. There is no information about the parameters domain, some don't even appear on the expression. Jan 31, 2023 at 15:06
• That is one of the benefits of using ProbabilityDistribution, you can add Method -> "Normalize", e.g., dist = ProbabilityDistribution[pdf[\[Mu], \[Sigma], \[Lambda], \[Alpha], \[Beta], y], {y, -Infinity, Infinity}, Method -> "Normalize", Assumptions -> {\[Sigma] > 0, \[Alpha] > -2, {\[Beta], \[Lambda]} \[Element] Reals}] (although I am just guessing at the appropriate Assumptions on the parameters). The PDF is then PDF[dist, y] Jan 31, 2023 at 15:18
• @BobHanlon I think the OP should ponder about just forcing normalization or finding the error on his definition of a PDF that doesn't integrate into 1. I wouldn't just "fix" the PDF without further thought. Jan 31, 2023 at 15:22