LazStats: Accept both decimal separators in the sub-menu forms of "Simulations" > "Probabilities"

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8048 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2021-06-04 09:59:27 +00:00
parent a7913ef0a4
commit 2004440204
16 changed files with 283 additions and 209 deletions

View File

@ -29,7 +29,7 @@ object FForm: TFForm
Cancel = True
Caption = 'Cancel'
ModalResult = 2
TabOrder = 0
TabOrder = 1
end
object ResetBtn: TButton
AnchorSideTop.Control = Bevel1
@ -45,7 +45,7 @@ object FForm: TFForm
BorderSpacing.Right = 12
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 1
TabOrder = 2
end
object ComputeBtn: TButton
AnchorSideTop.Control = Bevel1
@ -61,7 +61,7 @@ object FForm: TFForm
BorderSpacing.Right = 12
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 2
TabOrder = 3
end
object ReturnBtn: TButton
AnchorSideTop.Control = Bevel1
@ -79,7 +79,7 @@ object FForm: TFForm
BorderSpacing.Bottom = 8
Caption = 'Return'
ModalResult = 1
TabOrder = 3
TabOrder = 4
end
object Bevel1: TBevel
AnchorSideLeft.Control = Owner
@ -108,18 +108,18 @@ object FForm: TFForm
BevelOuter = bvNone
ClientHeight = 85
ClientWidth = 412
TabOrder = 4
TabOrder = 0
object Label1: TLabel
AnchorSideTop.Control = FEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label4
AnchorSideRight.Side = asrBottom
Left = 88
Left = 102
Height = 15
Top = 4
Width = 117
Width = 103
Anchors = [akTop, akRight]
Caption = 'Given: An F statistic = '
Caption = 'Given: An F statistic'
ParentColor = False
end
object FEdit: TEdit
@ -141,12 +141,12 @@ object FForm: TFForm
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label4
AnchorSideRight.Side = asrBottom
Left = 88
Left = 91
Height = 15
Top = 31
Width = 117
Width = 114
Anchors = [akTop, akRight]
Caption = 'with Deg. Freedom of '
Caption = 'with deg. freedom of '
ParentColor = False
end
object DF1Edit: TEdit
@ -199,7 +199,7 @@ object FForm: TFForm
Height = 15
Top = 66
Width = 205
Caption = 'then the probability of a larger value = '
Caption = 'then the probability of a larger value is'
ParentColor = False
end
object ProbEdit: TEdit

View File

@ -41,8 +41,10 @@ var
implementation
{$R *.lfm}
uses
Math, MathUnit;
Math, MathUnit, Utils;
{ TFForm }
@ -55,12 +57,31 @@ begin
end;
procedure TFForm.ComputeBtnClick(Sender: TObject);
VAR
F, df1, df2, prob : extended;
var
F, prob: Double;
df1, df2: Integer;
begin
F := StrToFloat(FEdit.Text);
df1 := StrToFloat(DF1Edit.Text);
df2 := StrToFloat(DF2Edit.Text);
if not MyTryStrToFloat(FEdit.Text, F) then
begin
FEdit.SetFocus;
ErrorMsg('No valid number.');
exit;
end;
if not TryStrToInt(DF1Edit.Text, df1) then
begin
DF1Edit.SetFocus;
ErrorMsg('No valid integer (must be positive).');
exit;
end;
if not TryStrToInt(DF2Edit.Text, df2) then
begin
DF2Edit.SetFocus;
ErrorMsg('No valid integer (must be positive).');
exit;
end;
prob := ProbF(F, df1, df2);
ProbEdit.Text := Format('%6.4f', [prob]);
end;
@ -77,8 +98,5 @@ begin
end;
initialization
{$I fprobunit.lrs}
end.

View File

@ -29,7 +29,7 @@ object InversezForm: TInversezForm
Cancel = True
Caption = 'Cancel'
ModalResult = 2
TabOrder = 0
TabOrder = 1
end
object ResetBtn: TButton
AnchorSideTop.Control = Bevel1
@ -45,7 +45,7 @@ object InversezForm: TInversezForm
BorderSpacing.Right = 12
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 1
TabOrder = 2
end
object ComputeBtn: TButton
AnchorSideTop.Control = Bevel1
@ -61,7 +61,7 @@ object InversezForm: TInversezForm
BorderSpacing.Right = 12
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 2
TabOrder = 3
end
object ReturnBtn: TButton
AnchorSideTop.Control = Bevel1
@ -78,7 +78,7 @@ object InversezForm: TInversezForm
BorderSpacing.Right = 16
Caption = 'Return'
ModalResult = 1
TabOrder = 3
TabOrder = 4
end
object Bevel1: TBevel
AnchorSideLeft.Control = Owner
@ -97,29 +97,29 @@ object InversezForm: TInversezForm
AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = Owner
Left = 54
Left = 65
Height = 54
Top = 8
Width = 239
Width = 217
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BevelOuter = bvNone
ClientHeight = 54
ClientWidth = 239
TabOrder = 4
ClientWidth = 217
TabOrder = 0
object Label1: TLabel
AnchorSideTop.Control = ProbEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label2
AnchorSideRight.Side = asrBottom
Left = 8
Left = 0
Height = 15
Top = 4
Width = 135
Width = 121
Anchors = [akTop, akRight]
Caption = 'Cumulative Probability = '
Caption = 'Cumulative Probability'
ParentColor = False
end
object ProbEdit: TEdit
@ -127,7 +127,7 @@ object InversezForm: TInversezForm
AnchorSideTop.Control = Panel1
AnchorSideRight.Control = ZEdit
AnchorSideRight.Side = asrBottom
Left = 151
Left = 129
Height = 23
Top = 0
Width = 88
@ -143,8 +143,8 @@ object InversezForm: TInversezForm
Left = 0
Height = 15
Top = 35
Width = 143
Caption = 'Corresponds to a z value = '
Width = 121
Caption = 'Corresponding z value '
ParentColor = False
end
object ZEdit: TEdit
@ -152,7 +152,7 @@ object InversezForm: TInversezForm
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ProbEdit
AnchorSideTop.Side = asrBottom
Left = 151
Left = 129
Height = 23
Top = 31
Width = 88

View File

@ -6,8 +6,7 @@ interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls,
Functionslib;
StdCtrls, ExtCtrls;
type
@ -38,8 +37,10 @@ var
implementation
{$R *.lfm}
uses
Math;
Math, MathUnit, Utils;
{ TInversezForm }
@ -50,14 +51,17 @@ begin
end;
procedure TInversezForm.ComputeBtnClick(Sender: TObject);
VAR
Prob, Zscore : double;
outvalue : string;
var
prob, zScore: double;
begin
Prob := StrToFloat(ProbEdit.Text);
Zscore := inversez(Prob);
outvalue := format('%6.4f',[Zscore]);
ZEdit.Text := outvalue;
if not MyTryStrToFloat(ProbEdit.Text, prob) then
begin
ProbEdit.SetFocus;
ErrorMsg('No valid number.');
exit;
end;
zScore := InverseNormalDist(prob);
ZEdit.Text := Format('%6.4f', [zScore]);
end;
procedure TInversezForm.FormActivate(Sender: TObject);
@ -71,8 +75,5 @@ begin
ReturnBtn.Constraints.MinWidth := w;
end;
initialization
{$I inversezunit.lrs}
end.

View File

@ -26,7 +26,7 @@ object ChiSqrProbForm: TChiSqrProbForm
Cancel = True
Caption = 'Cancel'
ModalResult = 2
TabOrder = 0
TabOrder = 1
end
object ResetBtn: TButton
AnchorSideTop.Control = ReturnBtn
@ -40,7 +40,7 @@ object ChiSqrProbForm: TChiSqrProbForm
BorderSpacing.Right = 8
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 1
TabOrder = 2
end
object ComputeBtn: TButton
AnchorSideTop.Control = ReturnBtn
@ -54,7 +54,7 @@ object ChiSqrProbForm: TChiSqrProbForm
BorderSpacing.Right = 8
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 2
TabOrder = 3
end
object ReturnBtn: TButton
AnchorSideTop.Control = Bevel1
@ -73,7 +73,7 @@ object ChiSqrProbForm: TChiSqrProbForm
BorderSpacing.Bottom = 8
Caption = 'Return'
ModalResult = 1
TabOrder = 3
TabOrder = 4
end
object Bevel1: TBevel
AnchorSideLeft.Control = Owner
@ -92,18 +92,18 @@ object ChiSqrProbForm: TChiSqrProbForm
AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = Owner
Left = 86
Left = 93
Height = 85
Top = 8
Width = 217
Width = 203
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BevelOuter = bvNone
ClientHeight = 85
ClientWidth = 217
TabOrder = 4
ClientWidth = 203
TabOrder = 0
object Label1: TLabel
AnchorSideTop.Control = ChiSqrEdit
AnchorSideTop.Side = asrCenter
@ -112,10 +112,10 @@ object ChiSqrProbForm: TChiSqrProbForm
Left = 30
Height = 15
Top = 4
Width = 105
Width = 91
Anchors = [akTop, akRight]
BorderSpacing.Left = 8
Caption = 'Chisquared value = '
Caption = 'Chisquared value'
ParentColor = False
end
object ChiSqrEdit: TEdit
@ -123,7 +123,7 @@ object ChiSqrProbForm: TChiSqrProbForm
AnchorSideTop.Control = Panel1
AnchorSideRight.Control = ProbEdit
AnchorSideRight.Side = asrBottom
Left = 143
Left = 129
Height = 23
Top = 0
Width = 74
@ -140,10 +140,10 @@ object ChiSqrProbForm: TChiSqrProbForm
Left = 24
Height = 15
Top = 31
Width = 111
Width = 97
Anchors = [akTop, akRight]
BorderSpacing.Left = 8
Caption = 'with deg. freedom = '
Caption = 'with deg. freedom'
ParentColor = False
end
object DFEdit: TEdit
@ -152,7 +152,7 @@ object ChiSqrProbForm: TChiSqrProbForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ProbEdit
AnchorSideRight.Side = asrBottom
Left = 143
Left = 129
Height = 23
Top = 27
Width = 74
@ -169,8 +169,8 @@ object ChiSqrProbForm: TChiSqrProbForm
Left = 0
Height = 15
Top = 66
Width = 135
Caption = 'Probability larger value = '
Width = 121
Caption = 'Probability larger value'
ParentColor = False
end
object ProbEdit: TEdit
@ -178,7 +178,7 @@ object ChiSqrProbForm: TChiSqrProbForm
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = DFEdit
AnchorSideTop.Side = asrBottom
Left = 143
Left = 129
Height = 23
Top = 62
Width = 74

View File

@ -40,8 +40,10 @@ var
implementation
{$R *.lfm}
uses
Math;
Math, MathUnit, Utils;
{ TChiSqrProbForm }
@ -53,16 +55,25 @@ begin
end;
procedure TChiSqrProbForm.ComputeBtnClick(Sender: TObject);
VAR
ChiSqr, Prob : double;
var
chiSqr, prob: double;
DF: integer;
outvalue : string;
begin
ChiSqr := StrToFloat(ChiSqrEdit.Text);
DF := StrToInt(DFEdit.Text);
Prob := 1.0 - chisquaredprob(ChiSqr,DF);
outvalue := format('%6.4f',[Prob]);
ProbEdit.Text := outvalue;
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]);
end;
procedure TChiSqrProbForm.FormActivate(Sender: TObject);
@ -76,8 +87,5 @@ begin
ReturnBtn.Constraints.MinWidth := w;
end;
initialization
{$I probchisqrunit.lrs}
end.

View File

