LazStats: Inherit ConcordanceUnit from TBasicStatsReportForm.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7819 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-10-27 18:34:00 +00:00
parent 8e59f55c29
commit 0269c3f49c
4 changed files with 253 additions and 318 deletions

View File

@ -737,7 +737,7 @@
<Unit79>
<Filename Value="forms\analysis\nonparametric\concordanceunit.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="ConcordFrm"/>
<ComponentName Value="ConcordForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="ConcordanceUnit"/>

View File

@ -1,207 +1,134 @@
object ConcordFrm: TConcordFrm
inherited ConcordForm: TConcordForm
AnchorSideBottom.Side = asrBottom
Left = 535
Height = 310
Height = 340
Top = 327
Width = 397
Width = 638
HelpType = htKeyword
HelpKeyword = 'html/KendallsCoefficientofConcordance.htm'
Anchors = [akLeft]
AutoSize = True
Caption = 'Kendal''s Coefficient of Concordance'
ClientHeight = 310
ClientWidth = 397
OnActivate = FormActivate
OnCreate = FormCreate
OnShow = FormShow
Position = poMainFormCenter
LCLVersion = '2.1.0.0'
object Label1: TLabel
AnchorSideLeft.Control = VarList
AnchorSideTop.Control = Owner
Left = 8
Height = 15
Top = 8
Width = 97
BorderSpacing.Top = 8
Caption = 'Avialable Variables'
ParentColor = False
ClientHeight = 340
ClientWidth = 638
inherited ParamsPanel: TPanel
Height = 324
ClientHeight = 324
inherited CloseBtn: TButton
Top = 299
end
inherited ComputeBtn: TButton
Top = 299
end
inherited ResetBtn: TButton
Top = 299
end
inherited HelpBtn: TButton
Top = 299
end
inherited ButtonBevel: TBevel
Top = 283
end
object Label1: TLabel[5]
AnchorSideLeft.Control = VarList
AnchorSideTop.Control = ParamsPanel
Left = 0
Height = 15
Top = 0
Width = 97
Caption = 'Avialable Variables'
ParentColor = False
end
object Label2: TLabel[6]
AnchorSideLeft.Control = SelList
AnchorSideTop.Control = ParamsPanel
Left = 171
Height = 15
Top = 0
Width = 93
Caption = 'Selected Variables'
ParentColor = False
end
object VarList: TListBox[7]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = Label1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = AllBtn
AnchorSideBottom.Control = ButtonBevel
Left = 0
Height = 266
Top = 17
Width = 119
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 2
BorderSpacing.Right = 6
ItemHeight = 0
MultiSelect = True
OnDblClick = VarListDblClick
OnSelectionChange = VarListSelectionChange
TabOrder = 4
end
object InBtn: TBitBtn[8]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
Left = 131
Height = 28
Top = 24
Width = 28
Images = MainDataModule.ImageList
ImageIndex = 1
OnClick = InBtnClick
Spacing = 0
TabOrder = 5
end
object OutBtn: TBitBtn[9]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
Left = 131
Height = 28
Top = 56
Width = 28
Images = MainDataModule.ImageList
ImageIndex = 0
OnClick = OutBtnClick
Spacing = 0
TabOrder = 6
end
object AllBtn: TBitBtn[10]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
Left = 125
Height = 25
Top = 104
Width = 40
AutoSize = True
Caption = 'All'
OnClick = AllBtnClick
Spacing = 0
TabOrder = 7
end
object SelList: TListBox[11]
AnchorSideLeft.Control = AllBtn
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Label2
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ButtonBevel
Left = 171
Height = 266
Top = 17
Width = 120
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 6
BorderSpacing.Top = 2
ItemHeight = 0
MultiSelect = True
OnDblClick = SelListDblClick
OnSelectionChange = VarListSelectionChange
TabOrder = 8
end
end
object Label2: TLabel
AnchorSideLeft.Control = SelList
AnchorSideTop.Control = Owner
Left = 229
Height = 15
Top = 8
Width = 93
BorderSpacing.Top = 8
Caption = 'Selected Variables'
ParentColor = False
end
object VarList: TListBox
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Label1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = AllBtn
AnchorSideBottom.Control = Bevel1
Left = 8
Height = 236
Top = 25
Width = 159
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Top = 2
BorderSpacing.Right = 8
Constraints.MinHeight = 200
ItemHeight = 0
MultiSelect = True
OnSelectionChange = VarListSelectionChange
TabOrder = 0
end
object InBtn: TBitBtn
AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
Left = 184
Height = 28
Top = 24
Width = 28
Images = MainDataModule.ImageList
ImageIndex = 1
OnClick = InBtnClick
Spacing = 0
TabOrder = 1
end
object OutBtn: TBitBtn
AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
Left = 184
Height = 28
Top = 56
Width = 28
Images = MainDataModule.ImageList
ImageIndex = 0
OnClick = OutBtnClick
Spacing = 0
TabOrder = 2
end
object AllBtn: TBitBtn
AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
Left = 175
Height = 25
Top = 104
Width = 46
AutoSize = True
Caption = 'ALL'
OnClick = AllBtnClick
Spacing = 0
TabOrder = 3
end
object SelList: TListBox
AnchorSideLeft.Control = AllBtn
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Label2
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Bevel1
Left = 229
Height = 236
Top = 25
Width = 160
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Top = 2
BorderSpacing.Right = 8
ItemHeight = 0
MultiSelect = True
OnSelectionChange = VarListSelectionChange
TabOrder = 4
end
object ResetBtn: TButton
AnchorSideRight.Control = ComputeBtn
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 188
Height = 25
Top = 277
Width = 54
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 6
end
object ComputeBtn: TButton
AnchorSideRight.Control = CloseBtn
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 250
Height = 25
Top = 277
Width = 76
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 7
end
object CloseBtn: TButton
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 334
Height = 25
Top = 277
Width = 55
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Close'
ModalResult = 11
TabOrder = 8
end
object HelpBtn: TButton
Tag = 115
AnchorSideRight.Control = ResetBtn
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 129
Height = 25
Top = 277
Width = 51
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Help'
OnClick = HelpBtnClick
TabOrder = 5
end
object Bevel1: TBevel
AnchorSideLeft.Control = Owner
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = CloseBtn
Left = 0
Height = 8
Top = 261
Width = 397
Anchors = [akLeft, akRight, akBottom]
Shape = bsBottomLine
inherited ParamsSplitter: TSplitter
Height = 340
end
end

