% 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
%
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.
% 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)
bar(X,Y/(sum(Y)*dX))
hold on;
plot(-6:0.01:6,pearspdf(-6:0.01:6,m{:}),'r')
Thax for replay.
Same wrong, arrya size dX[99]<>Y[100]
May be this is true:
%dX = diff(X);
%bar(X,(Y/(sum(Y)*dX)));
[Fxi,Xxi] = ecdf(x);
ecdfhist(Fxi,Xxi,100) %Norm hist
hold on;
plot(-6:0.01:6,pearspdf(-6:0.01:6,m{:}),'r');
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.
i.e.
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)
bar(X,Y/(sum(Y)*dX))
hold on;
plot(-6:0.01:6,pearspdf(-6:0.01:6,m{:}),'r')
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.
Example
x=x1,x2,....xn;
mu=mean(x);
sigma=std(x);
skew=skewness(x);
kurt=kurtosis(x);
[r,type,coefs] = pearsrnd(mu,sigma,skew,kurt,0,0)
if (sigma < 0) || (beta2 <= beta1 + 1)
p = NaN(sizeOut,outClass);
type = NaN;
coefs = NaN(1,3,outClass);
return
end
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));
or
2) Kapa2= - (skew^2*(K+2)^2)/(16*(K+1));
Hey,
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;