LazStats: Inherited SignTestUnit from TBasicStatsReportForm.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7810 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-10-26 14:32:48 +00:00
parent eb11d1eda2
commit ded71d0f59
2 changed files with 387 additions and 433 deletions

View File

@ -1,236 +1,181 @@
object SignTestFrm: TSignTestFrm inherited SignTestFrm: TSignTestFrm
Left = 550 Left = 550
Height = 372 Height = 345
Top = 297 Top = 297
Width = 391 Width = 382
AutoSize = True
Caption = 'The Matched Pairs Sign Test' Caption = 'The Matched Pairs Sign Test'
ClientHeight = 372 ClientHeight = 345
ClientWidth = 391 ClientWidth = 382
OnActivate = FormActivate inherited ParamsPanel: TPanel
OnCreate = FormCreate Height = 329
OnShow = FormShow ClientHeight = 329
LCLVersion = '2.1.0.0' inherited CloseBtn: TButton
object Label1: TLabel Top = 304
AnchorSideLeft.Control = Owner end
AnchorSideTop.Control = Owner inherited ComputeBtn: TButton
Left = 8 Top = 304
end
inherited ResetBtn: TButton
Top = 304
end
inherited HelpBtn: TButton
Top = 304
end
inherited ButtonBevel: TBevel
Top = 288
end
object Label1: TLabel[5]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = ParamsPanel
Left = 0
Height = 15 Height = 15
Top = 8 Top = 0
Width = 97 Width = 100
BorderSpacing.Left = 8 Caption = 'Available Variables:'
BorderSpacing.Top = 8
Caption = 'Variables Available'
ParentColor = False ParentColor = False
end end
object Label2: TLabel object Label2: TLabel[6]
AnchorSideLeft.Control = Var1Edit AnchorSideLeft.Control = Var1Edit
AnchorSideBottom.Control = Var1Edit AnchorSideBottom.Control = Var1Edit
Left = 217 Left = 166
Height = 15 Height = 15
Top = 33 Top = 21
Width = 50 Width = 50
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
BorderSpacing.Bottom = 2 BorderSpacing.Bottom = 2
Caption = 'Variable 1' Caption = 'Variable 1'
ParentColor = False ParentColor = False
end end
object Label3: TLabel object Label3: TLabel[7]
AnchorSideLeft.Control = Var2Edit AnchorSideLeft.Control = Var2Edit
AnchorSideBottom.Control = Var2Edit AnchorSideBottom.Control = Var2Edit
Left = 217 Left = 166
Height = 15 Height = 15
Top = 125 Top = 109
Width = 50 Width = 50
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
BorderSpacing.Bottom = 2 BorderSpacing.Bottom = 2
Caption = 'Variable 2' Caption = 'Variable 2'
ParentColor = False ParentColor = False
end end
object VarList: TListBox object VarList: TListBox[8]
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = Label1 AnchorSideTop.Control = Label1
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Var1In AnchorSideRight.Control = Var1In
AnchorSideBottom.Control = Bevel1 AnchorSideBottom.Control = ButtonBevel
Left = 8 Left = 0
Height = 298 Height = 271
Top = 25 Top = 17
Width = 165 Width = 126
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Top = 2 BorderSpacing.Top = 2
BorderSpacing.Right = 8 BorderSpacing.Right = 6
Constraints.MinHeight = 200
ItemHeight = 0 ItemHeight = 0
OnDblClick = VarListDblClick
OnSelectionChange = VarListSelectionChange OnSelectionChange = VarListSelectionChange
TabOrder = 0 TabOrder = 4
end end
object Var1In: TBitBtn object Var1In: TBitBtn[9]
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = VarList AnchorSideTop.Control = VarList
Left = 181 Left = 132
Height = 28 Height = 26
Top = 25 Top = 17
Width = 28 Width = 26
Images = MainDataModule.ImageList Images = MainDataModule.ImageList
ImageIndex = 1 ImageIndex = 1
OnClick = Var1InClick OnClick = Var1InClick
Spacing = 0 Spacing = 0
TabOrder = 1 TabOrder = 5
end end
object Var1Out: TBitBtn object Var1Out: TBitBtn[10]
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = Var1In AnchorSideTop.Control = Var1In
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 181 Left = 132
Height = 28 Height = 26
Top = 57 Top = 47
Width = 28 Width = 26
BorderSpacing.Top = 4 BorderSpacing.Top = 4
Images = MainDataModule.ImageList Images = MainDataModule.ImageList
ImageIndex = 0 ImageIndex = 0
OnClick = Var1OutClick OnClick = Var1OutClick
Spacing = 0 Spacing = 0
TabOrder = 2 TabOrder = 6
end end
object Var2In: TBitBtn object Var2In: TBitBtn[11]
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = Var1Out AnchorSideTop.Control = Var1Out
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 181 Left = 132
Height = 28 Height = 26
Top = 117 Top = 105
Width = 28 Width = 26
BorderSpacing.Top = 32 BorderSpacing.Top = 32
Images = MainDataModule.ImageList Images = MainDataModule.ImageList
ImageIndex = 1 ImageIndex = 1
OnClick = Var2InClick OnClick = Var2InClick
Spacing = 0 Spacing = 0
TabOrder = 4 TabOrder = 7
end end
object Var2Out: TBitBtn object Var2Out: TBitBtn[12]
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = Var2In AnchorSideTop.Control = Var2In
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 181 Left = 132
Height = 28 Height = 26
Top = 149 Top = 135
Width = 28 Width = 26
BorderSpacing.Top = 4 BorderSpacing.Top = 4
Images = MainDataModule.ImageList Images = MainDataModule.ImageList
ImageIndex = 0 ImageIndex = 0
OnClick = Var2OutClick OnClick = Var2OutClick
Spacing = 0 Spacing = 0
TabOrder = 5 TabOrder = 8
end end
object Var1Edit: TEdit object Var1Edit: TEdit[13]
AnchorSideLeft.Control = Var1In AnchorSideLeft.Control = Var1In
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideRight.Control = Owner AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Var1Out AnchorSideBottom.Control = Var1Out
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 217 Left = 166
Height = 23 Height = 23
Top = 50 Top = 38
Width = 166 Width = 125
Anchors = [akLeft, akRight, akBottom] Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Left = 8 BorderSpacing.Left = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 12 BorderSpacing.Bottom = 12
ReadOnly = True ReadOnly = True
TabOrder = 3 TabOrder = 9
Text = 'Var1Edit' Text = 'Var1Edit'
end end
object Var2Edit: TEdit object Var2Edit: TEdit[14]
AnchorSideLeft.Control = Var2In AnchorSideLeft.Control = Var2In
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideRight.Control = Owner AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Var2Out AnchorSideBottom.Control = Var2Out
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 217 Left = 166
Height = 23 Height = 23
Top = 142 Top = 126
Width = 166 Width = 125
Anchors = [akLeft, akRight, akBottom] Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Left = 8 BorderSpacing.Left = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 12 BorderSpacing.Bottom = 12
ReadOnly = True ReadOnly = True
TabOrder = 6 TabOrder = 10
Text = 'Var2Edit' Text = 'Var2Edit'
end end
object ResetBtn: TButton
AnchorSideRight.Control = ComputeBtn
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 182
Height = 25
Top = 339
Width = 54
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 7
end end
object ComputeBtn: TButton inherited ParamsSplitter: TSplitter
AnchorSideRight.Control = CloseBtn Height = 345
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 244
Height = 25
Top = 339
Width = 76
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 8
end
object CloseBtn: TButton
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 328
Height = 25
Top = 339
Width = 55
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Close'
ModalResult = 11
TabOrder = 9
end
object Bevel1: TBevel
AnchorSideLeft.Control = Owner
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = CloseBtn
Left = 0
Height = 8
Top = 323
Width = 391
Anchors = [akLeft, akRight, akBottom]
Shape = bsBottomLine
end end
end end

