Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created January 30, 2023 16:33
Show Gist options
  • Save abikoushi/8cd73841bccae232f3799ff2c42bf41c to your computer and use it in GitHub Desktop.
Save abikoushi/8cd73841bccae232f3799ff2c42bf41c to your computer and use it in GitHub Desktop.
excess length distribution of log normal
using Distributions
using SpecialFunctions
using QuadGK
using Plots
function eqcdf(d::LogNormal, x)
mu, sigma = params(d)
return 0.5*(1+x*erfc((log(x) - mu)/(sigma*sqrt(2)))*exp(-(mu + (sigma^2)/2)) - erf((mu + sigma^2 - log(x))/(sigma*sqrt(2))))
end
function rmst(d::UnivariateDistribution, x::Real)
return mean(d)*eqcdf(d,x)
end
function genericeqcdf(y, d::UnivariateDistribution)
v,_ = quadgk(x -> ccdf(d,x),0,y)
return v/mean(d)
end
plot(x-> eqcdf(LogNormal(2.0,0.2),x),0,100,legend=false)
plot!(x-> genericeqcdf(x, LogNormal(2.0,0.2)),0,100,legend=false)
plot(x-> eqcdf(LogNormal(0,0.5),x),0,10,legend=false)
plot!(x-> genericeqcdf(x, LogNormal(0,0.5)),0,10,legend=false)
plot(x-> eqcdf(LogNormal(-1,1.5),x),0,100,legend=false)
plot!(x-> genericeqcdf(x, LogNormal(-1,1.5)),0,100,legend=false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment