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:
@ -127,9 +127,9 @@ inherited LSMregForm: TLSMregForm
|
|||||||
Left = 0
|
Left = 0
|
||||||
Height = 15
|
Height = 15
|
||||||
Top = 232
|
Top = 232
|
||||||
Width = 163
|
Width = 192
|
||||||
BorderSpacing.Right = 8
|
BorderSpacing.Right = 8
|
||||||
Caption = 'Minimum Prob. to enter block:'
|
Caption = 'Minimum probability to enter block:'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
end
|
end
|
||||||
object OptionsGroup: TGroupBox[12]
|
object OptionsGroup: TGroupBox[12]
|
||||||
@ -194,7 +194,7 @@ inherited LSMregForm: TLSMregForm
|
|||||||
Caption = 'Show Variances'
|
Caption = 'Show Variances'
|
||||||
TabOrder = 4
|
TabOrder = 4
|
||||||
end
|
end
|
||||||
object SDChkBox: TCheckBox
|
object StdDevChkBox: TCheckBox
|
||||||
Left = 190
|
Left = 190
|
||||||
Height = 19
|
Height = 19
|
||||||
Top = 48
|
Top = 48
|
||||||
@ -295,7 +295,7 @@ inherited LSMregForm: TLSMregForm
|
|||||||
AnchorSideLeft.Side = asrBottom
|
AnchorSideLeft.Side = asrBottom
|
||||||
AnchorSideRight.Side = asrBottom
|
AnchorSideRight.Side = asrBottom
|
||||||
AnchorSideBottom.Control = OptionsGroup
|
AnchorSideBottom.Control = OptionsGroup
|
||||||
Left = 171
|
Left = 200
|
||||||
Height = 23
|
Height = 23
|
||||||
Top = 228
|
Top = 228
|
||||||
Width = 50
|
Width = 50
|
||||||
@ -326,7 +326,36 @@ inherited LSMregForm: TLSMregForm
|
|||||||
Left = 413
|
Left = 413
|
||||||
Height = 430
|
Height = 430
|
||||||
end
|
end
|
||||||
object SaveDialog: TSaveDialog[2]
|
object PageControl: TPageControl[2]
|
||||||
|
Left = 422
|
||||||
|
Height = 414
|
||||||
|
Top = 8
|
||||||
|
Width = 580
|
||||||
|
ActivePage = MeanVarStddevPage
|
||||||
|
Align = alClient
|
||||||
|
BorderSpacing.Left = 4
|
||||||
|
BorderSpacing.Top = 8
|
||||||
|
BorderSpacing.Right = 8
|
||||||
|
BorderSpacing.Bottom = 8
|
||||||
|
TabIndex = 4
|
||||||
|
TabOrder = 2
|
||||||
|
object RegressionPage: TTabSheet
|
||||||
|
Caption = 'Regression'
|
||||||
|
end
|
||||||
|
object CrossProductsPage: TTabSheet
|
||||||
|
Caption = 'Cross-Products Matrix'
|
||||||
|
end
|
||||||
|
object VarCovarPage: TTabSheet
|
||||||
|
Caption = 'Variance-Covariance'
|
||||||
|
end
|
||||||
|
object CorrelationsPage: TTabSheet
|
||||||
|
Caption = 'Correlations'
|
||||||
|
end
|
||||||
|
object MeanVarStddevPage: TTabSheet
|
||||||
|
Caption = 'MeanVarStdDev'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
object SaveDialog: TSaveDialog[3]
|
||||||
Left = 45
|
Left = 45
|
||||||
Top = 357
|
Top = 357
|
||||||
end
|
end
|
||||||
|
@ -6,14 +6,14 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
|
||||||
StdCtrls, Buttons, ExtCtrls, Globals, MainUnit, MatrixLib,
|
StdCtrls, Buttons, ExtCtrls, ComCtrls, Globals, MainUnit, MatrixLib,
|
||||||
DataProcs, DictionaryUnit, BasicStatsReportFormUnit;
|
DataProcs, DictionaryUnit, BasicStatsParamsFormUnit, ReportFrameUnit;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TLSMregForm }
|
{ TLSMregForm }
|
||||||
|
|
||||||
TLSMregForm = class(TBasicStatsReportForm)
|
TLSMregForm = class(TBasicStatsParamsForm)
|
||||||
AllBtn: TBitBtn;
|
AllBtn: TBitBtn;
|
||||||
IndepVars: TListBox;
|
IndepVars: TListBox;
|
||||||
CorrsChkBox: TCheckBox;
|
CorrsChkBox: TCheckBox;
|
||||||
@ -31,10 +31,16 @@ type
|
|||||||
Label5: TLabel;
|
Label5: TLabel;
|
||||||
MatSaveChkBox: TCheckBox;
|
MatSaveChkBox: TCheckBox;
|
||||||
MeansChkBox: TCheckBox;
|
MeansChkBox: TCheckBox;
|
||||||
|
PageControl: TPageControl;
|
||||||
SaveDialog: TSaveDialog;
|
SaveDialog: TSaveDialog;
|
||||||
OutBtn: TBitBtn;
|
OutBtn: TBitBtn;
|
||||||
PredictChkBox: TCheckBox;
|
PredictChkBox: TCheckBox;
|
||||||
SDChkBox: TCheckBox;
|
StdDevChkBox: TCheckBox;
|
||||||
|
RegressionPage: TTabSheet;
|
||||||
|
CrossProductsPage: TTabSheet;
|
||||||
|
CorrelationsPage: TTabSheet;
|
||||||
|
MeanVarStddevPage: TTabSheet;
|
||||||
|
VarCovarPage: TTabSheet;
|
||||||
VarChkBox: TCheckBox;
|
VarChkBox: TCheckBox;
|
||||||
VarList: TListBox;
|
VarList: TListBox;
|
||||||
procedure AllBtnClick(Sender: TObject);
|
procedure AllBtnClick(Sender: TObject);
|
||||||
@ -47,14 +53,21 @@ type
|
|||||||
procedure VarListSelectionChange(Sender: TObject; {%H-}User: boolean);
|
procedure VarListSelectionChange(Sender: TObject; {%H-}User: boolean);
|
||||||
private
|
private
|
||||||
{ private declarations }
|
{ private declarations }
|
||||||
|
FRegressionFrame: TReportFrame;
|
||||||
|
FCrossProductsFrame: TReportFrame;
|
||||||
|
FCorrelationsFrame: TReportFrame;
|
||||||
|
FVarCovarFrame: TReportFrame;
|
||||||
|
FMeanVarStddevFrame: TReportFrame;
|
||||||
IndepVarsCols: IntDyneVec;
|
IndepVarsCols: IntDyneVec;
|
||||||
NoVars: integer;
|
NoVars: integer;
|
||||||
NoBlocks: integer;
|
NoBlocks: integer;
|
||||||
|
procedure HideTabs;
|
||||||
protected
|
protected
|
||||||
procedure AdjustConstraints; override;
|
procedure AdjustConstraints; override;
|
||||||
procedure Compute; override;
|
procedure Compute; override;
|
||||||
procedure UpdateBtnStates; override;
|
procedure UpdateBtnStates; override;
|
||||||
public
|
public
|
||||||
|
constructor Create(AOwner: TComponent); override;
|
||||||
procedure Reset; override;
|
procedure Reset; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -73,6 +86,64 @@ uses
|
|||||||
|
|
||||||
{ TLSMregForm }
|
{ TLSMregForm }
|
||||||
|
|
||||||
|
constructor TLSMregForm.Create(AOwner: TComponent);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
|
||||||
|
FRegressionFrame := TReportFrame.Create(self);
|
||||||
|
FRegressionFrame.Name := '';
|
||||||
|
FRegressionFrame.Parent := RegressionPage;
|
||||||
|
FRegressionFrame.Align := alClient;
|
||||||
|
FRegressionFrame.BorderSpacing.Left := 0;
|
||||||
|
FRegressionFrame.BorderSpacing.Top := 0;
|
||||||
|
FRegressionFrame.BorderSpacing.Bottom := 0;
|
||||||
|
FRegressionFrame.BorderSpacing.Right := 0;
|
||||||
|
InitToolbar(FRegressionFrame.ReportToolbar, tpRight);
|
||||||
|
|
||||||
|
FCrossProductsFrame := TReportFrame.Create(self);
|
||||||
|
FCrossProductsFrame.Name := '';
|
||||||
|
FCrossProductsFrame.Parent := CrossProductsPage;
|
||||||
|
FCrossProductsFrame.Align := alClient;
|
||||||
|
FCrossProductsFrame.BorderSpacing.Left := 0;
|
||||||
|
FCrossProductsFrame.BorderSpacing.Top := 0;
|
||||||
|
FCrossProductsFrame.BorderSpacing.Bottom := 0;
|
||||||
|
FCrossProductsFrame.BorderSpacing.Right := 0;
|
||||||
|
InitToolbar(FCrossProductsFrame.ReportToolbar, tpRight);
|
||||||
|
|
||||||
|
FCorrelationsFrame := TReportFrame.Create(self);
|
||||||
|
FCorrelationsFrame.Name := '';
|
||||||
|
FCorrelationsFrame.Parent := CorrelationsPage;
|
||||||
|
FCorrelationsFrame.Align := alClient;
|
||||||
|
FCorrelationsFrame.BorderSpacing.Left := 0;
|
||||||
|
FCorrelationsFrame.BorderSpacing.Top := 0;
|
||||||
|
FCorrelationsFrame.BorderSpacing.Bottom := 0;
|
||||||
|
FCorrelationsFrame.BorderSpacing.Right := 0;
|
||||||
|
InitToolbar(FCorrelationsFrame.ReportToolbar, tpRight);
|
||||||
|
|
||||||
|
FVarCovarFrame := TReportFrame.Create(self);
|
||||||
|
FVarCovarFrame.Name := '';
|
||||||
|
FVarCovarFrame.Parent := VarCovarPage;
|
||||||
|
FVarCovarFrame.Align := alClient;
|
||||||
|
FVarCovarFrame.BorderSpacing.Left := 0;
|
||||||
|
FVarCovarFrame.BorderSpacing.Top := 0;
|
||||||
|
FVarCovarFrame.BorderSpacing.Bottom := 0;
|
||||||
|
FVarCovarFrame.BorderSpacing.Right := 0;
|
||||||
|
InitToolbar(FVarCovarFrame.ReportToolbar, tpRight);
|
||||||
|
|
||||||
|
FMeanVarStddevFrame := TReportFrame.Create(self);
|
||||||
|
FMeanVarStddevFrame.Name := '';
|
||||||
|
FMeanVarStddevFrame.Parent := MeanVarStdDevPage;
|
||||||
|
FMeanVarStddevFrame.Align := alClient;
|
||||||
|
FMeanVarStddevFrame.BorderSpacing.Left := 0;
|
||||||
|
FMeanVarStddevFrame.BorderSpacing.Top := 0;
|
||||||
|
FMeanVarStddevFrame.BorderSpacing.Bottom := 0;
|
||||||
|
FMeanVarStddevFrame.BorderSpacing.Right := 0;
|
||||||
|
InitToolbar(FMeanVarStddevFrame.ReportToolbar, tpRight);
|
||||||
|
|
||||||
|
PageControl.ActivePage := RegressionPage;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TLSMregForm.AdjustConstraints;
|
procedure TLSMregForm.AdjustConstraints;
|
||||||
begin
|
begin
|
||||||
ParamsPanel.Constraints.MinWidth := Max(
|
ParamsPanel.Constraints.MinWidth := Max(
|
||||||
@ -125,6 +196,14 @@ var
|
|||||||
errcode: boolean = false;
|
errcode: boolean = false;
|
||||||
anerror: Integer = 0;
|
anerror: Integer = 0;
|
||||||
lReport: TStrings;
|
lReport: TStrings;
|
||||||
|
|
||||||
|
procedure AddHeaderToReport;
|
||||||
|
begin
|
||||||
|
lReport.Clear;
|
||||||
|
lReport.Add('LEAST SQUARES MULTIPLE REGRESSION by Bill Miller');
|
||||||
|
lReport.Add('');
|
||||||
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
NCases := NoCases;
|
NCases := NoCases;
|
||||||
SetLength(corrs,NoVariables+1,NoVariables+1);
|
SetLength(corrs,NoVariables+1,NoVariables+1);
|
||||||
@ -159,8 +238,6 @@ begin
|
|||||||
|
|
||||||
lReport := TStringList.Create;
|
lReport := TStringList.Create;
|
||||||
try
|
try
|
||||||
lReport.Add('LEAST SQUARES MULTIPLE REGRESSION by Bill Miller');
|
|
||||||
lReport.Add('');
|
|
||||||
errorcode := false;
|
errorcode := false;
|
||||||
|
|
||||||
{ get dependendent variable column }
|
{ get dependendent variable column }
|
||||||
@ -199,55 +276,75 @@ begin
|
|||||||
if CPChkBox.Checked then
|
if CPChkBox.Checked then
|
||||||
begin
|
begin
|
||||||
title := 'Cross-Products Matrix';
|
title := 'Cross-Products Matrix';
|
||||||
|
AddHeaderToReport;
|
||||||
GridXProd(NEntered, ColEntered, Corrs, errcode, NCases);
|
GridXProd(NEntered, ColEntered, Corrs, errcode, NCases);
|
||||||
MatPrint(Corrs, NEntered, NEntered, title, IndRowLabels, IndColLabels, NCases, lReport);
|
MatPrint(Corrs, NEntered, NEntered, title, IndRowLabels, IndColLabels, NCases, lReport);
|
||||||
lReport.Add(DIVIDER_SMALL);
|
FCrossProductsFrame.DisplayReport(lReport);
|
||||||
end;
|
CrossProductsPage.TabVisible := true;
|
||||||
|
end else
|
||||||
|
CrossProductsPage.TabVisible := false;
|
||||||
|
|
||||||
if CovChkBox.Checked then
|
if CovChkBox.Checked then
|
||||||
begin
|
begin
|
||||||
title := 'Variance-Covariance Matrix';
|
title := 'Variance-Covariance Matrix';
|
||||||
|
AddHeaderToReport;
|
||||||
GridCovar(NEntered,ColEntered, Corrs, Means, Variances, StdDevs, errcode, NCases);
|
GridCovar(NEntered,ColEntered, Corrs, Means, Variances, StdDevs, errcode, NCases);
|
||||||
MatPrint(Corrs, NEntered, NEntered, title, IndRowLabels, IndColLabels, NCases, lReport);
|
MatPrint(Corrs, NEntered, NEntered, title, IndRowLabels, IndColLabels, NCases, lReport);
|
||||||
lReport.Add(DIVIDER_SMALL);
|
FVarCovarFrame.DisplayReport(lReport);
|
||||||
|
VarCovarPage.TabVisible := true;
|
||||||
|
// lReport.Add(DIVIDER_SMALL);
|
||||||
end;
|
end;
|
||||||
Correlations(NEntered,ColEntered,Corrs,Means,Variances, StdDevs,errcode,NCases);
|
|
||||||
|
|
||||||
|
Correlations(NEntered,ColEntered,Corrs,Means,Variances, StdDevs,errcode,NCases);
|
||||||
if CorrsChkBox.Checked then
|
if CorrsChkBox.Checked then
|
||||||
begin
|
begin
|
||||||
title := 'Product-Moment Correlations Matrix';
|
title := 'Product-Moment Correlations Matrix';
|
||||||
|
AddHeaderToReport;
|
||||||
MatPrint(Corrs, NEntered, NEntered, title, IndRowLabels, IndColLabels, NCases, lReport);
|
MatPrint(Corrs, NEntered, NEntered, title, IndRowLabels, IndColLabels, NCases, lReport);
|
||||||
lReport.Add(DIVIDER_SMALL);
|
FCorrelationsFrame.DisplayReport(lReport);
|
||||||
end;
|
CorrelationsPage.TabVisible := true;
|
||||||
|
end else
|
||||||
|
CorrelationsPage.TabVisible := false;
|
||||||
|
|
||||||
if MeansChkBox.Checked then
|
if MeansChkBox.Checked or VarChkBox.Checked or StdDevChkBox.Checked then
|
||||||
begin
|
begin
|
||||||
title := 'Means';
|
AddHeaderToReport;
|
||||||
DynVectorPrint(Means, NEntered, title, IndColLabels, NCases, lReport);
|
|
||||||
lReport.Add(DIVIDER_SMALL);
|
|
||||||
end;
|
|
||||||
|
|
||||||
if VarChkBox.Checked = true then
|
if MeansChkBox.Checked then
|
||||||
begin
|
begin
|
||||||
title := 'Variances';
|
title := 'Means';
|
||||||
DynVectorPrint(Variances, NEntered, title, IndColLabels, NCases, lReport);
|
DynVectorPrint(Means, NEntered, title, IndColLabels, NCases, lReport);
|
||||||
lReport.Add(DIVIDER_SMALL);
|
lReport.Add(DIVIDER_SMALL);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if SDChkBox.Checked = true then
|
if VarChkBox.Checked then
|
||||||
begin
|
begin
|
||||||
title := 'Standard Deviations';
|
title := 'Variances';
|
||||||
DynVectorPrint(StdDevs, NEntered, title, IndColLabels, NCases, lReport);
|
DynVectorPrint(Variances, NEntered, title, IndColLabels, NCases, lReport);
|
||||||
lReport.Add(DIVIDER_SMALL);
|
lReport.Add(DIVIDER_SMALL);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if StdDevChkBox.Checked then
|
||||||
|
begin
|
||||||
|
title := 'Standard Deviations';
|
||||||
|
DynVectorPrint(StdDevs, NEntered, title, IndColLabels, NCases, lReport);
|
||||||
|
lReport.Add(DIVIDER_SMALL);
|
||||||
|
end;
|
||||||
|
|
||||||
|
FMeanVarStddevFrame.DisplayReport(lReport);
|
||||||
|
MeanVarStddevPage.TabVisible := true;
|
||||||
|
end else
|
||||||
|
MeanVarStddevPage.TabVisible := false;
|
||||||
|
|
||||||
if errorcode then
|
if errorcode then
|
||||||
begin
|
begin
|
||||||
MessageDlg('A selected variable has no variability. Run aborted.', mtError, [mbOK], 0);
|
ErrorMsg('A selected variable has no variability. Run aborted.');
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
NoIndepVars := NEntered - 1;
|
NoIndepVars := NEntered - 1;
|
||||||
|
|
||||||
|
AddHeaderToReport;
|
||||||
|
|
||||||
MReg(NoIndepVars, ColEntered, DepVarCol, IndRowLabels, Means, Variances,
|
MReg(NoIndepVars, ColEntered, DepVarCol, IndRowLabels, Means, Variances,
|
||||||
StdDevs, BWeights, BetaWeights, BStdErrs, Bttests, tProbs, R2,
|
StdDevs, BWeights, BetaWeights, BStdErrs, Bttests, tProbs, R2,
|
||||||
StdErrEst, NCases, errorcode, true, lReport);
|
StdErrEst, NCases, errorcode, true, lReport);
|
||||||
@ -256,6 +353,7 @@ begin
|
|||||||
df2 := NCases - NoIndepVars - 1;
|
df2 := NCases - NoIndepVars - 1;
|
||||||
F := ((R2 - OldR2) / (1.0 - R2)) * df2 / df1;
|
F := ((R2 - OldR2) / (1.0 - R2)) * df2 / df1;
|
||||||
FProbF := ProbF(F,df1,df2);
|
FProbF := ProbF(F,df1,df2);
|
||||||
|
lReport.Add('');
|
||||||
if FProbF < probIn then
|
if FProbF < probIn then
|
||||||
lReport.Add('Entry requirements met')
|
lReport.Add('Entry requirements met')
|
||||||
else
|
else
|
||||||
@ -279,9 +377,6 @@ begin
|
|||||||
BetaWeights, StdErrEst, IndepVarsCols, NoIndepVars);
|
BetaWeights, StdErrEst, IndepVarsCols, NoIndepVars);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// OutputFrm.ShowModal;
|
|
||||||
// OutputFrm.RichEdit.Clear;
|
|
||||||
|
|
||||||
if MatSaveChkBox.Checked then
|
if MatSaveChkBox.Checked then
|
||||||
begin
|
begin
|
||||||
SaveDialog.Filter := 'LazStats matrix files (*.mat)|*.mat;*.MAT|All files (*.*)|*.*';
|
SaveDialog.Filter := 'LazStats matrix files (*.mat)|*.mat;*.MAT|All files (*.*)|*.*';
|
||||||
@ -293,7 +388,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
FReportFrame.DisplayReport(lReport);
|
FRegressionFrame.DisplayReport(lReport);
|
||||||
|
|
||||||
finally
|
finally
|
||||||
lReport.Free;
|
lReport.Free;
|
||||||
@ -358,6 +453,15 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TLSMregForm.HideTabs;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
for i := 1 to PageControl.PageCount-1 do // i=1 --> keep 1st page visible
|
||||||
|
PageControl.Pages[i].TabVisible := false;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TLSMregForm.OutBtnClick(Sender: TObject);
|
procedure TLSMregForm.OutBtnClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
i: integer;
|
i: integer;
|
||||||
@ -394,7 +498,7 @@ begin
|
|||||||
CorrsChkBox.Checked := true;
|
CorrsChkBox.Checked := true;
|
||||||
MeansChkBox.Checked := true;
|
MeansChkBox.Checked := true;
|
||||||
VarChkBox.Checked := false;
|
VarChkBox.Checked := false;
|
||||||
SDChkBox.Checked := true;
|
StdDevChkBox.Checked := true;
|
||||||
MatSaveChkBox.Checked := false;
|
MatSaveChkBox.Checked := false;
|
||||||
PredictChkBox.Checked := false;
|
PredictChkBox.Checked := false;
|
||||||
|
|
||||||
@ -403,6 +507,7 @@ begin
|
|||||||
InProb.Text := FormatFloat('0.00', DEFAULT_ALPHA_LEVEL);
|
InProb.Text := FormatFloat('0.00', DEFAULT_ALPHA_LEVEL);
|
||||||
SetLength(IndepVarsCols, NoVariables+1);
|
SetLength(IndepVarsCols, NoVariables+1);
|
||||||
|
|
||||||
|
HideTabs;
|
||||||
UpdateBtnStates;
|
UpdateBtnStates;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -412,11 +517,21 @@ var
|
|||||||
lSelected: Boolean;
|
lSelected: Boolean;
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
|
|
||||||
|
if Assigned(FRegressionFrame) then
|
||||||
|
FRegressionFrame.UpdateBtnStates;
|
||||||
|
if Assigned(FCrossProductsFrame) then
|
||||||
|
FCrossProductsFrame.UpdateBtnStates;
|
||||||
|
if Assigned(FCorrelationsFrame) then
|
||||||
|
FCorrelationsFrame.UpdateBtnStates;
|
||||||
|
if Assigned(FVarCovarFrame) then
|
||||||
|
FVarCovarFrame.UpdateBtnStates;
|
||||||
|
if Assigned(FMeanVarStddevFrame) then
|
||||||
|
FMeanVarStddevFrame.UpdateBtnStates;
|
||||||
|
|
||||||
lSelected := AnySelected(VarList);
|
lSelected := AnySelected(VarList);
|
||||||
DepInBtn.Enabled := lSelected;
|
DepInBtn.Enabled := lSelected;
|
||||||
InBtn.Enabled := lSelected;
|
InBtn.Enabled := lSelected;
|
||||||
|
|
||||||
OutBtn.Enabled := AnySelected(IndepVars);
|
OutBtn.Enabled := AnySelected(IndepVars);
|
||||||
DepOutBtn.Enabled := DepVar.Text <> '';
|
DepOutBtn.Enabled := DepVar.Text <> '';
|
||||||
AllBtn.Enabled := VarList.Items.Count > 0;
|
AllBtn.Enabled := VarList.Items.Count > 0;
|
||||||
|
@ -8,6 +8,9 @@ uses
|
|||||||
Classes, SysUtils, Dialogs,
|
Classes, SysUtils, Dialogs,
|
||||||
Globals, DictionaryUnit, FunctionsLib, DataProcs, MainUnit;
|
Globals, DictionaryUnit, FunctionsLib, DataProcs, MainUnit;
|
||||||
|
|
||||||
|
//type
|
||||||
|
// TRegItem = (riMeanVarStdDev, riXTX);
|
||||||
|
|
||||||
procedure GridDotProd(col1, col2: integer; out Product: double; var Ngood: integer);
|
procedure GridDotProd(col1, col2: integer; out Product: double; var Ngood: integer);
|
||||||
|
|
||||||
procedure GridXProd(NoSelected : 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;
|
procedure MatAxB(const A, B, C: DblDyneMat; BRows, BCols, CRows, CCols: Integer;
|
||||||
out ErrorCode: boolean);
|
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;
|
procedure nonsymroots(a : DblDyneMat; nv : integer;
|
||||||
var nf : integer; c : real;
|
var nf : integer; c : real;
|
||||||
@ -46,6 +49,7 @@ procedure EffectCode(GridCol, min, max : integer;
|
|||||||
VAR startcol : integer;
|
VAR startcol : integer;
|
||||||
VAR endcol : integer;
|
VAR endcol : integer;
|
||||||
VAR novectors : integer);
|
VAR novectors : integer);
|
||||||
|
|
||||||
procedure MReg(NoIndep: integer; const IndepCols: IntDyneVec; DepCol: integer;
|
procedure MReg(NoIndep: integer; const IndepCols: IntDyneVec; DepCol: integer;
|
||||||
const RowLabels: StrDyneVec;
|
const RowLabels: StrDyneVec;
|
||||||
const Means, Variances, StdDevs, BWeights, BetaWeights, BStdErrs, Bttests, tProbs: DblDyneVec;
|
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
|
// transpose the B matrix and return it in A
|
||||||
procedure MatTrn(var A, B: DblDyneMat; BRows, BCols : integer);
|
procedure MatTrn(var A: DblDyneMat; const B: DblDyneMat; BRows, BCols : integer);
|
||||||
var
|
var
|
||||||
i, j: integer;
|
i, j: integer;
|
||||||
begin
|
begin
|
||||||
@ -624,27 +628,27 @@ procedure MReg(NoIndep: integer; const IndepCols: IntDyneVec; DepCol: integer;
|
|||||||
PrintAll: boolean; AReport: TStrings);
|
PrintAll: boolean; AReport: TStrings);
|
||||||
var
|
var
|
||||||
i, j, N: integer;
|
i, j, N: integer;
|
||||||
X: DblDyneMat;
|
X: DblDyneMat = nil;
|
||||||
XT: DblDyneMat;
|
XT: DblDyneMat = nil;
|
||||||
XTX: DblDyneMat;
|
XTX: DblDyneMat = nil;
|
||||||
XTY: DblDyneVec;
|
XTY: DblDyneVec = nil;
|
||||||
Y: DblDyneVec;
|
Y: DblDyneVec = nil;
|
||||||
indx: IntDyneVec;
|
indx: IntDyneVec = nil;
|
||||||
ColLabels: StrDyneVec;
|
ColLabels: StrDyneVec = nil;
|
||||||
F, Prob, VarY, SDY, MeanY: double;
|
F, Prob, VarY, SDY, MeanY: double;
|
||||||
value, TOL, VIF, AdjR2: double;
|
value, TOL, VIF, AdjR2: double;
|
||||||
SSY, SSres, resvar, SSreg: double;
|
SSY, SSres, resvar, SSreg: double;
|
||||||
title: string;
|
title: string;
|
||||||
deplabel: string;
|
deplabel: string;
|
||||||
errcode: boolean;
|
errcode: boolean = false;
|
||||||
begin
|
begin
|
||||||
Assert(OS3MainFrm <> nil);
|
Assert(OS3MainFrm <> nil);
|
||||||
|
|
||||||
SetLength(X, NoCases+1, NoIndep+1); // augmented independent var. matrix
|
SetLength(X, NoCases+1, NoIndep+1); // augmented independent var. matrix
|
||||||
SetLength(XT, NoIndep+1, NoCases); // transpose of independent var's
|
SetLength(XT, NoIndep+1, NoCases); // transpose of independent var's
|
||||||
SetLength(XTX, NoIndep+1, NoIndep+1); // product of transpose X times X
|
SetLength(XTX, NoIndep+1, NoIndep+1); // product of (transpose X) times X
|
||||||
SetLength(Y, NCases+1); // Y variable values
|
SetLength(Y, NCases+1); // Y variable values
|
||||||
SetLength(XTY, NoIndep+1); // X transpose times Y
|
SetLength(XTY, NoIndep+1); // (X transpose) times Y
|
||||||
SetLength(indx, NoIndep+1);
|
SetLength(indx, NoIndep+1);
|
||||||
SetLength(ColLabels, NCases);
|
SetLength(ColLabels, NCases);
|
||||||
|
|
||||||
@ -706,9 +710,11 @@ begin
|
|||||||
VarY := VarY / (NCases - 1);
|
VarY := VarY / (NCases - 1);
|
||||||
SDY := sqrt(VarY);
|
SDY := sqrt(VarY);
|
||||||
|
|
||||||
AReport.Add('Variance Y: %10.3f', [VarY]);
|
AReport.Add('Sum of Squares Y: %20.3f', [SSY]);
|
||||||
AReport.Add('SSY: %10.3f', [SSY]);
|
AReport.Add('Variance Y: %20.3f', [VarY]);
|
||||||
AReport.Add('SDY: %10.3f', [SDY]);
|
AReport.Add('Std. Deviation Y: %20.3f', [SDY]);
|
||||||
|
AReport.Add('');
|
||||||
|
AReport.Add(DIVIDER_SMALL);
|
||||||
|
|
||||||
// augment the matrix
|
// augment the matrix
|
||||||
for i := 1 to NCases do
|
for i := 1 to NCases do
|
||||||
@ -719,8 +725,11 @@ begin
|
|||||||
MatTrn(XT, X, NCases, NoIndep+1);
|
MatTrn(XT, X, NCases, NoIndep+1);
|
||||||
if PrintAll then
|
if PrintAll then
|
||||||
begin
|
begin
|
||||||
|
AReport.Add('');
|
||||||
title := 'XT MATRIX';
|
title := 'XT MATRIX';
|
||||||
MatPrint(XT, NoIndep+1, NCases, title, RowLabels, ColLabels, NCases, AReport);
|
MatPrint(XT, NoIndep+1, NCases, title, RowLabels, ColLabels, NCases, AReport);
|
||||||
|
AReport.Add(DIVIDER_SMALL);
|
||||||
|
AReport.Add('');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// get product of the augmented X transpose times augmented X
|
// get product of the augmented X transpose times augmented X
|
||||||
@ -729,6 +738,8 @@ begin
|
|||||||
begin
|
begin
|
||||||
title := 'XTX MATRIX';
|
title := 'XTX MATRIX';
|
||||||
MatPrint(XTX, Noindep+1, NoIndep+1, title, RowLabels, RowLabels, NCases, AReport);
|
MatPrint(XTX, Noindep+1, NoIndep+1, title, RowLabels, RowLabels, NCases, AReport);
|
||||||
|
AReport.Add(DIVIDER_SMALL);
|
||||||
|
AReport.Add('');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
//Get means, variances and standard deviations
|
//Get means, variances and standard deviations
|
||||||
@ -747,8 +758,14 @@ begin
|
|||||||
if PrintAll then
|
if PrintAll then
|
||||||
begin
|
begin
|
||||||
DynVectorPrint(Means, NoIndep+1, 'MEANS', RowLabels, NCases, AReport);
|
DynVectorPrint(Means, NoIndep+1, 'MEANS', RowLabels, NCases, AReport);
|
||||||
|
AReport.Add(DIVIDER_SMALL);
|
||||||
|
AReport.Add('');
|
||||||
DynVectorPrint(Variances, NoIndep+1,'VARIANCES',RowLabels, NCases, AReport);
|
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;
|
end;
|
||||||
|
|
||||||
// get product of the augmented X transpose matrix times the Y vector
|
// get product of the augmented X transpose matrix times the Y vector
|
||||||
@ -756,14 +773,19 @@ begin
|
|||||||
for j := 0 to NCases-1 do
|
for j := 0 to NCases-1 do
|
||||||
XTY[i] := XTY[i] + (XT[i,j] * Y[j]);
|
XTY[i] := XTY[i] + (XT[i,j] * Y[j]);
|
||||||
if PrintAll then
|
if PrintAll then
|
||||||
|
begin
|
||||||
DynVectorPrint(XTY, NoIndep+1, 'XTY VECTOR', RowLabels, NCases, AReport);
|
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
|
// get inverse of the augmented cross products matrix among independent variables
|
||||||
SVDInverse(XTX,N);
|
SVDInverse(XTX,N);
|
||||||
if PrintAll then
|
if PrintAll then
|
||||||
begin
|
begin
|
||||||
|
AReport.Add('');
|
||||||
title := 'XTX MATRIX INVERSE';
|
title := 'XTX MATRIX INVERSE';
|
||||||
MatPrint(XTX, NoIndep+1, NoIndep+1, title, RowLabels, RowLabels, NCases, AReport);
|
MatPrint(XTX, NoIndep+1, NoIndep+1, title, RowLabels, RowLabels, NCases, AReport);
|
||||||
|
AReport.Add(DIVIDER);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// multiply augmented inverse matrix times the XTY vector
|
// multiply augmented inverse matrix times the XTY vector
|
||||||
@ -797,23 +819,24 @@ begin
|
|||||||
AdjR2 := 1.0 - (1.0 - R2) * (NCases - 1) / (NCases - N);
|
AdjR2 := 1.0 - (1.0 - R2) * (NCases - 1) / (NCases - N);
|
||||||
if PrintAll then
|
if PrintAll then
|
||||||
begin
|
begin
|
||||||
|
AReport.Add('');
|
||||||
AReport.Add('Dependent variable: ' + deplabel);
|
AReport.Add('Dependent variable: ' + deplabel);
|
||||||
AReport.Add('');
|
AReport.Add('');
|
||||||
DynVectorPrint(BWeights, NoIndep+1, 'B WEIGHTS', RowLabels, NCases, AReport);
|
DynVectorPrint(BWeights, NoIndep+1, 'B WEIGHTS', RowLabels, NCases, AReport);
|
||||||
AReport.Add('');
|
AReport.Add(DIVIDER_SMALL);
|
||||||
AReport.Add('');
|
AReport.Add('');
|
||||||
AReport.Add('Dependent variable: ' + deplabel);
|
AReport.Add('Dependent variable: ' + deplabel);
|
||||||
AReport.Add('');
|
AReport.Add('');
|
||||||
DynVectorPrint(BetaWeights, NoIndep, 'BETA WEIGHTS', RowLabels, NCases, AReport);
|
DynVectorPrint(BetaWeights, NoIndep, 'BETA WEIGHTS', RowLabels, NCases, AReport);
|
||||||
AReport.Add('');
|
AReport.Add(DIVIDER_SMALL);
|
||||||
AReport.Add('');
|
AReport.Add('');
|
||||||
DynVectorPrint(BStdErrs, NoIndep+1, 'B STD.ERRORS', RowLabels, NCases, AReport);
|
DynVectorPrint(BStdErrs, NoIndep+1, 'B STD.ERRORS', RowLabels, NCases, AReport);
|
||||||
AReport.Add('');
|
AReport.Add('');
|
||||||
DynVectorPrint(Bttests, NoIndep+1, 'B t-test VALUES', RowLabels, NCases, AReport);
|
DynVectorPrint(Bttests, NoIndep+1, 'B t-test VALUES', RowLabels, NCases, AReport);
|
||||||
AReport.Add('');
|
AReport.Add('');
|
||||||
DynVectorPrint(tprobs, NoIndep+1, 'B t VALUE PROBABILITIES', RowLabels, NCases, AReport);
|
DynVectorPrint(tprobs, NoIndep+1, 'B t VALUE PROBABILITIES', RowLabels, NCases, AReport);
|
||||||
|
AReport.Add(DIVIDER);
|
||||||
AReport.Add('');
|
AReport.Add('');
|
||||||
|
|
||||||
AReport.Add('SSY: %10.2f', [SSY]);
|
AReport.Add('SSY: %10.2f', [SSY]);
|
||||||
AReport.Add('SSreg: %10.2f', [SSreg]);
|
AReport.Add('SSreg: %10.2f', [SSreg]);
|
||||||
AReport.Add('SSres: %10.2f', [SSres]);
|
AReport.Add('SSres: %10.2f', [SSres]);
|
||||||
@ -829,6 +852,8 @@ begin
|
|||||||
//AReport.Add('Standard Error of Estimate = %8.2f', [stderrest]);
|
//AReport.Add('Standard Error of Estimate = %8.2f', [stderrest]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
AReport.Add(DIVIDER_SMALL);
|
||||||
|
AReport.Add('');
|
||||||
RowLabels[N-1] := 'Intercept';
|
RowLabels[N-1] := 'Intercept';
|
||||||
AReport.Add(' Variable Beta B Std.Err. t prob VIF TOL');
|
AReport.Add(' Variable Beta B Std.Err. t prob VIF TOL');
|
||||||
AReport.Add('---------- ---------- ---------- ---------- ---------- ---------- --------- ----------');
|
AReport.Add('---------- ---------- ---------- ---------- ---------- ---------- --------- ----------');
|
||||||
|
Reference in New Issue
Block a user