@ -29,7 +29,7 @@ object ProbSmallerzForm: TProbSmallerzForm
Cancel = True
Caption = 'Cancel'
ModalResult = 2
TabOrder = 0
TabOrder = 1
end
object ResetBtn: TButton
AnchorSideTop.Control = Bevel1
@ -45,7 +45,7 @@ object ProbSmallerzForm: TProbSmallerzForm
BorderSpacing.Right = 12
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 1
TabOrder = 2
end
object ComputeBtn: TButton
AnchorSideTop.Control = Bevel1
@ -61,7 +61,7 @@ object ProbSmallerzForm: TProbSmallerzForm
BorderSpacing.Right = 12
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 2
TabOrder = 3
end
object ReturnBtn: TButton
AnchorSideTop.Control = Bevel1
@ -79,38 +79,38 @@ object ProbSmallerzForm: TProbSmallerzForm
BorderSpacing.Bottom = 8
Caption = 'Return'
ModalResult = 1
TabOrder = 3
TabOrder = 4
end
object Panel1: TPanel
AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
Left = 57
Left = 64
Height = 54
Top = 4
Width = 194
Width = 180
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BevelOuter = bvNone
ClientHeight = 54
ClientWidth = 194
TabOrder = 4
ClientWidth = 180
TabOrder = 0
object Label1: TLabel
AnchorSideTop.Control = zEdit
AnchorSideTop.Side = asrCenter
Left = 0
Height = 15
Top = 4
Width = 103
Caption = 'Observed z score = '
Width = 89
Caption = 'Observed z score'
ParentColor = False
end
object zEdit: TEdit
AnchorSideLeft.Control = Label1
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
Left = 111
Left = 97
Height = 23
Top = 0
Width = 83
@ -127,9 +127,9 @@ object ProbSmallerzForm: TProbSmallerzForm
Left = 13
Height = 15
Top = 35
Width = 90
Width = 76
Anchors = [akTop, akRight]
Caption = 'Probability < z = '
Caption = 'Probability < z'
ParentColor = False
end
object ProbzEdit: TEdit
@ -138,7 +138,7 @@ object ProbSmallerzForm: TProbSmallerzForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = zEdit
AnchorSideRight.Side = asrBottom
Left = 111
Left = 97
Height = 23
Top = 31
Width = 83

View File

@ -6,8 +6,7 @@ interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls,
Functionslib;
StdCtrls, ExtCtrls;
type
@ -38,8 +37,10 @@ var
implementation
{$R *.lfm}
uses
Math;
Math, MathUnit, Utils;
{ TProbSmallerzForm }
@ -50,14 +51,17 @@ begin
end;
procedure TProbSmallerzForm.ComputeBtnClick(Sender: TObject);
VAR
var
zprob, z: double;
outvalue : string;
begin
z := StrToFloat(zEdit.Text);
zprob := probz(z);
outvalue := format('%6.4f',[zprob]);
ProbzEdit.Text := outvalue;
if not MyTryStrToFloat(zEdit.Text, z) then
begin
zEdit.SetFocus;
ErrorMsg('No valid number.');
exit;
end;
zProb := NormalDist(z);
ProbzEdit.Text := Format('%6.4f', [zProb]);
end;
procedure TProbSmallerzForm.FormActivate(Sender: TObject);
@ -71,8 +75,5 @@ begin
ReturnBtn.Constraints.MinWidth := w;
end;
initialization
{$I probsmallerzunit.lrs}
end.

View File

@ -29,7 +29,7 @@ object ProbzForm: TProbzForm
Cancel = True
Caption = 'Cancel'
ModalResult = 2
TabOrder = 0
TabOrder = 1
end
object ResetBtn: TButton
AnchorSideTop.Control = Bevel1
@ -45,7 +45,7 @@ object ProbzForm: TProbzForm
BorderSpacing.Right = 12
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 1
TabOrder = 2
end
object ComputeBtn: TButton
AnchorSideTop.Control = Bevel1
@ -61,7 +61,7 @@ object ProbzForm: TProbzForm
BorderSpacing.Right = 12
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 2
TabOrder = 3
end
object ReturnBtn: TButton
AnchorSideTop.Control = Bevel1
@ -79,7 +79,7 @@ object ProbzForm: TProbzForm
BorderSpacing.Bottom = 8
Caption = 'Return'
ModalResult = 1
TabOrder = 3
TabOrder = 4
end
object Bevel1: TBevel
AnchorSideLeft.Control = Owner
@ -98,18 +98,18 @@ object ProbzForm: TProbzForm
AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = Owner
Left = 58
Left = 65
Height = 55
Top = 8
Width = 194
Width = 180
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BevelOuter = bvNone
ClientHeight = 55
ClientWidth = 194
TabOrder = 4
ClientWidth = 180
TabOrder = 0
object Label1: TLabel
AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = zEdit
@ -117,14 +117,14 @@ object ProbzForm: TProbzForm
Left = 0
Height = 15
Top = 4
Width = 103
Caption = 'Observed z score = '
Width = 89
Caption = 'Observed z score'
ParentColor = False
end
object zEdit: TEdit
AnchorSideLeft.Control = Label1
AnchorSideLeft.Side = asrBottom
Left = 111
Left = 97
Height = 23
Top = 0
Width = 83
@ -141,16 +141,16 @@ object ProbzForm: TProbzForm
Left = 13
Height = 15
Top = 36
Width = 90
Width = 76
Anchors = [akTop, akRight]
Caption = 'Probability > z = '
Caption = 'Probability > z'
ParentColor = False
end
object ProbzEdit: TEdit
AnchorSideLeft.Control = zEdit
AnchorSideRight.Control = zEdit
AnchorSideRight.Side = asrBottom
Left = 111
Left = 97
Height = 23
Top = 32
Width = 83

