From c0b3a3c94134b5754e45232049a72c76eb5c3121 Mon Sep 17 00:00:00 2001 From: Oskar Laverny Date: Mon, 19 Feb 2024 15:54:56 +0100 Subject: [PATCH] stash stuff out --- src/Generator/FrailtyGenerator.jl | 38 +++++++++++++++++++ .../WilliamsonFromFrailty.jl | 2 - 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/Generator/FrailtyGenerator.jl diff --git a/src/Generator/FrailtyGenerator.jl b/src/Generator/FrailtyGenerator.jl new file mode 100644 index 00000000..16b7bcd6 --- /dev/null +++ b/src/Generator/FrailtyGenerator.jl @@ -0,0 +1,38 @@ +""" + FrailtyGenerator{TX} + +Fields: +* `X::TX` -- a random variable that represents the frailty distribution. + +Constructor + + FrailtyGenerator(X::Distributions.UnivariateDistribution) + +The `FrailtyGenerator` allows to construct a completely monotonous archimedean generator from a positive random variable `X::Distributions.UnivariateDistribution`, assuming the distribution has a completely monotonous laplace transform (which will be used as the generator). + +References: +* [williamson1955multiply](@cite) Williamson, R. E. (1956). Multiply monotone functions and their Laplace transforms. Duke Math. J. 23 189–207. MR0077581 +* [mcneil2009](@cite) McNeil, Alexander J., and Johanna Nešlehová. "Multivariate Archimedean copulas, d-monotone functions and ℓ 1-norm symmetric distributions." (2009): 3059-3097. +* [mcneil2008](@cite) M +""" +struct FrailtyGenerator{TX} <: Generator + X::TX + function FrailtyGenerator(X) + # Check that the laplace transfrom is implemented ? + # it can be through `mgf`, `cgf = log(mgf)` or `cf`. + # the link is `mgf(t) = cf(- im * t)` + + # What we want here is that laplac tranfrom, that is `mgf(-t)` or thus `real(cf(im * t))`. + + # the only condition is that the support of the R.V is positive according to + + # Check that X is indeed a positively supported random variable ? + + # Other conditions ? We should do a thorough check here. + return new{typeof(X)}(X) + end +end +max_monotony(::FrailtyGenerator) = Inf +ϕ(G::FrailtyGenerator, t) = Distributions.mgf(G.X,t) +williamson_dist(G::FrailtyGenerator, d) = WilliamsonFromFrailty(G.X,d) + diff --git a/src/UnivariateDistribution/WilliamsonFromFrailty.jl b/src/UnivariateDistribution/WilliamsonFromFrailty.jl index 19288d7b..8f6dd838 100644 --- a/src/UnivariateDistribution/WilliamsonFromFrailty.jl +++ b/src/UnivariateDistribution/WilliamsonFromFrailty.jl @@ -10,14 +10,12 @@ function Distributions.rand(rng::Distributions.AbstractRNG, D::WilliamsonFromFra return sy/f end function Distributions.cdf(D::WilliamsonFromFrailty{TF,d}, x::Real) where {TF,d} - # how to compute this cdf ? return 1 - Distributions.expectation( e -> Distributions.cdf(D.frailty_dist,e/x), Distributions.Erlang(d) ) end function Distributions.pdf(D::WilliamsonFromFrailty{TF,d}, x::Real) where {TF,d} - # how to compute this cdf ? return 1/x^2 * Distributions.expectation( e -> Distributions.pdf(D.frailty_dist,e/x), Distributions.Erlang(d)