LazStats: Inherit TwoPropUnit from TBasicStatsReportForm.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7842 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-11-03 23:54:55 +00:00
parent 4805815adb
commit 7613b7da31
5 changed files with 816 additions and 716 deletions

View File

@ -315,7 +315,7 @@
<Unit26>
<Filename Value="forms\analysis\comparisons\twopropunit.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="TwoPropFrm"/>
<ComponentName Value="TwoPropForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="TwoPropUnit"/>

View File

@ -5,43 +5,41 @@ unit TwoPropUnit;
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls,
Graphics, Dialogs, ExtCtrls, StdCtrls, ComCtrls, MainUnit, Globals,
FunctionsLib, OutPutUnit, DataProcs, contexthelpunit;
Classes, SysUtils, Forms, Controls,
Graphics, Dialogs, ExtCtrls, StdCtrls, ComCtrls, Buttons, MainUnit, Globals,
FunctionsLib, DataProcs, BasicStatsReportFormUnit;
type
{ TTwoPropFrm }
{ TTwoPropForm }
TTwoPropFrm = class(TForm)
Bevel1: TBevel;
TTwoPropForm = class(TBasicStatsReportForm)
Bevel2: TBevel;
Bevel3: TBevel;
Bevel4: TBevel;
Bevel5: TBevel;
HelpBtn: TButton;
LabelCorner: TLabel;
Notebook1: TNotebook;
Notebook: TNotebook;
Page1: TPage;
Page2: TPage;
Page3: TPage;
Panel1: TPanel;
Panel3: TPanel;
Panel4: TPanel;
ResetBtn: TButton;
ComputeBtn: TButton;
CloseBtn: TButton;
DepFreq00: TEdit;
DepFreq10: TEdit;
DepFreq01: TEdit;
DepFreq11: TEdit;
CInterval: TEdit;
Grp: TEdit;
CIntervalEdit: TEdit;
GrpEdit: TEdit;
GrpLabel: TLabel;
ConfLabel: TLabel;
Var2: TEdit;
SecdVarLabel: TLabel;
Var1: TEdit;
Var1In: TBitBtn;
Var2In: TBitBtn;
Var1Out: TBitBtn;
GrpIn: TBitBtn;
Var2Out: TBitBtn;
Var2Edit: TEdit;
Var2Label: TLabel;
Var1Edit: TEdit;
IndSize2: TEdit;
IndSize1: TEdit;
IndFreq2: TEdit;
@ -49,7 +47,7 @@ type
Samp1Label: TLabel;
Samp21Label: TLabel;
Label11: TLabel;
FirstVarLabel: TLabel;
Var1Label: TLabel;
Samp2Label: TLabel;
Samp1SizeLabel: TLabel;
Samp2SizeLabel: TLabel;
@ -58,106 +56,70 @@ type
Samp10Label: TLabel;
Samp11Label: TLabel;
Samp20Label: TLabel;
GrpOut: TBitBtn;
VarList: TListBox;
RadioGroup1: TRadioGroup;
RadioGroup2: TRadioGroup;
procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure HelpBtnClick(Sender: TObject);
DepIndepGroup: TRadioGroup;
procedure GrpInClick(Sender: TObject);
procedure GrpOutClick(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
procedure RadioGroup2Click(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
procedure VarListClick(Sender: TObject);
procedure DepIndepGroupClick(Sender: TObject);
procedure Var1InClick(Sender: TObject);
procedure Var1OutClick(Sender: TObject);
procedure Var2InClick(Sender: TObject);
procedure Var2OutClick(Sender: TObject);
procedure VarListDblClick(Sender: TObject);
procedure VarListSelectionChange(Sender: TObject; {%H-}User: boolean);
private
{ private declarations }
FAutoSized: Boolean;
independent: boolean;
griddata: boolean;
function Validate(out AMsg: String; out AControl: TWinControl): Boolean;
protected
procedure AdjustConstraints; override;
procedure Compute; override;
procedure UpdateBtnStates; override;
function Validate(out AMsg: String; out AControl: TWinControl): Boolean; override;
public
{ public declarations }
constructor Create(AOwner: TComponent); override;
procedure Reset; override;
end;
var
TwoPropFrm: TTwoPropFrm;
TwoPropForm: TTwoPropForm;
implementation
{$R *.lfm}
uses
Math;
{ TTwoPropFrm }
procedure TTwoPropFrm.ResetBtnClick(Sender: TObject);
var
i: integer;
{ TTwoPropForm }
constructor TTwoPropForm.Create(AOwner: TComponent);
begin
CInterval.Text := FormatFloat('0.0', DEFAULT_CONFIDENCE_LEVEL_PERCENT);
RadioGroup1.ItemIndex := 0;
RadioGroup2.ItemIndex := 0;
VarList.Clear;
Var1.Text := '';
Var2.Text := '';
independent := true;
griddata := false;
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
GrpLabel.Visible := true;
Grp.Visible := true;
Grp.Text := '';
Var2.Visible := false;
SecdVarLabel.Visible := false;
DepFreq00.Text := '';
DepFreq01.Text := '';
DepFreq10.Text := '';
DepFreq11.Text := '';
IndFreq1.Text := '';
IndFreq2.Text := '';
IndSize1.Text := '';
IndSize2.Text := '';
Notebook1.PageIndex := 1;
inherited;
CIntervalEdit.Text := FormatFloat('0.0', DEFAULT_CONFIDENCE_LEVEL_PERCENT);
end;
procedure TTwoPropFrm.VarListClick(Sender: TObject);
var
index: integer;
begin
index := VarList.ItemIndex;
if not independent then
begin
if Var1.Text <> '' then
Var2.Text := VarList.Items[index]
else
Var1.Text := VarList.Items[index];
end;
if independent then
begin
if Var1.Text <> '' then
Grp.Text := VarList.Items[index]
else
Var1.Text := VarList.Items[index];
end;
procedure TTwoPropForm.AdjustConstraints;
begin
inherited;
ParamsPanel.Constraints.MinWidth := Max(
4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left,
RadioGroup1.Width + Bevel5.Width + DepIndepGroup.Width
);
ParamsPanel.Constraints.MinHeight := GrpOut.Top + GrpOut.Height +
Notebook.BorderSpacing.Bottom + CIntervalEdit.Height + ButtonBevel.Height +
CloseBtn.BorderSpacing.Top + CloseBtn.Height;
end;
procedure TTwoPropFrm.FormShow(Sender: TObject);
begin
ResetBtnClick(self);
end;
procedure TTwoPropFrm.HelpBtnClick(Sender: TObject);
begin
if ContextHelpForm = nil then
Application.CreateForm(TContextHelpForm, ContextHelpForm);
ContextHelpForm.HelpMessage((Sender as TButton).tag);
end;
procedure TTwoPropFrm.ComputeBtnClick(Sender: TObject);
procedure TTwoPropForm.Compute;
var
ConfInt, Prop1, Prop2, zstatistic, zprobability: double;
PropDif, stderr, UCL, LCL, value1, value2, ztest: double;
@ -165,18 +127,8 @@ var
i, v1, v2, NoSelected, f1, f2, f3, f4, ncases1, ncases2: integer;
min, max, group, AB, AC, CD, BD: integer;
ColNoSelected: IntDyneVec = nil;
msg: String;
C: TWinControl;
lReport: TStrings;
begin
if not Validate(msg, C) then
begin
C.SetFocus;
MessageDlg(msg, mtError, [mbOK], 0);
ModalResult := mrNone;
exit;
end;
// Initialize output form
stderr := 0.0;
PropDif := 0.0;
@ -193,7 +145,7 @@ begin
SetLength(ColNoSelected,NoVariables);
ConfInt := (100.0 - StrToFloat(CInterval.Text)) / 2.0 ;
ConfInt := (100.0 - StrToFloat(CIntervalEdit.Text)) / 2.0 ;
ConfInt := (100.0 - ConfInt) / 100.0; // one tail
ncases1 := 0;
ncases2 := 0;
@ -202,19 +154,19 @@ begin
f3 := 0;
f4 := 0;
if independent then
Var2.Text := Grp.Text;
Var2Edit.Text := GrpEdit.Text;
if griddata then // data read from grid
begin
for i := 1 to NoVariables do
begin
if Var1.Text = OS3MainFrm.DataGrid.Cells[i,0] then
if Var1Edit.Text = OS3MainFrm.DataGrid.Cells[i,0] then
begin
v1 := i;
ColNoSelected[0] := i;
end;
if Var2.Text = OS3MainFrm.DataGrid.Cells[i,0] then
if Var2Edit.Text = OS3MainFrm.DataGrid.Cells[i,0] then
begin
v2 := i;
ColNoSelected[1] := i;
@ -244,7 +196,7 @@ begin
PropDif := Prop1 - Prop2;
zstatistic := PropDif / stderr;
ztest := inversez(ConfInt);
zprobability := 1.0 - probz(abs(zstatistic));
zprobability := 1.0 - ProbZ(abs(zstatistic));
UCL := PropDif + stderr * ztest;
LCL := PropDif - stderr * ztest;
end; // if not independent
@ -355,13 +307,14 @@ begin
lReport.Add(' --------|-------|------');
lReport.Add(' sum | %5d %5d %5d |', [AC, BD, ncases1]);
lReport.Add('');
lReport.Add('Confidence Level selected: %s', [CInterval.Text]);
lReport.Add('Confidence Level selected: %s', [CIntervalEdit.Text]);
lReport.Add('Proportion 1 = %.3f and Proportion 2 = %.3f with %d cases', [Prop1, Prop2, ncases1]);
lReport.Add('Difference in proportions: %9.3f', [PropDif]);
lReport.Add('Standard Error of Difference: %9.3f', [stderr]);
lReport.Add('z test statistic: %9.3f with probability = %.4f', [zstatistic, zprobability]);
lReport.Add('z value for confidence interval: %9.3f', [ztest]);
lReport.Add('Confidence Interval: (%.3f, %.3f)', [LCL, UCL]);
lReport.Add('z test statistic: %9.3f', [zStatistic]);
lReport.Add(' with probability %9.4f', [zProbability]);
lReport.Add('z value for confidence interval: %9.3f', [zTest]);
lReport.Add('Confidence Interval: %9.3f ... %.3f', [LCL, UCL]);
end;
if independent then
@ -377,114 +330,217 @@ begin
lReport.Add('Proportion 2: %9.3f', [Prop2]);
lReport.Add('Difference: %9.3f', [PropDif]);
lReport.Add('Standard Error of Difference: %9.3f', [stderr]);
lReport.Add('Confidence Level selected: %9s', [CInterval.Text]);
lReport.Add('z test statistic: %9.3f with probability = %.4f', [zstatistic, zprobability]);
lReport.Add('Confidence Level selected: %-9s', [CIntervalEdit.Text]);
lReport.Add('z test statistic: %9.3f', [zStatistic]);
lReport.Add(' with probability %9.4f', [zProbability]);
lReport.Add('z value for confidence interval: %9.3f', [ztest]);
lReport.Add('Confidence Interval: (%.3f, %.3f)', [LCL, UCL]);
lReport.Add('Confidence Interval: %9.3f ... %.3f', [LCL, UCL]);
end;
DisplayReport(lReport);
FReportFrame.DisplayReport(lReport);
finally
lReport.Free;
ColNoSelected := nil;
end;
end;
procedure TTwoPropFrm.FormActivate(Sender: TObject);
procedure TTwoPropForm.GrpInClick(Sender: TObject);
var
w: Integer;
index: Integer;
begin
if FAutoSized then
exit;
RadioGroup2.Constraints.MinWidth := RadioGroup1.Width;
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;
Width := Max(
RadioGroup2.Left + RadioGroup2.Width + RadioGroup2.BorderSpacing.Right,
Width - HelpBtn.Left + HelpBtn.BorderSpacing.Left
);
Constraints.MinWidth := Width;
Constraints.MinHeight := Height;
FAutoSized := true;
index := VarList.ItemIndex;
if (index > -1) and (GrpEdit.Text = '') then
begin
GrpEdit.Text := VarList.Items[index];
VarList.Items.Delete(index);
UpdateBtnStates;
end;
end;
procedure TTwoPropFrm.FormCreate(Sender: TObject);
procedure TTwoPropForm.GrpOutClick(Sender: TObject);
begin
Assert(OS3MainFrm <> nil);
if GrpEdit.Text <> '' then
begin
VarList.Items.Add(GrpEdit.Text);
GrpEdit.Text := '';
UpdateBtnStates;
end;
end;
procedure TTwoPropFrm.RadioGroup1Click(Sender: TObject);
procedure TTwoPropForm.RadioGroup1Click(Sender: TObject);
begin
griddata := RadioGroup1.ItemIndex = 1;
RadioGroup2Click(nil);
griddata := (RadioGroup1.ItemIndex = 1);
DepIndepGroupClick(nil);
end;
procedure TTwoPropFrm.RadioGroup2Click(Sender: TObject);
procedure TTwoPropForm.DepIndepGroupClick(Sender: TObject);
begin
case RadioGroup2.ItemIndex of
0: begin
independent := true;
if griddata then begin
Notebook1.PageIndex := 0;
Var2.Visible := false;
Grp.Visible := true;
SecdVarLabel.Visible := Var2.Visible;
GrpLabel.Visible := Grp.Visible;
end else
Notebook1.PageIndex := 1;
end;
1: begin
independent := false;
if griddata then begin
Notebook1.PageIndex := 0;
Var2.Visible := true;
Grp.Visible := false;
SecdVarLabel.Visible := Var2.Visible;
GrpLabel.Visible := Grp.Visible;
end else
Notebook1.PageIndex := 2;
end;
end;
case DepIndepGroup.ItemIndex of
0: begin
independent := true;
if griddata then
Notebook.PageIndex := 0
else
Notebook.PageIndex := 1;
end;
1: begin
independent := false;
if griddata then
Notebook.PageIndex := 0
else
Notebook.PageIndex := 2;
end;
end;
Var2Edit.Visible := independent;
Var2Label.Visible := independent;
Var2In.Visible := independent;
Var2Out.Visible := independent;
GrpEdit.Visible := not independent;
GrpLabel.Visible := not independent;
GrpIn.Visible := not independent;
GrpOut.Visible := not independent;
end;
function TTwoPropFrm.Validate(out AMsg: String; out AControl: TWinControl): Boolean;
procedure TTwoPropForm.Reset;
var
i: integer;
begin
inherited;
RadioGroup1.ItemIndex := 0;
DepIndepGroup.ItemIndex := 0;
VarList.Clear;
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
Var1Edit.Clear;
Var2Edit.Clear;
independent := true;
griddata := false;
GrpLabel.Visible := true;
GrpEdit.Visible := true;
GrpIn.Visible := true;
GrpOut.Visible := true;
GrpEdit.Clear;
Var2Edit.Visible := false;
Var2Label.Visible := false;
Var2In.Visible := false;
Var2Out.Visible := false;
DepFreq00.Clear;
DepFreq01.Clear;
DepFreq10.Clear;
DepFreq11.Clear;
IndFreq1.Clear;
IndFreq2.Clear;
IndSize1.Clear;
IndSize2.Clear;
Notebook.PageIndex := 1;
end;
procedure TTwoPropForm.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);
UpdateBtnStates;
end;
end;
procedure TTwoPropForm.Var1OutClick(Sender: TObject);
begin
if Var1Edit.Text <> '' then
begin
VarList.Items.Add(Var1Edit.Text);
Var1Edit.Text := '';
UpdateBtnStates;
end;
end;
procedure TTwoPropForm.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);
UpdateBtnStates;
end;
end;
procedure TTwoPropForm.Var2OutClick(Sender: TObject);
begin
if Var2Edit.Text <> '' then
begin
VarList.Items.Add(Var2Edit.Text);
Var2Edit.Text := '';
UpdateBtnStates;
end;
end;
procedure TTwoPropForm.UpdateBtnStates;
begin
inherited;
Var1In.Enabled := (VarList.ItemIndex > -1) and (Var1Edit.Text = '');
Var2In.Enabled := (VarList.ItemIndex > -1) and (Var2Edit.Text = '');
GrpIn.Enabled := (VarList.ItemIndex > -1) and (GrpEdit.Text = '');
Var1Out.Enabled := Var1Edit.Text <> '';
Var2Out.Enabled := Var2Edit.Text <> '';
GrpOut.Enabled := GrpEdit.Text <> '';
end;
function TTwoPropForm.Validate(out AMsg: String; out AControl: TWinControl): Boolean;
var
n: Integer;
begin
Result := false;
AControl := nil;
AMsg := '';
if Notebook1.PageIndex = 0 then
if Notebook.PageIndex = 0 then
begin
if Var1.Text = '' then
if Var1Edit.Text = '' then
begin
AControl := Var1;
AControl := Var1Edit;
AMsg := 'First variable not specified.';
exit;
end;
case RadioGroup2.ItemIndex of
0: if (Grp.Text = '') then
case DepIndepGroup.ItemIndex of
0: if (GrpEdit.Text = '') then
begin
AControl := Grp;
AControl := GrpEdit;
AMsg := 'Group code not specified';
exit;
end;
1: if (Var2.Text = '') then begin
AControl := Var2;
1: if (Var2Edit.Text = '') then begin
AControl := Var2Edit;
AMsg := 'Second variable not specified.';
exit;
end;
end;
end else
if Notebook1.PageIndex = 1 then
if Notebook.PageIndex = 1 then
begin
if (IndFreq1.Text = '') or not TryStrToInt(IndFreq1.Text, n) or (n < 0) then
begin
@ -511,7 +567,7 @@ begin
exit;
end;
end else
if Notebook1.PageIndex = 2 then
if Notebook.PageIndex = 2 then
begin
if (DepFreq00.Text = '') or not TryStrToInt(DepFreq00.Text, n) or (n < 0) then
AControl := DepFreq00
@ -534,8 +590,40 @@ begin
end;
initialization
{$I twopropunit.lrs}
procedure TTwoPropForm.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
begin
if independent then
begin
if GrpEdit.Text = '' then
GrpEdit.Text := s;
end else
begin
if Var2Edit.Text = '' then
Var2Edit.Text := s;
end;
end;
UpdateBtnStates;
end;
end;
procedure TTwoPropForm.VarListSelectionChange(Sender: TObject; User: boolean);
begin
UpdateBtnStates;
end;
end.