View File

@ -6,8 +6,7 @@ interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls,
FunctionsLib;
StdCtrls, ExtCtrls;
type
@ -38,8 +37,10 @@ var
implementation
{$R *.lfm}
uses
Math;
Math, MathUnit, Utils;
{ TProbzForm }
@ -50,14 +51,17 @@ begin
end;
procedure TProbzForm.ComputeBtnClick(Sender: TObject);
VAR
var
zprob, z: double;
outvalue : string;
begin
z := StrToFloat(zEdit.Text);
zprob := 1.0 - probz(z);
outvalue := format('%6.4f',[zprob]);
ProbzEdit.Text := outvalue;
if not MyTryStrToFloat(zEdit.Text, z) then
begin
zEdit.SetFocus;
ErrorMsg('No valid number.');
exit;
end;
zProb := 1.0 - NormalDist(z);
ProbzEdit.Text := Format('%6.4f', [zProb]);
end;
procedure TProbzForm.FormActivate(Sender: TObject);
@ -71,8 +75,5 @@ begin
ReturnBtn.Constraints.MinWidth := w;
end;
initialization
{$I probzunit.lrs}
end.

View File

@ -29,7 +29,7 @@ object TProbForm: TTProbForm
Cancel = True
Caption = 'Cancel'
ModalResult = 2
TabOrder = 0
TabOrder = 1
end
object ResetBtn: TButton
AnchorSideTop.Control = Bevel1
@ -45,7 +45,7 @@ object TProbForm: TTProbForm
BorderSpacing.Right = 12
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 1
TabOrder = 2
end
object ComputeBtn: TButton
AnchorSideTop.Control = Bevel1
@ -61,7 +61,7 @@ object TProbForm: TTProbForm
BorderSpacing.Right = 12
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 2
TabOrder = 3
end
object ReturnBtn: TButton
AnchorSideTop.Control = Bevel1
@ -79,7 +79,7 @@ object TProbForm: TTProbForm
BorderSpacing.Bottom = 8
Caption = 'Return'
ModalResult = 1
TabOrder = 3
TabOrder = 4
end
object Bevel1: TBevel
AnchorSideLeft.Control = Owner
@ -98,18 +98,18 @@ object TProbForm: TTProbForm
AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = Owner
Left = 87
Left = 94
Height = 85
Top = 8
Width = 217
Width = 203
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BevelOuter = bvNone
ClientHeight = 85
ClientWidth = 217
TabOrder = 4
ClientWidth = 203
TabOrder = 0
object Label1: TLabel
AnchorSideTop.Control = tValueEdit
AnchorSideTop.Side = asrCenter
@ -118,9 +118,9 @@ object TProbForm: TTProbForm
Left = 42
Height = 15
Top = 4
Width = 93
Width = 79
Anchors = [akTop, akRight]
Caption = 'Student t value = '
Caption = 'Student t value'
ParentColor = False
end
object tValueEdit: TEdit
@ -128,7 +128,7 @@ object TProbForm: TTProbForm
AnchorSideTop.Control = Panel1
AnchorSideRight.Control = ProbEdit
AnchorSideRight.Side = asrBottom
Left = 143
Left = 129
Height = 23
Top = 0
Width = 74
@ -145,9 +145,9 @@ object TProbForm: TTProbForm
Left = 24
Height = 15
Top = 31
Width = 111
Width = 97
Anchors = [akTop, akRight]
Caption = 'with deg. freedom = '
Caption = 'with deg. freedom'
ParentColor = False
end
object DFEdit: TEdit
@ -156,7 +156,7 @@ object TProbForm: TTProbForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ProbEdit
AnchorSideRight.Side = asrBottom
Left = 143
Left = 129
Height = 23
Top = 27
Width = 74
@ -173,8 +173,8 @@ object TProbForm: TTProbForm
Left = 0
Height = 15
Top = 66
Width = 135
Caption = 'Probability larger value = '
Width = 121
Caption = 'Probability larger value'
ParentColor = False
end
object ProbEdit: TEdit
@ -182,7 +182,7 @@ object TProbForm: TTProbForm
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = DFEdit
AnchorSideTop.Side = asrBottom
Left = 143
Left = 129
Height = 23
Top = 62
Width = 74