View File

@ -5,20 +5,15 @@ unit ConcordanceUnit;
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, Buttons, ExtCtrls,
MainUnit, Globals, OutputUnit, DataProcs, FunctionsLib, ContextHelpUnit;
MainUnit, Globals, FunctionsLib, BasicStatsReportFormUnit;
type
{ TConcordFrm }
{ TConcordForm }
TConcordFrm = class(TForm)
Bevel1: TBevel;
HelpBtn: TButton;
ResetBtn: TButton;
ComputeBtn: TButton;
CloseBtn: TButton;
TConcordForm = class(TBasicStatsReportForm)
InBtn: TBitBtn;
OutBtn: TBitBtn;
AllBtn: TBitBtn;
@ -27,83 +22,48 @@ type
SelList: TListBox;
VarList: TListBox;
procedure AllBtnClick(Sender: TObject);
procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure HelpBtnClick(Sender: TObject);
procedure InBtnClick(Sender: TObject);
procedure OutBtnClick(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
procedure SelListDblClick(Sender: TObject);
procedure VarListDblClick(Sender: TObject);
procedure VarListSelectionChange(Sender: TObject; {%H-}User: boolean);
private
{ private declarations }
FAutoSized: Boolean;
procedure UpdateBtnStates;
protected
procedure AdjustConstraints; override;
procedure Compute; override;
procedure UpdateBtnStates; override;
function Validate(out AMsg: String; out AControl: TWinControl): boolean; override;
public
{ public declarations }
procedure Reset; override;
end;
var
ConcordFrm: TConcordFrm;
ConcordForm: TConcordForm;
implementation
{$R *.lfm}
uses
GridProcs,
Math;
{ TConcordFrm }
procedure TConcordFrm.ResetBtnClick(Sender: TObject);
VAR i : integer;
{ TConcordForm }
procedure TConcordForm.AdjustConstraints;
begin
VarList.Clear;
SelList.Clear;
for i := 1 to NoVariables do
begin
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
end;
InBtn.Enabled := true;
OutBtn.Enabled := false;
inherited;
ParamsPanel.Constraints.MinWidth := 4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left;
ParamsPanel.Constraints.MinHeight := AllBtn.Top + AllBtn.Height +
ButtonBevel.Height + Closebtn.BorderSpacing.Top + CloseBtn.Height;
end;
procedure TConcordFrm.FormActivate(Sender: TObject);
var
w: Integer;
begin
if FAutoSized then
exit;
w := MaxValue([HelpBtn.Width, ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]);
HelpBtn.Constraints.MinWidth := w;
ResetBtn.Constraints.MinWidth := w;
ComputeBtn.Constraints.MinWidth := w;
CloseBtn.Constraints.MinWidth := w;
Constraints.MinWidth := Width;
Constraints.MinHeight := Height;
FAutoSized := false;
end;
procedure TConcordFrm.FormCreate(Sender: TObject);
begin
Assert(OS3MainFrm <> nil);
end;
procedure TConcordFrm.FormShow(Sender: TObject);
begin
ResetBtnClick(self);
end;
procedure TConcordFrm.HelpBtnClick(Sender: TObject);
begin
if ContextHelpForm = nil then
Application.CreateForm(TContextHelpForm, ContextHelpForm);
ContextHelpForm.HelpMessage((Sender as TButton).Tag);
end;
procedure TConcordFrm.AllBtnClick(Sender: TObject);
procedure TConcordForm.AllBtnClick(Sender: TObject);
var
index: integer;
begin
@ -113,27 +73,23 @@ begin
UpdateBtnStates;
end;
procedure TConcordFrm.ComputeBtnClick(Sender: TObject);
var
i, j, k, index, No_Judges, No_Objects, col, ties, start, last : integer;
Temp, TotalCorrect, JudgeCorrect, ChiSquare, Probability : double;
TotalRankSums, Concordance, AvgRankCorr, AvgTotalRanks : double;
statistic : double;
scorearray : DblDyneMat = nil;
temprank, ObjRankSums : DblDyneVec;
tempindex : IntDyneVec = nil;
done : boolean;
value, cellstring, outline : string;
ColNoSelected : IntDyneVec = nil;
ColLabels : StrDyneVec = nil;
lReport: TStrings;
begin
if SelList.Items.Count = 0 then
begin
MessageDlg('No variables selected.', mtError, [mbOK], 0);
exit;
end;
procedure TConcordForm.Compute;
var
i, j, k, index, No_Judges, No_Objects, col, ties, start, last: integer;
Temp, TotalCorrect, JudgeCorrect, ChiSquare, Probability: double;
TotalRankSums, Concordance, AvgRankCorr, AvgTotalRanks: double;
statistic: double;
scorearray: DblDyneMat = nil;
temprank: DblDyneVec = nil;
ObjRankSums: DblDyneVec = nil;
tempindex: IntDyneVec = nil;
done: boolean;
value, outline: string;
ColNoSelected: IntDyneVec = nil;
ColLabels: StrDyneVec = nil;
lReport: TStrings;
begin
No_Judges := 0;
No_Objects := SelList.Items.Count;
@ -146,23 +102,17 @@ begin
SetLength(ColNoSelected, NoVariables);
// get columns of variables selected
for i := 0 to No_Objects - 1 do
for i := 0 to No_Objects-1 do
begin
cellstring := SelList.Items.Strings[i];
for index := 1 to NoVariables do
begin
if (cellstring = OS3MainFrm.DataGrid.Cells[index,0]) then
begin
ColNoSelected[i] := index;
ColLabels[i] := cellstring;
end;
end;
ColNoSelected[i] := GetVariableIndex(OS3MainFrm.DataGrid, SelList.Items[i]);
ColLabels[i] := SelList.Items[i];
end;
SetLength(ColNoSelected, No_Objects);
//Read data from grid
for i := 1 to NoCases do
begin
if (not GoodRecord(i,No_Objects,ColNoSelected)) then continue;
if (not GoodRecord(OS3MainFrm.DataGrid, i, ColNoSelected)) then continue;
No_Judges := No_Judges + 1;
for j := 1 to No_Objects do
begin
@ -282,14 +232,14 @@ begin
for j := start to last do
begin
col := ColNoSelected[j-1];
outline := outline + format('%8s',[ColLabels[col-1]]);
outline := outline + format('%10s',[ColLabels[col-1]]);
end;
lReport.Add(outline);
outline := ' ';
for j := start to last do
begin
value := format('%8.4f',[scorearray[i-1,j-1]]);
value := format('%10.4f',[scorearray[i-1,j-1]]);
outline := outline + value;
end;
lReport.Add(outline);
@ -317,14 +267,14 @@ begin
for j := start to last do
begin
col := ColNoSelected[j-1];
value := Format('%8s', [ColLabels[col-1]]);
value := Format('%10s', [ColLabels[col-1]]);
outline := outline + value;
end;
lReport.Add(outline);
outline := ' ';
for j := start to last do
begin
value := Format('%8.4f',[ObjRankSums[j-1]]);
value := Format('%10.4f',[ObjRankSums[j-1]]);
outline := outline + value;
end;
lReport.Add(outline);
@ -339,24 +289,22 @@ begin
lReport.Add('Coefficient of concordance: %10.3f', [Concordance]);
lReport.Add('Average Spearman Rank Correlation: %10.3f', [AvgRankCorr]);
lReport.Add('Chi-Square Statistic: %10.3f', [ChiSquare]);
lReport.Add('Probability of a larger Chi-Square: %11.4f',[Probability]);
lReport.Add('Probability of a larger Chi-Square: %10.3f', [Probability]);
if (No_Objects < 7) then
lReport.Add('Warning - Above Chi-Square is very approximate with 7 or fewer variables!');
begin
lReport.Add('');
lReport.Add('Warning - Above Chi-Square is very approximate with 7 or fewer variables!');
end;
DisplayReport(lReport);
FReportFrame.DisplayReport(lReport);
finally
lReport.Free;
ColNoSelected := nil;
ColLabels := nil;
ObjRankSums := nil;
temprank := nil;
tempindex := nil;
scorearray := nil;
end;
end;
procedure TConcordFrm.InBtnClick(Sender: TObject);
procedure TConcordForm.InBtnClick(Sender: TObject);
var
i: integer;
begin
@ -374,7 +322,8 @@ begin
UpdateBtnStates;
end;
procedure TConcordFrm.OutBtnClick(Sender: TObject);
procedure TConcordForm.OutBtnClick(Sender: TObject);
var
index: integer;
begin
@ -387,11 +336,42 @@ begin
UpdateBtnStates;
end;
procedure TConcordFrm.UpdateBtnStates;
procedure TConcordForm.Reset;
var
i: integer;
begin
inherited;
VarList.Clear;
SelList.Clear;
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
UpdateBtnStates;
end;
procedure TConcordForm.SelListDblClick(Sender: TObject);
var
index: Integer;
begin
index := SelList.ItemIndex;
if index > -1 then
begin
VarList.Items.Add(SelList.Items[index]);
SelList.Items.Delete(index);
UpdateBtnStates;
end;
end;
procedure TConcordForm.UpdateBtnStates;
var
lSelected: Boolean;
i: Integer;
begin
inherited;
lSelected := false;
for i := 0 to VarList.Items.Count-1 do
if VarList.Selected[i] then
@ -412,13 +392,41 @@ begin
AllBtn.Enabled := VarList.Count > 0;
end;
procedure TConcordFrm.VarListSelectionChange(Sender: TObject; User: boolean);
function TConcordForm.Validate(out AMsg: string; out AControl: TWinControl): Boolean;
begin
Result := false;
if SelList.Items.Count = 0 then
begin
AMsg := 'No variables selected.';
AControl := SelList;
exit;
end;
Result := true;
end;
procedure TConcordForm.VarListDblClick(Sender: TObject);
var
index: Integer;
begin
index := VarList.ItemIndex;
if index > -1 then
begin
SelList.Items.Add(VarList.Items[index]);
Varlist.Items.Delete(index);
UpdateBtnStates;
end;
end;
procedure TConcordForm.VarListSelectionChange(Sender: TObject; User: boolean);
begin
UpdateBtnStates;
end;
initialization
{$I concordanceunit.lrs}
end.

View File

@ -1840,9 +1840,9 @@ end;
// Menu "Analysis" > "Nonparametric" > "Kendall's Coefficient of Concordance"
procedure TOS3MainFrm.mnuAnalysisNonPar_KendallClick(Sender: TObject);
begin
if ConcordFrm = nil then
Application.CreateForm(TConcordFrm, ConcordFrm);
ConcordFrm.ShowModal;
if ConcordForm = nil then
Application.CreateForm(TConcordForm, ConcordForm);
ConcordForm.Show;
end;
// Menu "Analysis" > "Nonparametric" > "Kruskal-Wallis One-Way mnuAnalysisComp_Anova"