You've already forked lazarus-ccr
LazStats: Split output of LSMRUnit into several tabs. Better layout of the output.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7769 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -8,6 +8,9 @@ uses
|
||||
Classes, SysUtils, Dialogs,
|
||||
Globals, DictionaryUnit, FunctionsLib, DataProcs, MainUnit;
|
||||
|
||||
//type
|
||||
// TRegItem = (riMeanVarStdDev, riXTX);
|
||||
|
||||
procedure GridDotProd(col1, col2: integer; out Product: double; var Ngood: integer);
|
||||
|
||||
procedure GridXProd(NoSelected : integer;
|
||||
@ -27,7 +30,7 @@ procedure Correlations(NoSelected: integer; const Selected: IntDyneVec;
|
||||
procedure MatAxB(const A, B, C: DblDyneMat; BRows, BCols, CRows, CCols: Integer;
|
||||
out ErrorCode: boolean);
|
||||
|
||||
procedure MatTrn(var A, B: DblDyneMat; BRows, BCols: Integer);
|
||||
procedure MatTrn(var A: DblDyneMat; const B: DblDyneMat; BRows, BCols: Integer);
|
||||
|
||||
procedure nonsymroots(a : DblDyneMat; nv : integer;
|
||||
var nf : integer; c : real;
|
||||
@ -46,6 +49,7 @@ procedure EffectCode(GridCol, min, max : integer;
|
||||
VAR startcol : integer;
|
||||
VAR endcol : integer;
|
||||
VAR novectors : integer);
|
||||
|
||||
procedure MReg(NoIndep: integer; const IndepCols: IntDyneVec; DepCol: integer;
|
||||
const RowLabels: StrDyneVec;
|
||||
const Means, Variances, StdDevs, BWeights, BetaWeights, BStdErrs, Bttests, tProbs: DblDyneVec;
|
||||
@ -368,8 +372,8 @@ end; { of MATAxB }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
// transpose the b matrix and return it in a
|
||||
procedure MatTrn(var A, B: DblDyneMat; BRows, BCols : integer);
|
||||
// transpose the B matrix and return it in A
|
||||
procedure MatTrn(var A: DblDyneMat; const B: DblDyneMat; BRows, BCols : integer);
|
||||
var
|
||||
i, j: integer;
|
||||
begin
|
||||
@ -624,27 +628,27 @@ procedure MReg(NoIndep: integer; const IndepCols: IntDyneVec; DepCol: integer;
|
||||
PrintAll: boolean; AReport: TStrings);
|
||||
var
|
||||
i, j, N: integer;
|
||||
X: DblDyneMat;
|
||||
XT: DblDyneMat;
|
||||
XTX: DblDyneMat;
|
||||
XTY: DblDyneVec;
|
||||
Y: DblDyneVec;
|
||||
indx: IntDyneVec;
|
||||
ColLabels: StrDyneVec;
|
||||
X: DblDyneMat = nil;
|
||||
XT: DblDyneMat = nil;
|
||||
XTX: DblDyneMat = nil;
|
||||
XTY: DblDyneVec = nil;
|
||||
Y: DblDyneVec = nil;
|
||||
indx: IntDyneVec = nil;
|
||||
ColLabels: StrDyneVec = nil;
|
||||
F, Prob, VarY, SDY, MeanY: double;
|
||||
value, TOL, VIF, AdjR2: double;
|
||||
SSY, SSres, resvar, SSreg: double;
|
||||
title: string;
|
||||
deplabel: string;
|
||||
errcode: boolean;
|
||||
errcode: boolean = false;
|
||||
begin
|
||||
Assert(OS3MainFrm <> nil);
|
||||
|
||||
SetLength(X, NoCases+1, NoIndep+1); // augmented independent var. matrix
|
||||
SetLength(XT, NoIndep+1, NoCases); // transpose of independent var's
|
||||
SetLength(XTX, NoIndep+1, NoIndep+1); // product of transpose X times X
|
||||
SetLength(Y, NCases+1); // Y variable values
|
||||
SetLength(XTY, NoIndep+1); // X transpose times Y
|
||||
SetLength(X, NoCases+1, NoIndep+1); // augmented independent var. matrix
|
||||
SetLength(XT, NoIndep+1, NoCases); // transpose of independent var's
|
||||
SetLength(XTX, NoIndep+1, NoIndep+1); // product of (transpose X) times X
|
||||
SetLength(Y, NCases+1); // Y variable values
|
||||
SetLength(XTY, NoIndep+1); // (X transpose) times Y
|
||||
SetLength(indx, NoIndep+1);
|
||||
SetLength(ColLabels, NCases);
|
||||
|
||||
@ -706,9 +710,11 @@ begin
|
||||
VarY := VarY / (NCases - 1);
|
||||
SDY := sqrt(VarY);
|
||||
|
||||
AReport.Add('Variance Y: %10.3f', [VarY]);
|
||||
AReport.Add('SSY: %10.3f', [SSY]);
|
||||
AReport.Add('SDY: %10.3f', [SDY]);
|
||||
AReport.Add('Sum of Squares Y: %20.3f', [SSY]);
|
||||
AReport.Add('Variance Y: %20.3f', [VarY]);
|
||||
AReport.Add('Std. Deviation Y: %20.3f', [SDY]);
|
||||
AReport.Add('');
|
||||
AReport.Add(DIVIDER_SMALL);
|
||||
|
||||
// augment the matrix
|
||||
for i := 1 to NCases do
|
||||
@ -719,8 +725,11 @@ begin
|
||||
MatTrn(XT, X, NCases, NoIndep+1);
|
||||
if PrintAll then
|
||||
begin
|
||||
AReport.Add('');
|
||||
title := 'XT MATRIX';
|
||||
MatPrint(XT, NoIndep+1, NCases, title, RowLabels, ColLabels, NCases, AReport);
|
||||
AReport.Add(DIVIDER_SMALL);
|
||||
AReport.Add('');
|
||||
end;
|
||||
|
||||
// get product of the augmented X transpose times augmented X
|
||||
@ -729,6 +738,8 @@ begin
|
||||
begin
|
||||
title := 'XTX MATRIX';
|
||||
MatPrint(XTX, Noindep+1, NoIndep+1, title, RowLabels, RowLabels, NCases, AReport);
|
||||
AReport.Add(DIVIDER_SMALL);
|
||||
AReport.Add('');
|
||||
end;
|
||||
|
||||
//Get means, variances and standard deviations
|
||||
@ -747,8 +758,14 @@ begin
|
||||
if PrintAll then
|
||||
begin
|
||||
DynVectorPrint(Means, NoIndep+1, 'MEANS', RowLabels, NCases, AReport);
|
||||
AReport.Add(DIVIDER_SMALL);
|
||||
AReport.Add('');
|
||||
DynVectorPrint(Variances, NoIndep+1,'VARIANCES',RowLabels, NCases, AReport);
|
||||
DynVectorPrint(StdDevs, NoIndep+1, 'STD. DEV.S', RowLabels, NCases, AReport);
|
||||
AReport.Add(DIVIDER_SMALL);
|
||||
AReport.Add('');
|
||||
DynVectorPrint(StdDevs, NoIndep+1, 'STD. DEVs', RowLabels, NCases, AReport);
|
||||
AReport.Add(DIVIDER_SMALL);
|
||||
AReport.Add('');
|
||||
end;
|
||||
|
||||
// get product of the augmented X transpose matrix times the Y vector
|
||||
@ -756,14 +773,19 @@ begin
|
||||
for j := 0 to NCases-1 do
|
||||
XTY[i] := XTY[i] + (XT[i,j] * Y[j]);
|
||||
if PrintAll then
|
||||
begin
|
||||
DynVectorPrint(XTY, NoIndep+1, 'XTY VECTOR', RowLabels, NCases, AReport);
|
||||
AReport.Add(DIVIDER_SMALL);
|
||||
end;
|
||||
|
||||
// get inverse of the augmented cross products matrix among independent variables
|
||||
SVDInverse(XTX,N);
|
||||
if PrintAll then
|
||||
begin
|
||||
AReport.Add('');
|
||||
title := 'XTX MATRIX INVERSE';
|
||||
MatPrint(XTX, NoIndep+1, NoIndep+1, title, RowLabels, RowLabels, NCases, AReport);
|
||||
AReport.Add(DIVIDER);
|
||||
end;
|
||||
|
||||
// multiply augmented inverse matrix times the XTY vector
|
||||
@ -797,23 +819,24 @@ begin
|
||||
AdjR2 := 1.0 - (1.0 - R2) * (NCases - 1) / (NCases - N);
|
||||
if PrintAll then
|
||||
begin
|
||||
AReport.Add('');
|
||||
AReport.Add('Dependent variable: ' + deplabel);
|
||||
AReport.Add('');
|
||||
DynVectorPrint(BWeights, NoIndep+1, 'B WEIGHTS', RowLabels, NCases, AReport);
|
||||
AReport.Add('');
|
||||
AReport.Add(DIVIDER_SMALL);
|
||||
AReport.Add('');
|
||||
AReport.Add('Dependent variable: ' + deplabel);
|
||||
AReport.Add('');
|
||||
DynVectorPrint(BetaWeights, NoIndep, 'BETA WEIGHTS', RowLabels, NCases, AReport);
|
||||
AReport.Add('');
|
||||
AReport.Add(DIVIDER_SMALL);
|
||||
AReport.Add('');
|
||||
DynVectorPrint(BStdErrs, NoIndep+1, 'B STD.ERRORS', RowLabels, NCases, AReport);
|
||||
AReport.Add('');
|
||||
DynVectorPrint(Bttests, NoIndep+1, 'B t-test VALUES', RowLabels, NCases, AReport);
|
||||
AReport.Add('');
|
||||
DynVectorPrint(tprobs, NoIndep+1, 'B t VALUE PROBABILITIES', RowLabels, NCases, AReport);
|
||||
AReport.Add(DIVIDER);
|
||||
AReport.Add('');
|
||||
|
||||
AReport.Add('SSY: %10.2f', [SSY]);
|
||||
AReport.Add('SSreg: %10.2f', [SSreg]);
|
||||
AReport.Add('SSres: %10.2f', [SSres]);
|
||||
@ -829,6 +852,8 @@ begin
|
||||
//AReport.Add('Standard Error of Estimate = %8.2f', [stderrest]);
|
||||
end;
|
||||
|
||||
AReport.Add(DIVIDER_SMALL);
|
||||
AReport.Add('');
|
||||
RowLabels[N-1] := 'Intercept';
|
||||
AReport.Add(' Variable Beta B Std.Err. t prob VIF TOL');
|
||||
AReport.Add('---------- ---------- ---------- ---------- ---------- ---------- --------- ----------');
|
||||
|
Reference in New Issue
Block a user