View File

@ -42,7 +42,7 @@ implementation
{$R *.lfm}
uses
Math, MathUnit;
Math, MathUnit, Utils;
{ TTProbForm }
@ -54,18 +54,32 @@ begin
end;
procedure TTProbForm.ComputeBtnClick(Sender: TObject);
VAR
tvalue, dfvalue, prob : double;
outvalue : string;
var
tvalue, prob: double;
dfValue: Integer;
begin
tvalue := StrToFloat(tValueEdit.Text);
dfvalue := StrToFloat(DFEdit.Text);
if tvalue >= 0.0 then prob := 0.5 * ProbT(tvalue,dfvalue);
if tvalue < 0.0 then prob := 1.0 - ProbT(tvalue,dfvalue) +
(0.5 * probt(tvalue,dfvalue)) ;
if tvalue = 0.0 then prob := 0.50;
outvalue := format('%6.4f',[prob]);
ProbEdit.Text := outvalue;
if not MyTryStrToFloat(tValueEdit.Text, tvalue) then
begin
tValueEdit.SetFocus;
ErrorMsg('No valid number.');
exit;
end;
if not TryStrToInt(DFEdit.Text, dfValue) then
begin
dfEdit.SetFocus;
ErrorMsg('Not a valid integer (must be positive).');
exit;
end;
if tvalue >= 0.0 then
prob := 0.5 * ProbT(tvalue, dfvalue)
else if tvalue < 0.0 then
prob := 1.0 - ProbT(tvalue, dfvalue) + (0.5 *ProbT(tvalue, dfvalue))
else
prob := 0.50;
ProbEdit.Text := Format('%6.4f', [prob]);
end;
procedure TTProbForm.FormActivate(Sender: TObject);

View File

@ -8,6 +8,7 @@ object TwozProbForm: TTwozProbForm
Caption = 'Probability between two z scores'
ClientHeight = 147
ClientWidth = 378
OnActivate = FormActivate
OnShow = ResetBtnClick
Position = poMainFormCenter
LCLVersion = '2.1.0.0'
@ -15,25 +16,25 @@ object TwozProbForm: TTwozProbForm
AnchorSideTop.Control = Bevel1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ResetBtn
Left = 57
Left = 81
Height = 25
Top = 109
Width = 62
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Left = 32
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 12
Cancel = True
Caption = 'Cancel'
ModalResult = 2
TabOrder = 0
TabOrder = 1
end
object ResetBtn: TButton
AnchorSideTop.Control = Bevel1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ComputeBtn
Left = 131
Left = 155
Height = 25
Top = 109
Width = 54
@ -43,13 +44,13 @@ object TwozProbForm: TTwozProbForm
BorderSpacing.Right = 12
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 1
TabOrder = 2
end
object ComputeBtn: TButton
AnchorSideTop.Control = Bevel1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ReturnBtn
Left = 197
Left = 221
Height = 25
Top = 109
Width = 76
@ -59,25 +60,25 @@ object TwozProbForm: TTwozProbForm
BorderSpacing.Right = 12
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 2
TabOrder = 3
end
object ReturnBtn: TButton
AnchorSideTop.Control = Bevel1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 285
Left = 309
Height = 25
Top = 109
Width = 61
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Top = 8
BorderSpacing.Right = 32
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Return'
ModalResult = 1
TabOrder = 3
TabOrder = 4
end
object Bevel1: TBevel
AnchorSideLeft.Control = Owner
@ -96,18 +97,18 @@ object TwozProbForm: TTwozProbForm
AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = Owner
Left = 74
Left = 81
Height = 85
Top = 8
Width = 231
Width = 217
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BevelOuter = bvNone
ClientHeight = 85
ClientWidth = 231
TabOrder = 4
ClientWidth = 217
TabOrder = 0
object Label1: TLabel
AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = Z1Edit
@ -115,15 +116,15 @@ object TwozProbForm: TTwozProbForm
Left = 0
Height = 15
Top = 4
Width = 155
Caption = 'The probability between z1 = '
Width = 141
Caption = 'The probability between z1'
ParentColor = False
end
object Z1Edit: TEdit
AnchorSideLeft.Control = Label1
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
Left = 163
Left = 149
Height = 23
Top = 0
Width = 68
@ -137,12 +138,12 @@ object TwozProbForm: TTwozProbForm
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label1
AnchorSideRight.Side = asrBottom
Left = 107
Left = 104
Height = 15
Top = 31
Width = 48
Width = 37
Anchors = [akTop, akRight]
Caption = 'and z2 = '
Caption = 'and z2 '
ParentColor = False
end
object Z2Edit: TEdit
@ -151,7 +152,7 @@ object TwozProbForm: TTwozProbForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Z1Edit
AnchorSideRight.Side = asrBottom
Left = 163
Left = 149
Height = 23
Top = 27
Width = 68
@ -169,9 +170,9 @@ object TwozProbForm: TTwozProbForm
Left = 84
Height = 15
Top = 66
Width = 71
Width = 57
Anchors = [akTop, akRight]
Caption = 'Probability = '
Caption = 'Probability'
ParentColor = False
end
object ProbEdit: TEdit
@ -180,7 +181,7 @@ object TwozProbForm: TTwozProbForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Z1Edit
AnchorSideRight.Side = asrBottom
Left = 163
Left = 149
Height = 23
Top = 62
Width = 68

