2020-03-30 18:01:44 +00:00
|
|
|
unit ProbChiSqrUnit;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
2020-11-06 00:04:57 +00:00
|
|
|
{$WARN 6058 off : Call to subroutine "$1" marked as inline is not inlined}
|
2020-03-30 18:01:44 +00:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
|
|
|
StdCtrls, ExtCtrls,
|
|
|
|
FunctionsLib;
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TChiSqrProbForm }
|
|
|
|
|
|
|
|
TChiSqrProbForm = class(TForm)
|
|
|
|
Bevel1: TBevel;
|
|
|
|
CancelBtn: TButton;
|
|
|
|
ChiSqrEdit: TEdit;
|
|
|
|
ComputeBtn: TButton;
|
|
|
|
DFEdit: TEdit;
|
|
|
|
Panel1: TPanel;
|
|
|
|
ProbEdit: TEdit;
|
|
|
|
Label1: TLabel;
|
|
|
|
Label2: TLabel;
|
|
|
|
Label3: TLabel;
|
|
|
|
ResetBtn: TButton;
|
|
|
|
ReturnBtn: TButton;
|
|
|
|
procedure ComputeBtnClick(Sender: TObject);
|
|
|
|
procedure FormActivate(Sender: TObject);
|
|
|
|
procedure ResetBtnClick(Sender: TObject);
|
|
|
|
private
|
|
|
|
{ private declarations }
|
|
|
|
public
|
|
|
|
{ public declarations }
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
ChiSqrProbForm: TChiSqrProbForm;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2021-06-04 09:59:27 +00:00
|
|
|
{$R *.lfm}
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
uses
|
2021-06-04 09:59:27 +00:00
|
|
|
Math, MathUnit, Utils;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
{ TChiSqrProbForm }
|
|
|
|
|
|
|
|
procedure TChiSqrProbForm.ResetBtnClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ChiSqrEdit.Text := '';
|
|
|
|
DFEdit.Text := '';
|
|
|
|
ProbEdit.Text := '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TChiSqrProbForm.ComputeBtnClick(Sender: TObject);
|
2021-06-04 09:59:27 +00:00
|
|
|
var
|
|
|
|
chiSqr, prob: double;
|
|
|
|
DF: integer;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2021-06-04 09:59:27 +00:00
|
|
|
if not MyTryStrToFloat(ChiSqrEdit.Text, chiSqr) then
|
|
|
|
begin
|
|
|
|
ChiSqrEdit.SetFocus;
|
|
|
|
ErrorMsg('No valid number.');
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if not TryStrToInt(DFEdit.Text, DF) or (DF <= 0) then begin
|
|
|
|
DFEdit.SetFocus;
|
|
|
|
ErrorMsg('No a valid integer (must be positive).');
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
prob := 1.0 - ChiSquaredProb(ChiSqr, DF);
|
|
|
|
ProbEdit.Text := Format('%6.4f', [prob]);
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TChiSqrProbForm.FormActivate(Sender: TObject);
|
|
|
|
var
|
|
|
|
w: Integer;
|
|
|
|
begin
|
|
|
|
w := MaxValue([CancelBtn.Width, ResetBtn.Width, ComputeBtn.Width, ReturnBtn.Width]);
|
|
|
|
CancelBtn.Constraints.MinWidth := w;
|
|
|
|
ResetBtn.Constraints.MinWidth := w;
|
|
|
|
ComputeBtn.Constraints.MinWidth := w;
|
|
|
|
ReturnBtn.Constraints.MinWidth := w;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|