LazStats: Inherit RunsTestUnit from TBasicStatsReportForm. Replace output edit controls by a report memo.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7816 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-10-26 22:21:25 +00:00
parent d4d71291e9
commit 677bb5d75f
4 changed files with 252 additions and 581 deletions

View File

@ -65,4 +65,5 @@ correlation, means, standard deviations and confidence interval for each correla
161=Directions:\n(1) Select the X variable common to all of the Y variables to be selected.\n(2) Select the Y variables.\n(3) Enter a label for the plot.\n(4) Select the options desired.\n(5) Click the Compute button to obtain results. 161=Directions:\n(1) Select the X variable common to all of the Y variables to be selected.\n(2) Select the Y variables.\n(3) Enter a label for the plot.\n(4) Select the options desired.\n(5) Click the Compute button to obtain results.
162=This procedure plots the frequency of cases in each of the groups in a group variable. The group variable should be defined as an integer variable.\n\nSelect the variable and type of plot and click the Compute button for the results. 162=This procedure plots the frequency of cases in each of the groups in a group variable. The group variable should be defined as an integer variable.\n\nSelect the variable and type of plot and click the Compute button for the results.
163=The Resistant Line procedure creates three equal groups by sorting on the X variable and obtaining the median value of each group.\n\nThe median values for these three groups on both the X and Y variables are then plotted. The line from the low group median to the middle group median is plotted as well as the line from the middle group to the top group median. A comparison of the slope of these two lines gives an indication of the degree to which the data fit a straight line. Enter the X and Y variables to be analyzed and click the compute button. 163=The Resistant Line procedure creates three equal groups by sorting on the X variable and obtaining the median value of each group.\n\nThe median values for these three groups on both the X and Y variables are then plotted. The line from the low group median to the middle group median is plotted as well as the line from the middle group to the top group median. A comparison of the slope of these two lines gives an indication of the degree to which the data fit a straight line. Enter the X and Y variables to be analyzed and click the compute button.
164=This procedure smooths data by averaging every three data points starting with the first three to the last three. The data smoothing can be repeated multiple times. The first and last data points are unchanged. 164=This procedure smooths data by averaging every three data points starting with the first three to the last three. The data smoothing can be repeated multiple times. The first and last data points are unchanged.
165=This is a test for the randomness of a series of values in a variable. Select the variable to analyze and click the Compute button.

View File

@ -1177,7 +1177,7 @@
<Unit134> <Unit134>
<Filename Value="forms\analysis\nonparametric\runstestunit.pas"/> <Filename Value="forms\analysis\nonparametric\runstestunit.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<ComponentName Value="runstestform"/> <ComponentName Value="RunsTestForm"/>
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="RunsTestUnit"/> <UnitName Value="RunsTestUnit"/>

View File

