function x = beta_inv(p, a, b)
% PURPOSE: inverse of the cdf (quantile) of the beta(a,b) distribution
%————————————————————–
% USAGE: x = beta_inv(p,a,b)
Copyright By PowCoder代写 加微信 powcoder
% where: p = vector of probabilities
% a = beta distribution parameter, a = scalar
% b = beta distribution parameter b = scalar
% NOTE: mean [beta(a,b)] = a/(a+b), variance = ab/((a+b)*(a+b)*(a+b+1))
%————————————————————–
% RETURNS: x at each element of p for the beta(a,b) distribution
%————————————————————–
% SEE ALSO: beta_d, beta_pdf, beta_inv, beta_rnd
%————————————————————–
% , 18-11-93
% Copyright (c)
% documentation modified by LeSage to
% match the format of the econometrics toolbox
if (nargin ~= 3)
error(‘Wrong # of arguments to beta_inv’);
if any(any((a<=0)|(b<=0)))
error('beta_inv parameter a or b is nonpositive');
if any(any(abs(2*p-1)>1))
error(‘beta_inv: A probability should be 0<=p<=1');
x = a ./ (a+b);
while any(any(abs(dx)>256*eps*max(x,1)))
dx = (betainc(x,a,b) – p) ./ beta_pdf(x,a,b);
x = x – dx;
x = x + (dx – x) / 2 .* (x<0);
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com