-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Inverse CDF of distributions #262
Comments
The normal InvCDF for FSharp.Stats/src/FSharp.Stats/Signal/QQPlot.fs Lines 91 to 92 in b74ecf2
I agree, we should add quantile functions as |
I've added an InvCDF member to all distributions by 3d6a220. // Testing FSharp.Stats
(Distributions.Continuous.Normal.InvCDF 0. 1. 0.5) //0. # Testing R
qnorm(0.5,0,1) # Testing Python
from scipy.stats import norm
norm.ppf(0.5, loc=0, scale=1)
While the deviation is small and just occurs at extreme values, it would be worth checking if the approximation presented in Wichura, “Algorithm AS 241: The Percentage Points of the Normal Distribution.”, 1988 should be implemented.
References |
I've implemented the quantile function of the normal distribution as described in Wichura et al.. Its accurate for |
Progress of adding InvCDF/quantile functions t continuous distributions
|
Many distributions have no closed form of the quantile function. Besides published approximations would be beneficial to add a member for each Distribution that approximates the correct x for a given p. The CDF is continuously increasing and therefore a root finding approach should work just fine. I propose the following: type MyDistribution =
static member PDF a b x = ...
static member CDF a b x = ...
static member InvCDF a b x = //possible no closed form exists
static member InvCDFApprox a b x accuracy =
///parameters: function (float -> float); accuracy (float); minimum (float); maximum (float); maxIterations
let tmp = Optimization.Bisection.tryFindRoot (fun x -> MyDistribution.CDF a b x - p) accuracy 0. 1. 1000
match tmp with
| Some x -> x
| None -> failwith "no InvCDF found to satisfy the given conditions" Drawbacks
To discuss:
|
Is your feature request related to a problem? Please describe.
Inverse CDFs are useful for calculating credible intervals for a given distribution, among other things.
Describe the solution you'd like
It would be great to have inverse CDFs for all distributions. But starting from normal distribution would be great.
The text was updated successfully, but these errors were encountered: