diff --git a/applications/lazstats/source/LazStats.lpi b/applications/lazstats/source/LazStats.lpi index e2ff2ca40..3e6beb8b6 100644 --- a/applications/lazstats/source/LazStats.lpi +++ b/applications/lazstats/source/LazStats.lpi @@ -1,13 +1,11 @@ - + - - - + @@ -94,6 +92,7 @@ + @@ -298,12 +297,12 @@ - + - + - + diff --git a/applications/lazstats/source/LazStats.res b/applications/lazstats/source/LazStats.res index 608538ce6..73ed432af 100644 Binary files a/applications/lazstats/source/LazStats.res and b/applications/lazstats/source/LazStats.res differ diff --git a/applications/lazstats/source/forms/analysis/one_sample_tests/onesampleunit.lfm b/applications/lazstats/source/forms/analysis/one_sample_tests/onesampleunit.lfm new file mode 100644 index 000000000..afc310f3e --- /dev/null +++ b/applications/lazstats/source/forms/analysis/one_sample_tests/onesampleunit.lfm @@ -0,0 +1,211 @@ +inherited OneSampleForm: TOneSampleForm + Left = 1258 + Height = 338 + Top = 230 + Width = 533 + BorderStyle = bsSingle + Caption = 'One Sample Tests' + ClientHeight = 338 + ClientWidth = 533 + inherited ParamsPanel: TPanel + Height = 322 + ClientHeight = 322 + inherited CloseBtn: TButton + Top = 297 + end + inherited ComputeBtn: TButton + Top = 297 + end + inherited ResetBtn: TButton + Top = 297 + end + inherited HelpBtn: TButton + Top = 297 + end + inherited ButtonBevel: TBevel + Top = 281 + end + object StatsGroup: TRadioGroup[5] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = ParamsPanel + AnchorSideBottom.Side = asrBottom + Left = 71 + Height = 114 + Top = 0 + Width = 149 + AutoFill = True + AutoSize = True + BorderSpacing.Left = 8 + Caption = 'Statistic of Interest' + ChildSizing.LeftRightSpacing = 12 + ChildSizing.TopBottomSpacing = 6 + ChildSizing.VerticalSpacing = 2 + ChildSizing.EnlargeHorizontal = crsHomogenousChildResize + ChildSizing.EnlargeVertical = crsHomogenousChildResize + ChildSizing.ShrinkHorizontal = crsScaleChilds + ChildSizing.ShrinkVertical = crsScaleChilds + ChildSizing.Layout = cclLeftToRightThenTopToBottom + ChildSizing.ControlsPerLine = 1 + ClientHeight = 94 + ClientWidth = 145 + ItemIndex = 0 + Items.Strings = ( + 'Sample Mean' + 'Sample Proportion' + 'Sample Correlation' + 'Sample Variance' + ) + OnClick = StatsGroupClick + TabOrder = 4 + end + object StatisticLabel: TLabel[6] + AnchorSideTop.Control = StatisticEdit + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = StdDevLabel + AnchorSideRight.Side = asrBottom + Left = 93 + Height = 15 + Top = 142 + Width = 99 + Anchors = [akTop, akRight] + Caption = 'Sample Proportion' + ParentColor = False + end + object ParameterLabel: TLabel[7] + AnchorSideTop.Control = ParameterEdit + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = StdDevLabel + AnchorSideRight.Side = asrBottom + Left = 74 + Height = 15 + Top = 169 + Width = 118 + Anchors = [akTop, akRight] + Caption = 'Population Parameter:' + ParentColor = False + end + object SizeLabel: TLabel[8] + AnchorSideTop.Control = SizeEdit + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = StdDevLabel + AnchorSideRight.Side = asrBottom + Left = 127 + Height = 15 + Top = 196 + Width = 65 + Anchors = [akTop, akRight] + Caption = 'Sample Size:' + ParentColor = False + end + object Label4: TLabel[9] + AnchorSideTop.Control = CIntervalEdit + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = StdDevLabel + AnchorSideRight.Side = asrBottom + Left = 80 + Height = 15 + Top = 250 + Width = 112 + Anchors = [akTop, akRight] + Caption = 'Confidence Level (%)' + ParentColor = False + end + object StdDevLabel: TLabel[10] + AnchorSideTop.Control = StdDevEdit + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = StdDevEdit + Left = 47 + Height = 15 + Top = 223 + Width = 145 + Anchors = [akTop, akRight] + BorderSpacing.Right = 8 + Caption = 'Sample Standard Deviation:' + ParentColor = False + end + object StatisticEdit: TEdit[11] + AnchorSideLeft.Control = StdDevEdit + AnchorSideTop.Control = StatsGroup + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = StdDevEdit + AnchorSideRight.Side = asrBottom + Left = 200 + Height = 23 + Top = 138 + Width = 91 + Alignment = taRightJustify + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Top = 24 + TabOrder = 5 + Text = 'StatisticEdit' + end + object StdDevEdit: TEdit[12] + AnchorSideTop.Control = SizeEdit + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + Left = 200 + Height = 23 + Top = 219 + Width = 91 + Alignment = taRightJustify + Anchors = [akTop, akRight] + BorderSpacing.Left = 8 + BorderSpacing.Top = 4 + TabOrder = 6 + Text = 'StdDevEdit' + end + object ParameterEdit: TEdit[13] + AnchorSideLeft.Control = StdDevEdit + AnchorSideTop.Control = StatisticEdit + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + Left = 200 + Height = 23 + Top = 165 + Width = 91 + Alignment = taRightJustify + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Top = 4 + TabOrder = 7 + Text = 'ParameterEdit' + end + object SizeEdit: TEdit[14] + AnchorSideLeft.Control = StdDevEdit + AnchorSideTop.Control = ParameterEdit + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + Left = 200 + Height = 23 + Top = 192 + Width = 91 + Alignment = taRightJustify + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Top = 4 + TabOrder = 8 + Text = 'SizeEdit' + end + object CIntervalEdit: TEdit[15] + AnchorSideLeft.Control = StdDevEdit + AnchorSideTop.Control = StdDevEdit + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = StdDevEdit + AnchorSideRight.Side = asrBottom + Left = 200 + Height = 23 + Top = 246 + Width = 91 + Alignment = taRightJustify + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Top = 4 + TabOrder = 9 + Text = 'CIntervalEdit' + end + end + inherited ParamsSplitter: TSplitter + Height = 338 + end +end diff --git a/applications/lazstats/source/forms/analysis/one_sample_tests/onesampleunit.pas b/applications/lazstats/source/forms/analysis/one_sample_tests/onesampleunit.pas new file mode 100644 index 000000000..808bf060f --- /dev/null +++ b/applications/lazstats/source/forms/analysis/one_sample_tests/onesampleunit.pas @@ -0,0 +1,316 @@ +unit OneSampleUnit; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, Forms, Controls, Graphics, Dialogs, + ExtCtrls, StdCtrls, BasicStatsReportFormUnit; + +type + + { TOneSampleForm } + + TOneSampleForm = class(TBasicStatsReportForm) + StatisticEdit: TEdit; + ParameterEdit: TEdit; + SizeEdit: TEdit; + CIntervalEdit: TEdit; + StdDevEdit: TEdit; + StatisticLabel: TLabel; + ParameterLabel: TLabel; + SizeLabel: TLabel; + Label4: TLabel; + StdDevLabel: TLabel; + StatsGroup: TRadioGroup; + procedure StatsGroupClick(Sender: TObject); + + private + + protected + procedure AdjustConstraints; override; + procedure Compute; override; + function Validate(out AMsg: String; out AControl: TWinControl): Boolean; override; + + public + constructor Create(AOwner: TComponent); override; + procedure Reset; override; + + end; + +var + OneSampleForm: TOneSampleForm; + +implementation + +{$R *.lfm} + +uses + Math, + Globals, FunctionsLib, MathUnit; + + +{ TOneSampleForm } + +constructor TOneSampleForm.Create(AOwner: TComponent); +begin + inherited; + CIntervalEdit.Text := FormatFloat('0', DEFAULT_CONFIDENCE_LEVEL_PERCENT); +end; + + +procedure TOneSampleForm.AdjustConstraints; +begin + inherited; + + ParamsPanel.Constraints.MinWidth := Max( + 4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left, + StdDevLabel.Width + StdDevEdit.BorderSpacing.Left + StdDevEdit.Width + ); + ParamsPanel.Constraints.MinHeight := CIntervalEdit.Top + CIntervalEdit.Height + + ButtonBevel.Height + CloseBtn.BorderSpacing.Top + CloseBtn.Height; +end; + + +procedure TOneSampleForm.Compute; +var + N: integer; + sampleValue, popValue, stdErr, sampleSD, probability, UCL, LCL: Double; + sampleTrans, popTrans: Double; + confidence, alpha, df: double; + z, zReject, zConf, t, testT: double; + chiSqrVal, lowChi, hiChi, testChi: double; + lReport: TStrings; +begin + lReport := TStringList.Create; + try + lReport.Add('ANALYSIS OF A ' + UpperCase(StatsGroup.Items[StatsGroup.ItemIndex])); + lReport.Add(''); + N := round(StrToFloat(SizeEdit.Text)); + confidence := StrToFloat(CIntervalEdit.Text) / 100.0; + case StatsGroup.ItemIndex of + 0 : begin // Means + sampleValue := StrToFloat(StatisticEdit.Text); + popValue := StrToFloat(ParameterEdit.Text); + sampleSD := StrToFloat(StdDevEdit.Text); + DF := N; + stdErr := sampleSD / sqrt(DF); + DF := N-1; + t := (sampleValue - popValue) / stdErr; + probability := ProbT(t, DF); + alpha := (1.0 - confidence) / 2.0; + testT := InverseT(1.0 - alpha, DF); + UCL := sampleValue + testT * stdErr; + LCL := sampleValue - testT * stdErr; + lReport.Add('Sample Mean: %9.3f', [sampleValue]); + lReport.Add('Population Mean: %9.3f', [popValue]); + lReport.Add('Sample Size: %9d', [N]); + lReport.Add('Standard error of Mean: %9.3f', [stdErr]); + lReport.Add('t test statistic: %9.3f', [t]); + lReport.Add(' with probability: %9.3f', [probability]); + lReport.Add('t value required for rejection: %9.3f', [testT]); + lReport.Add('Confidence Interval: %9.3f ... %.3f', [LCL, UCL]); + end; + 1 : begin // Proportions + sampleValue := StrToFloat(StatisticEdit.Text); + popValue := StrToFloat(ParameterEdit.Text); + stdErr := sqrt((sampleValue * (1.0 - sampleValue)) / N); + z := (sampleValue - popValue) / stdErr; + probability := 1.0 - ProbZ(z); + zReject := InverseZ(confidence); + zConf := abs(InverseZ((1.0 - confidence) / 2.0)); + UCL := sampleValue + (zconf * stdErr); + LCL := sampleValue - (zconf * stdErr); + lReport.Add('Sample Proportion: %9.3f', [sampleValue]); + lReport.Add('Population Proportion: %9.3f', [popValue]); + lReport.Add('Sample Size: %9d', [N]); + lReport.Add('Standard error of proportion: %9.3f', [stdErr]); + lReport.Add('z test statistic: %9.3f', [z]); + lReport.Add(' with probability > P: %9.3f', [probability]); + lReport.Add('z value required for rejection: %9.3f', [zReject]); + lReport.Add('Confidence Interval: %9.3f ... %.3f', [LCL, UCL]); + end; + 2 : begin // Correlation + sampleValue := StrToFloat(StatisticEdit.Text); + popValue := StrToFloat(ParameterEdit.Text); + zConf := abs(InverseZ((1.0 - confidence) / 2.0)); + sampleTrans := ln((1.0 + sampleValue) / (1.0 - sampleValue)) / 2.0; + popTrans := ln((1.0 + popValue) / (1.0 - popValue)) / 2.0; + stdErr := sqrt(1.0 / (N - 3.0)); + z := (sampleTrans - popTrans) / stdErr; + probability := ProbZ(z); + alpha := (1.0 - confidence) / 2.0; + zReject := InverseZ(1.0 - alpha); + UCL := sampleTrans + (zConf * stdErr); + LCL := sampleTrans - (zConf * stdErr); + UCL := (exp(2.0 * UCL) - 1.0) / (exp(2.0 * UCL) + 1.0); + LCL := (exp(2.0 * LCL) - 1.0) / (exp(2.0 * LCL) + 1.0); + lReport.Add('Sample Correlation: %9.3f', [sampleValue]); + lReport.Add('Population Correlation: %9.3f', [popValue]); + lReport.Add('Sample Size: %9d', [N]); + lReport.Add('z Transform of sample correlation: %9.3f', [sampleTrans]); + lReport.Add('z Transform of population correlation: %9.3f', [popTrans]); + lReport.Add('Standard error of transform: %9.3f', [stdErr]); + lReport.Add('z test statistic: %9.3f', [z]); + lReport.Add(' with probability: %9.3f', [probability]); + lReport.Add('z value required for rejection: %9.3f', [zReject]); + lReport.Add('Confidence Interval for sample correlation: %9.3f ... %.3f', [LCL, UCL]); + end; + 3 : begin // Variance + sampleValue := StrToFloat(StatisticEdit.Text); + popValue := StrToFloat(ParameterEdit.Text); + alpha := 1.0 - confidence; + chiSqrVal := ((N - 1.0) * sampleValue) / popValue; + probability := 1.0 - chiSquaredProb(chiSqrVal, N-1); + lowChi := InverseChi((1.0 - alpha / 2.0), N-1); + hiChi := InverseChi((alpha / 2.0), N-1); + LCL := ((N - 1.0) * sampleValue) / lowChi; + UCL := ((N - 1.0) * sampleValue) / hiChi; + if sampleValue > popValue then + testChi := lowChi + else + testChi := hiChi; + lReport.Add('Sample Variance: %9.3f', [sampleValue]); + lReport.Add('Population Variance: %9.3f', [popValue]); + lReport.Add('Sample Size: %9d', [N]); + lReport.Add('Chi-square statistic %9.3f', [chiSqrVal]); + lReport.Add(' with probability > chisquare %9.3f', [probability]); + lReport.Add(' and D.F. %9d', [N-1]); + lReport.Add('Chi-square value required for rejection: %9.3f', [testChi]); + lReport.Add('Chi-square Confidence Interval: %9.3f ... %.3f', [lowChi, hiChi]); + lReport.Add('Variance Confidence Interval: %9.3f ... %.3f', [LCL, UCL]); + end; + end; + FReportFrame.DisplayReport(lReport); + finally + lReport.Free; + end; +end; + + +procedure TOneSampleForm.Reset; +begin + inherited; + StatisticEdit.Clear; + ParameterEdit.Clear; + SizeEdit.Clear; + StdDevEdit.Clear; + StatsGroupClick(nil); +end; + + +procedure TOneSampleForm.StatsGroupClick(Sender: TObject); +var + StatisticName: String; +begin + StatisticName := StatsGroup.Items[StatsGroup.ItemIndex]; + Delete(StatisticName, 1, Length('Sample ')); + StatisticLabel.Caption := 'Sample ' + StatisticName; + ParameterLabel.Caption := 'Population ' + StatisticName; + + StdDevLabel.Enabled := StatsGroup.ItemIndex = 0; + StdDevEdit.Enabled := StatsGroup.ItemIndex = 0; +end; + + +function TOneSampleForm.Validate(out AMsg: String; out AControl: TWinControl): Boolean; +var + x: Double; + n: Integer; + s: String; +begin + Result := false; + + if StatisticEdit.Text = '' then + begin + AMsg := 'Value of sample proportion missing.'; + AControl := StatisticEdit; + exit; + end; + if not TryStrtoFloat(StatisticEdit.Text, x) then + begin + AMsg := 'Sample proportion is not a valid number.'; + AControl := StatisticEdit; + exit; + end; + if (StatsGroup.ItemIndex in [1, 2]) and ((x <= 0) or (x >= 1)) then + begin + AMsg := StatsGroup.Items[StatsGroup.ItemIndex] + ' must be between 0 and 1.'; + AControl := StatisticEdit; + exit; + end; + + if ParameterEdit.Text = '' then + begin + AMsg := 'Value of population parameter is missing.'; + AControl := ParameterEdit; + exit; + end; + if not TryStrToFloat(ParameterEdit.Text, x) then + begin + AMsg := 'Population parameter is not a valid number.'; + AControl := ParameterEdit; + exit; + end; + if (StatsGroup.ItemIndex in [1, 2]) and ((x <= 0) or (x >= 1)) then + begin + s := Lowercase(Copy(StatsGroup.Items[StatsGroup.ItemIndex], Length('Sample ')+1, MaxInt)); + AMsg := 'Population ' + s + ' must be between 0 and 1.'; + AControl := ParameterEdit; + exit; + end; + + if SizeEdit.Text = '' then + begin + AMsg := 'Value of sample size is missing.'; + AControl := SizeEdit; + exit; + end; + if not TryStrToInt(SizeEdit.Text, n) then + begin + AMsg := 'Sample size is not a valid number.'; + AControl := SizeEdit; + exit; + end; + + if StatsGroup.ItemIndex = 0 then + begin + if StdDevEdit.Text = '' then + begin + AMsg := 'Sample standard deviation is not specified.'; + AControl := StdDevEdit; + exit; + end; + if not TryStrToFloat(StdDevEdit.Text, x) then + begin + AMsg := 'Sample standard deviation is not a valid number.'; + AControl := StdDevEdit; + exit; + end; + end; + + if CIntervalEdit.Text = '' then + begin + AMsg := 'Confidence level is not specified.'; + AControl := CIntervalEdit; + exit; + end; + if not TryStrToFloat(CIntervalEdit.Text, x) then + begin + AMsg := 'Confidence level is not a valid number.'; + AControl := CIntervalEdit; + exit; + end; + if (x <= 0) or (x >= 100) then + begin + AMsg := 'Confidence level must be between 0 and 100.'; + AControl := CIntervalEdit; + exit; + end; + + Result := true; +end; + +end. + diff --git a/applications/lazstats/source/forms/analysis/one_sample_tests/onesampunit.lfm b/applications/lazstats/source/forms/analysis/one_sample_tests/onesampunit.lfm deleted file mode 100644 index 90f04f45e..000000000 --- a/applications/lazstats/source/forms/analysis/one_sample_tests/onesampunit.lfm +++ /dev/null @@ -1,271 +0,0 @@ -object OneSampFrm: TOneSampFrm - Left = 490 - Height = 188 - Top = 260 - Width = 430 - AutoSize = True - BorderStyle = bsSingle - Caption = 'One Sample Tests' - ClientHeight = 188 - ClientWidth = 430 - OnActivate = FormActivate - OnCreate = FormCreate - OnShow = FormShow - Position = poMainFormCenter - LCLVersion = '2.1.0.0' - object RadioGroup1: TRadioGroup - AnchorSideLeft.Control = Owner - AnchorSideTop.Control = Owner - AnchorSideBottom.Control = Panel1 - AnchorSideBottom.Side = asrBottom - Left = 8 - Height = 131 - Top = 8 - Width = 149 - Anchors = [akTop, akLeft, akBottom] - AutoFill = True - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - Caption = 'Statistic of Interest' - ChildSizing.LeftRightSpacing = 12 - ChildSizing.TopBottomSpacing = 6 - ChildSizing.EnlargeHorizontal = crsHomogenousChildResize - ChildSizing.EnlargeVertical = crsHomogenousChildResize - ChildSizing.ShrinkHorizontal = crsScaleChilds - ChildSizing.ShrinkVertical = crsScaleChilds - ChildSizing.Layout = cclLeftToRightThenTopToBottom - ChildSizing.ControlsPerLine = 1 - ClientHeight = 111 - ClientWidth = 145 - ItemIndex = 0 - Items.Strings = ( - 'Sample Mean' - 'Sample Proportion' - 'Sample Correlation' - 'Sample Variance' - ) - OnClick = RadioGroup1Click - TabOrder = 0 - end - object Panel1: TPanel - AnchorSideLeft.Control = RadioGroup1 - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = Owner - Left = 181 - Height = 131 - Top = 8 - Width = 236 - AutoSize = True - BorderSpacing.Left = 24 - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BevelOuter = bvNone - ClientHeight = 131 - ClientWidth = 236 - TabOrder = 1 - object Label1: TLabel - AnchorSideLeft.Control = Panel1 - AnchorSideTop.Control = Statistic - AnchorSideTop.Side = asrCenter - Left = 0 - Height = 15 - Top = 4 - Width = 99 - Caption = 'Sample Proportion' - ParentColor = False - end - object Label2: TLabel - AnchorSideLeft.Control = Panel1 - AnchorSideTop.Control = Parameter - AnchorSideTop.Side = asrCenter - Left = 0 - Height = 15 - Top = 31 - Width = 118 - Caption = 'Population Parameter:' - ParentColor = False - end - object Label3: TLabel - AnchorSideLeft.Control = Panel1 - AnchorSideTop.Control = Size - AnchorSideTop.Side = asrCenter - Left = 0 - Height = 15 - Top = 58 - Width = 65 - Caption = 'Sample Size:' - ParentColor = False - end - object Label4: TLabel - AnchorSideLeft.Control = Panel1 - AnchorSideTop.Control = CInterval - AnchorSideTop.Side = asrCenter - Left = 0 - Height = 15 - Top = 112 - Width = 112 - Caption = 'Confidence Level (%)' - ParentColor = False - end - object Label5: TLabel - AnchorSideLeft.Control = Panel1 - AnchorSideTop.Control = StdDev - AnchorSideTop.Side = asrCenter - Left = 0 - Height = 15 - Top = 85 - Width = 145 - Caption = 'Sample Standard Deviation:' - ParentColor = False - end - object Statistic: TEdit - AnchorSideLeft.Control = StdDev - AnchorSideTop.Control = Panel1 - AnchorSideRight.Control = StdDev - AnchorSideRight.Side = asrBottom - Left = 153 - Height = 23 - Top = 0 - Width = 83 - Alignment = taRightJustify - Anchors = [akTop, akLeft, akRight] - TabOrder = 0 - Text = 'Statistic' - end - object StdDev: TEdit - AnchorSideLeft.Control = Label5 - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = Size - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = Panel1 - AnchorSideRight.Side = asrBottom - Left = 153 - Height = 23 - Top = 81 - Width = 83 - Alignment = taRightJustify - BorderSpacing.Left = 8 - BorderSpacing.Top = 4 - TabOrder = 3 - Text = 'Edit1' - end - object Parameter: TEdit - AnchorSideLeft.Control = StdDev - AnchorSideTop.Control = Statistic - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = StdDev - AnchorSideRight.Side = asrBottom - Left = 153 - Height = 23 - Top = 27 - Width = 83 - Alignment = taRightJustify - Anchors = [akTop, akLeft, akRight] - BorderSpacing.Top = 4 - TabOrder = 1 - Text = 'Edit1' - end - object Size: TEdit - AnchorSideLeft.Control = StdDev - AnchorSideTop.Control = Parameter - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = StdDev - AnchorSideRight.Side = asrBottom - Left = 153 - Height = 23 - Top = 54 - Width = 83 - Alignment = taRightJustify - Anchors = [akTop, akLeft, akRight] - BorderSpacing.Top = 4 - TabOrder = 2 - Text = 'Edit1' - end - object CInterval: TEdit - AnchorSideLeft.Control = StdDev - AnchorSideTop.Control = StdDev - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = StdDev - AnchorSideRight.Side = asrBottom - Left = 153 - Height = 23 - Top = 108 - Width = 83 - Alignment = taRightJustify - Anchors = [akTop, akLeft, akRight] - BorderSpacing.Top = 4 - TabOrder = 4 - Text = 'Edit1' - end - end - object ResetBtn: TButton - AnchorSideTop.Control = Bevel1 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = ComputeBtn - AnchorSideBottom.Side = asrBottom - Left = 221 - Height = 25 - Top = 155 - Width = 54 - Anchors = [akTop, akRight] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Caption = 'Reset' - OnClick = ResetBtnClick - TabOrder = 2 - end - object CloseBtn: TButton - AnchorSideTop.Control = Bevel1 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Side = asrBottom - Left = 367 - Height = 25 - Top = 155 - Width = 55 - Anchors = [akTop, akRight] - AutoSize = True - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Caption = 'Close' - ModalResult = 11 - TabOrder = 4 - end - object ComputeBtn: TButton - AnchorSideTop.Control = Bevel1 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = CloseBtn - AnchorSideBottom.Side = asrBottom - Left = 283 - Height = 25 - Top = 155 - Width = 76 - Anchors = [akTop, akRight] - AutoSize = True - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Caption = 'Compute' - OnClick = ComputeBtnClick - TabOrder = 3 - end - object Bevel1: TBevel - AnchorSideLeft.Control = Owner - AnchorSideTop.Control = Panel1 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - Left = 0 - Height = 8 - Top = 139 - Width = 430 - Anchors = [akTop, akLeft, akRight] - Shape = bsBottomLine - end -end diff --git a/applications/lazstats/source/forms/analysis/one_sample_tests/onesampunit.pas b/applications/lazstats/source/forms/analysis/one_sample_tests/onesampunit.pas deleted file mode 100644 index 0e82c89ae..000000000 --- a/applications/lazstats/source/forms/analysis/one_sample_tests/onesampunit.pas +++ /dev/null @@ -1,313 +0,0 @@ -unit OneSampUnit; - -{$mode objfpc}{$H+} - -interface - -uses - Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, - ExtCtrls, StdCtrls; - -type - - { TOneSampFrm } - - TOneSampFrm = class(TForm) - Bevel1: TBevel; - ComputeBtn: TButton; - ResetBtn: TButton; - CloseBtn: TButton; - Statistic: TEdit; - Parameter: TEdit; - Size: TEdit; - CInterval: TEdit; - StdDev: TEdit; - Label1: TLabel; - Label2: TLabel; - Label3: TLabel; - Label4: TLabel; - Label5: TLabel; - Panel1: TPanel; - RadioGroup1: TRadioGroup; - procedure ComputeBtnClick(Sender: TObject); - procedure FormActivate(Sender: TObject); - procedure FormCreate(Sender: TObject); - procedure FormShow(Sender: TObject); - procedure RadioGroup1Click(Sender: TObject); - procedure ResetBtnClick(Sender: TObject); - private - { private declarations } - function Validate(out AMsg: String; out AControl: TWinControl): Boolean; - public - { public declarations } - end; - -var - OneSampFrm: TOneSampFrm; - -implementation - -uses - Math, - Globals, OutputUnit, FunctionsLib, MathUnit; - -{ TOneSampFrm } - -procedure TOneSampFrm.FormActivate(Sender: TObject); -var - w: Integer; -begin - w := MaxValue([ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]); - ResetBtn.Constraints.MinWidth := w; - ComputeBtn.Constraints.MinWidth := w; - CloseBtn.Constraints.MinWidth := w; -end; - -procedure TOneSampFrm.FormCreate(Sender: TObject); -begin - CInterval.Text := FormatFloat('0', DEFAULT_CONFIDENCE_LEVEL_PERCENT); -end; - -procedure TOneSampFrm.ResetBtnClick(Sender: TObject); -begin - Statistic.Text := ''; - Parameter.Text := ''; - Size.Text := ''; - StdDev.Text := ''; -end; - -procedure TOneSampFrm.FormShow(Sender: TObject); -begin - ResetBtnClick(self); -end; - -procedure TOneSampFrm.RadioGroup1Click(Sender: TObject); -begin - Label5.Enabled := RadioGroup1.ItemIndex = 0; - StdDev.Enabled := RadioGroup1.ItemIndex = 0; -{ if RadioGroup1.ItemIndex <> 0 then - begin - Label5.Visible := false; - StdDev.Visible := false; - end - else - begin - Label5.Visible := true; - StdDev.Visible := true; - end; -} -end; - -procedure TOneSampFrm.ComputeBtnClick(Sender: TObject); -var - N : integer; - sampmean, sampprop, sampcor, sampvar, Confidence, alpha, df : double; - popmean, popprop, popcor, popvar, stderr : double; - z, zprobability, zreject, zconf, UCL, LCL, sampsd : double; - t, tprobability, testt : double; - poptrans, samptrans, chisqrval, chiprob, lowchi, hichi, testchi : double; - lReport: TStrings; - msg: String; - C: TWinControl; -begin - if not Validate(msg, C) then - begin - C.SetFocus; - MessageDlg(msg, mtError, [mbOK], 0); - exit; - end; - - lReport := TStringList.Create; - try - N := round(StrToFloat(Size.Text)); - Confidence := StrToFloat(CInterval.Text) / 100.0; - case RadioGroup1.ItemIndex of - 0 : begin - sampmean := StrToFloat(Statistic.Text); - popmean := StrToFloat(Parameter.Text); - sampsd := StrToFloat(StdDev.Text); - df := N; - stderr := sampsd / sqrt(df); - df := N-1; - t := (sampmean - popmean) / stderr; - tprobability := probt(t,df); - alpha := (1.0 - confidence) / 2.0; - testt := inverset((1.0 - alpha),df); - UCL := sampmean + testt * stderr; - LCL := sampmean - testt * stderr; - lReport.Add('ANALYSIS OF A SAMPLE MEAN'); - lReport.Add(''); - lReport.Add('Sample Mean: %9.3f', [sampmean]); - lReport.Add('Population Mean: %9.3f', [popmean]); - lReport.Add('Sample Size: %9d', [N]); - lReport.Add('Standard error of Mean: %9.3f', [stderr]); - lReport.Add('t test statistic: %9.3f', [t]); - lReport.Add(' with probability: %9.3f', [tprobability]); - lReport.Add('t value required for rejection: %9.3f', [testt]); - lReport.Add('Confidence Interval: (%.3f ... %.3f)', [LCL, UCL]); - end; - 1 : begin - sampprop := StrToFloat(Statistic.Text); - popprop := StrToFloat(Parameter.Text); - stderr := sqrt((sampprop * (1.0 - sampprop)) / N); - z := (sampprop - popprop) / StdErr; - zprobability := 1.0 - probz(z); - zreject := inversez(confidence); - zconf := abs(inversez((1.0 - confidence) / 2.0)); - UCL := sampprop + (zconf * stderr); - LCL := sampprop - (zconf * stderr); - lReport.Add('ANALYSIS OF A SAMPLE PROPORTION'); - lReport.Add(''); - lReport.Add('Sample Proportion: %9.3f', [sampprop]); - lReport.Add('Population Proportion: %9.3f', [popprop]); - lReport.Add('Sample Size: %9d', [N]); - lReport.Add('Standard error of proportion: %9.3f', [stderr]); - lReport.Add('z test statistic: %9.3f', [z]); - lReport.Add(' with probability > P: %9.3f', [zprobability]); - lReport.Add('z value required for rejection: %9.3f', [zreject]); - lReport.Add('Confidence Interval: (%.3f ... %.3f)', [LCL, UCL]); - end; - 2 : begin - sampcor := StrToFloat(Statistic.Text); - popcor := StrToFloat(Parameter.Text); - zconf := abs(inversez((1.0 - confidence) / 2.0)); - samptrans := ln((1.0 + sampcor) / (1.0 - sampcor)) / 2.0; - poptrans := ln((1.0 + popcor) / (1.0 - popcor)) / 2.0; - stderr := sqrt(1.0 / (N - 3.0)); - z := (samptrans - poptrans) / stderr; - zprobability := probz(z); - alpha := (1.0 - confidence) / 2.0; - zreject := inversez(1.0 - alpha); - UCL := samptrans + (zconf * stderr); - LCL := samptrans - (zconf * stderr); - UCL := (exp(2.0 * UCL) - 1.0) / (exp(2.0 * UCL) + 1.0); - LCL := (exp(2.0 * LCL) - 1.0) / (exp(2.0 * LCL) + 1.0); - lReport.Add('ANALYSIS OF A SAMPLE CORRELATION'); - lReport.Add(''); - lReport.Add('Sample Correlation: %9.3f', [sampcor]); - lReport.Add('Population Correlation: %9.3f', [popcor]); - lReport.Add('Sample Size: %9d', [N]); - lReport.Add('z Transform of sample correlation: %9.3f', [samptrans]); - lReport.Add('z Transform of population correlation: %9.3f', [poptrans]); - lReport.Add('Standard error of transform: %9.3f', [stderr]); - lReport.Add('z test statistic: %9.3f', [z]); - lReport.Add(' with probability: %9.3f', [zprobability]); - lReport.Add('z value required for rejection: %9.3f', [zreject]); - lReport.Add('Confidence Interval for sample correlation: (%.3f ... %.3f)', [LCL, UCL]); - end; - 3 : begin - sampvar := StrToFloat(Statistic.Text); - popvar := StrToFloat(Parameter.Text); - alpha := 1.0 - confidence; - chisqrval := ((N - 1.0) * sampvar) / Popvar; - chiprob := 1.0 - chisquaredprob(chisqrval,N-1); - lowchi := inversechi((1.0 - alpha / 2.0),N-1); - hichi := inversechi((alpha / 2.0),N-1); - LCL := ((N - 1.0) * sampvar) / lowchi; - UCL := ((N - 1.0) * sampvar) / hichi; - if sampvar > popvar then - testchi := lowchi - else - testchi := hichi; - lReport.Add('ANALYSIS OF A SAMPLE VARIANCE'); - lReport.Add(''); - lReport.Add('Sample Variance: %9.3f', [sampvar]); - lReport.Add('Population Variance: %9.3f', [popvar]); - lReport.Add('Sample Size: %9d', [N]); - lReport.Add('Chi-square statistic %9.3f', [chisqrval]); - lReport.Add(' with probability > chisquare %9.3f', [chiprob]); - lReport.Add(' and D.F. %9d', [N-1]); - lReport.Add('Chi-square value required for rejection: %9.3f', [testchi]); - lReport.Add('Chi-square Confidence Interval: (%.3f ... %.3f)', [lowchi, hichi]); - lReport.Add('Variance Confidence Interval: (%.3f ... %.3f)', [LCL, UCL]); - end; - end; - DisplayReport(lReport); - finally - lReport.Free; - end; -end; - -function TOneSampFrm.Validate(out AMsg: String; out AControl: TWinControl): Boolean; -var - x: Double; - n: Integer; -begin - Result := false; - - if Statistic.Text = '' then - begin - AMsg := 'Value of sample proportion missing.'; - AControl := Statistic; - exit; - end; - if not TryStrtoFloat(Statistic.Text, x) then - begin - AMsg := 'Sample proportion is not a valid number.'; - AControl := Statistic; - exit; - end; - - if Parameter.Text = '' then - begin - AMsg := 'Value of population parameter is missing.'; - AControl := Parameter; - exit; - end; - if not TryStrToFloat(Parameter.Text, x) then - begin - AMsg := 'Population parameter is not a valid number.'; - AControl := Parameter; - exit; - end; - - if Size.Text = '' then - begin - AMsg := 'Value of sample size is missing.'; - AControl := Size; - exit; - end; - if not TryStrToInt(Size.Text, n) then - begin - AMsg := 'Sample size is not a valid number.'; - AControl := Size; - exit; - end; - - if RadioGroup1.ItemIndex = 0 then - begin - if StdDev.Text = '' then - begin - AMsg := 'Sample standard deviation is not specified.'; - AControl := StdDev; - exit; - end; - if not TryStrToFloat(StdDev.Text, x) then - begin - AMsg := 'Sample standard deviation is not a valid number.'; - AControl := StdDev; - exit; - end; - end; - - if CInterval.Text = '' then - begin - AMsg := 'Confidence level is not specified.'; - AControl := CInterval; - exit; - end; - if not TryStrToFloat(CInterval.Text, x) then - begin - AMsg := 'Confidence level is not a valid number.'; - AControl := CInterval; - exit; - end; - - Result := true; -end; - -initialization - {$I onesampunit.lrs} - -end. - diff --git a/applications/lazstats/source/forms/mainunit.lfm b/applications/lazstats/source/forms/mainunit.lfm index 8f1684b68..ed7347c7d 100644 --- a/applications/lazstats/source/forms/mainunit.lfm +++ b/applications/lazstats/source/forms/mainunit.lfm @@ -19,7 +19,7 @@ object OS3MainFrm: TOS3MainFrm OnCreate = FormCreate OnDestroy = FormDestroy OnShow = FormShow - LCLVersion = '2.1.0.0' + LCLVersion = '2.0.10.0' object PanelTop: TPanel Left = 0 Height = 35 diff --git a/applications/lazstats/source/forms/mainunit.pas b/applications/lazstats/source/forms/mainunit.pas index 9ab4f10bc..9e6f45a81 100644 --- a/applications/lazstats/source/forms/mainunit.pas +++ b/applications/lazstats/source/forms/mainunit.pas @@ -566,7 +566,7 @@ uses Utils, BasicStatsFormUnit, OptionsUnit, OutputUnit, LicenseUnit, TransFrmUnit, DescriptiveUnit, FreqUnit, CrossTabUnit, BreakDownUnit, BoxPlotUnit, NormalityUnit, Rot3DUnit, - PlotXYUnit, BubblePlotUnit, StemLeafUnit, MultXvsYUnit, OneSampUnit, + PlotXYUnit, BubblePlotUnit, StemLeafUnit, MultXvsYUnit, OneSampleUnit, TwoCorrsUnit, TwoPropUnit, TtestUnit, BlkAnovaUnit, WithinANOVAUnit, AxSAnovaUnit, ABRAnovaUnit, ANCOVAUNIT, LatinSqrsUnit, RMatUnit, PartialsUnit, AutoCorUnit, CanonUnit, GLMUnit, StepFwdMRUnit, BlkMRegUnit, BackRegUnit, @@ -902,9 +902,9 @@ end; // Menu "Analysis" > "One sample tests" procedure TOS3MainFrm.mnuAnalysisOneSampleTestsClick(Sender: TObject); begin - if OneSampFrm = nil then - Application.CreateForm(TOneSampFrm, OneSampFrm); - OneSampFrm.ShowModal; + if OneSampleForm = nil then + Application.CreateForm(TOneSampleForm, OneSampleForm); + OneSampleForm.Show; end;