0
$\begingroup$

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, β}
      ]
)
$\endgroup$
1
  • $\begingroup$ 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]]) ? $\endgroup$
    – rhermans
    Jan 31, 2023 at 12:08

1 Answer 1

1
$\begingroup$

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, β}
            ]
    )
]

enter image description here

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
]

enter image description here

$\endgroup$
4
  • $\begingroup$ NIntegrate[pdf[1, 1, 1, 1, -5, y], {y, -Infinity, Infinity}] does not equal 1. The pdf has not been normalized. $\endgroup$
    – Bob Hanlon
    Jan 31, 2023 at 15:04
  • $\begingroup$ @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. $\endgroup$
    – rhermans
    Jan 31, 2023 at 15:06
  • 1
    $\begingroup$ 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] $\endgroup$
    – Bob Hanlon
    Jan 31, 2023 at 15:18
  • $\begingroup$ @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. $\endgroup$
    – rhermans
    Jan 31, 2023 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.