From 3c8055a908a2e92450cf3118d6cfef8bfd02d074 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sun, 15 Nov 2020 23:31:39 +0000 Subject: [PATCH] LazStats: Inherit HierarchUnit from BasicStatsReportAndChartUnit. Use TAChart. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7871 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- applications/lazstats/source/LazStats.lpi | 4 +- .../analysis/correlation/autocorunit.lfm | 22 +- .../analysis/correlation/autocorunit.pas | 68 ++- .../analysis/multivariate/discrimunit.lfm | 8 +- .../analysis/multivariate/discrimunit.pas | 2 +- .../analysis/multivariate/hierarchunit.lfm | 540 +++++++++--------- .../analysis/multivariate/hierarchunit.pas | 446 ++++++++++----- .../lazstats/source/forms/mainunit.lfm | 18 +- .../lazstats/source/forms/mainunit.pas | 38 +- 9 files changed, 627 insertions(+), 519 deletions(-) diff --git a/applications/lazstats/source/LazStats.lpi b/applications/lazstats/source/LazStats.lpi index 9d233ce7d..a22bef228 100644 --- a/applications/lazstats/source/LazStats.lpi +++ b/applications/lazstats/source/LazStats.lpi @@ -453,7 +453,7 @@ - + @@ -581,7 +581,7 @@ - + diff --git a/applications/lazstats/source/forms/analysis/correlation/autocorunit.lfm b/applications/lazstats/source/forms/analysis/correlation/autocorunit.lfm index 18093ab14..c8e66bb7e 100644 --- a/applications/lazstats/source/forms/analysis/correlation/autocorunit.lfm +++ b/applications/lazstats/source/forms/analysis/correlation/autocorunit.lfm @@ -1,4 +1,4 @@ -object AutoCorrFrm: TAutoCorrFrm +object AutoCorrForm: TAutoCorrForm Left = 456 Height = 459 Top = 145 @@ -13,20 +13,20 @@ object AutoCorrFrm: TAutoCorrFrm OnCreate = FormCreate OnShow = FormShow Position = poMainFormCenter - LCLVersion = '2.1.0.0' + LCLVersion = '2.0.10.0' object GroupBox1: TGroupBox AnchorSideLeft.Control = Owner AnchorSideTop.Control = Owner Left = 8 Height = 68 Top = 8 - Width = 137 + Width = 126 AutoSize = True BorderSpacing.Left = 8 BorderSpacing.Top = 8 Caption = 'The series is code in:' ClientHeight = 48 - ClientWidth = 133 + ClientWidth = 122 TabOrder = 0 object ColBtn: TRadioButton AnchorSideLeft.Control = GroupBox1 @@ -34,9 +34,9 @@ object AutoCorrFrm: TAutoCorrFrm Left = 16 Height = 19 Top = 0 - Width = 99 + Width = 94 BorderSpacing.Left = 16 - Caption = 'A Grid Column' + Caption = 'a grid column' Checked = True OnClick = ColBtnClick TabOrder = 0 @@ -49,11 +49,11 @@ object AutoCorrFrm: TAutoCorrFrm Left = 16 Height = 19 Top = 21 - Width = 109 + Width = 73 BorderSpacing.Top = 2 BorderSpacing.Right = 8 BorderSpacing.Bottom = 8 - Caption = 'A row of the grid' + Caption = 'a grid row' OnClick = RowBtnClick TabOrder = 1 end @@ -62,7 +62,7 @@ object AutoCorrFrm: TAutoCorrFrm AnchorSideLeft.Control = GroupBox1 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Owner - Left = 169 + Left = 158 Height = 68 Top = 8 Width = 275 @@ -216,7 +216,7 @@ object AutoCorrFrm: TAutoCorrFrm OnClick = HelpBtnClick TabOrder = 4 end - object Bevel1: TBevel + object ButtonBevel: TBevel AnchorSideLeft.Control = Owner AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom @@ -233,7 +233,7 @@ object AutoCorrFrm: TAutoCorrFrm AnchorSideTop.Control = GroupBox2 AnchorSideTop.Side = asrBottom AnchorSideRight.Control = Panel2 - AnchorSideBottom.Control = Bevel1 + AnchorSideBottom.Control = ButtonBevel Left = 8 Height = 326 Top = 84 diff --git a/applications/lazstats/source/forms/analysis/correlation/autocorunit.pas b/applications/lazstats/source/forms/analysis/correlation/autocorunit.pas index 0aafe501f..99b7cd15a 100644 --- a/applications/lazstats/source/forms/analysis/correlation/autocorunit.pas +++ b/applications/lazstats/source/forms/analysis/correlation/autocorunit.pas @@ -9,19 +9,18 @@ unit AutoCorUnit; interface uses - Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, - StdCtrls, ExtCtrls, Buttons, + Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, Buttons, MainUnit, FunctionsLib, OutputUnit, Globals, GraphLib, DataProcs, MatrixLib, PointsUnit, DifferenceUnit, ContextHelpUnit; type - { TAutoCorrFrm } + { TAutoCorrForm } - TAutoCorrFrm = class(TForm) + TAutoCorrForm = class(TForm) AlphaEdit: TEdit; - Bevel1: TBevel; + ButtonBevel: TBevel; Bevel2: TBevel; HelpBtn: TButton; Panel1: TPanel; @@ -107,17 +106,19 @@ type end; var - AutoCorrFrm: TAutoCorrFrm; + AutoCorrForm: TAutoCorrForm; implementation +{$R *.lfm} + uses Math, MathUnit, MoveAvgUnit, AutoPlotUnit, PolynomialUnit, ExpSmoothUnit, FFTUnit; -{ TAutoCorrFrm } +{ TAutoCorrForm } -procedure TAutoCorrFrm.ResetBtnClick(Sender: TObject); +procedure TAutoCorrForm.ResetBtnClick(Sender: TObject); var i: integer; begin @@ -159,12 +160,12 @@ begin UpdateBtnStates; end; -procedure TAutoCorrFrm.CloseBtnClick(Sender: TObject); +procedure TAutoCorrForm.CloseBtnClick(Sender: TObject); begin Close; end; -procedure TAutoCorrFrm.RowBtnClick(Sender: TObject); +procedure TAutoCorrForm.RowBtnClick(Sender: TObject); var i: integer; begin @@ -176,7 +177,7 @@ begin OnlyCasesBtn.Caption := 'Only Columns From:'; end; -procedure TAutoCorrFrm.FormActivate(Sender: TObject); +procedure TAutoCorrForm.FormActivate(Sender: TObject); var w: Integer; begin @@ -199,25 +200,25 @@ begin FAutoSized := true; end; -procedure TAutoCorrFrm.FormCreate(Sender: TObject); +procedure TAutoCorrForm.FormCreate(Sender: TObject); begin Assert(OS3MainFrm <> nil); if PointsFrm = nil then Application.CreateForm(TPointsFrm, PointsFrm); end; -procedure TAutoCorrFrm.FormShow(Sender: TObject); +procedure TAutoCorrForm.FormShow(Sender: TObject); begin ResetBtnClick(nil); end; -procedure TAutoCorrFrm.HelpBtnClick(Sender: TObject); +procedure TAutoCorrForm.HelpBtnClick(Sender: TObject); begin if ContextHelpForm = nil then Application.CreateForm(TContextHelpForm, ContextHelpForm); ContextHelpForm.HelpMessage((Sender as TButton).Tag); end; -procedure TAutoCorrFrm.ComputeBtnClick(Sender: TObject); +procedure TAutoCorrForm.ComputeBtnClick(Sender: TObject); var X, Y, count, covzero, mean: double; uplimit, lowlimit, varresid, StdErr, lAlpha: double; @@ -682,7 +683,7 @@ begin end; end; -procedure TAutoCorrFrm.ColBtnClick(Sender: TObject); +procedure TAutoCorrForm.ColBtnClick(Sender: TObject); var i: integer; begin @@ -694,7 +695,7 @@ begin OnlyCasesBtn.Caption := 'Only Cases From:'; end; -procedure TAutoCorrFrm.InBtnClick(Sender: TObject); +procedure TAutoCorrForm.InBtnClick(Sender: TObject); var index: integer; begin @@ -707,7 +708,7 @@ begin end; end; -procedure TAutoCorrFrm.OutBtnClick(Sender: TObject); +procedure TAutoCorrForm.OutBtnClick(Sender: TObject); begin if DepVarEdit.Text <> '' then begin @@ -717,7 +718,7 @@ begin end; end; -procedure TAutoCorrFrm.Four1(var data: DblDyneVec; nn: longword; isign: integer); +procedure TAutoCorrForm.Four1(var data: DblDyneVec; nn: longword; isign: integer); var n, mmax, m, j, istep, i: longword; wtemp, wr, wpr, wpi, wi, theta: double; @@ -780,7 +781,7 @@ begin end; end; -procedure TAutoCorrFrm.RealFt(var data: DblDyneVec; n: longword; isign: integer); +procedure TAutoCorrForm.RealFt(var data: DblDyneVec; n: longword; isign: integer); var i,i1,i2,i3,i4,np3 : integer; // was: longword; c1,c2,h1r,h1i,h2r,h2i : double; @@ -836,7 +837,7 @@ begin end; end; -procedure TAutoCorrFrm.Fourier(var data: DblDyneVec; n, npts: integer); +procedure TAutoCorrForm.Fourier(var data: DblDyneVec; n, npts: integer); var nmin, m, mo2, i, k, j: integer; yn, y1, rn1, fac, cnst: double; @@ -893,7 +894,7 @@ begin y := nil; end; -procedure TAutoCorrFrm.PolyFit(const pts: DblDyneVec; var avg: DblDyneVec; +procedure TAutoCorrForm.PolyFit(const pts: DblDyneVec; var avg: DblDyneVec; NoPts, Order: integer); var X: DblDyneMat; @@ -1012,13 +1013,13 @@ begin X := nil; end; -procedure TAutoCorrFrm.UpdateBtnStates; +procedure TAutoCorrForm.UpdateBtnStates; begin InBtn.Enabled := (VarList.ItemIndex > -1) and (DepVarEdit.Text = ''); OutBtn.Enabled := (DepVarEdit.Text <> ''); end; -procedure TAutoCorrFrm.VarListSelectionChange(Sender: TObject; User: boolean); +procedure TAutoCorrForm.VarListSelectionChange(Sender: TObject; User: boolean); begin UpdateBtnStates; end; @@ -1026,7 +1027,7 @@ end; { Routines called from ComputeBtnClick } -function TAutoCorrFrm.CalcMean(const Pts: DblDyneVec; NoPts: Integer): Double; +function TAutoCorrForm.CalcMean(const Pts: DblDyneVec; NoPts: Integer): Double; var i: Integer; begin @@ -1036,7 +1037,7 @@ begin Result := Result / NoPts; end; -procedure TAutoCorrFrm.ExponentialSmooth(var Pts: DblDyneVec; NoPts: Integer); +procedure TAutoCorrForm.ExponentialSmooth(var Pts: DblDyneVec; NoPts: Integer); var F: TExpSmoothFrm; noProj: Integer; @@ -1117,7 +1118,7 @@ begin end; end; -procedure TAutoCorrFrm.FourierSmooth(var Pts: DblDyneVec; NoPts: Integer); +procedure TAutoCorrForm.FourierSmooth(var Pts: DblDyneVec; NoPts: Integer); var F: TFFTFrm; avg: DblDyneVec; @@ -1194,7 +1195,7 @@ begin end; end; -procedure TAutoCorrFrm.GetPts(var Pts: DblDyneVec; var NoPts: Integer; +procedure TAutoCorrForm.GetPts(var Pts: DblDyneVec; var NoPts: Integer; Depvar: Integer); var i: Integer; @@ -1241,7 +1242,7 @@ begin end; end; -procedure TAutoCorrFrm.MovingAverage(var Pts: DblDyneVec; NoPts: Integer); +procedure TAutoCorrForm.MovingAverage(var Pts: DblDyneVec; NoPts: Integer); var F: TMoveAvgFrm; i, j: Integer; @@ -1346,7 +1347,7 @@ begin end; end; -procedure TAutoCorrFrm.PlotDifferencesForLag(var Pts: DblDyneVec; NoPts: Integer); +procedure TAutoCorrForm.PlotDifferencesForLag(var Pts: DblDyneVec; NoPts: Integer); var F: TDifferenceFrm; lag: Integer; @@ -1415,7 +1416,7 @@ begin end; end; -procedure TAutoCorrFrm.PolynomialSmooth(var Pts: DblDyneVec; NoPts: Integer); +procedure TAutoCorrForm.PolynomialSmooth(var Pts: DblDyneVec; NoPts: Integer); var F: TPolynomialFrm; noProj: Integer; @@ -1494,7 +1495,7 @@ begin end; end; -procedure TAutoCorrFrm.RemoveMeans(var Pts: DblDyneVec; NoPts: Integer; AMean: Double); +procedure TAutoCorrForm.RemoveMeans(var Pts: DblDyneVec; NoPts: Integer; AMean: Double); var i: Integer; begin @@ -1503,8 +1504,5 @@ begin end; -initialization - {$I autocorunit.lrs} - end. diff --git a/applications/lazstats/source/forms/analysis/multivariate/discrimunit.lfm b/applications/lazstats/source/forms/analysis/multivariate/discrimunit.lfm index 8ed10cf79..e36a9c648 100644 --- a/applications/lazstats/source/forms/analysis/multivariate/discrimunit.lfm +++ b/applications/lazstats/source/forms/analysis/multivariate/discrimunit.lfm @@ -13,7 +13,7 @@ object DiscrimFrm: TDiscrimFrm OnCreate = FormCreate OnShow = FormShow Position = poMainFormCenter - LCLVersion = '2.1.0.0' + LCLVersion = '2.0.10.0' object ResetBtn: TButton AnchorSideRight.Control = ComputeBtn AnchorSideBottom.Control = Owner @@ -73,7 +73,7 @@ object DiscrimFrm: TDiscrimFrm AnchorSideLeft.Control = Owner AnchorSideTop.Control = Owner AnchorSideRight.Control = Panel2 - AnchorSideBottom.Control = Bevel1 + AnchorSideBottom.Control = ButtonBevel Left = 8 Height = 400 Top = 8 @@ -371,7 +371,7 @@ object DiscrimFrm: TDiscrimFrm TabOrder = 6 end end - object Bevel1: TBevel + object ButtonBevel: TBevel AnchorSideLeft.Control = Owner AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom @@ -387,7 +387,7 @@ object DiscrimFrm: TDiscrimFrm AnchorSideTop.Control = Owner AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = Bevel1 + AnchorSideBottom.Control = ButtonBevel Left = 412 Height = 408 Top = 0 diff --git a/applications/lazstats/source/forms/analysis/multivariate/discrimunit.pas b/applications/lazstats/source/forms/analysis/multivariate/discrimunit.pas index 729bbbf9a..682c1cdf3 100644 --- a/applications/lazstats/source/forms/analysis/multivariate/discrimunit.pas +++ b/applications/lazstats/source/forms/analysis/multivariate/discrimunit.pas @@ -17,7 +17,7 @@ type { TDiscrimFrm } TDiscrimFrm = class(TForm) - Bevel1: TBevel; + ButtonBevel: TBevel; Panel1: TPanel; Panel2: TPanel; ResetBtn: TButton; diff --git a/applications/lazstats/source/forms/analysis/multivariate/hierarchunit.lfm b/applications/lazstats/source/forms/analysis/multivariate/hierarchunit.lfm index 382413766..a0163a7a4 100644 --- a/applications/lazstats/source/forms/analysis/multivariate/hierarchunit.lfm +++ b/applications/lazstats/source/forms/analysis/multivariate/hierarchunit.lfm @@ -1,299 +1,269 @@ -object HierarchFrm: THierarchFrm +inherited HierarchForm: THierarchForm Left = 415 - Height = 319 + Height = 437 Top = 211 - Width = 442 + Width = 717 HelpType = htKeyword HelpKeyword = 'html/HierarchicalAnalysis.htm' - AutoSize = True Caption = 'Hierarchical Cluster Analysis' - ClientHeight = 319 - ClientWidth = 442 - OnActivate = FormActivate - OnCreate = FormCreate - OnShow = FormShow - Position = poMainFormCenter - LCLVersion = '2.1.0.0' - object Label1: TLabel - AnchorSideLeft.Control = Owner - AnchorSideTop.Control = Owner - Left = 8 - Height = 15 - Top = 8 - Width = 97 - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - Caption = 'Available Variables' - ParentColor = False - end - object Label2: TLabel - AnchorSideLeft.Control = PredList - AnchorSideTop.Control = Owner - Left = 228 - Height = 15 - Top = 8 - Width = 97 - BorderSpacing.Top = 8 - Caption = 'Predictor Variables' - ParentColor = False - end - object VarList: TListBox - AnchorSideLeft.Control = Owner - AnchorSideTop.Control = Label1 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = PredIn - AnchorSideBottom.Control = Bevel1 - Left = 8 - Height = 245 - Top = 25 - Width = 176 - Anchors = [akTop, akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Top = 2 - BorderSpacing.Right = 8 - ItemHeight = 0 - MultiSelect = True - OnSelectionChange = VarListSelectionChange - TabOrder = 0 - end - object PredIn: TBitBtn - AnchorSideTop.Control = VarList - AnchorSideRight.Control = GroupBox1 - Left = 192 - Height = 28 - Top = 25 - Width = 28 - Anchors = [akTop, akRight] - BorderSpacing.Right = 8 - Images = MainDataModule.ImageList - ImageIndex = 1 - OnClick = PredInClick - Spacing = 0 - TabOrder = 1 - end - object PredOut: TBitBtn - AnchorSideLeft.Control = PredIn - AnchorSideTop.Control = PredIn - AnchorSideTop.Side = asrBottom - Left = 192 - Height = 28 - Top = 57 - Width = 28 - BorderSpacing.Top = 4 - Images = MainDataModule.ImageList - ImageIndex = 0 - OnClick = PredOutClick - Spacing = 0 - TabOrder = 2 - end - object PredList: TListBox - AnchorSideLeft.Control = GroupBox1 - AnchorSideTop.Control = Label2 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = GroupBox1 - Left = 228 - Height = 62 - Top = 25 - Width = 206 - Anchors = [akTop, akLeft, akRight, akBottom] - BorderSpacing.Top = 2 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - ItemHeight = 0 - MultiSelect = True - OnSelectionChange = VarListSelectionChange - TabOrder = 3 - end - object GroupBox1: TGroupBox - AnchorSideLeft.Control = PredIn - AnchorSideLeft.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = Bevel1 - Left = 228 - Height = 175 - Top = 95 - Width = 206 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Right = 8 - Caption = 'Options' - ClientHeight = 155 - ClientWidth = 202 - TabOrder = 4 - object STDChk: TCheckBox - AnchorSideLeft.Control = GroupBox1 - AnchorSideTop.Control = GroupBox1 - Left = 12 - Height = 19 - Top = 2 - Width = 131 - BorderSpacing.Left = 12 - BorderSpacing.Top = 2 - Caption = 'Standardize Variables' - TabOrder = 0 + ClientHeight = 437 + ClientWidth = 717 + inherited ParamsPanel: TPanel + Height = 421 + ClientHeight = 421 + inherited CloseBtn: TButton + Top = 396 + TabOrder = 8 end - object ReplaceChk: TCheckBox - AnchorSideLeft.Control = STDChk - AnchorSideTop.Control = STDChk - AnchorSideTop.Side = asrBottom - Left = 12 - Height = 19 - Top = 23 - Width = 123 - BorderSpacing.Top = 2 - Caption = 'Replace Grid Values' - TabOrder = 1 - end - object StatsChk: TCheckBox - AnchorSideLeft.Control = GroupBox1 - AnchorSideTop.Control = ReplaceChk - AnchorSideTop.Side = asrBottom - Left = 12 - Height = 19 - Top = 44 - Width = 127 - BorderSpacing.Left = 12 - BorderSpacing.Top = 2 - Caption = 'Descriptive Statistics' - TabOrder = 2 - end - object PlotChk: TCheckBox - AnchorSideLeft.Control = GroupBox1 - AnchorSideTop.Control = StatsChk - AnchorSideTop.Side = asrBottom - Left = 12 - Height = 19 - Top = 65 - Width = 151 - BorderSpacing.Left = 12 - BorderSpacing.Top = 2 - Caption = 'No. Groups vs Errors Plot' - TabOrder = 3 - end - object MaxGrpsChk: TCheckBox - AnchorSideLeft.Control = GroupBox1 - AnchorSideTop.Control = PlotChk - AnchorSideTop.Side = asrBottom - Left = 12 - Height = 19 - Top = 86 - Width = 141 - BorderSpacing.Left = 12 - BorderSpacing.Top = 2 - Caption = 'Maximum No. Groups:' - TabOrder = 4 - end - object MembersChk: TCheckBox - AnchorSideLeft.Control = GroupBox1 - AnchorSideTop.Control = MaxGrpsChk - AnchorSideTop.Side = asrBottom - Left = 12 - Height = 19 - Top = 107 - Width = 151 - BorderSpacing.Left = 12 - BorderSpacing.Top = 2 - Caption = 'Print Group Membership' - TabOrder = 6 - end - object VarChk: TCheckBox - AnchorSideLeft.Control = GroupBox1 - AnchorSideTop.Control = MembersChk - AnchorSideTop.Side = asrBottom - Left = 12 - Height = 19 - Top = 128 - Width = 162 - BorderSpacing.Left = 12 - BorderSpacing.Top = 2 - BorderSpacing.Bottom = 8 - Caption = 'Cluster Variables, not cases' + inherited ComputeBtn: TButton + Top = 396 TabOrder = 7 end - object MaxGrps: TEdit - AnchorSideLeft.Control = MaxGrpsChk - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = MaxGrpsChk - AnchorSideTop.Side = asrCenter - Left = 157 - Height = 23 - Top = 84 - Width = 37 - Alignment = taRightJustify - BorderSpacing.Left = 4 - BorderSpacing.Right = 8 + inherited ResetBtn: TButton + Top = 396 + TabOrder = 6 + end + inherited HelpBtn: TButton + Top = 396 TabOrder = 5 - Text = 'MaxGrps' + end + inherited ButtonBevel: TBevel + Top = 380 + end + object PredIn: TBitBtn[5] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = VarList + AnchorSideRight.Control = OptionsGroup + Left = 132 + Height = 26 + Top = 17 + Width = 26 + Images = MainDataModule.ImageList + ImageIndex = 1 + OnClick = PredInClick + Spacing = 0 + TabOrder = 1 + end + object PredOut: TBitBtn[6] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = PredIn + AnchorSideTop.Side = asrBottom + Left = 132 + Height = 26 + Top = 47 + Width = 26 + BorderSpacing.Top = 4 + Images = MainDataModule.ImageList + ImageIndex = 0 + OnClick = PredOutClick + Spacing = 0 + TabOrder = 2 + end + object Label1: TLabel[7] + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = ParamsPanel + Left = 0 + Height = 15 + Top = 0 + Width = 97 + Caption = 'Available Variables' + ParentColor = False + end + object Label2: TLabel[8] + AnchorSideLeft.Control = PredList + AnchorSideTop.Control = ParamsPanel + Left = 164 + Height = 15 + Top = 0 + Width = 97 + Caption = 'Predictor Variables' + ParentColor = False + end + object VarList: TListBox[9] + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = Label1 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = PredIn + AnchorSideBottom.Control = OptionsGroup + Left = 0 + Height = 180 + Top = 17 + Width = 126 + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Top = 2 + BorderSpacing.Right = 6 + BorderSpacing.Bottom = 8 + ItemHeight = 0 + MultiSelect = True + OnDblClick = VarListDblClick + OnSelectionChange = VarListSelectionChange + TabOrder = 0 + end + object PredList: TListBox[10] + AnchorSideLeft.Control = PredIn + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = Label2 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = VarList + AnchorSideBottom.Side = asrBottom + Left = 164 + Height = 180 + Top = 17 + Width = 127 + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Left = 6 + BorderSpacing.Top = 2 + ItemHeight = 0 + MultiSelect = True + OnDblClick = PredListDblClick + OnSelectionChange = VarListSelectionChange + TabOrder = 3 + end + object OptionsGroup: TGroupBox[11] + AnchorSideLeft.Control = ParamsPanel + AnchorSideRight.Control = Owner + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = ButtonBevel + Left = 0 + Height = 175 + Top = 205 + Width = 226 + Anchors = [akLeft, akBottom] + AutoSize = True + BorderSpacing.Right = 8 + Caption = 'Options' + ClientHeight = 155 + ClientWidth = 222 + TabOrder = 4 + object STDChk: TCheckBox + AnchorSideLeft.Control = OptionsGroup + AnchorSideTop.Control = OptionsGroup + Left = 12 + Height = 19 + Top = 2 + Width = 131 + BorderSpacing.Left = 12 + BorderSpacing.Top = 2 + Caption = 'Standardize Variables' + TabOrder = 0 + end + object ReplaceChk: TCheckBox + AnchorSideLeft.Control = STDChk + AnchorSideTop.Control = STDChk + AnchorSideTop.Side = asrBottom + Left = 32 + Height = 19 + Top = 23 + Width = 123 + BorderSpacing.Left = 20 + BorderSpacing.Top = 2 + Caption = 'Replace Grid Values' + TabOrder = 1 + end + object StatsChk: TCheckBox + AnchorSideLeft.Control = OptionsGroup + AnchorSideTop.Control = ReplaceChk + AnchorSideTop.Side = asrBottom + Left = 12 + Height = 19 + Top = 44 + Width = 127 + BorderSpacing.Left = 12 + BorderSpacing.Top = 2 + Caption = 'Descriptive Statistics' + TabOrder = 2 + end + object PlotChk: TCheckBox + AnchorSideLeft.Control = OptionsGroup + AnchorSideTop.Control = StatsChk + AnchorSideTop.Side = asrBottom + Left = 12 + Height = 19 + Top = 65 + Width = 151 + BorderSpacing.Left = 12 + BorderSpacing.Top = 2 + Caption = 'No. Groups vs Errors Plot' + TabOrder = 3 + end + object MaxGrpsChk: TCheckBox + AnchorSideLeft.Control = OptionsGroup + AnchorSideTop.Control = PlotChk + AnchorSideTop.Side = asrBottom + Left = 12 + Height = 19 + Top = 86 + Width = 148 + BorderSpacing.Left = 12 + BorderSpacing.Top = 2 + Caption = 'Max Number of Groups:' + TabOrder = 4 + end + object MembersChk: TCheckBox + AnchorSideLeft.Control = OptionsGroup + AnchorSideTop.Control = MaxGrpsChk + AnchorSideTop.Side = asrBottom + Left = 12 + Height = 19 + Top = 107 + Width = 151 + BorderSpacing.Left = 12 + BorderSpacing.Top = 2 + Caption = 'Print Group Membership' + TabOrder = 6 + end + object VarChk: TCheckBox + AnchorSideLeft.Control = OptionsGroup + AnchorSideTop.Control = MembersChk + AnchorSideTop.Side = asrBottom + Left = 12 + Height = 19 + Top = 128 + Width = 162 + BorderSpacing.Left = 12 + BorderSpacing.Top = 2 + BorderSpacing.Bottom = 8 + Caption = 'Cluster Variables, not cases' + TabOrder = 7 + end + object MaxGrps: TEdit + AnchorSideLeft.Control = MaxGrpsChk + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = MaxGrpsChk + AnchorSideTop.Side = asrCenter + Left = 164 + Height = 23 + Top = 84 + Width = 50 + Alignment = taRightJustify + BorderSpacing.Left = 4 + BorderSpacing.Right = 8 + TabOrder = 5 + Text = 'MaxGrps' + end end end - object ResetBtn: TButton - AnchorSideRight.Control = ComputeBtn - AnchorSideBottom.Control = Owner - AnchorSideBottom.Side = asrBottom - Left = 233 - Height = 25 - Top = 286 - Width = 54 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Caption = 'Reset' - OnClick = ResetBtnClick - TabOrder = 5 + inherited ParamsSplitter: TSplitter + Height = 437 end - object ComputeBtn: TButton - AnchorSideRight.Control = CloseBtn - AnchorSideBottom.Control = Owner - AnchorSideBottom.Side = asrBottom - Left = 295 - Height = 25 - Top = 286 - Width = 76 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Caption = 'Compute' - OnClick = ComputeBtnClick - TabOrder = 6 - end - object CloseBtn: TButton - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = Owner - AnchorSideBottom.Side = asrBottom - Left = 379 - Height = 25 - Top = 286 - Width = 55 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Caption = 'Close' - ModalResult = 11 - TabOrder = 7 - end - object Bevel1: TBevel - AnchorSideLeft.Control = Owner - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = CloseBtn - Left = 0 - Height = 8 - Top = 270 - Width = 442 - Anchors = [akLeft, akRight, akBottom] - Shape = bsBottomLine + inherited PageControl: TPageControl + Height = 421 + Width = 397 + ActivePage = StatsPage + inherited ReportPage: TTabSheet + Caption = 'Results' + end + object StatsPage: TTabSheet[1] + Caption = 'Descriptive Stats' + TabVisible = False + end + inherited ChartPage: TTabSheet[2] + Caption = 'Groups Count vs. Errors Plot' + TabVisible = False + end end end diff --git a/applications/lazstats/source/forms/analysis/multivariate/hierarchunit.pas b/applications/lazstats/source/forms/analysis/multivariate/hierarchunit.pas index 4213b2d92..f8755ceca 100644 --- a/applications/lazstats/source/forms/analysis/multivariate/hierarchunit.pas +++ b/applications/lazstats/source/forms/analysis/multivariate/hierarchunit.pas @@ -1,25 +1,27 @@ // Sample file for testing: cansas.laz, use all variiables. +// WARNING: THE OUTPUT OF THIS FORM DOES NOT AGREE WITH THE SAME FORM OF +// OPENSTAT OR STATS4U + unit HierarchUnit; {$mode objfpc}{$H+} +{$DEFINE OLD_PLOT} + interface uses - Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, - StdCtrls, Buttons, ExtCtrls, - MainUnit, OutputUnit, Globals, MatrixLib, GraphLib, DataProcs; + Classes, SysUtils, Forms, Controls, Graphics, Dialogs, + StdCtrls, Buttons, ExtCtrls, ComCtrls, + {$IFDEF OLD_PLOT} GraphLib, {$ENDIF} + MainUnit, Globals, MatrixLib, ReportFrameUnit, BasicStatsReportAndChartFormUnit; type - { THierarchFrm } + { THierarchForm } - THierarchFrm = class(TForm) - Bevel1: TBevel; - ResetBtn: TButton; - ComputeBtn: TButton; - CloseBtn: TButton; + THierarchForm = class(TBasicStatsReportAndChartForm) MaxGrps: TEdit; STDChk: TCheckBox; ReplaceChk: TCheckBox; @@ -27,117 +29,111 @@ type PlotChk: TCheckBox; MaxGrpsChk: TCheckBox; MembersChk: TCheckBox; + StatsPage: TTabSheet; VarChk: TCheckBox; - GroupBox1: TGroupBox; + OptionsGroup: TGroupBox; PredIn: TBitBtn; PredOut: TBitBtn; Label1: TLabel; Label2: TLabel; PredList: TListBox; VarList: TListBox; - procedure ComputeBtnClick(Sender: TObject); - procedure FormActivate(Sender: TObject); - procedure FormCreate(Sender: TObject); - procedure FormShow(Sender: TObject); procedure PredInClick(Sender: TObject); + procedure PredListDblClick(Sender: TObject); procedure PredOutClick(Sender: TObject); - procedure ResetBtnClick(Sender: TObject); + procedure VarListDblClick(Sender: TObject); procedure VarListSelectionChange(Sender: TObject; {%H-}User: boolean); private - { private declarations } - FAutoSized: Boolean; - procedure UpdateBtnStates; + FStatsReportFrame: TReportFrame; + + procedure Plot_GroupCount_Error(const AGrpCount, AError: DblDyneVec; + ADataCount: Integer); + + procedure ShowDescriptiveStats(const AMeans, AVars, AStdDevs: DblDyneVec; + ANumCols, ANumCases: Integer; const AVarLabels: StrDyneVec); + + protected + procedure AdjustConstraints; override; + procedure Compute; override; + procedure UpdateBtnStates; override; + function Validate(out AMsg: String; out AControl: TWincontrol): Boolean; override; + public - { public declarations } + constructor Create(AOwner: TComponent); override; + procedure Reset; override; + end; var - HierarchFrm: THierarchFrm; + HierarchForm: THierarchForm; + implementation +{$R *.lfm} + uses - Math, Utils; + TAChartUtils, TACustomSeries, + Utils, DataProcs, ChartFrameUnit; -{ THierarchFrm } -procedure THierarchFrm.ResetBtnClick(Sender: TObject); -var - i: integer; +{ THierarchForm } + +constructor THierarchForm.Create(AOwner: TComponent); begin - VarList.Clear; - PredList.Clear; - StdChk.Checked := false; - ReplaceChk.Checked := false; - StatsChk.Checked := false; - PlotChk.Checked := false; - MaxGrpsChk.Checked := false; - VarChk.Checked := false; - MaxGrps.Text := ''; - for i := 1 to NoVariables do - VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); - UpdateBtnStates; -end; + inherited; -procedure THierarchFrm.FormActivate(Sender: TObject); -var - w: Integer; -begin - if FAutoSized then - exit; + InitToolbar(FReportFrame.ReportToolbar, tpTop); + FReportFrame.ClearBorderSpacings; - w := MaxValue([ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]); - ResetBtn.Constraints.MinWidth := w; - ComputeBtn.Constraints.MinWidth := w; - CloseBtn.Constraints.MinWidth := w; - VarList.Constraints.MinWidth := PredList.Width; + FStatsReportFrame := TReportFrame.Create(self); + FStatsReportFrame.Parent := StatsPage; + FStatsReportFrame.Align := alClient; + StatsPage.PageIndex := 1; - Constraints.MinWidth := Width; - Constraints.MinHeight := Height; - - FAutoSized := true; -end; - -procedure THierarchFrm.FormCreate(Sender: TObject); -begin - Assert(OS3MainFrm <> nil); + {$IFDEF OLD_PLOTS} if GraphFrm = nil then Application.CreateForm(TGraphFrm, GraphFrm); + {$ENDIF} + + PageControl.ActivePageIndex := 0; end; -procedure THierarchFrm.FormShow(Sender: TObject); + +procedure THierarchForm.AdjustConstraints; begin - ResetBtnClick(self); + inherited; + + ParamsPanel.Constraints.MinWidth := 4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left; + ParamsPanel.Constraints.MinHeight := PredOut.Top + PredOut.Height + + VarList.BorderSpacing.Bottom + OptionsGroup.Height + + ButtonBevel.Height + CloseBtn.Height; end; -procedure THierarchFrm.ComputeBtnClick(Sender: TObject); + +procedure THierarchForm.Compute; label next1; var - varlabels, rowlabels : StrDyneVec; - cellstring : string; + varLabels: StrDyneVec = nil; + rowLabels: StrDyneVec = nil; + w2: IntDyneVec = nil; + k4: IntDyneVec = nil; + k5: IntDyneVec = nil; + L1: IntDyneVec = nil; + ColSelected: IntDyneVec = nil; + W: DblDyneVec = nil; + XAxis: DblDyneVec = nil; + YAxis: DblDyneVec = nil; + means: DblDyneVec = nil; + variances: DblDyneVec = nil; + stddevs: DblDyneVec = nil; + Distance : DblDyneMat = nil; + cellstring: string; i, j, k, k1, k3, L, w3, n3, n4, n5, M, col, count: integer; GrpCnt, Nrows, Ncols, NoSelected: integer; - w2, k4, k5, L1 : IntDyneVec; - ColSelected : IntDyneVec = nil; - X, Y, d1, x1, MaxError : double; - W, XAxis, YAxis, means, variances, stddevs : DblDyneVec; - Distance : DblDyneMat = nil; + X, Y, d1, x1, MaxError: double; lReport: TStrings; begin - if MaxGrpsChk.Checked then - begin - if MaxGrps.Text = '' then - begin - MessageDlg('Maximum number of groups not specified.', mtError, [mbOK], 0); - exit; - end; - if not TryStrToInt(MaxGrps.Text, k1) or (k1 < 1) then - begin - Messagedlg('No valid number of groups given.', mtError, [mbOK], 0); - exit; - end; - end; - MaxError := 0.0; GrpCnt := 0; NoSelected := PredList.Items.Count; @@ -157,9 +153,10 @@ begin SetLength(varlabels,NoSelected); SetLength(rowlabels,NoCases); SetLength(ColSelected,NoSelected); - Ncols := NoSelected; - Nrows := NoCases; - for i := 0 to Ncols - 1 do + nCols := NoSelected; + nRows := NoCases; + + for i := 0 to nCols - 1 do begin cellstring := PredList.Items.Strings[i]; for j := 1 to NoVariables do @@ -191,7 +188,7 @@ begin Ncols := NoCases; Nrows := NoSelected; //Get labels of selected variables - for i := 0 to Nrows - 1 do + for i := 0 to nRows - 1 do begin cellstring := PredList.Items.Strings[i]; for j := 1 to NoVariables do @@ -207,23 +204,29 @@ begin varlabels[i] := IntToStr(i); end; - if MembersChk.Checked then k3 := 1 else k3 := 0; + if MaxGrpsChk.Checked then + k1 := StrToInt(MaxGrps.Text); - for j := 0 to Ncols-1 do + if MembersChk.Checked then + k3 := 1 + else + k3 := 0; + + for j := 0 to nCols-1 do begin means[j] := 0.0; variances[j] := 0.0; stddevs[j] := 0.0; end; - if VarChk.Checked = false then + if not VarChk.Checked then begin // Get labels of rows // for i := 1 to Nrows do rowlabels[i-1] := MainFrm.Grid.Cells[0,i]; // Get data into the distance matrix count := 0; - for i := 1 to Nrows do + for i := 1 to nRows do begin if (not GoodRecord(i,NoSelected,ColSelected)) then continue; count := count + 1; @@ -243,31 +246,38 @@ begin // Get data into the distance matrix count := 0; - for i := 1 to Nrows do // actually grid column in this case + for i := 0 to nRows-1 do // actually grid column in this case begin // if (not GoodRecord(i,NoSelected,ColSelected)) then continue; count := count + 1; - for j := 1 to Ncols do // actually grid rows in this case + for j := 0 to Ncols-1 do // actually grid rows in this case begin // if (not GoodRecord(j,NoSelected,ColSelected)) then continue; - col := ColSelected[i-1]; - X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[col,j])); - means[j-1] := means[j-1] + X; - variances[j-1] := variances[j-1] + (X * X); - Distance[i-1,j-1] := X; + col := ColSelected[i]; + X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[col, j+1])); + means[j] := means[j] + X; + variances[j] := variances[j] + (X * X); + Distance[i, j] := X; end; end; end; // Calculate means and standard deviations of variables - for j := 0 to Ncols-1 do + for j := 0 to nCols-1 do begin - variances[j] := variances[j] - (means[j] * means[j] / count); - variances[j] := variances[j] / (count - 1); + variances[j] := (variances[j] - sqr(means[j]) / count) / (count - 1); stddevs[j] := sqrt(variances[j]); means[j] := means[j] / count; end; + // Report descriptive statistics + if StatsChk.Checked then + begin + StatsPage.TabVisible := true; + ShowDescriptiveStats(means, variances, stddevs, nCols, count, varlabels); + end else + StatsPage.TabVisible := false; + // Ready the output form lReport := TStringList.Create; try @@ -276,33 +286,24 @@ begin lReport.Add('Number of objects to cluster: %d on %d variables.', [Nrows, Ncols]); lReport.Add(''); - if StatsChk.Checked then - begin - DynVectorPrint(means, Ncols, 'Variable Means', varlabels, count, lReport); - DynVectorPrint(variances, Ncols, 'Variable Variances', varlabels, count, lReport); - DynVectorPrint(stddevs, Ncols, 'Variable Standard Deviations', varlabels, count, lReport); - lReport.Add(DIVIDER); - lReport.Add(''); - end; - // Standardize the distance scores if elected if StdChk.Checked then begin - for j := 0 to Ncols-1 do - for i := 0 to Nrows-1 do + for j := 0 to nCols-1 do + for i := 0 to nRows-1 do Distance[i,j] := (Distance[i,j] - means[j]) / stddevs[j]; end; // replace original values in grid with z scores if elected if ReplaceChk.Checked then begin - for i := 1 to Nrows do + for i := 0 to nRows-1 do begin - if not GoodRecord(i,NoSelected,ColSelected) then continue; - for j := 1 to Ncols do + if not GoodRecord(i+1, NoSelected, ColSelected) then continue; + for j := 0 to nCols-1 do begin - col := ColSelected[j-1]; - OS3MainFrm.DataGrid.Cells[col,i] := Format('%6.4f', [Distance[i-1,j-1]]); + col := ColSelected[j]; + OS3MainFrm.DataGrid.Cells[col, i+1] := Format('%6.4f', [Distance[i, j]]); end; end; end; @@ -327,14 +328,10 @@ begin // Now, group the cases for maximum groups down if MaxGrpsChk.Checked then - begin - k1 := StrToInt(MaxGrps.Text); - n3 := Nrows; - end else - begin + k1 := StrToInt(MaxGrps.Text) + else k1 := 2; - n3 := Nrows; - end; + n3 := nRows; // Initialize group membership and group-n vectors for i := 0 to Nrows-1 do @@ -346,11 +343,15 @@ begin // Locate optimal combination, if more than 2 groups remain + next1: n3 := n3 - 1; if (n3 > 1) then begin + + //repeat; + // n3 := n3 - 1; x1 := 100000000000.0; for i := 1 to Nrows do begin @@ -374,9 +375,10 @@ next1: n4 := w2[L-1]; n5 := w2[M-1]; + XAxis[GrpCnt] := n3; + YAxis[GrpCnt] := x1; GrpCnt := GrpCnt + 1; - XAxis[GrpCnt-1] := n3; - YAxis[GrpCnt-1] := x1; + if (x1 > MaxError) then MaxError := x1; lReport.Add('%2.d groups after combining group %2.d (n = %2.d) and group %2.d (n = %2.d), error: %7.3f', [n3, L, n4, M, n5, x1]); @@ -406,10 +408,13 @@ next1: end; end; w2[L-1] := w3; - if (n3 > k1) then goto next1; + if (n3 > k1) then + //Continue; + goto next1; - // print group memberships of all objects, if optioned - for i := 1 to Nrows do + // Print group memberships of all objects, if optioned + lReport.Add(''); + for i := 1 to nRows do begin if (k5[i-1] = i) then begin @@ -431,13 +436,19 @@ next1: end; // end if end; // end if end; // next i + lReport.Add(''); goto next1; - end; // end if + //until n3 = 2; + end; // end if - DisplayReport(lReport); + FReportFrame.DisplayReport(lReport); if PlotChk.Checked then begin + ChartPage.TabVisible := true; + Plot_GroupCount_Error(XAxis, YAxis, GrpCnt); + + {$IFDEF OLD_PLOTS} SetLength(GraphFrm.Ypoints,1,GrpCnt); SetLength(GraphFrm.Xpoints,1,GrpCnt); for i := 1 to GrpCnt do @@ -458,30 +469,38 @@ next1: GraphFrm.BackColor := clCream; GraphFrm.ShowBackWall := true; GraphFrm.ShowModal; - end; + {$ENDIF} + end else + ChartPage.TabVisible := false; finally lReport.Free; - ColSelected := nil; - rowlabels := nil; - varlabels := nil; - Distance := nil; - stddevs := nil; - variances := nil; - means := nil; - YAxis := nil; - XAxis := nil; - W := nil; - L1 := nil; - k5 := nil; - k4 := nil; - w2 := nil; - GraphFrm.Xpoints := nil; - GraphFrm.Ypoints := nil; end; end; -procedure THierarchFrm.PredInClick(Sender: TObject); + +procedure THierarchForm.Plot_GroupCount_Error(const AGrpCount, AError: DblDyneVec; + ADataCount: Integer); +var + ser: TChartSeries; + i: Integer; +begin + FChartFrame.Clear; + FChartFrame.SetTitle('Number of Groups vs. Grouping Error'); + FChartFrame.SetXTitle('Number of Groups'); + FChartFrame.SetYTitle('Grouping Error'); + + ser := FChartFrame.PlotXY(ptSymbols, nil, nil, nil, nil, '', DATA_COLORS[0]); + for i := 0 to ADataCount-1 do + ser.AddXY(i, AError[i], Format('%.0f', [AGrpCount[i]])); + + FChartFrame.Chart.BottomAxis.Marks.Source := ser.Source; + FChartFrame.Chart.BottomAxis.Marks.Style := smsLabel; + FChartFrame.Chart.Legend.Visible := false; +end; + + +procedure THierarchForm.PredInClick(Sender: TObject); var i: integer; begin @@ -499,7 +518,22 @@ begin UpdateBtnStates; end; -procedure THierarchFrm.PredOutClick(Sender: TObject); + +procedure THierarchForm.PredListDblClick(Sender: TObject); +var + index: Integer; +begin + index := PredList.ItemIndex; + if index > -1 then + begin + VarList.Items.Add(PredList.Items[index]); + PredList.Items.Delete(index); + UpdateBtnStates; + end; +end; + + +procedure THierarchForm.PredOutClick(Sender: TObject); var i: integer; begin @@ -517,19 +551,125 @@ begin UpdateBtnStates; end; -procedure THierarchFrm.UpdateBtnStates; + +procedure THierarchForm.Reset; +var + i: integer; begin + inherited; + + if FStatsReportFrame <> nil then + FStatsReportFrame.Clear; + + VarList.Clear; + for i := 1 to NoVariables do + VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); + PredList.Clear; + + StdChk.Checked := false; + ReplaceChk.Checked := false; + StatsChk.Checked := false; + PlotChk.Checked := false; + MaxGrpsChk.Checked := false; + VarChk.Checked := false; + + MaxGrps.Clear; + + UpdateBtnStates; +end; + + +procedure THierarchForm.ShowDescriptiveStats(const AMeans, AVars, AStdDevs: DblDyneVec; + ANumCols, ANumCases: Integer; const AVarLabels: StrDyneVec); +var + lReport: TStrings; +begin + lReport := TStringList.Create; + try + DynVectorPrint(AMeans, ANumCols, 'Variable Means', AVarLabels, ANumCases, lReport); + + lReport.Add(DIVIDER_SMALL_AUTO); + lReport.Add(''); + + DynVectorPrint(AVars, ANumCols, 'Variable Variances', AVarLabels, ANumCases, lReport); + + lReport.Add(DIVIDER_SMALL_AUTO); + lReport.Add(''); + + DynVectorPrint(AStdDevs, ANumCols, 'Variable Standard Deviations', AVarLabels, ANumCases, lReport); + + FStatsReportFrame.DisplayReport(lReport); + finally + lReport.Free; + end; +end; + + +procedure THierarchForm.UpdateBtnStates; +begin + inherited; + + if FStatsReportFrame <> nil then + FStatsReportFrame.UpdateBtnStates; + PredIn.Enabled := AnySelected(VarList); PredOut.Enabled := AnySelected(PredList); end; -procedure THierarchFrm.VarListSelectionChange(Sender: TObject; User: boolean); + +function THierarchForm.Validate(out AMsg: String; out AControl: TWincontrol): Boolean; +var + n: Integer; +begin + Result := false; + + if PredList.Items.Count = 0 then + begin + AMsg := 'No Predictor Variables selected.'; + AControl := VarList; + exit; + end; + + if MaxGrpsChk.Checked then + begin + if MaxGrps.Text = '' then + begin + AMsg := 'Maximum number of groups not specified.'; + AControl := MaxGrps; + exit; + end; + if not TryStrToInt(MaxGrps.Text, n) or (n < 1) then + begin + AMsg := 'No valid number of groups given.'; + AControl := MaxGrps; + exit; + end; + end; + + Result := true; +end; + + +procedure THierarchForm.VarListDblClick(Sender: TObject); +var + index: Integer; + s: String; +begin + index := VarList.ItemIndex; + if index > -1 then + begin + PredList.Items.Add(VarList.Items[index]); + VarList.Items.Delete(index); + UpdateBtnStates; + end; +end; + + +procedure THierarchForm.VarListSelectionChange(Sender: TObject; User: boolean); begin UpdateBtnStates; end; -initialization - {$I hierarchunit.lrs} end. diff --git a/applications/lazstats/source/forms/mainunit.lfm b/applications/lazstats/source/forms/mainunit.lfm index 3b5aae725..81c81f59e 100644 --- a/applications/lazstats/source/forms/mainunit.lfm +++ b/applications/lazstats/source/forms/mainunit.lfm @@ -599,23 +599,23 @@ object OS3MainFrm: TOS3MainFrm OnClick = mnuAnalysisComp_LatinSquaresClick end end - object mnuAnalysisCorrel: TMenuItem + object mnuAnalysisCorr: TMenuItem Caption = 'Correlation' - object mnuAnalysisCorrel_ProductMoment: TMenuItem + object mnuAnalysisCorr_ProductMoment: TMenuItem Caption = 'Product-Moment' - OnClick = mnuAnalysisCorrel_ProductMomentClick + OnClick = mnuAnalysisCorr_ProductMomentClick end - object mnuAnalysisCorrel_Partial: TMenuItem + object mnuAnalysisCorr_Partial: TMenuItem Caption = 'Partial, Semipartial' - OnClick = mnuAnalysisCorrel_PartialClick + OnClick = mnuAnalysisCorr_PartialClick end - object mnuAnalysisCorrel_AutoCorr: TMenuItem + object mnuAnalysisCorr_AutoCorr: TMenuItem Caption = 'Autocorrelation' - OnClick = mnuAnalysisCorrel_AutoCorrClick + OnClick = mnuAnalysisCorr_AutoCorrClick end - object mnuAnalysisCorrel_Canonical: TMenuItem + object mnuAnalysisCorr_Canonical: TMenuItem Caption = 'Canonical' - OnClick = mnuAnalysisCorrel_CanonicalClick + OnClick = mnuAnalysisCorr_CanonicalClick end end object mnuAnalysisMultReg: TMenuItem diff --git a/applications/lazstats/source/forms/mainunit.pas b/applications/lazstats/source/forms/mainunit.pas index c0ad68d97..a6fa8b952 100644 --- a/applications/lazstats/source/forms/mainunit.pas +++ b/applications/lazstats/source/forms/mainunit.pas @@ -85,11 +85,11 @@ type mnuAnalysisComp_WithinAnova: TMenuItem; // Menu "Analysis" > "Correlation" - mnuAnalysisCorrel: TMenuItem; - mnuAnalysisCorrel_ProductMoment: TMenuItem; - mnuAnalysisCorrel_Partial: TMenuItem; - mnuAnalysisCorrel_AutoCorr: TMenuItem; - mnuAnalysisCorrel_Canonical: TMenuItem; + mnuAnalysisCorr: TMenuItem; + mnuAnalysisCorr_ProductMoment: TMenuItem; + mnuAnalysisCorr_Partial: TMenuItem; + mnuAnalysisCorr_AutoCorr: TMenuItem; + mnuAnalysisCorr_Canonical: TMenuItem; // Menu "Analysis" > "Descriptive" mnuAnalysisDescr: TMenuItem; @@ -351,10 +351,10 @@ type procedure mnuAnalysisComp_WithinAnovaClick(Sender: TObject); // Menu "Analysis" > "Correlation" - procedure mnuAnalysisCorrel_AutoCorrClick(Sender: TObject); - procedure mnuAnalysisCorrel_CanonicalClick(Sender: TObject); - procedure mnuAnalysisCorrel_PartialClick(Sender: TObject); - procedure mnuAnalysisCorrel_ProductMomentClick(Sender: TObject); + procedure mnuAnalysisCorr_AutoCorrClick(Sender: TObject); + procedure mnuAnalysisCorr_CanonicalClick(Sender: TObject); + procedure mnuAnalysisCorr_PartialClick(Sender: TObject); + procedure mnuAnalysisCorr_ProductMomentClick(Sender: TObject); // Menu "Analysis" > "Descriptive" procedure mnuAnalysisDescr_BoxPlotClick(Sender: TObject); @@ -768,9 +768,9 @@ end; // Menu "Analysis" > "Multivariate" > "Hierarchical Analysis" procedure TOS3MainFrm.mnuAnalysisMulti_HierarchicalClick(Sender: TObject); begin - if HierarchFrm = nil then - Application.CreateForm(THierarchFrm, HierarchFrm); - HierarchFrm.ShowModal; + if HierarchForm = nil then + Application.CreateForm(THierarchForm, HierarchForm); + HierarchForm.Show; end; // Menu "Analysis" > "Multivariate" > "Path analysis" @@ -1665,7 +1665,7 @@ end; { "Correlation" commands } // Menu "Correlation" > "Product-Moment" -procedure TOS3MainFrm.mnuAnalysisCorrel_ProductMomentClick(Sender: TObject); +procedure TOS3MainFrm.mnuAnalysisCorr_ProductMomentClick(Sender: TObject); begin if RMatForm = nil then Application.CreateForm(TRMatForm, RMatForm); @@ -1673,7 +1673,7 @@ begin end; // Menu "Correlation" > "Partial, Semipartial" -procedure TOS3MainFrm.mnuAnalysisCorrel_PartialClick(Sender: TObject); +procedure TOS3MainFrm.mnuAnalysisCorr_PartialClick(Sender: TObject); begin if PartialsForm = nil then Application.CreateForm(TPartialsForm, PartialsForm); @@ -1681,15 +1681,15 @@ begin end; // Menu "Correlation" > "Autocorrelation" -procedure TOS3MainFrm.mnuAnalysisCorrel_AutoCorrClick(Sender: TObject); +procedure TOS3MainFrm.mnuAnalysisCorr_AutoCorrClick(Sender: TObject); begin - if AutoCorrFrm = nil then - Application.CreateForm(TAutoCorrFrm, AutoCorrFrm); - AutocorrFrm.Show; + if AutoCorrForm = nil then + Application.CreateForm(TAutoCorrForm, AutoCorrForm); + AutocorrForm.Show; end; // Menu "Correlation" > "Canonical" -procedure TOS3MainFrm.mnuAnalysisCorrel_CanonicalClick(Sender: TObject); +procedure TOS3MainFrm.mnuAnalysisCorr_CanonicalClick(Sender: TObject); begin if CanonicalForm = nil then Application.CreateForm(TCanonicalForm, CanonicalForm);