@ -1,456 +1,142 @@
object runstestform: Trunstestform inherited RunsTestForm: TRunsTestForm
Left = 1138 Left = 660
Height = 438 Height = 355
Top = 277 Top = 233
Width = 376 Width = 748
HelpType = htKeyword HelpType = htKeyword
HelpKeyword = 'html/RunsTestforNormality.htm' HelpKeyword = 'html/RunsTestforNormality.htm'
AutoSize = True
Caption = 'Test for Randomness' Caption = 'Test for Randomness'
ClientHeight = 438 ClientHeight = 355
ClientWidth = 376 ClientWidth = 748
OnActivate = FormActivate inherited ParamsPanel: TPanel
OnCreate = FormCreate Height = 339
OnShow = ResetBtnClick Width = 297
Position = poMainFormCenter ClientHeight = 339
LCLVersion = '2.1.0.0' ClientWidth = 297
object Label1: TLabel inherited CloseBtn: TButton
AnchorSideLeft.Control = Owner Left = 242
AnchorSideTop.Control = Memo1 Top = 314
AnchorSideTop.Side = asrBottom TabOrder = 7
Left = 8 end
Height = 15 inherited ComputeBtn: TButton
Top = 54 Left = 158
Width = 100 Top = 314
BorderSpacing.Left = 8 TabOrder = 6
BorderSpacing.Top = 16 end
Caption = 'Available Variables:' inherited ResetBtn: TButton
ParentColor = False Left = 96
Top = 314
TabOrder = 5
end
inherited HelpBtn: TButton
Tag = 165
Left = 37
Top = 314
TabOrder = 4
end
inherited ButtonBevel: TBevel
Top = 298
Width = 297
end
object Label1: TLabel[5]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = ParamsPanel
Left = 0
Height = 15
Top = 0
Width = 97
Caption = 'Available Variables'
ParentColor = False
end
object Label2: TLabel[6]
AnchorSideLeft.Control = TestVarEdit
AnchorSideBottom.Control = TestVarEdit
Left = 167
Height = 15
Top = 21
Width = 105
Anchors = [akLeft, akBottom]
BorderSpacing.Bottom = 2
Caption = 'Test Randomness of'
ParentColor = False
end
object VarList: TListBox[7]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = Label1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = InBtn
AnchorSideBottom.Control = ButtonBevel
Left = 0
Height = 281
Top = 17
Width = 129
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Top = 2
BorderSpacing.Right = 6
ItemHeight = 0
MultiSelect = True
OnDblClick = VarListDblClick
OnSelectionChange = VarListSelectionChange
TabOrder = 0
end
object InBtn: TBitBtn[8]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = VarList
Left = 135
Height = 26
Top = 17
Width = 26
Images = MainDataModule.ImageList
ImageIndex = 1
OnClick = InBtnClick
Spacing = 0
TabOrder = 1
end
object OutBtn: TBitBtn[9]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = InBtn
AnchorSideTop.Side = asrBottom
Left = 135
Height = 26
Top = 47
Width = 26
BorderSpacing.Top = 4
Images = MainDataModule.ImageList
ImageIndex = 0
OnClick = OutBtnClick
Spacing = 0
TabOrder = 2
end
object TestVarEdit: TEdit[10]
AnchorSideLeft.Control = InBtn
AnchorSideLeft.Side = asrBottom
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = OutBtn
AnchorSideBottom.Side = asrBottom
Left = 167
Height = 23
Top = 38
Width = 130
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Left = 6
BorderSpacing.Bottom = 12
ReadOnly = True
TabOrder = 3
Text = 'TestVarEdit'
end
end end
object Label2: TLabel inherited ParamsSplitter: TSplitter
AnchorSideLeft.Control = TestVarEdit Left = 309
AnchorSideBottom.Control = TestVarEdit Height = 355
Left = 210
Height = 15
Top = 79
Width = 108
Anchors = [akLeft, akBottom]
BorderSpacing.Bottom = 2
Caption = 'Test Randomness of:'
ParentColor = False
end end
object VarList: TListBox object Bevel2: TBevel[2]
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Label1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = InBtn
AnchorSideBottom.Control = ProbEdit
AnchorSideBottom.Side = asrBottom
Left = 8
Height = 287
Top = 71
Width = 158
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Top = 2
BorderSpacing.Right = 8
ItemHeight = 0
MultiSelect = True
OnSelectionChange = VarListSelectionChange
TabOrder = 0
end
object InBtn: TBitBtn
AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = VarList
Left = 174
Height = 28
Top = 71
Width = 28
Images = MainDataModule.ImageList
ImageIndex = 1
OnClick = InBtnClick
Spacing = 0
TabOrder = 1
end
object OutBtn: TBitBtn
AnchorSideLeft.Control = InBtn
AnchorSideTop.Control = InBtn
AnchorSideTop.Side = asrBottom
Left = 174
Height = 28
Top = 103
Width = 28
BorderSpacing.Top = 4
Images = MainDataModule.ImageList
ImageIndex = 0
OnClick = OutBtnClick
Spacing = 0
TabOrder = 2
end
object TestVarEdit: TEdit
AnchorSideLeft.Control = InBtn
AnchorSideLeft.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = OutBtn
AnchorSideBottom.Side = asrBottom
Left = 210
Height = 23
Top = 96
Width = 158
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 12
ReadOnly = True
TabOrder = 3
Text = 'TestVarEdit'
end
object Label3: TLabel
AnchorSideTop.Control = MeanEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = MeanEdit
Left = 244
Height = 15
Top = 177
Width = 33
Anchors = [akTop, akRight]
BorderSpacing.Right = 8
Caption = 'Mean:'
ParentColor = False
end
object Label4: TLabel
AnchorSideLeft.Control = InBtn
AnchorSideTop.Control = StdDevEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = StdDevEdit
Left = 174
Height = 15
Top = 204
Width = 103
BorderSpacing.Right = 8
Caption = 'Standard Deviation:'
ParentColor = False
end
object Label5: TLabel
AnchorSideTop.Control = NUpEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = NUpEdit
Left = 185
Height = 15
Top = 231
Width = 92
Anchors = [akTop, akRight]
BorderSpacing.Right = 8
Caption = 'N Values > Mean:'
ParentColor = False
end
object Label6: TLabel
AnchorSideTop.Control = NDownEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = NDownEdit
Left = 185
Height = 15
Top = 258
Width = 92
Anchors = [akTop, akRight]
BorderSpacing.Right = 8
Caption = 'N Values < Mean:'
ParentColor = False
end
object Label7: TLabel
AnchorSideTop.Control = NRunsEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = NRunsEdit
Left = 187
Height = 15
Top = 285
Width = 90
Anchors = [akTop, akRight]
BorderSpacing.Right = 8
Caption = 'Number of Runs:'
ParentColor = False
end
object Label8: TLabel
AnchorSideTop.Control = StatEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = StatEdit
Left = 210
Height = 15
Top = 312
Width = 67
Anchors = [akTop, akRight]
BorderSpacing.Right = 8
Caption = 'Test Statistic:'
ParentColor = False
end
object Label9: TLabel
AnchorSideTop.Control = ProbEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = ProbEdit
Left = 217
Height = 15
Top = 339
Width = 60
Anchors = [akTop, akRight]
BorderSpacing.Right = 8
Caption = 'Probability:'
ParentColor = False
end
object Label10: TLabel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = ConclusionEdit
AnchorSideTop.Side = asrCenter
Left = 8
Height = 15
Top = 370
Width = 63
BorderSpacing.Left = 8
BorderSpacing.Right = 8
Caption = 'Conclusion:'
ParentColor = False
end
object MeanEdit: TEdit
AnchorSideLeft.Control = StdDevEdit
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = StdDevEdit
Left = 285
Height = 23
Top = 173
Width = 83
Alignment = taRightJustify
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Right = 8
BorderSpacing.Bottom = 4
Font.Style = [fsBold]
ParentFont = False
ReadOnly = True
TabOrder = 4
Text = 'MeanEdit'
end
object StdDevEdit: TEdit
AnchorSideLeft.Control = Label4
AnchorSideLeft.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = NUpEdit
Left = 285
Height = 23
Top = 200
Width = 83
Alignment = taRightJustify
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 4
Font.Style = [fsBold]
ParentFont = False
ReadOnly = True
TabOrder = 5
Text = 'StdDevEdit'
end
object NUpEdit: TEdit
AnchorSideLeft.Control = StdDevEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = NDownEdit
Left = 285
Height = 23
Top = 227
Width = 83
Alignment = taRightJustify
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Right = 8
BorderSpacing.Bottom = 4
Font.Style = [fsBold]
ParentFont = False
ReadOnly = True
TabOrder = 6
Text = 'NUpEdit'
end
object NDownEdit: TEdit
AnchorSideLeft.Control = StdDevEdit
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = NRunsEdit
Left = 285
Height = 23
Top = 254
Width = 83
Alignment = taRightJustify
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Right = 8
BorderSpacing.Bottom = 4
Font.Style = [fsBold]
ParentFont = False
ReadOnly = True
TabOrder = 7
Text = 'NDownEdit'
end
object NRunsEdit: TEdit
AnchorSideLeft.Control = StdDevEdit
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = StatEdit
Left = 285
Height = 23
Top = 281
Width = 83
Alignment = taRightJustify
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Right = 8
BorderSpacing.Bottom = 4
Font.Style = [fsBold]
ParentFont = False
ReadOnly = True
TabOrder = 8
Text = 'NRunsEdit'
end
object StatEdit: TEdit
AnchorSideLeft.Control = StdDevEdit
AnchorSideRight.Control = StdDevEdit
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ProbEdit
Left = 285
Height = 23
Top = 308
Width = 83
Alignment = taRightJustify
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Bottom = 4
Font.Style = [fsBold]
ParentFont = False
ReadOnly = True
TabOrder = 9
Text = 'StatEdit'
end
object ProbEdit: TEdit
AnchorSideLeft.Control = StdDevEdit
AnchorSideRight.Control = StdDevEdit
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ConclusionEdit
Left = 285
Height = 23
Top = 335
Width = 83
Alignment = taRightJustify
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Bottom = 8
Font.Style = [fsBold]
ParentFont = False
ReadOnly = True
TabOrder = 10
Text = 'ProbEdit'
end
object ConclusionEdit: TEdit
AnchorSideLeft.Control = Label10
AnchorSideLeft.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Bevel1
Left = 79
Height = 23
Top = 366
Width = 289
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Right = 8
Font.Style = [fsBold]
ParentFont = False
ReadOnly = True
TabOrder = 11
Text = 'ConclusionEdit'
end
object ResetBtn: TButton
AnchorSideRight.Control = ComputeBtn
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 167
Height = 25
Top = 405
Width = 54
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 12
end
object ComputeBtn: TButton
AnchorSideRight.Control = CloseBtn
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 229
Height = 25
Top = 405
Width = 76
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 13
end
object CloseBtn: TButton
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 313
Height = 25
Top = 405
Width = 55
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Close'
ModalResult = 11
TabOrder = 14
end
object Bevel1: TBevel
AnchorSideLeft.Control = Owner
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = CloseBtn
Left = 0
Height = 8
Top = 389
Width = 376
Anchors = [akLeft, akRight, akBottom]
Shape = bsBottomLine
end
object Bevel2: TBevel
Left = 3 Left = 3
Height = 21 Height = 21
Top = 414 Top = 414
Width = 15 Width = 15
Shape = bsSpacer Shape = bsSpacer
end end
object Memo1: TLabel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 8
Height = 30
Top = 8
Width = 360
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
Caption = 'This is a test for the randomness of a series of values in a variable. Select the variable to analyze and click the Compute button.'
ParentColor = False
WordWrap = True
end
end end