View File

@ -6,8 +6,7 @@ interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls,
FunctionsLib;
StdCtrls, ExtCtrls;
type
@ -27,6 +26,7 @@ type
Z1Edit: TEdit;
Label1: TLabel;
procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
private
{ private declarations }
@ -39,6 +39,11 @@ var
implementation
{$R *.lfm}
uses
Math, MathUnit, Utils;
{ TTwozProbForm }
procedure TTwozProbForm.ResetBtnClick(Sender: TObject);
@ -49,26 +54,37 @@ begin
end;
procedure TTwozProbForm.ComputeBtnClick(Sender: TObject);
VAR
var
z1, z2, prob : double;
outvalue : string;
begin
z1 := StrToFloat(Z1Edit.Text);
z2 := StrToFloat(Z2Edit.Text);
if z1 < z2 then
if not MyTryStrToFloat(Z1Edit.Text, z1) then
begin
prob := probz(z2) - probz(z1);
end;
if z1 > z2 then
begin
prob := probz(z1) - probz(z2);
end;
outvalue := format('%6.4f',[prob]);
ProbEdit.Text := outvalue;
Z1Edit.SetFocus;
ErrorMsg('No valid number.');
exit;
end;
initialization
{$I twozprobunit.lrs}
if not MyTryStrToFloat(Z2Edit.Text, z2) then
begin
Z2Edit.SetFocus;
ErrorMsg('No valid number.');
exit;
end;
prob := abs(NormalDist(z2) - NormalDist(z1));
ProbEdit.Text := Format('%6.4f', [prob]);
end;
procedure TTwozProbForm.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.

View File

@ -46,6 +46,7 @@ function FactorialLn(n: Integer): Double;
function PoissonPDF(n: integer; a: double): Double;
function PoissonCDF(n: Integer; a: double): Double;
function MyTryStrToFloat(S: String; out AValue: Double): Boolean;
implementation
@ -569,6 +570,20 @@ begin
end;
{ Converts a string to a floating point value. Checks for comma or point as
decimal separator }
function MyTryStrToFloat(S: String; out AValue: Double): Boolean;
var
fs: TFormatSettings;
begin
Result := TryStrToFloat(S, AValue);
if not Result then
begin
fs := FormatSettings;
if fs.DecimalSeparator = '.' then fs.DecimalSeparator := ',' else fs.DecimalSeparator := '.';
Result := TryStrToFloat(S, AValue, fs);
end;
end;
initialization
InitFactLn();

View File

@ -194,4 +194,3 @@ end;
end.