View File

@ -141,7 +141,7 @@ inherited WithinANOVAFrm: TWithinANOVAFrm
Top = 25
Width = 124
Caption = 'Test Assumptions'
TabOrder = 1
TabOrder = 2
end
object PlotChk: TCheckBox
Left = 156
@ -149,7 +149,7 @@ inherited WithinANOVAFrm: TWithinANOVAFrm
Top = 6
Width = 79
Caption = 'Plot Means'
TabOrder = 2
TabOrder = 1
end
end
object SelList: TListBox[11]

View File

@ -911,9 +911,9 @@ end;
// Menu "Analysis" > "Comparisons" > "Difference beween Proportions"
procedure TOS3MainFrm.mnuAnalysisComp_PropDiffClick(Sender: TObject);
begin
if TwoPropFrm = nil then
Application.CreateForm(TTwoPropFrm, TwoPropFrm);
TwoPropFrm.ShowModal;
if TwoPropForm = nil then
Application.CreateForm(TTwoPropForm, TwoPropForm);
TwoPropForm.Show;
end;
// Menu "Analysis" > "Comparisons" > "t-tests"
@ -924,14 +924,6 @@ begin
TTestFrm.ShowModal;
end;
// Menu "Analysis" > "Nonparametric" > "Kappa and Weighted Kappa"
procedure TOS3MainFrm.mnuAnalysisNonPar_WeightedKappaClick(Sender: TObject);
begin
if WeightedKappaFrm = nil then
Application.CreateForm(TWeightedKappaFrm, WeightedKappaFrm);
WeightedKappaFrm.ShowModal;
end;
// Menu "Analysis" > "Comparisons" > "Within Subjects mnuAnalysisComp_Anova"
procedure TOS3MainFrm.mnuAnalysisComp_WithinAnovaClick(Sender: TObject);
begin
@ -1661,14 +1653,6 @@ end;
// Menu "Analysis" > "Nonparametric" > "Generalized Kappa"
procedure TOS3MainFrm.mnuAnalysisNonPar_GenKappaClick(Sender: TObject);
begin
if GenKappaFrm = nil then
Application.CreateForm(TGenKappaFrm, GenKappaFrm);
GenKappaFrm.ShowModal;
end;
// Menu "Analysis" > "Nonparametric" > "General Linear Model"
procedure TOS3MainFrm.mnuAnalysisComp_GLMClick(Sender: TObject);
begin
@ -1717,14 +1701,6 @@ begin
LatinSqrsFrm.ShowModal;
end;
// Menu "Analysis" > "Nonparametric" > "Life table"
procedure TOS3MainFrm.mnuAnalysisNonPar_LifeTableClick(Sender: TObject);
begin
if LifeTableForm = nil then
Application.CreateForm(TLifeTableForm, LifeTableForm);
LifeTableForm.ShowModal;
end;
procedure TOS3MainFrm.MatManMnuClick(Sender: TObject);
begin
if MatManFrm = nil then
@ -1919,6 +1895,30 @@ begin
SRHTestForm.Show;
end;
// Menu "Analysis" > "Nonparametric" > "Generalized Kappa"
procedure TOS3MainFrm.mnuAnalysisNonPar_GenKappaClick(Sender: TObject);
begin
if GenKappaFrm = nil then
Application.CreateForm(TGenKappaFrm, GenKappaFrm);
GenKappaFrm.ShowModal;
end;
// Menu "Analysis" > "Nonparametric" > "Kappa and Weighted Kappa"
procedure TOS3MainFrm.mnuAnalysisNonPar_WeightedKappaClick(Sender: TObject);
begin
if WeightedKappaFrm = nil then
Application.CreateForm(TWeightedKappaFrm, WeightedKappaFrm);
WeightedKappaFrm.ShowModal;
end;
// Menu "Analysis" > "Nonparametric" > "Life table"
procedure TOS3MainFrm.mnuAnalysisNonPar_LifeTableClick(Sender: TObject);
begin
if LifeTableForm = nil then
Application.CreateForm(TLifeTableForm, LifeTableForm);
LifeTableForm.ShowModal;
end;
{ Descriptive statistics commands }