View File

@ -7,95 +7,70 @@ unit RunsTestUnit;
interface interface
uses uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, Buttons, ExtCtrls, StdCtrls, Buttons, ExtCtrls,
MainUnit, Globals, DataProcs; MainUnit, Globals, BasicStatsReportFormUnit;
type type
{ TRunstestform } { TRunsTestForm }
Trunstestform = class(TForm) TRunsTestForm = class(TBasicStatsReportForm)
Bevel1: TBevel; Bevel1: TBevel;
Bevel2: TBevel; Bevel2: TBevel;
ComputeBtn: TButton;
MeanEdit: TEdit;
Memo1: TLabel;
ResetBtn: TButton;
CloseBtn: TButton;
StdDevEdit: TEdit;
NUpEdit: TEdit;
NDownEdit: TEdit;
NRunsEdit: TEdit;
StatEdit: TEdit;
ProbEdit: TEdit;
ConclusionEdit: TEdit;
InBtn: TBitBtn; InBtn: TBitBtn;
OutBtn: TBitBtn; OutBtn: TBitBtn;
Label10: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
TestVarEdit: TEdit; TestVarEdit: TEdit;
Label1: TLabel; Label1: TLabel;
Label2: TLabel; Label2: TLabel;
VarList: TListBox; VarList: TListBox;
procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure InBtnClick(Sender: TObject); procedure InBtnClick(Sender: TObject);
procedure OutBtnClick(Sender: TObject); procedure OutBtnClick(Sender: TObject);
procedure ResetBtnClick(Sender: TObject); procedure VarListDblClick(Sender: TObject);
procedure VarListSelectionChange(Sender: TObject; User: boolean); procedure VarListSelectionChange(Sender: TObject; {%H-}User: boolean);
private private
{ private declarations }
FAutoSized: Boolean; protected
procedure UpdateBtnStates; procedure AdjustConstraints; override;
procedure Compute; override;
procedure UpdateBtnStates; override;
public public
{ public declarations } { public declarations }
procedure Reset; override;
end; end;
var var
runstestform: Trunstestform; RunsTestForm: TRunsTestForm;
implementation implementation
{$R *.lfm}
uses uses
Math, Utils; Math,
Utils, GridProcs, MatrixUnit;
{ Trunstestform }
procedure Trunstestform.ResetBtnClick(Sender: TObject); { TRunsTestForm }
var
i: integer; procedure TRunsTestForm.AdjustConstraints;
begin begin
VarList.Clear; inherited;
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); ParamsPanel.Constraints.MinWidth := 4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left;
TestVarEdit.Text := ''; ParamsPanel.Constraints.MinHeight := OutBtn.Top + OutBtn.Height +
MeanEdit.Text := ''; ButtonBevel.Height + CloseBtn.BorderSpacing.Top + CloseBtn.Height;
StdDevEdit.Text := '';
NUpEdit.Text := '';
NDownEdit.Text := '';
StatEdit.Text := '';
ProbEdit.Text := '';
ConclusionEdit.Text := '';
NRunsEdit.Text := '';
UpdateBtnStates;
end; end;
procedure Trunstestform.ComputeBtnClick(Sender: TObject);
procedure TRunsTestForm.Compute;
var var
a, i, col, N, N1, N2, NLess, Nmore, R: integer; a, i, col, N, N1, N2, NLess, Nmore, R: integer;
Mean, ExpMean, SD1, SD2, SD3, SD4, SD, z1, z2, z, t, p1, p: double; mean, expMean, SD1, SD2, SD3, SD4, SD, z1, z2, z, t, p1, p: double;
strvalue: string; values: DblDyneVec = nil;
values: DblDyneVec; lReport: TStrings;
begin begin
col := 0;
N := 0; N := 0;
N1 := 0; N1 := 0;
N2 := 0; N2 := 0;
@ -103,35 +78,25 @@ begin
Nmore := 0; Nmore := 0;
R := 1; R := 1;
Mean := 0.0; Mean := 0.0;
for i := 1 to NoVariables do
col := GetVariableIndex(OS3MainFrm.DataGrid, TestVarEdit.Text);
if col = -1 then
begin begin
strvalue := Trim(OS3MainFrm.DataGrid.Cells[i,0]); ErrorMsg('No variable was selected.');
if TestVarEdit.Text = strvalue then col := i;
end;
if col = 0 then
begin
MessageDlg('No variable was selected.', mtError, [mbOK], 0);
exit; exit;
end; end;
SetLength(Values, NoCases); values := CollectVecValues(OS3MainFrm.DataGrid, col);
for i := 1 to NoCases do N := Length(Values);
begin
if not ValidValue(i, col) then continue;
Values[i-1] := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[col,i]));
N := N + 1;
end;
if N <= 10 then if N <= 10 then
begin begin
MessageDlg('Insufficient data. You must have at least 11 values.', mtError, [mbOK], 0); ErrorMsg('Insufficient data. You must have at least 11 values.');
Values := nil; Values := nil;
exit; exit;
end; end;
for i := 0 to N-1 do mean := VecMean(values);
Mean := Mean + values[i];
Mean := Mean / N;
// run through each value and compare with the mean // run through each value and compare with the mean
for i := 0 to N-1 do for i := 0 to N-1 do
@ -145,12 +110,12 @@ begin
while a > 0 do while a > 0 do
begin begin
a := a - 1; a := a - 1;
if Values[a] <> Mean then break; if values[a] <> mean then break;
end; end;
if Values[a] < Mean then if values[a] < mean then
begin begin
R := R + 1; R := R + 1;
NLess := NLess + 1; nLess := nLess + 1;
end; end;
end end
else // check to see if it is less than the mean else // check to see if it is less than the mean
@ -161,19 +126,19 @@ begin
while a > 0 do while a > 0 do
begin begin
a := a - 1; a := a - 1;
if Values[a] <> Mean then break; if values[a] <> mean then break;
end; end;
if Values[a] > Mean then if values[a] > mean then
begin begin
R := R + 1; R := R + 1;
Nmore := Nmore + 1; nMore := nMore + 1;
end; end;
end; // close of else i end;
end; // end of if values[i] not equal to the mean end;
end; // end of i loop end;
// compute the expected mean and variance of R // Compute the expected mean and variance of R
ExpMean := 1.0 + ((2 * N1 * N2) / (N1 + N2)); // mean mu expMean := 1.0 + ((2 * N1 * N2) / (N1 + N2)); // mean mu
SD1 := 2 * N1 * N2 * (2 * N1 * N2 - N1 - N2); SD1 := 2 * N1 * N2 * (2 * N1 * N2 - N1 - N2);
SD2 := power((N1 + N2), 2); SD2 := power((N1 + N2), 2);
SD3 := N1 + N2 - 1; SD3 := N1 + N2 - 1;
@ -181,7 +146,7 @@ begin
SD := sqrt(SD4); SD := sqrt(SD4);
// calculating P Value // calculating P Value
z1 := (R - ExpMean) / SD; z1 := (R - expMean) / SD;
z2 := abs(z1); z2 := abs(z1);
z := z2; z := z2;
if z > 0 then if z > 0 then
@ -195,58 +160,47 @@ begin
); );
p := 1.0 - p1 / 2.0; p := 1.0 - p1 / 2.0;
if z > 0.0 then if z > 0.0 then
t := 1.0 - p p := 1.0 - p
else else
t := 1.0 - (1.0 - p); // this is P value p := 1.0 - (1.0 - p);
// show results // show results
MeanEdit.Text := Format('%.3f', [Mean]); lReport := TStringList.Create;
StdDevEdit.Text := Format('%.3f', [SD]); try
NUpEdit.Text := IntToStr(N1); lReport.Add('RUNS TEST FOR RANDOMNESS');
NDownEdit.Text := IntToStr(N2); lReport.Add('');
NRunsEdit.Text := IntToStr(R); lReport.Add('Variable: %22s', [TestVarEdit.Text]);
StatEdit.Text := Format('%.3f', [z]); lReport.Add('');
ProbEdit.Text := Format('%.3f', [z]); lReport.Add('Mean: %12.3f', [mean]);
lReport.Add('Standard deviation: %12.3f', [SD]);
lReport.Add('N values > mean: %12d', [N1]);
lReport.Add('N values < mean: %12d', [N2]);
lReport.Add('Number of runs: %12d', [R]);
lReport.Add('Test statistic: %12.3f', [z]);
lReport.Add('Probability: %12.3f', [p]);
lReport.Add('');
lReport.Add('Conclusion:');
// determine the conclusion // determine the conclusion
if t < 0.01 then if p < 0.01 then
ConclusionEdit.Text := 'Very strong evidence against randomness (trend or seasonality' lReport.Add('Very strong evidence against randomness (trend or seasonality')
else if (t < 0.05) and (t >= 0.01) then else if (p < 0.05) and (p >= 0.01) then
ConclusionEdit.Text := 'Moderate evidence against randomness' lReport.Add('Moderate evidence against randomness')
else if (t < 0.10) and (t >= 0.05) then else if (p < 0.10) and (p >= 0.05) then
ConclusionEdit.Text := 'Suggestive evidence against normality' lReport.Add('Suggestive evidence against normality')
else if t >= 0.10 then else if p >= 0.10 then
ConclusionEdit.Text := 'Little or no real evidence against randomness' lReport.Add('Little or no real evidence against randomness')
else else
ConclusionEdit.Text := 'Strong evidence against randomness (trend or seasonality exists)'; lReport.Add('Strong evidence against randomness (trend or seasonality exists)');;
Values := nil; FReportFrame.DisplayReport(lReport);
finally
lReport.Free;
end;
end; end;
procedure Trunstestform.FormActivate(Sender: TObject);
var
w: Integer;
begin
if FAutoSized then
exit;
w := MaxValue([ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]); procedure TRunsTestForm.InBtnClick(Sender: TObject);
ResetBtn.Constraints.MinWidth := w;
ComputeBtn.Constraints.MinWidth := w;
CloseBtn.Constraints.MinWidth := w;
Constraints.MinWidth := Width;
Constraints.MinHeight := Height;
FAutoSized := true;
end;
procedure Trunstestform.FormCreate(Sender: TObject);
begin
Assert(OS3Mainfrm <> nil);
end;
procedure Trunstestform.InBtnClick(Sender: TObject);
var var
index: integer; index: integer;
begin begin
@ -259,7 +213,8 @@ begin
end; end;
end; end;
procedure Trunstestform.OutBtnClick(Sender: TObject);
procedure TRunsTestForm.OutBtnClick(Sender: TObject);
begin begin
if TestVarEdit.Text <> '' then if TestVarEdit.Text <> '' then
begin begin
@ -269,19 +224,48 @@ begin
end; end;
end; end;
procedure TRunsTestForm.Reset;
var
i: integer;
begin
inherited;
TestVarEdit.Clear;
VarList.Clear;
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
UpdateBtnStates;
end;
procedure TRunsTestForm.UpdateBtnStates; procedure TRunsTestForm.UpdateBtnStates;
begin begin
inherited;
InBtn.Enabled := AnySelected(VarList) and (TestVarEdit.Text = ''); InBtn.Enabled := AnySelected(VarList) and (TestVarEdit.Text = '');
OutBtn.Enabled := TestVarEdit.Text <> ''; OutBtn.Enabled := TestVarEdit.Text <> '';
end; end;
procedure Trunstestform.VarListSelectionChange(Sender: TObject; User: boolean);
procedure TRunsTestForm.VarListDblClick(Sender: TObject);
var
index: Integer;
begin
index := VarList.ItemIndex;
if (index > -1) then begin
if (TestVarEdit.Text <> '') then
VarList.Items.Add(TestVarEdit.Text);
TestVarEdit.Text := VarList.Items[index];
VarList.Items.Delete(index);
UpdateBtnStates;
end;
end;
procedure TRunsTestForm.VarListSelectionChange(Sender: TObject; User: boolean);
begin begin
UpdateBtnStates; UpdateBtnStates;
end; end;
initialization
{$I runstestunit.lrs}
end. end.