2020-03-30 18:01:44 +00:00
|
|
|
unit TTestUnit;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2020-11-04 23:14:23 +00:00
|
|
|
Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
|
|
|
|
ExtCtrls, StdCtrls, Buttons,
|
|
|
|
MainUnit, Globals, BasicStatsReportFormUnit;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
|
2020-11-04 23:14:23 +00:00
|
|
|
{ TTtestForm }
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-11-04 23:14:23 +00:00
|
|
|
TTtestForm = class(TBasicStatsReportForm)
|
2020-03-30 18:01:44 +00:00
|
|
|
Bevel3: TBevel;
|
|
|
|
Bevel4: TBevel;
|
|
|
|
Bevel5: TBevel;
|
2020-11-04 23:14:23 +00:00
|
|
|
TailCombo: TComboBox;
|
|
|
|
GroupCodeGroup: TGroupBox;
|
|
|
|
GroupCodeChk: TCheckBox;
|
|
|
|
Grp1CodeEdit: TEdit;
|
|
|
|
Grp2CodeEdit: TEdit;
|
2020-03-30 18:01:44 +00:00
|
|
|
GrpCodeLabel1: TLabel;
|
|
|
|
GrpCodeLabel2: TLabel;
|
2020-11-04 23:14:23 +00:00
|
|
|
GrpIn: TBitBtn;
|
|
|
|
GrpOut: TBitBtn;
|
|
|
|
Label2: TLabel;
|
|
|
|
Notebook: TNotebook;
|
2020-03-30 18:01:44 +00:00
|
|
|
Page1: TPage;
|
|
|
|
Page2: TPage;
|
2020-11-04 23:14:23 +00:00
|
|
|
Cor12Label: TLabel;
|
2020-03-30 18:01:44 +00:00
|
|
|
Cor12: TEdit;
|
|
|
|
CInterval: TEdit;
|
2020-11-04 23:14:23 +00:00
|
|
|
GrpEdit: TEdit;
|
2020-03-30 18:01:44 +00:00
|
|
|
Label1: TLabel;
|
2020-11-04 23:14:23 +00:00
|
|
|
Var1In: TBitBtn;
|
|
|
|
Var1Out: TBitBtn;
|
|
|
|
Var2Edit: TEdit;
|
|
|
|
Var1Edit: TEdit;
|
|
|
|
Var1Label: TLabel;
|
2020-03-30 18:01:44 +00:00
|
|
|
GrpLabel: TLabel;
|
2020-11-04 23:14:23 +00:00
|
|
|
Var2Label: TLabel;
|
|
|
|
VarList: TListBox;
|
2020-03-30 18:01:44 +00:00
|
|
|
SelVarLabel: TLabel;
|
|
|
|
N2: TEdit;
|
|
|
|
N1: TEdit;
|
|
|
|
SampSize2Label: TLabel;
|
|
|
|
SampSize1Label: TLabel;
|
|
|
|
SD2: TEdit;
|
|
|
|
SD1: TEdit;
|
|
|
|
SD2Label: TLabel;
|
|
|
|
SD1Label: TLabel;
|
|
|
|
Mean2: TEdit;
|
|
|
|
Mean1: TEdit;
|
|
|
|
Mean2Label: TLabel;
|
|
|
|
Mean1Label: TLabel;
|
2020-11-04 23:14:23 +00:00
|
|
|
DataEntryGroup: TRadioGroup;
|
|
|
|
DepIndepGroup: TRadioGroup;
|
|
|
|
Var2In: TBitBtn;
|
|
|
|
Var2Out: TBitBtn;
|
|
|
|
procedure GroupCodeChkChange(Sender: TObject);
|
|
|
|
procedure DataEntryGroupClick(Sender: TObject);
|
|
|
|
procedure DepIndepGroupClick(Sender: TObject);
|
|
|
|
procedure GrpInClick(Sender: TObject);
|
|
|
|
procedure GrpOutClick(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; User: boolean);
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
private
|
|
|
|
independent: boolean;
|
|
|
|
griddata: boolean;
|
2020-11-04 23:14:23 +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-04 23:14:23 +00:00
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
procedure Reset; override;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
2020-11-04 23:14:23 +00:00
|
|
|
TtestForm: TTtestForm;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
|
2020-11-04 23:14:23 +00:00
|
|
|
implementation
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-11-04 23:14:23 +00:00
|
|
|
{$R *.lfm}
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-11-04 23:14:23 +00:00
|
|
|
uses
|
|
|
|
Math,
|
|
|
|
MathUnit, GridProcs;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
|
2020-11-04 23:14:23 +00:00
|
|
|
{ TTtestForm }
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-11-04 23:14:23 +00:00
|
|
|
constructor TTtestForm.Create(AOwner: TComponent);
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-04 23:14:23 +00:00
|
|
|
inherited;
|
|
|
|
CInterval.Text := FormatFloat('0.0', DEFAULT_CONFIDENCE_LEVEL_PERCENT);
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-11-04 23:14:23 +00:00
|
|
|
procedure TTtestForm.AdjustConstraints;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-04 23:14:23 +00:00
|
|
|
inherited;
|
|
|
|
|
|
|
|
ParamsPanel.Constraints.MinWidth := Max(
|
|
|
|
DataEntryGroup.Width + DepIndepGroup.BorderSpacing.Left + DepIndepGroup.Width,
|
|
|
|
4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left
|
|
|
|
);
|
|
|
|
ParamsPanel.Constraints.MinHeight := DataEntryGroup.Height +
|
|
|
|
TailCombo.BorderSpacing.Top + TailCombo.Height +
|
|
|
|
CInterval.BorderSpacing.Top + CInterval.Height + CInterval.BorderSpacing.Bottom +
|
|
|
|
Bevel3.Height + Bevel3.BorderSpacing.Bottom +
|
|
|
|
GrpIn.Top + GroupCodeGroup.Height +
|
|
|
|
ButtonBevel.Height + CloseBtn.BorderSpacing.Top + CloseBtn.Height;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-11-04 23:14:23 +00:00
|
|
|
|
|
|
|
procedure TTtestForm.Compute;
|
2020-03-30 18:01:44 +00:00
|
|
|
var
|
|
|
|
M1, M2, Dif, stddev1, stddev2, r12, stderr1, stderr2: double;
|
|
|
|
tequal, tunequal, cov12, lowci, hici, F, Fp, df1, df2: double;
|
|
|
|
tprobability, value1, value2: double;
|
|
|
|
variance1, variance2, pooled, sedif, df, ConfInt, tconfint: double;
|
2020-11-04 23:14:23 +00:00
|
|
|
i, nCases1, nCases2: integer;
|
2020-03-30 18:01:44 +00:00
|
|
|
group, min, max: integer;
|
2020-10-26 18:00:52 +00:00
|
|
|
ColNoSelected: IntDyneVec = nil;
|
2020-03-30 18:01:44 +00:00
|
|
|
label1Str, label2Str: string;
|
|
|
|
lReport: TStrings;
|
|
|
|
begin
|
|
|
|
SetLength(ColNoSelected,NoVariables);
|
|
|
|
ncases1 := 0;
|
|
|
|
ncases2 := 0;
|
|
|
|
variance1 := 0.0;
|
|
|
|
variance2 := 0.0;
|
|
|
|
M1 := 0.0;
|
|
|
|
M2 := 0.0;
|
|
|
|
Dif := 0.0;
|
|
|
|
r12 := 0.0;
|
|
|
|
stddev1 := 0.0;
|
|
|
|
stddev2 := 0.0;
|
|
|
|
|
|
|
|
ConfInt := (100.0 - StrToFloat(CInterval.Text)) / 2.0 ;
|
|
|
|
ConfInt := (100.0 - ConfInt) / 100.0; // one tail
|
|
|
|
|
|
|
|
if independent then
|
2020-11-04 23:14:23 +00:00
|
|
|
Var2Edit.Text := GrpEdit.Text;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
// data read from grid
|
|
|
|
if griddata then
|
|
|
|
begin
|
2020-11-04 23:14:23 +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
|
|
|
|
|
|
|
ncases1 := 0;
|
|
|
|
ncases2 := 0;
|
|
|
|
M1 := 0.0;
|
|
|
|
M2 := 0.0;
|
|
|
|
variance1 := 0.0;
|
|
|
|
variance2 := 0.0;
|
|
|
|
r12 := 0.0;
|
|
|
|
if not independent then // correlated data
|
|
|
|
begin
|
|
|
|
for i := 1 to NoCases do
|
|
|
|
begin
|
2020-11-04 23:14:23 +00:00
|
|
|
if not GoodRecord(OS3MainFrm.DataGrid, i, ColNoSelected) then continue;
|
2020-03-30 18:01:44 +00:00
|
|
|
ncases1 := ncases1 + 1;
|
2020-11-04 23:14:23 +00:00
|
|
|
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
|
|
|
M1 := M1 + value1;
|
|
|
|
M2 := M2 + value2;
|
|
|
|
variance1 := variance1 + value1 * value1;
|
|
|
|
variance2 := variance2 + value2 * value2;
|
|
|
|
r12 := r12 + value1 * value2;
|
|
|
|
end;
|
|
|
|
|
|
|
|
ncases2 := ncases1;
|
|
|
|
variance1 := variance1 - (M1 * M1 / ncases1);
|
|
|
|
variance1 := variance1 / (ncases1 - 1);
|
|
|
|
stddev1 := sqrt(variance1);
|
|
|
|
variance2 := variance2 - (M2 * M2 / ncases2);
|
|
|
|
variance2 := variance2 / (ncases2 - 1);
|
|
|
|
stddev2 := sqrt(variance2);
|
|
|
|
r12 := r12 - (M1 * M2 / ncases1);
|
|
|
|
r12 := r12 / (ncases1 - 1);
|
|
|
|
cov12 := r12;
|
|
|
|
r12 := r12 / (stddev1 * stddev2);
|
|
|
|
M1 := M1 / ncases1;
|
|
|
|
M2 := M2 / ncases2;
|
|
|
|
Dif := M1 - M2;
|
|
|
|
end; //if not independent
|
|
|
|
|
|
|
|
if independent then
|
|
|
|
begin
|
2020-11-04 23:14:23 +00:00
|
|
|
if GroupCodeChk.Checked then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-04 23:14:23 +00:00
|
|
|
min := StrToInt(Grp1CodeEdit.Text);
|
|
|
|
max := StrToInt(Grp2CodeEdit.Text);
|
2020-03-30 18:01:44 +00:00
|
|
|
end else
|
|
|
|
begin
|
2020-11-04 23:14:23 +00:00
|
|
|
min := MaxInt;
|
2020-03-30 18:01:44 +00:00
|
|
|
max := min;
|
|
|
|
end;
|
|
|
|
|
2020-11-04 23:14:23 +00:00
|
|
|
for i := 1 to NoCases do
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-04 23:14:23 +00:00
|
|
|
if not GoodRecord(OS3MainFrm.DataGrid, i, ColNoSelected) then continue;
|
|
|
|
group := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[1], i])));
|
|
|
|
if not GroupCodeChk.Checked then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
|
|
|
if group < min then min := group;
|
|
|
|
if group > max then max := group;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
for i := 1 to NoCases do
|
|
|
|
begin
|
2020-11-04 23:14:23 +00:00
|
|
|
if not GoodRecord(OS3MainFrm.DataGrid, i, ColNoSelected) then continue;
|
|
|
|
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
|
|
|
group := round(value2);
|
|
|
|
if group = min then
|
|
|
|
begin
|
|
|
|
M1 := M1 + value1;
|
|
|
|
variance1 := variance1 + (value1 * value1);
|
|
|
|
ncases1 := ncases1 + 1;
|
|
|
|
end else if group = max then
|
|
|
|
begin
|
|
|
|
M2 := M2 + value1;
|
|
|
|
variance2 := variance2 + (value1 * value1);
|
|
|
|
ncases2 := Ncases2 + 1;
|
|
|
|
end;
|
|
|
|
end; // next case
|
|
|
|
|
|
|
|
variance1 := variance1 - ((M1 * M1) / ncases1);
|
|
|
|
variance1 := variance1 / (ncases1 - 1);
|
|
|
|
stddev1 := sqrt(variance1);
|
|
|
|
variance2 := variance2 - ((M2 * M2) / ncases2);
|
|
|
|
variance2 := variance2 / (ncases2 - 1);
|
|
|
|
stddev2 := sqrt(variance2);
|
|
|
|
M1 := M1 / ncases1;
|
|
|
|
M2 := M2 / ncases2;
|
|
|
|
Dif := M1 - M2;
|
|
|
|
Label1Str := format('Group %d',[min]);
|
|
|
|
Label2Str := format('Group %d',[max]);
|
|
|
|
end; // if independent data
|
|
|
|
end; // if reading grid data
|
|
|
|
|
|
|
|
if not griddata then // data read from form
|
|
|
|
begin
|
|
|
|
M1 := StrToFloat(Mean1.Text);
|
|
|
|
M2 := StrToFloat(Mean2.Text);
|
|
|
|
stddev1 := StrToFloat(SD1.Text);
|
|
|
|
stddev2 := StrToFloat(SD2.Text);
|
|
|
|
ncases1 := round(StrToFloat(N1.Text));
|
|
|
|
ncases2 := round(StrToFloat(N2.Text));
|
|
|
|
variance1 := stddev1 * stddev1;
|
|
|
|
variance2 := stddev2 * stddev2;
|
|
|
|
Label1Str := 'Group 1';
|
|
|
|
Label2Str := 'Group 2';
|
|
|
|
Dif := M1 - M2;
|
|
|
|
if not independent then
|
|
|
|
begin
|
|
|
|
r12 := StrToFloat(Cor12.Text);
|
|
|
|
cov12 := r12 * stddev1 * stddev2;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
// Initialize output form
|
|
|
|
lReport := TStringList.Create;
|
|
|
|
try
|
|
|
|
lReport.Add('COMPARISON OF TWO MEANS');
|
|
|
|
lReport.Add('');
|
|
|
|
|
|
|
|
// Calculate pooled and independent t and z values and test statistic
|
|
|
|
if independent then
|
|
|
|
begin
|
|
|
|
stderr1 := sqrt(variance1 / ncases1);
|
|
|
|
Stderr2 := sqrt(variance2 / ncases2);
|
|
|
|
lReport.Add('Variable Mean Variance Std.Dev. S.E.Mean N');
|
|
|
|
lReport.Add('%-10s%8.2f %8.2f %8.2f %8.2f %d', [Label1Str, M1, variance1, stddev1, stderr1, ncases1]);
|
|
|
|
lReport.Add('%-10s%8.2f %8.2f %8.2f %8.2f %d', [Label2Str, M2, variance2, stddev2, stderr2, ncases2]);
|
|
|
|
lReport.Add('');
|
|
|
|
|
|
|
|
pooled := ((ncases1-1) * variance1) + ((ncases2-1) * variance2);
|
|
|
|
pooled := pooled / (ncases1 + ncases2 - 2);
|
|
|
|
pooled := pooled * ( 1.0 / ncases1 + 1.0 / ncases2);
|
|
|
|
sedif := sqrt(pooled);
|
|
|
|
tequal := dif / sedif;
|
|
|
|
df := ncases1 + ncases2 - 2;
|
2020-11-04 23:14:23 +00:00
|
|
|
tprobability := ProbT(tequal, df);
|
|
|
|
if TailCombo.ItemIndex = 1 then tprobability := 0.5 * tprobability;
|
2020-03-30 18:01:44 +00:00
|
|
|
lReport.Add('Assuming equal variances, t = %.3f with probability = %.4f and %.0f degrees of freedom', [
|
|
|
|
tequal, tprobability, df
|
|
|
|
]);
|
|
|
|
lReport.Add('Difference = %.2f and Standard Error of difference = %.2f', [dif, sedif]);
|
|
|
|
|
|
|
|
tconfint := inverset(ConfInt,df);
|
|
|
|
lowci := dif - tconfint * sedif;
|
|
|
|
hici := dif + tconfint * sedif;
|
|
|
|
lReport.Add('Confidence interval = (%.2f ... %.2f)', [lowci, hici]);
|
2020-11-04 23:14:23 +00:00
|
|
|
lReport.Add('');
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
// now for unequal variances
|
|
|
|
sedif := sqrt((variance1 / ncases1) + (variance2 / ncases2));
|
|
|
|
tunequal := dif / sedif;
|
|
|
|
df := sqr((variance1 / ncases1) + (variance2 / ncases2));
|
|
|
|
df := df / (sqr(variance1 / ncases1) / (ncases1 - 1) + sqr(variance2 / ncases2) / (ncases2 - 1) );
|
2020-11-04 23:14:23 +00:00
|
|
|
tprobability := ProbT(tequal, df);
|
|
|
|
if TailCombo.ItemIndex = 1 then tprobability := 0.5 * tprobability;
|
2020-03-30 18:01:44 +00:00
|
|
|
lReport.Add('Assuming unequal variances, t = %.3f with probability = %.4f and %.0f degrees of freedom', [
|
|
|
|
tunequal, tprobability, df
|
|
|
|
]);
|
|
|
|
lReport.Add('Difference = %.2f and Standard Error of difference = %.2f', [dif, sedif]);
|
|
|
|
|
|
|
|
tconfint := inverset(ConfInt,df);
|
|
|
|
lowci := dif - tconfint * sedif;
|
|
|
|
hici := dif + tconfint * sedif;
|
|
|
|
lReport.Add('Confidence interval = (%.2f ... %.2f)', [lowci, hici]);
|
2020-11-04 23:14:23 +00:00
|
|
|
lReport.Add('');
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
df1 := ncases1 - 1;
|
|
|
|
df2 := ncases2 - 1;
|
|
|
|
if variance1 > variance2 then
|
|
|
|
begin
|
|
|
|
F := variance1 / variance2;
|
2020-09-28 14:05:34 +00:00
|
|
|
Fp := ProbF(F, df1, df2);
|
2020-03-30 18:01:44 +00:00
|
|
|
end else
|
|
|
|
begin
|
|
|
|
F := variance2 / variance1;
|
2020-09-28 14:05:34 +00:00
|
|
|
Fp := ProbF(F, df2, df1);
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
lReport.Add('F test for equal variances = %.3f, Probability = %.4f', [F, fp]);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
// dependent t test
|
|
|
|
begin
|
|
|
|
stderr1 := sqrt(variance1 / ncases1);
|
|
|
|
Stderr2 := sqrt(variance2 / ncases2);
|
|
|
|
lReport.Add('Variable Mean Variance Std.Dev. S.E.Mean N');
|
|
|
|
lReport.Add('%-10s%8.2f %8.2f %8.2f %8.2f %d', [Label1Str, M1, variance1, stddev1, stderr1, ncases1]);
|
|
|
|
lReport.Add('%-10s%8.2f %8.2f %8.2f %8.2f %d', [Label2Str,M2, variance2, stddev2, stderr2, ncases2]);
|
|
|
|
lReport.Add('');
|
|
|
|
sedif := variance1 + variance2 - (2.0 * cov12);
|
|
|
|
sedif := sqrt(sedif / ncases1);
|
|
|
|
tequal := Dif / sedif;
|
|
|
|
df := ncases1 - 1;
|
|
|
|
tprobability := probt(tequal,df);
|
|
|
|
lReport.Add('Assuming dependent samples, t = %.3f with probability = %.4f and %.0f degrees of freedom', [
|
|
|
|
tequal, tprobability, df
|
|
|
|
]);
|
|
|
|
lReport.Add('Correlation between %s and %s = %.3f', [Label1Str, Label2Str, r12]);
|
|
|
|
lReport.Add('Difference = %.2f and Standard Error of difference = %.2f', [dif, sedif]);
|
|
|
|
|
|
|
|
tconfint := inverset(ConfInt,df);
|
|
|
|
lowci := dif - tconfint * sedif;
|
|
|
|
hici := dif + tconfint * sedif;
|
|
|
|
lReport.Add('Confidence interval = (%.2f ... %.2f)', [lowci, hici]);
|
|
|
|
|
|
|
|
tequal := variance1 - variance2;
|
|
|
|
tequal := tequal / sqrt( (4 * variance1 * variance2)/(ncases1 - 2) * (1.0 - sqr(r12)) );
|
|
|
|
df := ncases1 - 2;
|
|
|
|
tprobability := probt(tequal,df);
|
|
|
|
lReport.Add('t for test of equal variances = %.3f with probability = %.4f', [tequal, tprobability]);
|
|
|
|
end;
|
|
|
|
|
2020-11-04 23:14:23 +00:00
|
|
|
FReportFrame.DisplayReport(lReport);
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
finally
|
|
|
|
lReport.Free;
|
|
|
|
ColNoSelected := nil;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2020-11-04 23:14:23 +00:00
|
|
|
|
|
|
|
procedure TTtestForm.DataEntryGroupClick(Sender: TObject);
|
|
|
|
var
|
|
|
|
index: integer;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-04 23:14:23 +00:00
|
|
|
index := DataEntryGroup.ItemIndex;
|
|
|
|
Notebook.PageIndex := index;
|
|
|
|
gridData := (index = 1);
|
|
|
|
if index = 1 then
|
|
|
|
begin
|
|
|
|
if DepIndepGroup.ItemIndex = 1 then
|
|
|
|
Var2Edit.Visible := true
|
|
|
|
else
|
|
|
|
Var2Edit.Visible := false;
|
|
|
|
end;
|
|
|
|
|
|
|
|
Var2Label.Visible := Var2Edit.Visible;
|
|
|
|
Var2In.Visible := Var2Edit.Visible;
|
|
|
|
Var2Out.Visible := Var2Edit.Visible;
|
|
|
|
|
|
|
|
GrpEdit.Visible := not Var2Edit.Visible;
|
|
|
|
GrpLabel.Visible := GrpEdit.Visible;
|
|
|
|
GrpIn.Visible := GrpEdit.Visible;
|
|
|
|
GrpOut.Visible := GrpEdit.Visible;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-11-04 23:14:23 +00:00
|
|
|
|
|
|
|
procedure TTtestForm.DepIndepGroupClick(Sender: TObject);
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-04 23:14:23 +00:00
|
|
|
independent := (DepIndepGroup.ItemIndex = 0);
|
|
|
|
|
|
|
|
GrpEdit.Visible := independent;
|
|
|
|
GrpLabel.Visible := independent;
|
|
|
|
GrpIn.Visible := independent;
|
|
|
|
GrpOut.Visible := independent;
|
|
|
|
|
|
|
|
GroupCodeChk.Visible := independent;
|
|
|
|
GroupCodeGroup.Visible := independent;
|
|
|
|
|
|
|
|
Var2Label.Visible := not independent;
|
|
|
|
Var2Edit.Visible := not independent;
|
|
|
|
Var2In.Visible := not independent;
|
|
|
|
Var2Out.Visible := not independent;
|
|
|
|
|
|
|
|
Cor12.Visible := not independent;
|
|
|
|
Cor12Label.Visible := not independent;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TTtestForm.GroupCodeChkChange(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Grp1CodeEdit.Enabled := GroupCodeChk.Checked;
|
|
|
|
Grp2CodeEdit.Enabled := GroupCodeChk.Checked;
|
|
|
|
GrpCodeLabel1.Enabled := GroupCodeChk.Checked;
|
|
|
|
GrpCodeLabel2.Enabled := GroupCodeChk.Checked;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-11-04 23:14:23 +00:00
|
|
|
|
|
|
|
procedure TTtestForm.GrpInClick(Sender: TObject);
|
2020-03-30 18:01:44 +00:00
|
|
|
var
|
2020-11-04 23:14:23 +00:00
|
|
|
index: Integer;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-04 23:14:23 +00:00
|
|
|
index := VarList.ItemIndex;
|
|
|
|
if (index > -1) and (GrpEdit.Text = '') then
|
|
|
|
begin
|
|
|
|
GrpEdit.Text := VarList.Items[index];
|
|
|
|
VarList.Items.Delete(index);
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TTtestForm.GrpOutClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if GrpEdit.Text <> '' then
|
|
|
|
begin
|
|
|
|
VarList.Items.Add(GrpEdit.Text);
|
|
|
|
GrpEdit.Text := '';
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-11-04 23:14:23 +00:00
|
|
|
|
|
|
|
procedure TTtestForm.Reset;
|
|
|
|
var
|
|
|
|
i: integer;
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
DataEntryGroup.ItemIndex := 0;
|
|
|
|
DepIndepGroup.ItemIndex := 0;
|
|
|
|
Notebook.PageIndex := DataEntryGroup.ItemIndex;
|
|
|
|
independent := true;
|
|
|
|
griddata := false;
|
|
|
|
|
|
|
|
VarList.Clear;
|
|
|
|
for i := 1 to NoVariables do
|
|
|
|
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
|
|
|
|
Var1Edit.Clear;
|
|
|
|
Var2Edit.Clear;
|
|
|
|
Mean1.Clear;
|
|
|
|
Mean2.Clear;
|
|
|
|
SD1.Clear;
|
|
|
|
SD2.Clear;
|
|
|
|
N1.Clear;
|
|
|
|
N2.Clear;
|
|
|
|
Cor12.Clear;
|
|
|
|
GroupCodeChk.Checked := false;
|
|
|
|
GrpEdit.Clear;
|
|
|
|
Grp1CodeEdit.Clear;
|
|
|
|
Grp2CodeEdit.Clear;
|
|
|
|
|
|
|
|
DepIndepGroupClick(nil);
|
|
|
|
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TTtestForm.UpdateBtnStates;
|
|
|
|
begin
|
|
|
|
inherited UpdateBtnStates;
|
|
|
|
|
|
|
|
Var1In.Enabled := (Var1Edit.Text = '') and (VarList.ItemIndex > -1);
|
|
|
|
Var2In.Enabled := (Var2Edit.Text = '') and (VarList.ItemIndex > -1);
|
|
|
|
GrpIn.Enabled := (GrpEdit.Text = '') and (VarList.ItemIndex > -1);
|
|
|
|
|
|
|
|
Var1Out.Enabled := Var1Edit.Text <> '';
|
|
|
|
Var2Out.Enabled := Var2Edit.Text <> '';
|
|
|
|
GrpOut.Enabled := GrpEdit.Text <> '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TTtestForm.Validate(out AMsg: String; out AControl: TWinControl): Boolean;
|
2020-03-30 18:01:44 +00:00
|
|
|
var
|
|
|
|
n: Integer;
|
|
|
|
x: Double;
|
|
|
|
begin
|
|
|
|
Result := false;
|
|
|
|
AControl := nil;
|
|
|
|
AMsg := '';
|
2020-11-04 23:14:23 +00:00
|
|
|
if Notebook.PageIndex = 0 then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
|
|
|
if (Mean1.Text = '') or not TryStrToFloat(Mean1.Text, x) then
|
|
|
|
begin
|
|
|
|
AControl := Mean1;
|
|
|
|
AMsg := 'Invalid input for the mean of sample 1';
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
if (SD1.Text = '') or not TryStrToFloat(SD1.Text, x) or (x <= 0) then
|
|
|
|
begin
|
|
|
|
AControl := SD1;
|
|
|
|
AMsg := 'Invald input for the standard deviation of sample 1';
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
if (N1.Text = '') or not TryStrToInt(N1.Text, n) or (n <= 0) then
|
|
|
|
begin
|
|
|
|
AControl := N1;
|
|
|
|
AMsg := 'Invald input for the size of sample 1';
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
if (Mean2.Text = '') or not TryStrToFloat(Mean2.Text, x) then
|
|
|
|
begin
|
|
|
|
AControl := Mean2;
|
|
|
|
AMsg := 'Invalid input for the mean of sample 2';
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
if (SD2.Text = '') or not TryStrToFloat(SD2.Text, x) or (x <= 0) then
|
|
|
|
begin
|
|
|
|
AControl := SD2;
|
|
|
|
AMsg := 'Invald input for the standard deviation of sample 2';
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
if (N2.Text = '') or not TryStrToInt(N2.Text, n) or (n <= 0) then
|
|
|
|
begin
|
|
|
|
AControl := N2;
|
|
|
|
AMsg := 'Invald input for the size of sample 2';
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end else
|
2020-11-04 23:14:23 +00:00
|
|
|
if Notebook.PageIndex = 1 then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-04 23:14:23 +00:00
|
|
|
if (Var1Edit.Text = '') then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-04 23:14:23 +00:00
|
|
|
AControl := Var1Edit;
|
2020-03-30 18:01:44 +00:00
|
|
|
AMsg := 'Variable 1 not specified.';
|
|
|
|
exit;
|
|
|
|
end;
|
2020-11-04 23:14:23 +00:00
|
|
|
if Var2Edit.Visible and (Var2Edit.Text = '') then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-04 23:14:23 +00:00
|
|
|
AControl := Var2Edit;
|
2020-03-30 18:01:44 +00:00
|
|
|
AMsg := 'Variable 2 not specified.';
|
|
|
|
exit;
|
|
|
|
end;
|
2020-11-04 23:14:23 +00:00
|
|
|
if GrpEdit.Visible and (GrpEdit.Text = '') then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-04 23:14:23 +00:00
|
|
|
AControl := GrpEdit;
|
2020-03-30 18:01:44 +00:00
|
|
|
AMsg := 'Group variable not specified.';
|
|
|
|
exit;
|
|
|
|
end;
|
2020-11-04 23:14:23 +00:00
|
|
|
if Grp1CodeEdit.Visible and ((Grp1CodeEdit.Text = '') or not TryStrToInt(Grp1CodeEdit.Text, n))then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-04 23:14:23 +00:00
|
|
|
AControl := Grp1CodeEdit;
|
2020-03-30 18:01:44 +00:00
|
|
|
AMsg := 'Code for group 1 missing.';
|
|
|
|
exit;
|
|
|
|
end;
|
2020-11-04 23:14:23 +00:00
|
|
|
if Grp2CodeEdit.Visible and ((Grp2CodeEdit.Text = '') or not TryStrToInt(Grp2CodeEdit.Text, n))then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-11-04 23:14:23 +00:00
|
|
|
AControl := Grp2CodeEdit;
|
2020-03-30 18:01:44 +00:00
|
|
|
AMsg := 'Code for group 2 missing.';
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
Result := true;
|
|
|
|
end;
|
|
|
|
|
2020-11-04 23:14:23 +00:00
|
|
|
|
|
|
|
procedure TTtestForm.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 TTtestForm.Var1OutClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if Var1Edit.Text <> '' then
|
|
|
|
begin
|
|
|
|
VarList.Items.Add(Var1Edit.Text);
|
|
|
|
Var1Edit.Text := '';
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TTtestForm.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 TTtestForm.Var2OutClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if Var2Edit.Text <> '' then
|
|
|
|
begin
|
|
|
|
VarList.Items.Add(Var2Edit.Text);
|
|
|
|
Var2Edit.Text := '';
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TTtestForm.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
|
|
|
|
Var1Edit.Text := s;
|
|
|
|
VarList.Items.Delete(index);
|
|
|
|
end else
|
|
|
|
if independent then
|
|
|
|
begin
|
|
|
|
if GrpEdit.Text = '' then
|
|
|
|
begin
|
|
|
|
GrpEdit.Text := s;
|
|
|
|
VarList.Items.Delete(index);
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
if Var2Edit.Text = '' then
|
|
|
|
begin
|
|
|
|
Var2Edit.Text := s;
|
|
|
|
VarList.Items.Delete(index);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TTtestForm.VarListSelectionChange(Sender: TObject; User: boolean);
|
|
|
|
begin
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
end.
|
|
|
|
|