2020-03-30 18:01:44 +00:00
|
|
|
unit TwoPropUnit;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2020-11-03 23:54:55 +00:00
|
|
|
Classes, SysUtils, Forms, Controls,
|
|
|
|
Graphics, Dialogs, ExtCtrls, StdCtrls, ComCtrls, Buttons, MainUnit, Globals,
|
|
|
|
FunctionsLib, DataProcs, BasicStatsReportFormUnit;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
{ TTwoPropForm }
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
TTwoPropForm = class(TBasicStatsReportForm)
|
2020-03-30 18:01:44 +00:00
|
|
|
Bevel2: TBevel;
|
|
|
|
Bevel3: TBevel;
|
|
|
|
Bevel5: TBevel;
|
|
|
|
LabelCorner: TLabel;
|
2020-11-03 23:54:55 +00:00
|
|
|
Notebook: TNotebook;
|
2020-03-30 18:01:44 +00:00
|
|
|
Page1: TPage;
|
|
|
|
Page2: TPage;
|
|
|
|
Page3: TPage;
|
|
|
|
Panel3: TPanel;
|
|
|
|
Panel4: TPanel;
|
|
|
|
DepFreq00: TEdit;
|
|
|
|
DepFreq10: TEdit;
|
|
|
|
DepFreq01: TEdit;
|
|
|
|
DepFreq11: TEdit;
|
2020-11-03 23:54:55 +00:00
|
|
|
CIntervalEdit: TEdit;
|
|
|
|
GrpEdit: TEdit;
|
2020-03-30 18:01:44 +00:00
|
|
|
GrpLabel: TLabel;
|
|
|
|
ConfLabel: TLabel;
|
2020-11-03 23:54:55 +00:00
|
|
|
Var1In: TBitBtn;
|
|
|
|
Var2In: TBitBtn;
|
|
|
|
Var1Out: TBitBtn;
|
|
|
|
GrpIn: TBitBtn;
|
|
|
|
Var2Out: TBitBtn;
|
|
|
|
Var2Edit: TEdit;
|
|
|
|
Var2Label: TLabel;
|
|
|
|
Var1Edit: TEdit;
|
2020-03-30 18:01:44 +00:00
|
|
|
IndSize2: TEdit;
|
|
|
|
IndSize1: TEdit;
|
|
|
|
IndFreq2: TEdit;
|
|
|
|
IndFreq1: TEdit;
|
|
|
|
Samp1Label: TLabel;
|
|
|
|
Samp21Label: TLabel;
|
|
|
|
Label11: TLabel;
|
2020-11-03 23:54:55 +00:00
|
|
|
Var1Label: TLabel;
|
2020-03-30 18:01:44 +00:00
|
|
|
Samp2Label: TLabel;
|
|
|
|
Samp1SizeLabel: TLabel;
|
|
|
|
Samp2SizeLabel: TLabel;
|
|
|
|
DepSamp2Label: TLabel;
|
|
|
|
DepSamp1Label: TLabel;
|
|
|
|
Samp10Label: TLabel;
|
|
|
|
Samp11Label: TLabel;
|
|
|
|
Samp20Label: TLabel;
|
2020-11-03 23:54:55 +00:00
|
|
|
GrpOut: TBitBtn;
|
2020-03-30 18:01:44 +00:00
|
|
|
VarList: TListBox;
|
2020-11-04 17:53:45 +00:00
|
|
|
DataSourceGroup: TRadioGroup;
|
2020-11-03 23:54:55 +00:00
|
|
|
DepIndepGroup: TRadioGroup;
|
|
|
|
procedure GrpInClick(Sender: TObject);
|
|
|
|
procedure GrpOutClick(Sender: TObject);
|
2020-11-04 17:53:45 +00:00
|
|
|
procedure DataSourceGroupClick(Sender: TObject);
|
2020-11-03 23:54:55 +00:00
|
|
|
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);
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
private
|
|
|
|
independent: boolean;
|
|
|
|
griddata: boolean;
|
2020-11-03 23:54:55 +00:00
|
|
|
|
|
|
|
protected
|
|
|
|
procedure AdjustConstraints; override;
|
|
|
|
procedure Compute; override;
|
|
|
|
procedure UpdateBtnStates; override;
|
|
|
|
function Validate(out AMsg: String; out AControl: TWinControl): Boolean; override;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
public
|
2020-11-03 23:54:55 +00:00
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
procedure Reset; override;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
2020-11-03 23:54:55 +00:00
|
|
|
TwoPropForm: TTwoPropForm;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
{$R *.lfm}
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
uses
|
2020-11-04 17:53:45 +00:00
|
|
|
Math,
|
|
|
|
GridProcs;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
{ TTwoPropForm }
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
constructor TTwoPropForm.Create(AOwner: TComponent);
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-03 23:54:55 +00:00
|
|
|
inherited;
|
|
|
|
CIntervalEdit.Text := FormatFloat('0.0', DEFAULT_CONFIDENCE_LEVEL_PERCENT);
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
procedure TTwoPropForm.AdjustConstraints;
|
2020-11-04 17:53:45 +00:00
|
|
|
var
|
|
|
|
w: Integer;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-03 23:54:55 +00:00
|
|
|
inherited;
|
2020-11-04 17:53:45 +00:00
|
|
|
|
|
|
|
w := Max(DataSourceGroup.Width, DepIndepGroup.Width);
|
|
|
|
DataSourceGroup.Constraints.MinWidth := w;
|
|
|
|
DepIndepGroup.Constraints.MinWidth := w;
|
2020-11-03 23:54:55 +00:00
|
|
|
ParamsPanel.Constraints.MinWidth := Max(
|
|
|
|
4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left,
|
2020-11-04 17:53:45 +00:00
|
|
|
2*w + Bevel5.Width
|
2020-11-03 23:54:55 +00:00
|
|
|
);
|
2020-11-04 17:53:45 +00:00
|
|
|
ParamsPanel.Constraints.MinHeight := DataSourceGroup.Height +
|
|
|
|
Notebook.BorderSpacing.Top + Var2Out.Top + Var2Out.Height +
|
2020-11-03 23:54:55 +00:00
|
|
|
Notebook.BorderSpacing.Bottom + CIntervalEdit.Height + ButtonBevel.Height +
|
|
|
|
CloseBtn.BorderSpacing.Top + CloseBtn.Height;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
|
|
|
|
procedure TTwoPropForm.Compute;
|
2020-03-30 18:01:44 +00:00
|
|
|
var
|
|
|
|
ConfInt, Prop1, Prop2, zstatistic, zprobability: double;
|
|
|
|
PropDif, stderr, UCL, LCL, value1, value2, ztest: double;
|
|
|
|
P, Q: double;
|
2020-11-04 17:53:45 +00:00
|
|
|
i: Integer; //, v1, v2, NoSelected,
|
|
|
|
f1, f2, f3, f4, ncases1, ncases2: integer;
|
2020-03-30 18:01:44 +00:00
|
|
|
min, max, group, AB, AC, CD, BD: integer;
|
2020-10-26 18:00:52 +00:00
|
|
|
ColNoSelected: IntDyneVec = nil;
|
2020-03-30 18:01:44 +00:00
|
|
|
lReport: TStrings;
|
|
|
|
begin
|
|
|
|
// Initialize output form
|
|
|
|
stderr := 0.0;
|
|
|
|
PropDif := 0.0;
|
2020-11-04 17:53:45 +00:00
|
|
|
// v2 := 0;
|
2020-03-30 18:01:44 +00:00
|
|
|
ztest := 0.0;
|
|
|
|
Prop1 := 0.0;
|
|
|
|
Prop2 := 0.0;
|
2020-11-04 17:53:45 +00:00
|
|
|
// NoSelected := 0;
|
|
|
|
// v1 := 0;
|
2020-03-30 18:01:44 +00:00
|
|
|
zstatistic := 0.0;
|
|
|
|
zprobability := 0.0;
|
|
|
|
UCL := 0.0;
|
|
|
|
LCL := 0.0;
|
|
|
|
|
|
|
|
SetLength(ColNoSelected,NoVariables);
|
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
ConfInt := (100.0 - StrToFloat(CIntervalEdit.Text)) / 2.0 ;
|
2020-03-30 18:01:44 +00:00
|
|
|
ConfInt := (100.0 - ConfInt) / 100.0; // one tail
|
2020-11-04 17:53:45 +00:00
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
ncases1 := 0;
|
|
|
|
ncases2 := 0;
|
|
|
|
f1 := 0;
|
|
|
|
f2 := 0;
|
|
|
|
f3 := 0;
|
|
|
|
f4 := 0;
|
|
|
|
if independent then
|
2020-11-03 23:54:55 +00:00
|
|
|
Var2Edit.Text := GrpEdit.Text;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
if griddata then // data read from grid
|
|
|
|
begin
|
2020-11-04 17:53:45 +00:00
|
|
|
SetLength(ColNoSelected, 2);
|
|
|
|
ColNoSelected[0] := GetVariableIndex(OS3MainFrm.DataGrid, Var1Edit.Text);
|
|
|
|
ColNoSelected[1] := GetVariableIndex(OS3MainFrm.DataGrid, Var2Edit.Text);
|
|
|
|
{
|
2020-03-30 18:01:44 +00:00
|
|
|
for i := 1 to NoVariables do
|
|
|
|
begin
|
2020-11-03 23:54:55 +00:00
|
|
|
if Var1Edit.Text = OS3MainFrm.DataGrid.Cells[i,0] then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
|
|
|
v1 := i;
|
|
|
|
ColNoSelected[0] := i;
|
|
|
|
end;
|
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
if Var2Edit.Text = OS3MainFrm.DataGrid.Cells[i,0] then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
|
|
|
v2 := i;
|
|
|
|
ColNoSelected[1] := i;
|
|
|
|
end;
|
|
|
|
end; // next variable
|
2020-11-04 17:53:45 +00:00
|
|
|
}
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-11-04 17:53:45 +00:00
|
|
|
f1 := 0;
|
|
|
|
f2 := 0;
|
|
|
|
nCases1 := 0;
|
2020-03-30 18:01:44 +00:00
|
|
|
if not independent then // correlated data
|
|
|
|
begin
|
|
|
|
for i := 1 to NoCases do
|
|
|
|
begin
|
2020-11-04 17:53:45 +00:00
|
|
|
if not GoodRecord(OS3MainFrm.DataGrid, i, ColNoSelected) then continue;
|
|
|
|
nCases1 := nCases1 + 1;
|
|
|
|
value1 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[0], i]));
|
|
|
|
value2 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[1], i]));
|
2020-03-30 18:01:44 +00:00
|
|
|
f1 := f1 + round(value1);
|
|
|
|
f2 := f2 + round(value2);
|
|
|
|
end; // next case
|
2020-11-04 17:53:45 +00:00
|
|
|
f3 := nCases1 - f1;
|
|
|
|
f4 := nCases1 - f2;
|
2020-03-30 18:01:44 +00:00
|
|
|
AB := f1 + f2;
|
|
|
|
AC := f1 + f3;
|
|
|
|
CD := f3 + f4;
|
|
|
|
BD := f2 + f4;
|
2020-11-04 17:53:45 +00:00
|
|
|
Prop1 := BD / nCases1;
|
|
|
|
Prop2 := AB / nCases1;
|
|
|
|
stderr := sqrt((f1 / nCases1 + f4 / nCases1) / nCases1);
|
2020-03-30 18:01:44 +00:00
|
|
|
PropDif := Prop1 - Prop2;
|
|
|
|
zstatistic := PropDif / stderr;
|
2020-11-04 17:53:45 +00:00
|
|
|
ztest := InverseZ(ConfInt);
|
2020-11-03 23:54:55 +00:00
|
|
|
zprobability := 1.0 - ProbZ(abs(zstatistic));
|
2020-03-30 18:01:44 +00:00
|
|
|
UCL := PropDif + stderr * ztest;
|
|
|
|
LCL := PropDif - stderr * ztest;
|
|
|
|
end; // if not independent
|
|
|
|
|
|
|
|
if independent then
|
|
|
|
begin
|
2020-11-04 17:53:45 +00:00
|
|
|
min := MaxInt;
|
2020-03-30 18:01:44 +00:00
|
|
|
max := min;
|
2020-11-04 17:53:45 +00:00
|
|
|
for i := 1 to NoCases do
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-04 17:53:45 +00:00
|
|
|
if not GoodRecord(OS3MainFrm.DataGrid, i, ColNoSelected) then continue;
|
|
|
|
group := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[1], i])));
|
2020-03-30 18:01:44 +00:00
|
|
|
if group < min then min := group;
|
|
|
|
if group > max then max := group;
|
|
|
|
end;
|
|
|
|
|
|
|
|
for i := 1 to NoCases do
|
|
|
|
begin
|
2020-11-04 17:53:45 +00:00
|
|
|
if not GoodRecord(OS3MainFrm.DataGrid, i, ColNoSelected) then continue;
|
|
|
|
value1 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[0], i]));
|
|
|
|
group := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[1], i])));
|
2020-03-30 18:01:44 +00:00
|
|
|
if group = min then
|
|
|
|
begin
|
|
|
|
f1 := f1 + round(value1);
|
|
|
|
ncases1 := ncases1 + 1;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
f2 := f2 + round(value1);
|
|
|
|
ncases2 := ncases2 + 1;
|
|
|
|
end;
|
|
|
|
end; // next case
|
|
|
|
|
|
|
|
Prop1 := f1 / ncases1;
|
|
|
|
Prop2 := f2 / ncases2;
|
|
|
|
PropDif := Prop1 - Prop2;
|
|
|
|
P := (f1 + f2) / (ncases1 + ncases2);
|
|
|
|
Q := 1.0 - P;
|
|
|
|
stderr := sqrt(P * Q * ((1.0 / ncases1) + (1.0 / ncases2)));
|
|
|
|
zstatistic := (Prop1 - Prop2) / stderr;
|
|
|
|
zprobability := 1.0 - probz(abs(zstatistic));
|
|
|
|
ztest := inversez(ConfInt);
|
|
|
|
UCL := PropDif + ztest * stderr;
|
|
|
|
LCL := PropDif - ztest * stderr;
|
|
|
|
end; // end if independent
|
|
|
|
end; // if reading grid data
|
|
|
|
|
|
|
|
if not griddata then // data read from form
|
|
|
|
begin
|
|
|
|
if not independent then // correlated data
|
|
|
|
begin
|
|
|
|
f1 := round(StrToFloat(DepFreq00.Text));
|
|
|
|
f2 := round(StrToFloat(DepFreq10.Text));
|
|
|
|
f3 := round(StrToFloat(DepFreq01.Text));
|
|
|
|
f4 := round(StrToFloat(DepFreq11.Text));
|
|
|
|
ncases1 := f1 + f2 + f3 + f4;
|
|
|
|
AB := f1 + f2;
|
|
|
|
AC := f1 + f3;
|
|
|
|
CD := f3 + f4;
|
|
|
|
BD := f2 + f4;
|
|
|
|
Prop1 := BD / ncases1;
|
|
|
|
Prop2 := AB / ncases1;
|
|
|
|
stderr := sqrt((f1 / ncases1 + f4 / ncases1) / ncases1);
|
|
|
|
PropDif := Prop1 - Prop2;
|
|
|
|
zstatistic := PropDif / stderr;
|
|
|
|
ztest := inversez(ConfInt);
|
|
|
|
zprobability := 1.0 - probz(abs(zstatistic));
|
|
|
|
UCL := PropDif + stderr * ztest;
|
|
|
|
LCL := PropDif - stderr * ztest;
|
|
|
|
end; // if not independent
|
|
|
|
|
|
|
|
if independent then // independent data
|
|
|
|
begin
|
|
|
|
f1 := StrToInt(IndFreq1.Text);
|
|
|
|
f2 := StrToInt(IndFreq2.Text);
|
|
|
|
ncases1 := StrToInt(IndSize1.Text);
|
|
|
|
ncases2 := StrToInt(IndSize2.Text);
|
|
|
|
Prop1 := f1 / ncases1;
|
|
|
|
Prop2 := f2 / ncases2;
|
|
|
|
PropDif := Prop1 - Prop2;
|
|
|
|
P := (f1 + f2) / (ncases1 + ncases2);
|
|
|
|
Q := 1.0 - P;
|
|
|
|
stderr := sqrt(P * Q * ((1.0 / ncases1) + (1.0 / ncases2)));
|
|
|
|
zstatistic := (Prop1 - Prop2) / stderr;
|
|
|
|
zprobability := 1.0 - probz(abs(zstatistic));
|
|
|
|
ztest := inversez(ConfInt);
|
|
|
|
UCL := PropDif + ztest * stderr;
|
|
|
|
LCL := PropDif - ztest * stderr;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
// Print the results
|
|
|
|
lReport := TStringList.Create;
|
|
|
|
try
|
|
|
|
lReport.Add('COMPARISON OF TWO PROPORTIONS');
|
|
|
|
lReport.Add('');
|
|
|
|
if not independent then
|
|
|
|
begin
|
|
|
|
lReport.Add('Test for Difference Between Two Dependent Proportions');
|
|
|
|
lReport.Add('');
|
|
|
|
lReport.Add('Entered Values');
|
|
|
|
lReport.Add('');
|
|
|
|
lReport.Add('Sample 1');
|
|
|
|
lReport.Add(' 0 1 sum');
|
|
|
|
lReport.Add(' -----------------------');
|
|
|
|
lReport.Add(' 0 |%5d %5d %5d |', [f1, f2, AB]);
|
|
|
|
lReport.Add(' 2 --------|-------|------');
|
|
|
|
lReport.Add(' 1 |%5d %5d %5d |', [f3, f4, CD]);
|
|
|
|
lReport.Add(' --------|-------|------');
|
|
|
|
lReport.Add(' sum | %5d %5d %5d |', [AC, BD, ncases1]);
|
|
|
|
lReport.Add('');
|
2020-11-04 17:53:45 +00:00
|
|
|
lReport.Add('Confidence Level selected: %9s', [CIntervalEdit.Text]);
|
|
|
|
lReport.Add('Proportion 1: %9.3f', [Prop1]);
|
|
|
|
lReport.Add('Proportion 2: %9.3f', [Prop2]);
|
|
|
|
lReport.Add('Number of cases: %9d', [nCases1]);
|
2020-03-30 18:01:44 +00:00
|
|
|
lReport.Add('Difference in proportions: %9.3f', [PropDif]);
|
|
|
|
lReport.Add('Standard Error of Difference: %9.3f', [stderr]);
|
2020-11-03 23:54:55 +00:00
|
|
|
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]);
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
if independent then
|
|
|
|
begin
|
|
|
|
lReport.Add('Test for Difference Between Two Independent Proportions');
|
|
|
|
lReport.Add('');
|
|
|
|
lReport.Add('Entered Values');
|
|
|
|
lReport.Add('');
|
2020-11-04 17:53:45 +00:00
|
|
|
lReport.Add('Sample 1: Frequency %5d for %5d cases.', [f1, ncases1]);
|
|
|
|
lReport.Add('Sample 2: Frequency %5d for %5d cases.', [f2, ncases2]);
|
2020-03-30 18:01:44 +00:00
|
|
|
lReport.Add('');
|
|
|
|
lReport.Add('Proportion 1: %9.3f', [Prop1]);
|
|
|
|
lReport.Add('Proportion 2: %9.3f', [Prop2]);
|
|
|
|
lReport.Add('Difference: %9.3f', [PropDif]);
|
|
|
|
lReport.Add('Standard Error of Difference: %9.3f', [stderr]);
|
2020-11-04 17:53:45 +00:00
|
|
|
lReport.Add('Confidence Level selected: %9s', [CIntervalEdit.Text]);
|
2020-11-03 23:54:55 +00:00
|
|
|
lReport.Add('z test statistic: %9.3f', [zStatistic]);
|
|
|
|
lReport.Add(' with probability %9.4f', [zProbability]);
|
2020-03-30 18:01:44 +00:00
|
|
|
lReport.Add('z value for confidence interval: %9.3f', [ztest]);
|
2020-11-03 23:54:55 +00:00
|
|
|
lReport.Add('Confidence Interval: %9.3f ... %.3f', [LCL, UCL]);
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
FReportFrame.DisplayReport(lReport);
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
finally
|
|
|
|
lReport.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
|
|
|
|
procedure TTwoPropForm.GrpInClick(Sender: TObject);
|
2020-03-30 18:01:44 +00:00
|
|
|
var
|
2020-11-03 23:54:55 +00:00
|
|
|
index: Integer;
|
|
|
|
begin
|
|
|
|
index := VarList.ItemIndex;
|
|
|
|
if (index > -1) and (GrpEdit.Text = '') then
|
|
|
|
begin
|
|
|
|
GrpEdit.Text := VarList.Items[index];
|
|
|
|
VarList.Items.Delete(index);
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TTwoPropForm.GrpOutClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if GrpEdit.Text <> '' then
|
|
|
|
begin
|
|
|
|
VarList.Items.Add(GrpEdit.Text);
|
|
|
|
GrpEdit.Text := '';
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-11-04 17:53:45 +00:00
|
|
|
procedure TTwoPropForm.DataSourceGroupClick(Sender: TObject);
|
2020-11-03 23:54:55 +00:00
|
|
|
begin
|
2020-11-04 17:53:45 +00:00
|
|
|
griddata := (DataSourceGroup.ItemIndex = 1);
|
2020-11-03 23:54:55 +00:00
|
|
|
DepIndepGroupClick(nil);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TTwoPropForm.DepIndepGroupClick(Sender: TObject);
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-03 23:54:55 +00:00
|
|
|
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;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
Var2Edit.Visible := independent;
|
|
|
|
Var2Label.Visible := independent;
|
|
|
|
Var2In.Visible := independent;
|
|
|
|
Var2Out.Visible := independent;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
GrpEdit.Visible := not independent;
|
|
|
|
GrpLabel.Visible := not independent;
|
|
|
|
GrpIn.Visible := not independent;
|
|
|
|
GrpOut.Visible := not independent;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
end;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
|
|
|
|
procedure TTwoPropForm.Reset;
|
|
|
|
var
|
|
|
|
i: integer;
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
2020-11-04 17:53:45 +00:00
|
|
|
DataSourceGroup.ItemIndex := 0;
|
2020-11-03 23:54:55 +00:00
|
|
|
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;
|
2020-11-04 23:14:23 +00:00
|
|
|
|
|
|
|
UpdateBtnStates;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
|
|
|
|
procedure TTwoPropForm.Var1InClick(Sender: TObject);
|
|
|
|
var
|
|
|
|
index: Integer;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-03 23:54:55 +00:00
|
|
|
index := VarList.ItemIndex;
|
|
|
|
if (index > -1) and (Var1Edit.Text = '') then
|
|
|
|
begin
|
|
|
|
Var1Edit.Text := VarList.Items[index];
|
|
|
|
VarList.Items.Delete(index);
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
|
|
|
|
procedure TTwoPropForm.Var1OutClick(Sender: TObject);
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-03 23:54:55 +00:00
|
|
|
if Var1Edit.Text <> '' then
|
|
|
|
begin
|
|
|
|
VarList.Items.Add(Var1Edit.Text);
|
|
|
|
Var1Edit.Text := '';
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
|
|
|
|
procedure TTwoPropForm.Var2InClick(Sender: TObject);
|
|
|
|
var
|
|
|
|
index: Integer;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-03 23:54:55 +00:00
|
|
|
index := VarList.ItemIndex;
|
|
|
|
if (index > -1) and (Var2Edit.Text = '') then
|
|
|
|
begin
|
|
|
|
Var2Edit.Text := VarList.Items[index];
|
|
|
|
VarList.Items.Delete(index);
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
|
|
|
|
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;
|
2020-03-30 18:01:44 +00:00
|
|
|
var
|
|
|
|
n: Integer;
|
|
|
|
begin
|
|
|
|
Result := false;
|
|
|
|
AControl := nil;
|
|
|
|
AMsg := '';
|
2020-11-03 23:54:55 +00:00
|
|
|
if Notebook.PageIndex = 0 then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-03 23:54:55 +00:00
|
|
|
if Var1Edit.Text = '' then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-03 23:54:55 +00:00
|
|
|
AControl := Var1Edit;
|
2020-03-30 18:01:44 +00:00
|
|
|
AMsg := 'First variable not specified.';
|
|
|
|
exit;
|
|
|
|
end;
|
2020-11-03 23:54:55 +00:00
|
|
|
case DepIndepGroup.ItemIndex of
|
|
|
|
0: if (GrpEdit.Text = '') then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-03 23:54:55 +00:00
|
|
|
AControl := GrpEdit;
|
2020-03-30 18:01:44 +00:00
|
|
|
AMsg := 'Group code not specified';
|
|
|
|
exit;
|
|
|
|
end;
|
2020-11-03 23:54:55 +00:00
|
|
|
1: if (Var2Edit.Text = '') then begin
|
|
|
|
AControl := Var2Edit;
|
2020-03-30 18:01:44 +00:00
|
|
|
AMsg := 'Second variable not specified.';
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end else
|
2020-11-03 23:54:55 +00:00
|
|
|
if Notebook.PageIndex = 1 then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
|
|
|
if (IndFreq1.Text = '') or not TryStrToInt(IndFreq1.Text, n) or (n < 0) then
|
|
|
|
begin
|
|
|
|
AControl := IndFreq1;
|
|
|
|
AMsg := 'Invalid input for Sample 1 frequency';
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
if (IndFreq2.Text = '') or not TryStrToInt(IndFreq2.Text, n) or (n < 0) then
|
|
|
|
begin
|
|
|
|
AControl := IndFreq2;
|
|
|
|
AMsg := 'Invalid input for Sample 2 frequency';
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
if (IndSize1.Text = '') or not TryStrToInt(IndSize1.Text, n) or (n <= 0) then
|
|
|
|
begin
|
|
|
|
AControl := IndSize1;
|
|
|
|
AMsg := 'Invald input for size of sample 1';
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
if (IndSize2.Text = '') or not TryStrToInt(IndSize2.Text, n) or (n <= 0) then
|
|
|
|
begin
|
|
|
|
AControl := IndSize2;
|
|
|
|
AMsg := 'Invalud input for size of sample 2';
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end else
|
2020-11-03 23:54:55 +00:00
|
|
|
if Notebook.PageIndex = 2 then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
|
|
|
if (DepFreq00.Text = '') or not TryStrToInt(DepFreq00.Text, n) or (n < 0) then
|
|
|
|
AControl := DepFreq00
|
|
|
|
else
|
|
|
|
if (DepFreq01.Text = '') or not TryStrToInt(DepFreq01.Text, n) or (n < 0) then
|
|
|
|
AControl := DepFreq01
|
|
|
|
else
|
|
|
|
if (DepFreq10.Text = '') or not TryStrToInt(DepFreq10.Text, n) or (n < 0) then
|
|
|
|
AControl := DepFreq10
|
|
|
|
else
|
|
|
|
if (DepFreq11.Text = '') or not TryStrToInt(DepFreq11.Text, n) or (n < 0) then
|
|
|
|
AControl := DepFreq11;
|
|
|
|
if AControl <> nil then
|
|
|
|
begin
|
|
|
|
AMsg := 'Invalid input.';
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
Result := true;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-11-03 23:54:55 +00:00
|
|
|
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
|
|
|
|
begin
|
2020-11-04 17:53:45 +00:00
|
|
|
Var1Edit.Text := s;
|
|
|
|
VarList.Items.Delete(index);
|
|
|
|
end else
|
|
|
|
if independent and (GrpEdit.Text = '') then
|
|
|
|
begin
|
|
|
|
GrpEdit.Text := s;
|
|
|
|
VarList.Items.Delete(index);
|
|
|
|
end else
|
|
|
|
if (not independent) and (Var2Edit.Text = '') then
|
|
|
|
begin
|
|
|
|
Var2Edit.Text := s;
|
|
|
|
VarList.Items.Delete(index);
|
2020-11-03 23:54:55 +00:00
|
|
|
end;
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TTwoPropForm.VarListSelectionChange(Sender: TObject; User: boolean);
|
|
|
|
begin
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
end.
|
|
|
|
|