Discussion of article "Statistical Distributions in MQL5 - taking the best of R" - page 18

 
Alexey Nikolaev:

Hello,
encountered a problem when calculating the quantile of gamma distribution
in R:
> qgamma(0.05,2,scale=1)
[1] 0.3553615
> qgamma(0.05,10,scale=1)
[1] 5.425406

in mql5:

Results:
0.3553615106986621
Error 4

build 1596

Changed calculation of quantiles of gamma distribution. Fixed version of Gamma.mqh in the appendix (replace in MQL5\Include\Math\Stat\).

Calculation result:

2017.11.06 21:03:56.580 TestExample (USDJPY,M5) 0.3553615106986623
2017.11.06 21:03:56.580 TestExample (USDJPY,M5) 5.425405697091294
Files:
Gamma.mqh  32 kb
 
The help page says MathProbabilityDensityGamma() instead of MathProbabilityDensityNoncentralBeta()
 
Aleksey Nikolayev:
The help page says MathProbabilityDensityGamma() instead of MathProbabilityDensityNoncentralBeta()

Thanks, corrected

 

CDF of hypergeometric distribution is incorrectly calculated by MathCumulativeDistributionHypergeometric() function. By definition, the probability distribution function must be defined for any real number. Below is a script on mql5 with its results and, for comparison, the same on R.

#include <Math\Stat\Hypergeometric.mqh>

input int nall=9;  // all
input int nsc=2;   // all success
input int nsm=8;   // sample size

void OnStart()
  { int er;
    double k[]={-1,0,0.5,1};
    for(int i=0; i<4; ++i)
      Print((string)k[i]+" "+(string)MathCumulativeDistributionHypergeometric(k[i],nall,nsc,nsm,er)+" "+(string)er);
  }

result:

-1.0 nan 2

0.0 0.0 0

0.5 nan 2

zero divide in 'Hypergeometric.mqh' (241,35)

nall <- 9 #  all
nsc <- 2  #  all success
nsm <- 8  #  sample size

k <- c(-1, 0, 0.5, 1)
phyper(k, nsc, nall-nsc, nsm)

result:

[1] 0.0000000 0.0000000 0.0000000 0.2222222

 
Aleksey Nikolayev:

The CDF of hypergeometric distribution is incorrectly calculated by MathCumulativeDistributionHypergeometric().

Thanks for the message, we will look into it.

 
There is a wish to add Kolmogorov distribution to the library. It is very useful because of its use in the Kolmogorov-Smirnov criterion and in the problem of searching for the discord of a random process.
 

If I haven't messed anything up, the MathQuickSort*() quick sort functions don't populate the index array of the original array:

#include <Math\Stat\Math.mqh>

void OnStart()
  { double a[]={1.5, 2.0, -1.0, 0.0};
    int na=ArraySize(a);
    int ix[]; ArrayResize(ix,na);
    for(int i=0; i<na; ++i) ix[i]=0;
    
    //MathQuickSort(a,ix,1,2,1);
    //MathQuickSort(a,ix,1,2,-1);
    MathQuickSortAscending(a,ix,1,2);
    //MathQuickSortDescending(a,ix,1,2);
    
    for(int i=0; i<na; ++i)
      Print((string)ix[i]+" "+(string)a[i]);
  }

result:

0 1.5

0 -1.0

0 2.0

0 0.0

 
Aleksey Nikolayev:

Unless I'm confused, the MathQuickSort*() quick sort functions don't populate the index array of the original array:

In our implementation, the index array itself is not filled, the index values have to be prepared by yourself before calling the sort:

    for(int i=0; i<na; ++i) ix[i]=i;

or

    for(int i=0; i<na; ++i) ix[i]=i+1;
if natural order is required.
 

Setslav

>>>The productwas hidden to draw your attention to it.

Plus, I can't find a button to publish a new product in the Market. Is it like this for everyone, or is it just me? How can I publish the MT5 version?

If a product is hidden by a moderator, the author cannot return it. This is logical

 

Some (not all) binomial coefficients are negative, for example:

#include <Math\Stat\Math.mqh>

void OnStart()
  { Print(MathBinomialCoefficient(62,28));
  }

result: -309196571788882235

should be: 349615716557887488