Hello,
I was playing with the statistical routines in Math and I came across a behaviour that I am not sure is ok.
The portion of code "All samples with distinct values" fails only for 0 and 1.This is senseful because for the requested calculations at least 2 samples are requested.
Maybe putting a check in the method could slow down excessively on frequent repeated calls .
The portion of code "All samples with same value" fails periodically (btw in correspondence of powers of 2).This probably due to the fact that the samples are a fake distribution with no spreadness.
Is that the caller obeyed to make a preverification that the sample set is somehow spread to a minimum?program Project1;
uses
SysUtils, Math;
var
a: array of float;
Mean, StdDev: float;
m1, m2, m3, m4, Skewness, Kurtosis: float;
n, i: Integer;
begin
// All samples with same value
for n := 0 to 99 do
try
SetLength(a, n);
for i := 0 to n - 1 do a[i] := 9;
MeanAndStdDev(a, Mean, StdDev);
MomentSkewKurtosis(a, m1, m2, m3, m4, Skewness, Kurtosis);
Writeln(Format('%d done', [n]));
except
Writeln(Format('%d failed', [n]));
end;
// All samples with distinct values
for n := 0 to 99 do
try
SetLength(a, n);
for i := 0 to n - 1 do a[i] := 9 + i;
MeanAndStdDev(a, Mean, StdDev);
MomentSkewKurtosis(a, m1, m2, m3, m4, Skewness, Kurtosis);
Writeln(Format('%d done', [n]));
except
Writeln(Format('%d failed', [n]));
end;
end.