Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Computing Quantile in MATLAB

Is there any built-in function in MATLAB to compute

0.025th quantile of Binomial distribution with parameter n=60 and p=0.4

0.975 quantile of standard normal distribution ?

like image 780
user2983722 Avatar asked Jan 30 '26 10:01

user2983722


2 Answers

Do you have the Statistics toolbox? If yes,

>> binoinv(.025,60,.4)

ans =

    17

>> norminv(.975,0,1)

ans =

    1.9600

If not, you could use the following equivalences:

  • The inverse normal CDF can be expressed in terms of the erfinv function
  • The binomial CDF can be expressed in terms of the betainc function
like image 197
Luis Mendo Avatar answered Feb 01 '26 16:02

Luis Mendo


First, the accepted answer is correct and provides the direct, distribution-specific functions. However, there are more general functions that can do this for those needing a wider array of functions and probability distributions.

For those with the Stats toolbox, MATLAB introduced probability distribution objects in 2013 which provide very convenient ways to work with distributions and statistical functions.

One can use makedist() to create the distribution objects needed.

% MATLAB R2022a
% Parameters
n = 60;
p = 0.4;
mu = 0;
sigma = 1;

% X ~ Binomial(n,p)
pdX = makedist('Binomial','N',n,'p',p)

% Y ~ Normal(0,1)  
pdY = makedist('Normal','mu',mu,'sigma',sigma)

Remembering that the quantile function is the inverse cumulative distribution function, calling icdf() gets the job done.

x = icdf(pdX,0.025)    % x = 17

y = icdf(pdY,0.975)    % y = 1.9600
like image 38
SecretAgentMan Avatar answered Feb 01 '26 16:02

SecretAgentMan