File Exchange

image thumbnail


version 1.4 (4.83 KB) by

Pearson system probability distributions



View License

% pearspdf
% [p,type,coefs] = pearspdf(X,mu,sigma,skew,kurt)
% Returns the probability distribution denisty of the pearsons distribution
% with mean `mu`, standard deviation `sigma`, skewness `skew` and
% kurtosis `kurt`, evaluated at the values in X.
% Some combinations of moments are not valid for any random variable, and in
% particular, the kurtosis must be greater than the square of the skewness
% plus 1. The kurtosis of the normal distribution is defined to be 3.
% The seven distribution types in the Pearson system correspond to the
% following distributions:
% Type 0: Normal distribution
% Type 1: Four-parameter beta
% Type 2: Symmetric four-parameter beta
% Type 3: Three-parameter gamma
% Type 4: Not related to any standard distribution. Density proportional
% to (1+((x-a)/b)^2)^(-c) * exp(-d*arctan((x-a)/b)).
% Type 5: Inverse gamma location-scale
% Type 6: F location-scale
% Type 7: Student's t location-scale
% Examples
% See also
% pearspdf pearsrnd mean std skewness kurtosis

It's a modification of the pearsrnd function

Comments and Ratings (26)

is there an analytical way to find the value of the random variable (X) at peak of the pdf?

I am just curious. Numerically I can find the answer easily.
Thanks so much to the autors and the contributers :)


khoshi (view profile)

Dear all
I need to apply Pearson type 5 distribution
to number data following code includes all types how can i extract just type 5?

Pierce Brady

Hey guys,
I appreciate all the comments etc.
But i don't have the time to fix these corrections. Its open source so feel free to change it and reuse it yourself.

Carsten Allefeld has made some modifications that fix the normalisation problem. Except in the case of the type 5 distribution.

The sizeOut error has also been fixed.


Daryl (view profile)


Occasionally I get an error Undefined function or variable 'sizeOut'. I can't find this value or variable in the code. Can anyone help?

edit your file:

122: case 1
136: p = betapdf(X,m1+1,m2+1)/sigma;
137: p=p/55;

177: case 6
187: p = fpdf(X,nu1,nu2)/sigma;
188: p=p/3;


195: p = fpdf(X,nu1,nu2)/sigma;
196: p=p/3;

it is not correct, but plot norm PDF hold on Hist (ecdfhist)

and not correct for Pearson Type I
coefs = [1.2197 0.30669 -0.07322]

for m = {100,10,0.5,3};
not correct

Pierce Brady

add this at line 164

p = p/sigma;

just after
p = pearson4pdf(X,m,nu,a,lambda);

it seems the the pdfs are off by this factor

Ok, try your code for m = {0,10,0.5,5};

Pierce Brady

% You need to normalise the histogram properly
[Y,X] = hist(pearsrnd(m{:},100000,1),100)
dX = diff(X)
% Forgot to include this line
dX = dX(1)
hold on;

Try his code:
%m = {0,1,0,3}; %GOOD
%m = {100,1,1,5}; %GOOD
m = {100,10,1,5}; %BAD. WHY ?! same else scale....
[x,type, coefs] = pearsrnd(m{:},10000,1);
m2 = [mean(x) std(x) skewness(x) kurtosis(x)];
clf;[Y,X] = hist(pearsrnd(m{:},10000,1),100);
%dX = diff(X);
[Fxi,Xxi] = ecdf(x);
ecdfhist(Fxi,Xxi,100) %Norm hist
hold on;
title(['\bfType (', num2str(type), '), coefs: ',num2str(coefs)])

Thax for replay.
Same wrong, arrya size dX[99]<>Y[100]

May be this is true:
%dX = diff(X);
[Fxi,Xxi] = ecdf(x);
ecdfhist(Fxi,Xxi,100) %Norm hist
hold on;

Pierce Brady

