const
{$IFDEF PAIDVERS}
SDLVersionInfo = 'statis_r1000_full';
IsLightEd = false;
{$ELSE}
SDLVersionInfo = 'statis_r1000_lighted';
IsLightEd = true;
{$ENDIF}
release = 1000;
type
ESDLStatisError = class(ESDLError); { exception type to indicate errors }
TSignifLevel = (Dot20, Dot15, Dot10, Dot05, Dot01);
TSignifLevelEx = (Dot001, Dot002, Dot005, Dot010, Dot020,
Dot050, Dot100, Dot200, Dot500);
TtTestVersion = (ttPaired, ttHomoScedastic, ttHeteroScedastic);
TRandGen = class (TComponent)
private
FLowBorder : double;
FHighBorder : double;
FResolution : integer;
FDistVec : array of double;
procedure SetResolution (res: integer);
function GetProbability (Idx: integer): double;
function GetRandNum: double;
function GetLambda (ix: integer): double;
procedure SetProbability (Idx: integer; Value: double);
public
constructor Create (AOwner: TComponent); override;
destructor Destroy; override;
property Lambda[ix: integer]: double read GetLambda;
procedure Normalize;
function Standardize: boolean;
procedure NormalDistri (m, s: double);
property Probability[ix: integer]: double
read GetProbability write SetProbability;
property Random: double read GetRandNum;
function IndexOfLambda (Lambda: double): integer;
procedure tDistri (df: integer);
procedure Chi2Distri (df: integer);
procedure FDistri (df1, df2: integer);
procedure UniformDistri;
procedure WeibullDistri (beta, eta: double);
published
property HighBorder: double read FHighBorder write FHighBorder;
property LowBorder: double read FLowBorder write FLowBorder;
property Resolution: integer read FResolution write SetResolution;
end;
TOnModelApplyRequestEvent = procedure (Sender: TObject; PercentDone: integer;
Predictors: TDoubleArray; var Response: TDoubleArray) of object;
TOnModelCreateRequestEvent = procedure (Sender: TObject; PercentDone: integer;
ObjectList: TIntArray; var Success: boolean) of object;
TCrossValidator = class(TComponent)
private
FTestSize : integer;
FPress : double;
FXMat : TMatrix; // pointer to external descriptor matrix (X)
FYMat : TMatrix; // pointer to external response matrix (Y)
FOnModelApplyRequest : TOnModelApplyRequestEvent;
FOnModelCreateRequest : TOnModelCreateRequestEvent;
FOnCheckAbort : TOnCheckAbortEvent;
procedure SetTestSize (size: integer);
public
constructor Create (AOwner: TComponent); override;
destructor Destroy; override;
function Execute: boolean;
property RMSEP: double read FPress;
published
property XMat: TMatrix read FXMat write FXMat;
property YMat: TMatrix read FYMat write FYMat;
property SizeTestSet: integer read FTestSize write SetTestSize;
property OnModelApplyRequest: TOnModelApplyRequestEvent
read FOnModelApplyRequest write FOnModelApplyRequest;
property OnModelCreateRequest: TOnModelCreateRequestEvent
read FOnModelCreateRequest write FOnModelCreateRequest;
property OnCheckAbort: TOnCheckAbortEvent
read FOnCheckAbort write FOnCheckAbort;
end;
TPLSSclMode = (scmCenter, scmStandardize);
{$IFDEF PAIDVERS}
TPLSModel = class(TComponent)
private
FScoreX : TMatrix;
FScoreY : TMatrix;
FLoadX : TMatrix;
FLoadY : TMatrix;
FWgtX : TMatrix;
FOrthoLd : TMatrix;
FVarX : TVector;
FVarY : TVector;
FXMat : TMatrix;
FYMat : TMatrix;
FNFact : integer;
FRegCoeffs : TMatrix;
FXNames : array of TDTNameStr; // names of predictors
FYNames : array of TDTNameStr; // names of response variables
FScalMod : TPLSSclMode;
FOnPercentDone : TOnPercentDoneEvent;
FOnCheckCVDAbort: TOnCheckAbortEvent;
function GetPredName (ix: integer): string;
procedure SetPredName (ix: integer; value: string);
function GetRespoName (ix: integer): string;
procedure SetRespoName (ix: integer; value: string);
procedure CVDModelApplyRequest(Sender: TObject; PercentDone: integer;
Predictors: TDoubleArray; var Response: TDoubleArray);
procedure CVDModelCreateRequest(Sender: TObject; PercentDone: integer;
ObjectList: TIntArray; var Success: Boolean);
procedure CVDModelCheckAbort (Sender: TObject; var AbortProcess: boolean);
procedure SetNFactors (nfac: integer);
procedure PercDone (Sender: TObject; Percent: longint);
public
constructor Create (AOwner: TComponent); override;
destructor Destroy; override;
property ScoreX: TMatrix read FScoreX;
property ScoreY: TMatrix read FScoreY;
function LoadModelCoefficients (FileName: string;
var Comment: string): integer;
property LoadX: TMatrix read FLoadX;
property LoadY: TMatrix read FLoadY;
property NamePredictor[ix: integer]: string
read GetPredName write SetPredName;
property NameResponse[ix: integer]: string
read GetRespoName write SetRespoName;
property OrthoLd: TMatrix read FOrthoLd;
property WgtX: TMatrix read FWgtX;
property VarX: TVector read FVarX;
property VarY: TVector read FVarY;
property RegCoeff: TMatrix read FRegCoeffs;
procedure SaveModelCoefficients (FileName, Comment: string);
property XMat: TMatrix read FXMat write FYMat;
property YMat: TMatrix read FYMat write FYMat;
procedure CalculateModel;
function MaxFactors: integer;
procedure Predict (XData: TDoubleArray; var YHat: TDoubleArray); overload;
procedure Predict (XData: TMatrix; var YHat: TMatrix); overload;
function CrossValidateModel (SizeTestSet: integer): double;
published
property Factors: integer read FNFact write SetNFactors;
property ScalingMode: TPLSSclMode read FScalMod write FScalMod;
property OnCheckCVDAbort: TOnCheckAbortEvent
read FOnCheckCVDAbort write FOnCheckCVDAbort;
property OnPercentDone: TOnPercentDoneEvent
read FOnPercentDone write FOnPercentDone;
end;
{$ENDIF}
const
NumericSigLevel : array[TSignifLevelEx] of double = (0.001, 0.002, 0.005, 0.010,
0.020, 0.050, 0.100, 0.200, 0.500);
function BinomCoeff
(n : integer; { total number of elements }
k : integer) { number of drawn elements }
: longint; { binomial coefficient }
function CalcFishQ
(m1,m2, { mean values, class 1 & 2 }
s1,s2 : double) { standard deviations }
: double; { Fisher ratio }
function Chi2DistriDensity
(chi2 : double; { chi square quantile }
df : integer) { degrees of freedom }
: double; { density of chi square distribution }
function chi2DistriIntegral
(chi2 : double; { chi square quantile }
df : integer) { degrees of freedom }
: double; { probability }
function chi2DistriQuantile
(p : double; { probability }
df : integer) { degrees of freedom }
: double; { quantile of chi2-distribution }
function ConfidenceInterval
(alpha : double; { level of significance }
StdDev : double; { standard deviation }
NumData : integer) { sample size }
: double; { confidence interval }
function DeanDixonCriticalValues
(NData : integer; { number of data }
SigLevel : TSignifLevelEx) { level of significance }
: double; { critical value }
function DeanDixonTest
(Data : TVector; { data to be tested }
SigLevel : TSignifLevelEx; { level of significance }
var Statistic : double) { test statistic }
: integer; { index of outlier }
function Erf
(x : double) { parameters }
: double; { function result }
function ErfApprox
(x : double) { parameters }
: double; { function result }
procedure EstimateProbDensity
(const SampleData : TVector; { sample data }
var Probability : TVector; { resulting prob. density }
LowBorder, { lower border of estimation }
HighBorder, { upper border of estimation }
Smoothing : double; { width of the Gaussian kernel }
WindowWidth : double; { width of local density estimation }
Resolution : integer; { resolution of the prob. density }
var MinDensIx, { minium density }
MaxDensIx : integer; { maximum density }
Feedback : TFeedbackProc); { feedback routine }
function FDistriDensity
(F : double; { F quantile }
df1, df2 : integer) { degrees of freedom }
: double; { density of F distribution }
function FDistriIntegral
(F : double; { F quantile }
df1 : integer; { degrees of freedom }
df2 : integer) { degrees of freedom }
: double; { probability }
function FDistriQuantile
(p : double; { probability }
df1 : integer; { degrees of freedom }
df2 : integer) { degrees of freedom }
: double; { quantile }
function FisherTransform
(x : double) { argument }
: double; { Fisher's transform }
function FisherTransformInv
(x : double) { argument }
: double; { inverse Fisher transform }
function GrubbsCriticalValues
(NData : integer; { number of data points }
alpha : double; { level of significance }
twosided : boolean) { TRUE: two-sided test }
: double; { critical value for 2-sided Grubbs test }
function GrubbsTest
(Data : TVector; { data to be tested }
SigLevel : double; { level of significance }
var Statistic : double) { test statistic }
: integer; { index of outlier }
function HyperGeoDistriDensity
(p : double; { probability of interesting cases }
npop : integer; { total number of cases }
nsample : integer; { no. of samples drawn }
k : integer) { no. of interesting cases to be expected }
: double; { probab. to observe exactly k interesting cases }
function IncompleteBeta
(x : double; { quantile }
a, b : double) { parameters }
: double; { function result }
function IncompleteGamma
(x, a : double): { parameters }
double; { function result }
function KolmogSmir1SampleTestStat
(SampleSize : integer; { size of sample to be tested }
alpha : TSignifLevel) { level of significance }
: double; { critical KS value }
function LnBeta
(z,w : double) { arguments of beta function }
: double; { Beta(z,w) }
function LnBinomCoeff
(n : integer; { total number of elements }
k : integer) { number of drawn elements }
: double; { logarithm of binomial coefficient }
function LnGamma
(x : double) { argument of gamma function }
: double; { ln(gamma(x)) }
function nDistriDensity
(u : double) { critical value }
: double; { density of normal distribution }
function nDistriIntegral
(u : double) { argument }
: double; {integral of norm.dens.funct.}
function nDistriQuantile
(p : double) { probability }
: double; { normal distribution }
function Perform2SampleTTest
(Data1, Data2 : TVector; { data points of the two samples }
TestType : TtTestVersion; { kind of t-test to be performed }
OneSided : boolean) { TRUE: one sided probability }
: double; overload; { probability }
function Perform2SampleTTest
(Data1, Data2 : TVector; { data points of the two samples }
TestType : TtTestVersion; { kind of t-test to be performed }
OneSided : boolean; { TRUE: one sided probability }
var Mean1, Mean2, { means of the two samples }
Stdv1, Stdv2, { standard deviations of the two samples }
MeanDiff, { mean of difference of sample pairs }
StdDiff, { standard deviation of difference of sample pairs }
tStatistic : double; { t-statistic }
var df : integer) { degrees of freedom }
: double; overload; { probability }
function PerformMannWhitneyUTest
(Data1, Data2 : TVector; { data points of the two samples }
OneSided : boolean; { TRUE: one sided probability }
var UStatistic : double) { U-statistic }
: double; { probability }
function tDistriDensity
(t : double; { t value }
df : integer) { degrees of freedom }
: double; { density of t distribution }
function tDistriIntegral
(t : double; { t value }
df : integer) { degrees of freedom }
: double; { probability }
function tDistriQuantile
(p : double; { probability }
df : integer) { degrees of freedom }
: double; { quantile of t-distribution }
function UDistriDensity
(U : integer; { U statistic }
M, N : integer) { number of data of each distribution }
: double; { density of the U distribution }
function UDistriIntegral
(U : integer; { U statistic }
M, N : integer) { number of data of each distribution }
: double; { probability }
function UDistriQuantile
(m, n : integer; { number of data of each distribution }
prob : double) { probability }
: integer; { quantile of U-distribution }
function WeibullDensity
(x : double; { argument }
beta : double; { parameters of Weibull distribution }
eta : double)
: double; { density }
|