View File

@ -5,19 +5,14 @@ unit SignTestUnit;
interface interface
uses uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Buttons, ExtCtrls,
StdCtrls, Buttons, ExtCtrls, MainUnit, FunctionsLib, Globals, BasicStatsReportFormUnit;
MainUnit, OutputUnit, FunctionsLib, Globals, DataProcs;
type type
{ TSignTestFrm } { TSignTestFrm }
TSignTestFrm = class(TForm) TSignTestFrm = class(TBasicStatsReportForm)
Bevel1: TBevel;
ResetBtn: TButton;
ComputeBtn: TButton;
CloseBtn: TButton;
Var1In: TBitBtn; Var1In: TBitBtn;
Var1Out: TBitBtn; Var1Out: TBitBtn;
Var2In: TBitBtn; Var2In: TBitBtn;
@ -28,22 +23,22 @@ type
Label2: TLabel; Label2: TLabel;
Label3: TLabel; Label3: TLabel;
VarList: TListBox; VarList: TListBox;
procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
procedure Var1InClick(Sender: TObject); procedure Var1InClick(Sender: TObject);
procedure Var1OutClick(Sender: TObject); procedure Var1OutClick(Sender: TObject);
procedure Var2InClick(Sender: TObject); procedure Var2InClick(Sender: TObject);
procedure Var2OutClick(Sender: TObject); procedure Var2OutClick(Sender: TObject);
procedure VarListDblClick(Sender: TObject);
procedure VarListSelectionChange(Sender: TObject; User: boolean); procedure VarListSelectionChange(Sender: TObject; User: boolean);
private private
{ private declarations }
FAutoSized: Boolean; protected
procedure UpdateBtnStates; procedure AdjustConstraints; override;
procedure Compute; override;
procedure UpdateBtnStates; override;
function Validate(out AMsg: String; out AControl: TWinControl): boolean; override;
public public
{ public declarations } procedure Reset; override;
end; end;
var var
@ -51,136 +46,41 @@ var
implementation implementation
{$R *.lfm}
uses uses
Math; Math,
GridProcs;
{ TSignTestFrm } { TSignTestFrm }
procedure TSignTestFrm.ResetBtnClick(Sender: TObject); procedure TSignTestFrm.AdjustConstraints;
begin
inherited;
ParamsPanel.Constraints.MinWidth := 4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left;
ParamsPanel.Constraints.MinHeight := Var2Out.Top + Var2Out.Height +
ButtonBevel.Height + CloseBtn.Height + CloseBtn.Borderspacing.Top;
end;
procedure TSignTestFrm.Compute;
var var
i: integer; ColNoSelected: IntDyneVec = nil;
begin DifSigns: IntDyneVec = nil;
Var1Edit.Text := ''; i, col1, col2, X, N, A, b, Temp: integer;
Var2Edit.Text := '';
VarList.Items.Clear;
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
UpdateBtnStates;
end;
procedure TSignTestFrm.Var1InClick(Sender: TObject);
var
index: integer;
begin
index := VarList.ItemIndex;
if (index > -1) and (Var1Edit.Text = '') then
begin
Var1Edit.Text := VarList.Items[index];
VarList.Items.Delete(index);
end;
UpdateBtnStates;
end;
procedure TSignTestFrm.Var1OutClick(Sender: TObject);
begin
if Var1Edit.Text <> '' then
begin
VarList.Items.Add(Var1Edit.Text);
Var1Edit.Text := '';
end;
UpdateBtnStates;
end;
procedure TSignTestFrm.Var2InClick(Sender: TObject);
var
index: integer;
begin
index := VarList.ItemIndex;
if (index > -1) and (Var2Edit.Text = '') then
begin
Var2Edit.Text := VarList.Items[index];
VarList.Items.Delete(index);
end;
UpdateBtnStates;
end;
procedure TSignTestFrm.Var2OutClick(Sender: TObject);
begin
if Var2Edit.Text <> '' then
begin
VarList.Items.Add(Var2Edit.Text);
Var2Edit.Text := '';
end;
UpdateBtnStates;
end;
procedure TSignTestFrm.VarListSelectionChange(Sender: TObject; User: boolean);
begin
UpdateBtnStates;
end;
procedure TSignTestFrm.FormActivate(Sender: TObject);
var
w: Integer;
begin
if FAutoSized then
exit;
w := MaxValue([ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]);
ResetBtn.Constraints.MinWidth := w;
ComputeBtn.Constraints.MinWidth := w;
CloseBtn.Constraints.MinWidth := w;
Constraints.MinWidth := 4*w; //Width;
Constraints.MinHeight := Height;
FAutoSized := true;
end;
procedure TSignTestFrm.FormCreate(Sender: TObject);
begin
Assert(OS3MainFrm <> nil);
end;
procedure TSignTestFrm.FormShow(Sender: TObject);
begin
ResetBtnClick(self);
end;
procedure TSignTestFrm.ComputeBtnClick(Sender: TObject);
var
i, k, col1, col2, X, N, A, b, Temp : integer;
ColNoSelected : IntDyneVec;
DifSigns : IntDyneVec;
p, Q, Probability, z, NoDiff, CorrectedA, x1, x2: double; p, Q, Probability, z, NoDiff, CorrectedA, x1, x2: double;
SumProb: double; SumProb: double;
cellstring: string;
lReport: TStrings; lReport: TStrings;
begin begin
if Var1Edit.Text = '' then
begin
MessageDlg('Variable 1 not selected.', mtError, [mbOK], 0);
exit;
end;
if Var2Edit.Text = '' then
begin
MessageDlg('Variable 2 not selected.', mtError, [mbOK], 0);
exit;
end;
SumProb := 0.0; SumProb := 0.0;
SetLength(DifSigns, NoCases); SetLength(DifSigns, NoCases);
SetLength(ColNoSelected,NoVariables);
k := 2;
// Get column numbers and labels of variables selected // Get column numbers and labels of variables selected
for i := 1 to NoVariables do SetLength(ColNoSelected, 2);
begin ColNoSelected[0] := GetVariableIndex(OS3MainFrm.DataGrid, Var1Edit.Text);
cellstring := OS3MainFrm.DataGrid.Cells[i,0]; ColNoSelected[1] := GetVariableIndex(OS3MainFrm.DataGrid, Var2Edit.Text);
if cellstring = Var1Edit.Text then ColNoSelected[0] := i;
if cellstring = Var2Edit.Text then ColNoSelected[1] := i;
end;
p := 0.5; p := 0.5;
Q := 0.5; Q := 0.5;
@ -191,7 +91,7 @@ begin
NoDiff := 0.0; NoDiff := 0.0;
for i := 1 to NoCases do for i := 1 to NoCases do
begin begin
if (not GoodRecord(i,k,ColNoSelected)) then continue; if (not GoodRecord(OS3MainFrm.DataGrid, i, ColNoSelected)) then continue;
col1 := ColNoSelected[0]; col1 := ColNoSelected[0];
col2 := ColNoSelected[1]; col2 := ColNoSelected[1];
x1 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[col1, i])); x1 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[col1, i]));
@ -243,7 +143,7 @@ begin
if (A > N * p) then CorrectedA := A - 0.5; if (A > N * p) then CorrectedA := A - 0.5;
z := (CorrectedA - N * p) / sqrt(N * p * Q); z := (CorrectedA - N * p) / sqrt(N * p * Q);
lReport.Add('Z value for Normal Distribution approximation: %.3f', [z]); lReport.Add('Z value for Normal Distribution approximation: %.3f', [z]);
Probability := probz(z); Probability := ProbZ(z);
lReport.Add('Probability: %.4f', [Probability]); lReport.Add('Probability: %.4f', [Probability]);
end end
else // Use binomial fomula else // Use binomial fomula
@ -259,14 +159,126 @@ begin
lReport.Add('Binomial Probability of %d or smaller out of %d: %.4f', [A, N, SumProb]); lReport.Add('Binomial Probability of %d or smaller out of %d: %.4f', [A, N, SumProb]);
end; end;
DisplayReport(lReport); FReportFrame.DisplayReport(lReport);
finally finally
lReport.Free; lReport.Free;
DifSigns := nil;
ColNoSelected := nil;
end; end;
end; end;
procedure TSignTestFrm.Reset;
var
i: integer;
begin
inherited;
Var1Edit.Clear;
Var2Edit.Clear;
VarList.Items.Clear;
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
UpdateBtnStates;
end;
function TSignTestFrm.Validate(out AMsg: String; out AControl: TWinControl): boolean;
begin
Result := false;
if Var1Edit.Text = '' then
begin
AMsg := 'Variable 1 not selected.';
AControl := Var1Edit;
exit;
end;
if Var2Edit.Text = '' then
begin
AMsg := 'Variable 2 not selected.';
AControl := Var2Edit;
exit;
end;
Result := true;
end;
procedure TSignTestFrm.Var1InClick(Sender: TObject);
var
index: integer;
begin
index := VarList.ItemIndex;
if (index > -1) and (Var1Edit.Text = '') then
begin
Var1Edit.Text := VarList.Items[index];
VarList.Items.Delete(index);
end;
UpdateBtnStates;
end;
procedure TSignTestFrm.Var1OutClick(Sender: TObject);
begin
if Var1Edit.Text <> '' then
begin
VarList.Items.Add(Var1Edit.Text);
Var1Edit.Text := '';
end;
UpdateBtnStates;
end;
procedure TSignTestFrm.Var2InClick(Sender: TObject);
var
index: integer;
begin
index := VarList.ItemIndex;
if (index > -1) and (Var2Edit.Text = '') then
begin
Var2Edit.Text := VarList.Items[index];
VarList.Items.Delete(index);
end;
UpdateBtnStates;
end;
procedure TSignTestFrm.Var2OutClick(Sender: TObject);
begin
if Var2Edit.Text <> '' then
begin
VarList.Items.Add(Var2Edit.Text);
Var2Edit.Text := '';
end;
UpdateBtnStates;
end;
procedure TSignTestFrm.VarListDblClick(Sender: TObject);
var
index: Integer;
s: String;
begin
index := Varlist.ItemIndex;;
if index > -1 then
begin
s := VarList.Items[index];
if Var1Edit.Text = '' then
Var1Edit.Text := s
else
if Var2Edit.Text = '' then
Var2Edit.Text := s;
Varlist.Items.Delete(index);
UpdateBtnStates;
end;
end;
procedure TSignTestFrm.VarListSelectionChange(Sender: TObject; User: boolean);
begin
UpdateBtnStates;
end;
procedure TSignTestFrm.UpdateBtnStates; procedure TSignTestFrm.UpdateBtnStates;
begin begin
Var1In.Enabled := (VarList.ItemIndex > -1) and (Var1Edit.Text = ''); Var1In.Enabled := (VarList.ItemIndex > -1) and (Var1Edit.Text = '');
@ -276,8 +288,5 @@ begin
end; end;
initialization
{$I signtestunit.lrs}
end. end.