2020-04-26 22:36:07 +00:00
|
|
|
// Testing: no file needed
|
|
|
|
//
|
|
|
|
// Test input parameters:
|
|
|
|
// - F distribution: DF1 = 3, DF2 = 20
|
|
|
|
|
2020-08-24 22:36:30 +00:00
|
|
|
// ToDo: Fix calculation of t distribution
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
unit DistribUnit;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2020-09-06 16:03:58 +00:00
|
|
|
Classes, SysUtils, FileUtil, TAFuncSeries, //TAGraph, TAFuncSeries, TASeries,
|
|
|
|
//PrintersDlgs, LResources,
|
|
|
|
Forms, Controls, Graphics, Dialogs, StdCtrls,
|
|
|
|
//Printers,
|
|
|
|
ExtCtrls, ExtDlgs, ComCtrls, Math,
|
|
|
|
Globals, FunctionsLib, ChartFrameUnit;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TDistribFrm }
|
|
|
|
|
|
|
|
TDistribFrm = class(TForm)
|
|
|
|
AlphaEdit: TEdit;
|
2020-08-28 21:58:45 +00:00
|
|
|
Bevel2: TBevel;
|
|
|
|
ShowCriticalValuesChk: TCheckBox;
|
|
|
|
CumulativeChk: TCheckBox;
|
2020-08-24 22:36:30 +00:00
|
|
|
tChk: TRadioButton;
|
2020-09-06 16:03:58 +00:00
|
|
|
ToolBar1: TToolBar;
|
|
|
|
tbSave: TToolButton;
|
|
|
|
tbPrint: TToolButton;
|
|
|
|
tbErase: TToolButton;
|
2020-08-24 22:54:29 +00:00
|
|
|
ParameterPanel: TPanel;
|
2020-04-26 22:36:07 +00:00
|
|
|
ChiChk: TRadioButton;
|
2020-03-30 18:01:44 +00:00
|
|
|
DF1Edit: TEdit;
|
|
|
|
DF2Edit: TEdit;
|
2020-04-26 22:36:07 +00:00
|
|
|
FChk: TRadioButton;
|
|
|
|
NDChk: TRadioButton;
|
2020-08-24 22:54:29 +00:00
|
|
|
ChartPanel: TPanel;
|
2020-03-30 18:01:44 +00:00
|
|
|
ResetBtn: TButton;
|
|
|
|
ComputeBtn: TButton;
|
2020-04-26 22:36:07 +00:00
|
|
|
CloseBtn: TButton;
|
2020-03-30 18:01:44 +00:00
|
|
|
GroupBox2: TGroupBox;
|
|
|
|
AlphaLabel: TLabel;
|
2020-04-26 22:36:07 +00:00
|
|
|
DF1Label: TLabel;
|
|
|
|
DF2Label: TLabel;
|
2020-03-30 18:01:44 +00:00
|
|
|
GroupBox1: TGroupBox;
|
|
|
|
procedure ComputeBtnClick(Sender: TObject);
|
2020-04-26 22:36:07 +00:00
|
|
|
procedure FormActivate(Sender: TObject);
|
2020-09-06 16:03:58 +00:00
|
|
|
procedure FormCreate(Sender: TObject);
|
2020-03-30 18:01:44 +00:00
|
|
|
procedure FormShow(Sender: TObject);
|
2020-08-28 21:58:45 +00:00
|
|
|
procedure CalcChi2(const AX: Double; out AY: Double);
|
|
|
|
procedure CalcChi2_Cumulative(const AX: Double; out AY: Double);
|
2020-08-24 22:36:30 +00:00
|
|
|
procedure CalcF(const AX: Double; out AY: Double);
|
2020-08-28 21:58:45 +00:00
|
|
|
procedure CalcF_Cumulative(const AX: Double; out AY: Double);
|
2020-08-24 22:36:30 +00:00
|
|
|
procedure CalcND(const AX: Double; out AY: Double);
|
2020-08-28 21:58:45 +00:00
|
|
|
procedure CalcND_Cumulative(const AX: Double; out AY: Double);
|
|
|
|
procedure CalcT(const AX: Double; out AY: Double);
|
|
|
|
procedure CalcT_Cumulative(const AX: Double; out AY: Double);
|
2020-08-26 21:20:02 +00:00
|
|
|
procedure DistributionClick(Sender: TObject);
|
2020-08-24 22:36:30 +00:00
|
|
|
procedure PrintBtnClick(Sender: TObject);
|
2020-03-30 18:01:44 +00:00
|
|
|
procedure ResetBtnClick(Sender: TObject);
|
2020-09-06 16:03:58 +00:00
|
|
|
procedure ShowCriticalValuesChkChange(Sender: TObject);
|
|
|
|
procedure tbEraseClick(Sender: TObject);
|
|
|
|
procedure tbPrintClick(Sender: TObject);
|
|
|
|
procedure tbSaveClick(Sender: TObject);
|
2020-03-30 18:01:44 +00:00
|
|
|
private
|
|
|
|
{ private declarations }
|
2020-09-06 16:03:58 +00:00
|
|
|
ChartFrame: TChartFrame;
|
|
|
|
Alpha: Double;
|
2020-08-24 22:36:30 +00:00
|
|
|
DF1: Integer;
|
|
|
|
DF2: Integer;
|
2020-09-06 16:03:58 +00:00
|
|
|
procedure AddSeries(ATitle: string; XMin, XMax: Double;
|
|
|
|
xCrit, yCrit: Double; Cumulative: Boolean; ACalcFunc: TFuncCalculateEvent);
|
2020-08-26 21:20:02 +00:00
|
|
|
procedure NormalDistPlot;
|
2020-08-28 21:58:45 +00:00
|
|
|
procedure Chi2Plot;
|
2020-04-26 22:36:07 +00:00
|
|
|
procedure FPlot;
|
2020-08-24 22:36:30 +00:00
|
|
|
procedure tPlot;
|
2020-04-26 22:36:07 +00:00
|
|
|
|
|
|
|
function Validate(out AMsg: String; out AControl: TWinControl): Boolean;
|
2020-03-30 18:01:44 +00:00
|
|
|
public
|
|
|
|
{ public declarations }
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
DistribFrm: TDistribFrm;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2020-09-06 16:03:58 +00:00
|
|
|
{$R *.lfm}
|
|
|
|
|
2020-08-24 22:36:30 +00:00
|
|
|
uses
|
2020-09-06 16:03:58 +00:00
|
|
|
TAChartUtils, TALegend, TASeries,
|
2020-08-26 21:20:02 +00:00
|
|
|
MathUnit;
|
2020-08-24 22:36:30 +00:00
|
|
|
|
2020-09-06 16:03:58 +00:00
|
|
|
const
|
|
|
|
P_LIMIT = 0.9999;
|
2020-08-24 22:36:30 +00:00
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
{ TDistribFrm }
|
|
|
|
|
2020-09-06 16:03:58 +00:00
|
|
|
procedure TDistribFrm.AddSeries(ATitle: string; XMin, XMax: Double;
|
|
|
|
xCrit, yCrit: Double; Cumulative: Boolean; ACalcFunc: TFuncCalculateEvent);
|
|
|
|
var
|
|
|
|
funcSer: TFuncSeries;
|
|
|
|
vertSer, horSer: TLineSeries;
|
|
|
|
i: Integer;
|
|
|
|
ext: TDoubleRect;
|
|
|
|
allCumulative: Boolean;
|
|
|
|
allDensity: Boolean;
|
|
|
|
begin
|
|
|
|
funcSer := TFuncSeries.Create(ChartFrame);
|
|
|
|
funcSer.OnCalculate := ACalcFunc;
|
|
|
|
funcSer.ExtentAutoY := true;
|
|
|
|
funcSer.Extent.XMin := XMin;
|
|
|
|
funcSer.Extent.XMax := XMax;
|
|
|
|
funcSer.Extent.UseXMin := true;
|
|
|
|
funcSer.Extent.UseXMax := true;
|
|
|
|
funcSer.Pen.Color := DATA_COLORS[(ChartFrame.Chart.SeriesCount div 3) mod Length(DATA_COLORS)];
|
|
|
|
funcSer.Title := ATitle;
|
|
|
|
if Cumulative then funcSer.Tag := 1;
|
|
|
|
if XMin = 0 then
|
|
|
|
funcSer.DomainExclusions.AddRange(-Infinity, 0, [ioOpenEnd]);
|
|
|
|
ChartFrame.Chart.AddSeries(funcSer);
|
|
|
|
|
|
|
|
if Cumulative then
|
|
|
|
yCrit := 1.0 - Alpha;
|
|
|
|
|
|
|
|
// vertical indicator
|
|
|
|
vertSer := TLineSeries.Create(ChartFrame);
|
|
|
|
vertSer.LinePen.Color := funcSer.Pen.Color;
|
|
|
|
vertSer.LinePen.Style := psDot;
|
|
|
|
vertser.Legend.Visible := false;
|
|
|
|
vertSer.AddXY(xCrit, yCrit);
|
|
|
|
vertSer.AddXY(xCrit, 0);
|
|
|
|
if Cumulative then vertSer.Tag := 1;
|
|
|
|
vertSer.Active := ShowCriticalValuesChk.Checked;
|
|
|
|
ChartFrame.Chart.AddSeries(vertSer);
|
|
|
|
|
|
|
|
// horizontal indicator
|
|
|
|
horSer := TLineSeries.Create(ChartFrame);
|
|
|
|
horSer.LinePen.Color := funcSer.Pen.Color;
|
|
|
|
horSer.LinePen.Style := psDot;
|
|
|
|
horSer.Legend.Visible := false;
|
|
|
|
horSer.AddXY(0, yCrit);
|
|
|
|
horSer.AddXY(xCrit, yCrit);
|
|
|
|
if Cumulative then horSer.Tag := 1;
|
|
|
|
horSer.Active := ShowCriticalValuesChk.Checked and Cumulative;
|
|
|
|
ChartFrame.Chart.AddSeries(horSer);
|
|
|
|
|
|
|
|
ext := ChartFrame.Chart.GetFullExtent();
|
|
|
|
i := 2;
|
|
|
|
while i < ChartFrame.Chart.SeriesCount do
|
|
|
|
begin
|
|
|
|
(ChartFrame.Chart.Series[i] as TLineSeries).XValue[0] := ext.a.x;
|
|
|
|
inc(i, 3);
|
|
|
|
end;
|
|
|
|
|
|
|
|
allCumulative := true;
|
|
|
|
allDensity := true;
|
|
|
|
i := 0;
|
|
|
|
while i < ChartFrame.Chart.SeriesCount-1 do
|
|
|
|
begin
|
|
|
|
case ChartFrame.Chart.Series[i].Tag of
|
|
|
|
0: allCumulative := false;
|
|
|
|
1: allDensity := false;
|
|
|
|
end;
|
|
|
|
inc(i);
|
|
|
|
end;
|
|
|
|
if allCumulative then
|
|
|
|
ChartFrame.SetYTitle('Cumulative Probability')
|
|
|
|
else
|
|
|
|
if allDensity then
|
|
|
|
ChartFrame.SetYTitle('Probability Density')
|
|
|
|
else
|
|
|
|
ChartFrame.SetYTitle('Probability Density, Cumulative Probability');
|
|
|
|
ChartFrame.SetXTitle('x Value');
|
|
|
|
ChartFrame.Chart.Legend.Visible := true;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
procedure TDistribFrm.ResetBtnClick(Sender: TObject);
|
|
|
|
begin
|
2020-04-26 22:36:07 +00:00
|
|
|
NDChk.Checked := false;
|
2020-08-24 22:36:30 +00:00
|
|
|
tChk.Checked := false;
|
2020-04-26 22:36:07 +00:00
|
|
|
FChk.Checked := false;
|
2020-08-24 22:36:30 +00:00
|
|
|
ChiChk.Checked := false;
|
2020-04-26 22:36:07 +00:00
|
|
|
AlphaEdit.Text := FormatFloat('0.00', DEFAULT_ALPHA_LEVEL);
|
|
|
|
DF1Edit.Text := '';
|
|
|
|
DF2Edit.Text := '';
|
|
|
|
GroupBox2.Enabled := false;
|
2020-09-06 16:03:58 +00:00
|
|
|
ChartFrame.Clear;
|
2020-08-24 22:36:30 +00:00
|
|
|
end;
|
|
|
|
|
2020-08-28 21:58:45 +00:00
|
|
|
|
2020-09-06 16:03:58 +00:00
|
|
|
procedure TDistribFrm.ShowCriticalValuesChkChange(Sender: TObject);
|
2020-08-24 22:36:30 +00:00
|
|
|
var
|
2020-09-06 16:03:58 +00:00
|
|
|
i: Integer;
|
2020-08-24 22:36:30 +00:00
|
|
|
begin
|
2020-09-06 16:03:58 +00:00
|
|
|
i := 1;
|
|
|
|
while i < ChartFrame.Chart.SeriesCount do
|
2020-08-24 22:36:30 +00:00
|
|
|
begin
|
2020-09-06 16:03:58 +00:00
|
|
|
ChartFrame.Chart.Series[i].Active := ShowCriticalValuesChk.Checked;
|
|
|
|
ChartFrame.Chart.Series[i+1].Active := ShowCriticalValuesChk.Checked;
|
|
|
|
inc(i, 3);
|
2020-08-24 22:36:30 +00:00
|
|
|
end;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-08-28 21:58:45 +00:00
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
procedure TDistribFrm.FormShow(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ResetBtnClick(self);
|
|
|
|
end;
|
|
|
|
|
2020-08-28 21:58:45 +00:00
|
|
|
|
2020-08-24 22:36:30 +00:00
|
|
|
procedure TDistribFrm.CalcF(const AX: Double; out AY: Double);
|
|
|
|
begin
|
2020-08-26 21:20:02 +00:00
|
|
|
AY := FDensity(AX, DF1, DF2);
|
2020-08-24 22:36:30 +00:00
|
|
|
end;
|
|
|
|
|
2020-08-28 21:58:45 +00:00
|
|
|
|
|
|
|
procedure TDistribFrm.CalcF_Cumulative(const AX: Double; out AY: Double);
|
|
|
|
begin
|
|
|
|
AY := 1.0 - ProbF(AX, DF1, DF2);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-08-24 22:36:30 +00:00
|
|
|
procedure TDistribFrm.CalcND(const AX: Double; out AY: Double);
|
|
|
|
begin
|
|
|
|
AY := 1.0 / sqrt(TWO_PI) * exp(-sqr(AX)/ 2.0);
|
|
|
|
end;
|
|
|
|
|
2020-08-28 21:58:45 +00:00
|
|
|
|
|
|
|
procedure TDistribFrm.CalcND_Cumulative(const AX: Double; out AY: Double);
|
|
|
|
begin
|
|
|
|
// AY := ProbZ(AX); -- very slow
|
|
|
|
AY := NormalDist(AX); // borrowed from NumLib
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TDistribFrm.CalcChi2(const AX: Double; out AY: Double);
|
2020-08-24 22:36:30 +00:00
|
|
|
begin
|
2020-08-26 21:20:02 +00:00
|
|
|
AY := Chi2Density(AX, DF1);
|
2020-08-24 22:36:30 +00:00
|
|
|
end;
|
|
|
|
|
2020-08-28 21:58:45 +00:00
|
|
|
|
|
|
|
procedure TDistribFrm.CalcChi2_Cumulative(const AX: Double; out AY: Double);
|
|
|
|
begin
|
|
|
|
AY := ChiSquaredProb(AX, DF1);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-08-24 22:36:30 +00:00
|
|
|
procedure TDistribFrm.Calct(const AX: Double; out AY: Double);
|
|
|
|
begin
|
2020-08-26 21:20:02 +00:00
|
|
|
AY := tDensity(AX, DF1);
|
2020-08-24 22:36:30 +00:00
|
|
|
end;
|
|
|
|
|
2020-08-28 21:58:45 +00:00
|
|
|
|
|
|
|
procedure TDistribFrm.CalcT_Cumulative(const AX: Double; out AY: Double);
|
|
|
|
const
|
|
|
|
ONE_SIDED = true;
|
|
|
|
begin
|
|
|
|
if AX < 0 then
|
|
|
|
AY := tDist(-AX, DF1, ONE_SIDED)
|
|
|
|
else
|
|
|
|
AY := 1.0 - tDist(AX, DF1, ONE_SIDED);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-08-26 21:20:02 +00:00
|
|
|
procedure TDistribFrm.DistributionClick(Sender: TObject);
|
|
|
|
var
|
|
|
|
rb: TRadiobutton;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-08-26 21:20:02 +00:00
|
|
|
rb := Sender as TRadioButton;
|
|
|
|
|
|
|
|
GroupBox2.Enabled := rb.Checked;
|
|
|
|
|
|
|
|
AlphaLabel.Enabled := rb.Checked;
|
|
|
|
AlphaEdit.Enabled := rb.Checked;
|
|
|
|
|
|
|
|
DF1Edit.Enabled := (rb <> NDChk) and rb.Checked;
|
|
|
|
DF1Label.Enabled := DF1Edit.Enabled;
|
|
|
|
|
|
|
|
DF2Edit.Enabled := (rb = FChk) and rb.Checked;
|
|
|
|
DF2Label.Enabled := DF2Edit.Enabled;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-08-28 21:58:45 +00:00
|
|
|
|
2020-08-24 22:36:30 +00:00
|
|
|
procedure TDistribFrm.PrintBtnClick(Sender: TObject);
|
|
|
|
begin
|
2020-09-06 16:03:58 +00:00
|
|
|
ChartFrame.Print;
|
2020-08-24 22:36:30 +00:00
|
|
|
end;
|
|
|
|
|
2020-08-28 21:58:45 +00:00
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
procedure TDistribFrm.ComputeBtnClick(Sender: TObject);
|
2020-04-26 22:36:07 +00:00
|
|
|
var
|
|
|
|
msg: String;
|
|
|
|
C: TWinControl;
|
|
|
|
ok: Boolean;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-04-26 22:36:07 +00:00
|
|
|
if not Validate(msg, C) then
|
|
|
|
begin
|
|
|
|
C.SetFocus;
|
|
|
|
MessageDlg(msg, mtError, [mbOK], 0);
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
ok := false;
|
|
|
|
if NDChk.Checked then
|
|
|
|
begin
|
2020-08-26 21:20:02 +00:00
|
|
|
NormalDistPlot();
|
2020-04-26 22:36:07 +00:00
|
|
|
ok := true;
|
|
|
|
end;
|
|
|
|
|
2020-08-24 22:36:30 +00:00
|
|
|
if tChk.Checked then
|
|
|
|
begin
|
|
|
|
tPlot();
|
|
|
|
ok := true;
|
|
|
|
end;
|
|
|
|
|
2020-04-26 22:36:07 +00:00
|
|
|
if ChiChk.Checked then
|
|
|
|
begin
|
2020-08-28 21:58:45 +00:00
|
|
|
Chi2Plot();
|
2020-04-26 22:36:07 +00:00
|
|
|
ok := true;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if FChk.Checked then
|
|
|
|
begin
|
|
|
|
FPlot();
|
|
|
|
ok := true;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if not ok then
|
|
|
|
MessageDlg('Please select a distribution.', mtError, [mbOK], 0);
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-08-28 21:58:45 +00:00
|
|
|
|
2020-08-26 21:20:02 +00:00
|
|
|
procedure TDistribFrm.NormalDistPlot;
|
2020-03-30 18:01:44 +00:00
|
|
|
var
|
2020-08-28 21:58:45 +00:00
|
|
|
zMax, zMin, zCrit, pCrit: Double;
|
2020-09-06 16:03:58 +00:00
|
|
|
title: String;
|
|
|
|
func: TFuncCalculateEvent;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-09-06 16:03:58 +00:00
|
|
|
zMax := inverseZ(P_LIMIT);
|
2020-08-28 21:58:45 +00:00
|
|
|
zMin := -zMax;
|
2020-09-06 16:03:58 +00:00
|
|
|
zCrit := inversez(1.0 - Alpha);
|
2020-08-24 22:36:30 +00:00
|
|
|
CalcND(zCrit, pCrit);
|
|
|
|
|
2020-09-06 16:03:58 +00:00
|
|
|
title := Format('Normal (α=%s, x<sub>crit</sub>=%.3f)', [AlphaEdit.Text, zCrit]);
|
2020-08-28 21:58:45 +00:00
|
|
|
if CumulativeChk.Checked then
|
2020-09-06 16:03:58 +00:00
|
|
|
func := @CalcND_Cumulative
|
2020-08-28 21:58:45 +00:00
|
|
|
else
|
2020-09-06 16:03:58 +00:00
|
|
|
func := @CalcND;
|
|
|
|
AddSeries(title, zMin, zMax, zCrit, pCrit, CumulativeChk.Checked, func);
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-08-28 21:58:45 +00:00
|
|
|
|
|
|
|
procedure TDistribFrm.Chi2Plot;
|
2020-03-30 18:01:44 +00:00
|
|
|
var
|
2020-08-28 21:58:45 +00:00
|
|
|
chi2Max, chi2Crit, pCrit: Double;
|
2020-09-06 16:03:58 +00:00
|
|
|
title: String;
|
|
|
|
func: TFuncCalculateEvent;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-09-06 16:03:58 +00:00
|
|
|
chi2Max := InverseChi(P_LIMIT, DF1);
|
|
|
|
chi2Crit := InverseChi(1.0 - Alpha, DF1);
|
2020-08-28 21:58:45 +00:00
|
|
|
CalcChi2(chi2Crit, pCrit);
|
2020-08-24 22:36:30 +00:00
|
|
|
|
2020-09-06 16:03:58 +00:00
|
|
|
title := Format('Chi-sq (&alpha=%s; DF=%d; x<sub>crit</sub>=%.3f)', [AlphaEdit.Text, DF1, Chi2Crit]);
|
2020-08-28 21:58:45 +00:00
|
|
|
if CumulativeChk.Checked then
|
2020-09-06 16:03:58 +00:00
|
|
|
func := @CalcChi2_Cumulative
|
2020-08-28 21:58:45 +00:00
|
|
|
else
|
2020-09-06 16:03:58 +00:00
|
|
|
func := @CalcChi2;
|
|
|
|
AddSeries(title, 0.0, chi2Max, chi2Crit, pCrit, CumulativeChk.Checked, func);
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-08-28 21:58:45 +00:00
|
|
|
|
2020-04-26 22:36:07 +00:00
|
|
|
procedure TDistribFrm.FPlot;
|
2020-03-30 18:01:44 +00:00
|
|
|
var
|
2020-08-24 22:54:29 +00:00
|
|
|
FMax, FCrit, pCrit: Double;
|
2020-09-06 16:03:58 +00:00
|
|
|
title: String;
|
|
|
|
func: TFuncCalculateEvent;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-09-06 16:03:58 +00:00
|
|
|
FMax := FPercentPoint(P_LIMIT, DF1, DF2);
|
|
|
|
FCrit := FPercentPoint(1.0 - Alpha, DF1, DF2);
|
2020-08-24 22:36:30 +00:00
|
|
|
CalcF(FCrit, pCrit);
|
|
|
|
|
2020-09-06 16:03:58 +00:00
|
|
|
title := Format('F (α=%s; DF1=%d, DF2=%d, x<sub>crit</sub>=%.3f)', [AlphaEdit.Text, DF1, DF2, FCrit]);
|
2020-08-28 21:58:45 +00:00
|
|
|
if CumulativeChk.Checked then
|
2020-09-06 16:03:58 +00:00
|
|
|
func := @CalcF_Cumulative
|
2020-08-28 21:58:45 +00:00
|
|
|
else
|
2020-09-06 16:03:58 +00:00
|
|
|
func := @CalcF;
|
|
|
|
AddSeries(title, 0.0, FMax, FCrit, pCrit, CumulativeChk.Checked, func);
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-08-28 21:58:45 +00:00
|
|
|
|
2020-08-24 22:36:30 +00:00
|
|
|
procedure TDistribFrm.tPlot;
|
2020-03-30 18:01:44 +00:00
|
|
|
var
|
2020-08-28 21:58:45 +00:00
|
|
|
tMin, tMax, tCrit, pCrit: Double;
|
2020-09-06 16:03:58 +00:00
|
|
|
title: String;
|
|
|
|
func: TFuncCalculateEvent;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-09-06 16:03:58 +00:00
|
|
|
tMax := Inverset(P_LIMIT, DF1);
|
2020-08-28 21:58:45 +00:00
|
|
|
tMin := -tMax;
|
2020-09-06 16:03:58 +00:00
|
|
|
tCrit := Inverset(1.0 - Alpha, DF1);
|
2020-08-24 22:36:30 +00:00
|
|
|
Calct(tCrit, pCrit);
|
|
|
|
|
2020-09-06 16:03:58 +00:00
|
|
|
title := Format('t (α=%s; DF=%d; x<sub>crit</sub>=%.3f)', [AlphaEdit.Text, DF1, tCrit]);
|
2020-08-28 21:58:45 +00:00
|
|
|
if CumulativeChk.Checked then
|
2020-09-06 16:03:58 +00:00
|
|
|
func := @CalcT_Cumulative
|
2020-08-28 21:58:45 +00:00
|
|
|
else
|
2020-09-06 16:03:58 +00:00
|
|
|
func := @CalcT;
|
|
|
|
AddSeries(title, tMin, tMax, tCrit, pCrit, CumulativeChk.Checked, func);
|
2020-04-26 22:36:07 +00:00
|
|
|
end;
|
|
|
|
|
2020-08-28 21:58:45 +00:00
|
|
|
|
2020-04-26 22:36:07 +00:00
|
|
|
procedure TDistribFrm.FormActivate(Sender: TObject);
|
|
|
|
var
|
|
|
|
w: Integer;
|
|
|
|
begin
|
2020-09-06 16:03:58 +00:00
|
|
|
w := MaxValue([ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]);
|
2020-04-26 22:36:07 +00:00
|
|
|
ResetBtn.Constraints.MinWidth := w;
|
|
|
|
ComputeBtn.Constraints.MinWidth := w;
|
|
|
|
CloseBtn.Constraints.MinWidth := w;
|
2020-09-06 16:03:58 +00:00
|
|
|
|
|
|
|
Constraints.MinHeight :=
|
|
|
|
ShowCriticalValuesChk.Top + ShowCriticalValuesChk.Height + 16 +
|
|
|
|
CloseBtn.Height + CloseBtn.BorderSpacing.Bottom;
|
|
|
|
Constraints.MinWidth := ParameterPanel.Width * 2;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TDistribFrm.FormCreate(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ChartFrame := TChartFrame.Create(self);
|
|
|
|
ChartFrame.Parent := ChartPanel;
|
|
|
|
ChartFrame.Align := alClient;
|
|
|
|
ChartFrame.Chart.Legend.Alignment := laBottomCenter;
|
|
|
|
ChartFrame.Chart.Legend.ColumnCount := 3;
|
|
|
|
ChartFrame.Chart.Legend.TextFormat := tfHTML;
|
|
|
|
ChartFrame.Chart.BottomAxis.Intervals.MaxLength := 80;
|
|
|
|
ChartFrame.Chart.BottomAxis.Intervals.MinLength := 30;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TDistribFrm.tbEraseClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ChartFrame.Clear;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TDistribFrm.tbPrintClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ChartFrame.Print;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TDistribFrm.tbSaveClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ChartFrame.Save;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-04-26 22:36:07 +00:00
|
|
|
function TDistribFrm.Validate(out AMsg: String; out AControl: TWinControl): boolean;
|
|
|
|
begin
|
|
|
|
Result := false;
|
|
|
|
if AlphaEdit.Text = '' then
|
|
|
|
begin
|
|
|
|
AMsg := 'Input required.';
|
|
|
|
AControl := AlphaEdit;
|
2020-09-06 16:03:58 +00:00
|
|
|
Alpha := NaN;
|
2020-04-26 22:36:07 +00:00
|
|
|
exit;
|
|
|
|
end;
|
2020-09-06 16:03:58 +00:00
|
|
|
if not TryStrToFloat(AlphaEdit.Text, Alpha) or (Alpha <= 0) or (Alpha >= 1.0) then
|
2020-04-26 22:36:07 +00:00
|
|
|
begin
|
|
|
|
AMsg := 'Numerical value between 0 and 1 required.';
|
|
|
|
AControl := AlphaEdit;
|
2020-09-06 16:03:58 +00:00
|
|
|
Alpha := NaN;
|
2020-04-26 22:36:07 +00:00
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
2020-09-06 16:03:58 +00:00
|
|
|
if tChk.Checked or ChiChk.Checked or FChk.Checked then
|
2020-04-26 22:36:07 +00:00
|
|
|
begin
|
|
|
|
if DF1Edit.Text = '' then
|
|
|
|
begin
|
|
|
|
AMsg := 'Input required.';
|
|
|
|
AControl := DF1Edit;
|
2020-09-06 16:03:58 +00:00
|
|
|
DF1 := -1;
|
2020-04-26 22:36:07 +00:00
|
|
|
exit;
|
|
|
|
end;
|
2020-09-06 16:03:58 +00:00
|
|
|
if not TryStrToInt(DF1Edit.Text, DF1) or (DF1 <= 0) then
|
2020-04-26 22:36:07 +00:00
|
|
|
begin
|
|
|
|
AMsg := 'Positive numerical value required.';
|
|
|
|
AControl := DF1Edit;
|
2020-09-06 16:03:58 +00:00
|
|
|
DF1 := -1;
|
2020-04-26 22:36:07 +00:00
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if FChk.Checked then
|
|
|
|
begin
|
|
|
|
if DF2Edit.Text = '' then
|
|
|
|
begin
|
|
|
|
AMsg := 'Input required.';
|
|
|
|
AControl := DF2Edit;
|
2020-09-06 16:03:58 +00:00
|
|
|
DF2 := -1;
|
2020-04-26 22:36:07 +00:00
|
|
|
exit;
|
|
|
|
end;
|
2020-09-06 16:03:58 +00:00
|
|
|
if not TryStrToInt(DF2Edit.Text, DF2) or (DF2 <= 0) then
|
2020-04-26 22:36:07 +00:00
|
|
|
begin
|
|
|
|
AMsg := 'Positive numerical value required.';
|
|
|
|
AControl := DF2Edit;
|
2020-09-06 16:03:58 +00:00
|
|
|
DF2 := -1;
|
2020-04-26 22:36:07 +00:00
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
Result := true;
|
|
|
|
end;
|
|
|
|
|
2020-09-06 16:03:58 +00:00
|
|
|
//initialization
|
|
|
|
// {$I distribunit.lrs}
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
end.
|
|
|
|
|