m and m2 will be different. pearsrnd generates random numbers that follow the distribution.
if you generate more numbers the values will begin to match much better.
m = {0,1,0,3};%Norm Distrib
[x,type, coefs] = pearsrnd(m{:},100000,1);
m2 = [mean(x) std(x) skewness(x) kurtosis(x)]

% better

m = {0,1,0,3};%Norm Distrib
[x,type, coefs] = pearsrnd(m{:},100000000000000,1);
m2 = [mean(x) std(x) skewness(x) kurtosis(x)]
% Won't have a enough memory
% m and m2 should be very close if not the same

% As you you generate more and more numbers, the error
% between m and m2 will become smaller and smaller

% You need to normalise the histogram properly
[Y,X] = hist(pearsrnd(m{:},100000,1),100)
dX = diff(X)
hold on;

1: m = {mean(x),std(x),skewness(x),kurtosis(x)};
2:[r,type,coefs] = pearsrnd(m{:},10000,1);
3:hold on; [Fxi,Xxi] = ecdf(x);
5:Yxi=pearspdf(sort(x),m{:}); plot(sort(x),Yxi,'-y','LineWidth',1)

Hist genering by pearsrnd and plot of p(x) in same else scale, why ?
Where my bug ?

Q1: How plot p(x) (by pearspdf()) hold on Norm Hist(pearsrnd()) ?

m = {0,1,0,3};%Norm Distrib
[x,type, coefs] = pearsrnd(m{:},1000,1);
m2 = [mean(x) std(x) skewness(x) kurtosis(x)]
m2 =
-0.0404 1.0045 0.0485 3.1589

Why m <> m2 ?!

*** sigma=std(x)^2;

From Matlab help:
[r,type,coefs] = pearsrnd(mu,sigma,skew,kurt,m,n) returns the type of the specified distribution within the Pearson system.
(!) Set m and n to 0 to identify the distribution type without generating any random values.

[r,type,coefs] = pearsrnd(mu,sigma,skew,kurt,0,0)

ok. thanx

In string 57: p = NaN(sizeOut,outClass);

if (sigma < 0) || (beta2 <= beta1 + 1)
p = NaN(sizeOut,outClass);
type = NaN;
coefs = NaN(1,3,outClass);

Not define - sizeOut
May be have - sizeOut=size(X) ?

But type of Pearson Curve define from parameter Kapa:
1) Kapa=skew^2*(kurt+3)^2/(4*(4*kurt-3*skew^2)*(2*kurt-3*skew^2-6));
2) Kapa2= - (skew^2*(K+2)^2)/(16*(K+1));

Pierce Brady

you'll have to write them yourself so

can find pdf, cdf and inv-files for all distribution.

We have't its for pears.... ^( Onle pearspdf.m (your local file)

I want have pearcdf.m, pearsinv.m for using mle.m, adding Pearson for Maxumum Likehood estimation (MLE metod).

For example

Pierce Brady

I'm not sure where you can find pearsinv
this file is just a modifcation to the pearsrnd function.

but for the cdf
1. caculate the distribution using pearspdf
2. use cumsum on the result to obtain cdf
3. normalise by the total sum, to ensure limit is 0 to 1

a = cumsum(pearspdf(-3:.01:3,0,0,0,3))
b = sum(pearspdf(-3:.01:3,0,0,0,3))
cdf = a/b;

Where can i finf pearscdf.m, pearsinv.m files for Pearson Distribution ?
Mail me -


John Peterson

Thanks, I've been looking for this. Would it be possible to always have the probability sum to one? Or to create a pearscdf function?



Many thanks to Carsten Allefeld who has modified the code so that pdfs are normalised correctly.

The type 5 distribution is not normalised correctly, so a warning is thrown to indicate this.


Added the line at 164
p = p/sigma;

as the type 4 distributions where off by this factor

MATLAB Release
MATLAB 7.9 (R2009b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today