icdf versus erfinv?
Show older comments
What is the difference between using the icdf function and the erfinv function to compute the inverse CDF for a normal distribution? Consisder the example below. When I choose a value for p in the 'heart' of the distribution (e.g., p = 0.2) or in the upper tail (e.g., p = 1 - 1e-9), then the difference between x1 and x2 is zero. However when I choose a value for p close to zero, as shown in the example, there is a non-zero difference between x1 and x2. Which of these two computations is more accurate, and why?
% Mean and standard deviation of a normal distribution
mu = 3.0;
sig = 1.5;
% Quantile for which we want to find the associated value of x
p = 1e-9;
% Use the icdf function to determing x at p
x1 = icdf('Normal',p,mu,sig);
% Now define an anonymous function to perform the same computation, using the erfinv function
myinversefun = @(p,m,s) (s*sqrt(2))*erfinv(2*p-1) + m;
x2 = myinversefun(p,mu,sig);
% Print the difference in results in exponential format
fprintf('difference = %16.9e\n',x1-x2);
Accepted Answer
More Answers (0)
Categories
Find more on Special Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!