From e04a433d41c3c7105b11c15a41c11bd6514e1e12 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 22 Oct 2020 10:24:24 +0000 Subject: [PATCH] LazStats: Inherit the remaining regression forms from TBasicStatsReportForm. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7791 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- applications/lazstats/source/LazStats.lpi | 14 +- .../multiple_regression/bestregunit.lfm | 689 +++++------ .../multiple_regression/bestregunit.pas | 567 ++++----- .../multiple_regression/blkmregunit.lfm | 805 ++++++------- .../multiple_regression/blkmregunit.pas | 258 ++-- .../multiple_regression/coxregunit.lfm | 701 +++++------ .../multiple_regression/coxregunit.pas | 317 ++--- .../multiple_regression/linprounit.lfm | 10 +- .../multiple_regression/linprounit.pas | 52 +- .../multiple_regression/logregunit.lfm | 541 ++++----- .../multiple_regression/logregunit.pas | 1053 +++++++++-------- .../multiple_regression/simultregunit.lfm | 504 ++++---- .../multiple_regression/simultregunit.pas | 215 ++-- .../multiple_regression/twoslsunit.lfm | 649 +++++----- .../multiple_regression/twoslsunit.pas | 324 ++--- .../analysis/multiple_regression/wlsunit.lfm | 10 +- .../lazstats/source/forms/mainunit.pas | 43 +- .../source/frames/reportframeunit.lfm | 3 +- 18 files changed, 3263 insertions(+), 3492 deletions(-) diff --git a/applications/lazstats/source/LazStats.lpi b/applications/lazstats/source/LazStats.lpi index 941f47cb5..496f0ba73 100644 --- a/applications/lazstats/source/LazStats.lpi +++ b/applications/lazstats/source/LazStats.lpi @@ -497,7 +497,7 @@ - + @@ -513,7 +513,7 @@ - + @@ -521,7 +521,7 @@ - + @@ -529,7 +529,7 @@ - + @@ -537,7 +537,7 @@ - + @@ -545,7 +545,7 @@ - + @@ -905,7 +905,7 @@ - + diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/bestregunit.lfm b/applications/lazstats/source/forms/analysis/multiple_regression/bestregunit.lfm index 439de220d..99f007685 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/bestregunit.lfm +++ b/applications/lazstats/source/forms/analysis/multiple_regression/bestregunit.lfm @@ -1,398 +1,351 @@ -object BestRegFrm: TBestRegFrm - Left = 869 +inherited BestRegForm: TBestRegForm + Left = 525 Height = 433 - Top = 266 - Width = 474 + Top = 233 + Width = 843 HelpType = htKeyword HelpKeyword = 'html/BestCombinationMultipleRegressio.htm' - AutoSize = True Caption = 'Best Combination Multiple Regression' ClientHeight = 433 - ClientWidth = 474 - 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 = BlockList - AnchorSideTop.Control = InBtn - Left = 268 - Height = 15 - Top = 105 - Width = 93 - Caption = 'Selected Variables' - ParentColor = False - end - object Label3: TLabel - AnchorSideLeft.Control = DepVar - AnchorSideBottom.Control = DepVar - Left = 268 - Height = 15 - Top = 33 - Width = 102 - Anchors = [akLeft, akBottom] - BorderSpacing.Bottom = 2 - Caption = 'Dependent Variable' - ParentColor = False - end - object Label4: TLabel - AnchorSideLeft.Control = Owner - AnchorSideTop.Control = InProb - AnchorSideTop.Side = asrCenter - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = GroupBox1 - Left = 8 - Height = 15 - Top = 224 - Width = 185 - BorderSpacing.Left = 8 - BorderSpacing.Top = 16 - BorderSpacing.Right = 8 - Caption = 'Minimum Probability for Inclusion:' - ParentColor = False - WordWrap = True - end - object VarList: TListBox - AnchorSideLeft.Control = Owner - AnchorSideTop.Control = Label1 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = AllBtn - AnchorSideBottom.Control = InProb - Left = 8 - Height = 187 - Top = 25 - Width = 198 - Anchors = [akTop, akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Top = 2 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 6 - ItemHeight = 0 - MultiSelect = True - OnSelectionChange = VarListSelectionChange - TabOrder = 0 - end - object InBtn: TBitBtn - AnchorSideLeft.Control = AllBtn - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = DepOutBtn - AnchorSideTop.Side = asrBottom - Left = 223 - Height = 28 - Top = 105 - Width = 28 - BorderSpacing.Top = 20 - Images = MainDataModule.ImageList - ImageIndex = 1 - OnClick = InBtnClick - Spacing = 0 - TabOrder = 1 - end - object OutBtn: TBitBtn - AnchorSideLeft.Control = AllBtn - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = InBtn - AnchorSideTop.Side = asrBottom - Left = 223 - Height = 28 - Top = 137 - Width = 28 - BorderSpacing.Top = 4 - Images = MainDataModule.ImageList - ImageIndex = 0 - OnClick = OutBtnClick - Spacing = 0 - TabOrder = 2 - end - object AllBtn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = OutBtn - AnchorSideTop.Side = asrBottom - Left = 214 - Height = 25 - Top = 185 - Width = 46 - AutoSize = True - BorderSpacing.Top = 20 - Caption = 'ALL' - OnClick = AllBtnClick - Spacing = 0 - TabOrder = 3 - end - object BlockList: TListBox - AnchorSideLeft.Control = AllBtn - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = Label2 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = VarList - AnchorSideBottom.Side = asrBottom - Left = 268 - Height = 90 - Top = 122 - Width = 198 - Anchors = [akTop, akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Top = 2 - BorderSpacing.Right = 8 - ItemHeight = 0 - MultiSelect = True - OnSelectionChange = VarListSelectionChange - TabOrder = 4 - end - object DepInBtn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = VarList - Left = 223 - Height = 28 - Top = 25 - Width = 28 - Images = MainDataModule.ImageList - ImageIndex = 1 - OnClick = DepInBtnClick - Spacing = 0 - TabOrder = 5 - end - object DepOutBtn: TBitBtn - AnchorSideLeft.Control = DepInBtn - AnchorSideTop.Control = DepInBtn - AnchorSideTop.Side = asrBottom - Left = 223 - Height = 28 - Top = 57 - Width = 28 - BorderSpacing.Top = 4 - Images = MainDataModule.ImageList - ImageIndex = 0 - OnClick = DepOutBtnClick - Spacing = 0 - TabOrder = 6 - end - object DepVar: TEdit - AnchorSideLeft.Control = AllBtn - AnchorSideLeft.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = DepOutBtn - AnchorSideBottom.Side = asrBottom - Left = 268 - Height = 23 - Top = 50 - Width = 198 - Anchors = [akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 12 - TabOrder = 7 - Text = 'DepVar' - end - object GroupBox1: TGroupBox - AnchorSideLeft.Control = Owner - AnchorSideBottom.Control = Bevel1 - Left = 8 - Height = 135 - Top = 249 - Width = 459 - Anchors = [akLeft, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Right = 8 - Caption = 'Options' - ChildSizing.LeftRightSpacing = 12 - ChildSizing.TopBottomSpacing = 6 - ChildSizing.VerticalSpacing = 2 - ChildSizing.Layout = cclTopToBottomThenLeftToRight - ChildSizing.ControlsPerLine = 5 - ClientHeight = 115 - ClientWidth = 455 - TabOrder = 8 - object CPChkBox: TCheckBox - Left = 12 - Height = 19 - Top = 6 - Width = 223 - Caption = 'Show Cross-Products Matrix' - TabOrder = 0 + ClientWidth = 843 + inherited ParamsPanel: TPanel + Height = 417 + Width = 467 + ClientHeight = 417 + ClientWidth = 467 + inherited CloseBtn: TButton + Left = 412 + Top = 392 end - object CovChkBox: TCheckBox - Left = 12 - Height = 19 - Top = 27 - Width = 223 - Caption = 'Show Deviation Cross-Products Matrix' - TabOrder = 1 + inherited ComputeBtn: TButton + Left = 328 + Top = 392 end - object CorrsChkBox: TCheckBox - Left = 12 - Height = 19 - Top = 48 - Width = 223 - Caption = 'Show Intercorrelations Matrix' - TabOrder = 2 + inherited ResetBtn: TButton + Left = 266 + Top = 392 end - object MeansChkBox: TCheckBox - Left = 12 - Height = 19 - Top = 69 - Width = 223 - Caption = 'Show Means' - TabOrder = 3 + inherited HelpBtn: TButton + Left = 207 + Top = 392 end - object VarChkBox: TCheckBox - Left = 12 - Height = 19 - Top = 90 - Width = 223 - Caption = 'Show Variances' + inherited ButtonBevel: TBevel + Top = 376 + Width = 467 + 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 = BlockList + AnchorSideTop.Control = InBtn + Left = 259 + Height = 15 + Top = 93 + Width = 93 + Caption = 'Selected Variables' + ParentColor = False + end + object Label3: TLabel[7] + AnchorSideLeft.Control = DepVarEdit + AnchorSideBottom.Control = DepVarEdit + Left = 259 + Height = 15 + Top = 21 + Width = 102 + Anchors = [akLeft, akBottom] + BorderSpacing.Bottom = 2 + Caption = 'Dependent Variable' + ParentColor = False + end + object Label4: TLabel[8] + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = InProbEdit + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = Owner + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = GroupBox1 + Left = 0 + Height = 15 + Top = 214 + Width = 185 + BorderSpacing.Top = 16 + BorderSpacing.Right = 8 + Caption = 'Minimum Probability for Inclusion:' + ParentColor = False + WordWrap = True + end + object VarList: TListBox[9] + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = Label1 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = AllBtn + AnchorSideBottom.Control = InProbEdit + Left = 0 + Height = 185 + Top = 17 + Width = 207 + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Top = 2 + BorderSpacing.Right = 6 + BorderSpacing.Bottom = 8 + ItemHeight = 0 + MultiSelect = True + OnDblClick = VarListDblClick + OnSelectionChange = VarListSelectionChange TabOrder = 4 end - object SDChkBox: TCheckBox - Left = 235 - Height = 19 - Top = 6 - Width = 208 - Caption = 'Show Standard Deviations' + object InBtn: TBitBtn[10] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = DepOutBtn + AnchorSideTop.Side = asrBottom + Left = 219 + Height = 26 + Top = 93 + Width = 28 + BorderSpacing.Top = 20 + Images = MainDataModule.ImageList + ImageIndex = 1 + OnClick = InBtnClick + Spacing = 0 TabOrder = 5 end - object MatSaveChkBox: TCheckBox - Left = 235 - Height = 19 - Top = 27 - Width = 208 - Caption = 'Save Correlation Matrix' + object OutBtn: TBitBtn[11] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = InBtn + AnchorSideTop.Side = asrBottom + Left = 219 + Height = 26 + Top = 123 + Width = 28 + BorderSpacing.Top = 4 + Images = MainDataModule.ImageList + ImageIndex = 0 + OnClick = OutBtnClick + Spacing = 0 TabOrder = 6 end - object PredictChkBox: TCheckBox - Left = 235 - Height = 19 - Top = 48 - Width = 208 - Caption = 'Predictions, residuals, C.I''s to grid' + object AllBtn: TBitBtn[12] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = OutBtn + AnchorSideTop.Side = asrBottom + Left = 213 + Height = 25 + Top = 169 + Width = 40 + AutoSize = True + BorderSpacing.Top = 20 + Caption = 'All' + OnClick = AllBtnClick + Spacing = 0 TabOrder = 7 end - object MatInChkBox: TCheckBox - Left = 235 - Height = 19 - Top = 69 + object BlockList: TListBox[13] + AnchorSideLeft.Control = AllBtn + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = Label2 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = VarList + AnchorSideBottom.Side = asrBottom + Left = 259 + Height = 92 + Top = 110 Width = 208 - Caption = 'Enter Data from a Matrix' + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Left = 6 + BorderSpacing.Top = 2 + ItemHeight = 0 + MultiSelect = True + OnDblClick = BlockListDblClick + OnSelectionChange = VarListSelectionChange TabOrder = 8 end - object ComboShowChkBox: TCheckBox - Left = 235 - Height = 19 - Top = 90 - Width = 208 - Caption = 'Show Results for each Combination' + object DepInBtn: TBitBtn[14] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = VarList + Left = 219 + Height = 26 + Top = 17 + Width = 28 + Images = MainDataModule.ImageList + ImageIndex = 1 + OnClick = DepInBtnClick + Spacing = 0 TabOrder = 9 end + object DepOutBtn: TBitBtn[15] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = DepInBtn + AnchorSideTop.Side = asrBottom + Left = 219 + Height = 26 + Top = 47 + Width = 28 + BorderSpacing.Top = 4 + Images = MainDataModule.ImageList + ImageIndex = 0 + OnClick = DepOutBtnClick + Spacing = 0 + TabOrder = 10 + end + object DepVarEdit: TEdit[16] + AnchorSideLeft.Control = AllBtn + AnchorSideLeft.Side = asrBottom + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = DepOutBtn + AnchorSideBottom.Side = asrBottom + Left = 259 + Height = 23 + Top = 38 + Width = 208 + Anchors = [akLeft, akRight, akBottom] + BorderSpacing.Left = 6 + BorderSpacing.Bottom = 12 + TabOrder = 11 + Text = 'DepVarEdit' + end + object GroupBox1: TGroupBox[17] + AnchorSideLeft.Control = ParamsPanel + AnchorSideBottom.Control = ButtonBevel + Left = 0 + Height = 135 + Top = 241 + Width = 459 + Anchors = [akLeft, akBottom] + AutoSize = True + BorderSpacing.Right = 8 + Caption = 'Options' + ChildSizing.LeftRightSpacing = 12 + ChildSizing.TopBottomSpacing = 6 + ChildSizing.VerticalSpacing = 2 + ChildSizing.Layout = cclTopToBottomThenLeftToRight + ChildSizing.ControlsPerLine = 5 + ClientHeight = 115 + ClientWidth = 455 + TabOrder = 12 + object CPChkBox: TCheckBox + Left = 12 + Height = 19 + Top = 6 + Width = 223 + Caption = 'Show Cross-Products Matrix' + TabOrder = 0 + end + object CovChkBox: TCheckBox + Left = 12 + Height = 19 + Top = 27 + Width = 223 + Caption = 'Show Deviation Cross-Products Matrix' + TabOrder = 1 + end + object CorrsChkBox: TCheckBox + Left = 12 + Height = 19 + Top = 48 + Width = 223 + Caption = 'Show Intercorrelations Matrix' + TabOrder = 2 + end + object MeansChkBox: TCheckBox + Left = 12 + Height = 19 + Top = 69 + Width = 223 + Caption = 'Show Means' + TabOrder = 3 + end + object VarChkBox: TCheckBox + Left = 12 + Height = 19 + Top = 90 + Width = 223 + Caption = 'Show Variances' + TabOrder = 4 + end + object SDChkBox: TCheckBox + Left = 235 + Height = 19 + Top = 6 + Width = 208 + Caption = 'Show Standard Deviations' + TabOrder = 5 + end + object MatSaveChkBox: TCheckBox + Left = 235 + Height = 19 + Top = 27 + Width = 208 + Caption = 'Save Correlation Matrix' + TabOrder = 6 + end + object PredictChkBox: TCheckBox + Left = 235 + Height = 19 + Top = 48 + Width = 208 + Caption = 'Predictions, residuals, C.I''s to grid' + TabOrder = 7 + end + object MatInChkBox: TCheckBox + Left = 235 + Height = 19 + Top = 69 + Width = 208 + Caption = 'Enter Data from a Matrix' + TabOrder = 8 + end + object ComboShowChkBox: TCheckBox + Left = 235 + Height = 19 + Top = 90 + Width = 208 + Caption = 'Show Results for each Combination' + TabOrder = 9 + end + end + object InProbEdit: TEdit[18] + AnchorSideLeft.Control = Label4 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = Label4 + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Control = GroupBox1 + Left = 193 + Height = 23 + Top = 210 + Width = 59 + Alignment = taRightJustify + Anchors = [akLeft, akBottom] + BorderSpacing.Top = 8 + BorderSpacing.Bottom = 8 + TabOrder = 13 + Text = 'InProbEdit' + end end - object InProb: TEdit - AnchorSideLeft.Control = Label4 - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = Label4 - AnchorSideTop.Side = asrBottom - AnchorSideBottom.Control = GroupBox1 - Left = 201 - Height = 23 - Top = 220 - Width = 59 - Alignment = taRightJustify - Anchors = [akLeft, akBottom] - BorderSpacing.Top = 8 - BorderSpacing.Bottom = 6 - TabOrder = 9 - Text = 'InProb' + inherited ParamsSplitter: TSplitter + Left = 479 + Height = 433 end - object ResetBtn: TButton - AnchorSideRight.Control = ComputeBtn - AnchorSideBottom.Control = Owner - AnchorSideBottom.Side = asrBottom - Left = 265 - Height = 25 - Top = 400 - Width = 54 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Caption = 'Reset' - OnClick = ResetBtnClick - TabOrder = 10 - end - object ComputeBtn: TButton - AnchorSideRight.Control = CloseBtn - AnchorSideBottom.Control = Owner - AnchorSideBottom.Side = asrBottom - Left = 327 - Height = 25 - Top = 400 - Width = 76 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Caption = 'Compute' - OnClick = ComputeBtnClick - TabOrder = 11 - end - object CloseBtn: TButton - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = Owner - AnchorSideBottom.Side = asrBottom - Left = 411 - Height = 25 - Top = 400 - Width = 55 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Caption = 'Close' - ModalResult = 11 - TabOrder = 12 - end - object Bevel1: TBevel - AnchorSideLeft.Control = Owner - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = CloseBtn - Left = 0 - Height = 8 - Top = 384 - Width = 474 - Anchors = [akLeft, akRight, akBottom] - Shape = bsBottomLine - end - object OpenDialog1: TOpenDialog + object OpenDialog1: TOpenDialog[2] Left = 56 Top = 40 end - object SaveDialog1: TSaveDialog + object SaveDialog1: TSaveDialog[3] Left = 56 Top = 104 end diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/bestregunit.pas b/applications/lazstats/source/forms/analysis/multiple_regression/bestregunit.pas index 0651b6687..9c1f2d611 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/bestregunit.pas +++ b/applications/lazstats/source/forms/analysis/multiple_regression/bestregunit.pas @@ -5,17 +5,16 @@ unit BestRegUnit; interface uses - Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Buttons, ExtCtrls, - Globals, MainUnit, MatrixLib, OutputUnit, FunctionsLib, DataProcs; + Globals, MainUnit, MatrixLib, FunctionsLib, DataProcs, BasicStatsReportFormUnit; type - { TBestRegFrm } + { TBestRegForm } - TBestRegFrm = class(TForm) - Bevel1: TBevel; + TBestRegForm = class(TBasicStatsReportForm) CPChkBox: TCheckBox; ComboShowChkBox: TCheckBox; CovChkBox: TCheckBox; @@ -31,11 +30,8 @@ type AllBtn: TBitBtn; DepInBtn: TBitBtn; DepOutBtn: TBitBtn; - ResetBtn: TButton; - ComputeBtn: TButton; - CloseBtn: TButton; - DepVar: TEdit; - InProb: TEdit; + DepVarEdit: TEdit; + InProbEdit: TEdit; GroupBox1: TGroupBox; Label1: TLabel; Label2: TLabel; @@ -47,21 +43,16 @@ type VarList: TListBox; procedure AllBtnClick(Sender: TObject); - procedure ComputeBtnClick(Sender: TObject); + procedure BlockListDblClick(Sender: TObject); procedure DepInBtnClick(Sender: TObject); procedure DepOutBtnClick(Sender: TObject); - procedure FormActivate(Sender: TObject); - procedure FormCreate(Sender: TObject); - procedure FormShow(Sender: TObject); procedure InBtnClick(Sender: TObject); - procedure ResetBtnClick(Sender: TObject); procedure OutBtnClick(Sender: TObject); + procedure VarListDblClick(Sender: TObject); procedure VarListSelectionChange(Sender: TObject; User: boolean); - private { private declarations } - FAutoSized: boolean; pred_labels : StrDyneVec; y_ptr, v : integer; ii, jj : integer; @@ -119,53 +110,183 @@ type procedure BestSetStats(AReport: TStrings); procedure BumpOne; procedure StartSet; - procedure Reset; - - procedure UpdateBtnStates; + procedure ResetVars; + + protected + procedure AdjustConstraints; override; + procedure Compute; override; + procedure UpdateBtnStates; override; public - { public declarations } + constructor Create(AOwner: TComponent); override; + procedure Reset; override; end; var - BestRegFrm: TBestRegFrm; + BestRegForm: TBestRegForm; implementation +{$R *.lfm} + uses Math, Utils, MathUnit; -{ TBestRegFrm } -procedure TBestRegFrm.ResetBtnClick(Sender: TObject); -var - i: integer; +{ TBestRegForm } + +constructor TBestRegForm.Create(AOwner: TComponent); begin - BlockList.Clear; + inherited; + InProbEdit.Text := FormatFloat('0.00', DEFAULT_ALPHA_LEVEL); +end; + + +procedure TBestRegForm.AdjustConstraints; +begin + inherited; + + ParamsPanel.Constraints.MinWidth := Max( + 4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left, + Groupbox1.Width); + ParamsPanel.Constraints.MinHeight := InProbEdit.Top + InProbEdit.Height + + InProbEdit.BorderSpacing.Top + GroupBox1.Height + ButtonBevel.Height + + CloseBtn.BorderSpacing.Top + CloseBtn.Height; +end; + + +procedure TBestRegForm.AllBtnClick(Sender: TObject); +var + index: integer; +begin + for index := 0 to VarList.Items.Count-1 do + BlockList.Items.Add(VarList.Items[index]); VarList.Clear; - for i := 1 to NoVariables do - VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); - DepVar.Text := ''; - - CPChkBox.Checked := false; - CovChkBox.Checked := false; - CorrsChkBox.Checked := true; - MeansChkBox.Checked := true; - VarChkBox.Checked := false; - SDChkBox.Checked := true; - MatSaveChkBox.Checked := false; - PredictChkBox.Checked := false; - UpdateBtnStates; end; -procedure TBestRegFrm.FormShow(Sender: TObject); + +procedure TBestRegForm.BestSetStats(AReport: TStrings); +var + i, j: integer; + outline: string; begin - ResetBtnClick(self); + AReport.Add(''); + AReport.Add('Variables entered in step %d', [sets]); + for i := 1 to sets do + begin + ii := max_set[i-1]; + selected[i-1] := max_set[i-1]; + AReport.Add('%2d %s',[max_set[i-1],ColLabels[ii-1]]); + end; + AReport.Add(''); + + Regress(AReport); + + AReport.Add('Squared Multiple Correlation: %.4f', [mult_r2]); + AReport.Add('Dependent variable: %s', [ColLabels[y_ptr-1]]); + AReport.Add(''); + AReport.Add('ANOVA for Regression Effects: '); + AReport.Add('SOURCE df SS MS F Prob'); + + df_reg := sets; + df_res := round(NCases) - sets - 1; + df_tot := round(NCases) - 1; + ms_reg := ss_reg / df_reg; + ss_res := ( 1.0 - mult_R2) * ss_total ; + ms_res := ss_res / df_res ; + f_test := ms_reg / ms_res ; + prob_f := ProbF(f_test, df_reg,df_res); + + { Get variance of b coefficients } + AReport.Add('Regression %3d %14.4f %14.4f %14.4f %14.4f', [df_reg, ss_reg, ms_reg, f_test, prob_f]); + AReport.Add('Residual %3d %14.4f %14.4f', [df_res, ss_res, ms_res]); + AReport.Add('Total %3d %14.4f', [df_tot, ss_total]); + AReport.Add(''); + + AReport.Add('Variables in the equation'); + AReport.Add('VARIABLE b s.e. b Beta t prob. t'); + for i := 1 to sets do + for j := 1 to sets do + ind_mat[i-1,j-1] := ind_mat[i-1,j-1] * ms_res ; + for i := 1 to sets do + begin + ii := selected[i-1]; + pred_labels[i-1] := ColLabels[ii-1]; + outline := Format('%16s %10.5f ',[ColLabels[ii-1],raw_b[i-1]]); + seb := sqrt(ind_mat[i-1,i-1]); + t := raw_b[i-1] / seb ; + f_test := t * t ; + prob_f := probf(f_test,1,df_res); + beta := raw_b[i-1] * stddev[ii-1] / stddev[y_ptr-1] ; + outline := outline + Format('%8.4f %8.4f %6.3f %6.4f', [seb,beta,t,prob_f]); + AReport.Add(outline); + end; + + AReport.Add('(Intercept) %10.5f',[b_zero]); + AReport.Add(''); + +{ MAT_PRINT(sets,ind_mat,pred_labels,'Variance-covariance matrix of b s');} + + { Now see if the gain was significant over last step } + df1 := sets - last_set ; + f_test := ((mult_R2 - last_R2 ) / df1 ) / ( (1.0 - mult_R2) / df_res) ; + prob_f := probf(f_test, df1,df_res); + if prob_f > stop_prob then more_to_do := FALSE ; + R2_diff := mult_R2 - last_R2 ; + AReport.Add('Increase in squared R for this step: %8.6f', [R2_diff]); + AReport.Add('F: %.4f with D.F. %d and %d with Probability %.4f', [f_test, df1, df_res, prob_f]); + AReport.Add(''); + AReport.Add('----------------------------------------------------------'); + + last_set := sets; + last_R2 := mult_R2; end; -procedure TBestRegFrm.ComputeBtnClick(Sender: TObject); + +procedure TBestRegForm.BlockListDblClick(Sender: TObject); +var + index: Integer; +begin + index := BlockList.ItemIndex; + if index > -1 then + begin + VarList.Items.Add(BlockList.Items[index]); + BlockList.Items.Delete(index); + UpdatebtnStates; + end; +end; + + +procedure TBestRegForm.BumpOne; +begin + if selected[first_pt-1] < no_predictors then + selected[first_pt-1] := selected[first_pt-1] + 1 + else + begin + all_done := false; + while not all_done do + begin + first_pt := first_pt -1; + if first_pt < 1 then + all_done := true + else + begin + selected[first_pt-1] := selected[first_pt-1] + 1; + if selected[first_pt-1] < selected[first_pt] then + begin + ResetVars(); + first_pt := pointer; + all_done := true; + end else + selected[first_pt-1] := selected[first_pt-1] - 1; + end; + end; + end; +end; + +procedure TBestRegForm.Compute; var i, j: integer; title: string; @@ -177,16 +298,16 @@ var constant: double; lReport: TStrings; begin - if InProb.Text = '' then + if InProbEdit.Text = '' then begin - InProb.SetFocus; + InProbEdit.SetFocus; MessageDlg('Probability for inclusion not specified.', mtError, [mbOK], 0); exit; end; - if not TryStrToFloat(InProb.Text, stop_prob) then // probability to include a block + if not TryStrToFloat(InProbEdit.Text, stop_prob) then // probability to include a block begin - InProb.SetFocus; + InProbEdit.SetFocus; MessageDlg('No number given for probability.', mtError, [mbOk], 0); exit; end; @@ -271,7 +392,7 @@ begin DepVarCol := NoVars; y_ptr := NoVars; - DepVar.Text := RowLabels[NoVars]; + DepVarEdit.Text := RowLabels[NoVars]; { convert correlations to deviation cross-products } for i := 1 to NoVars do @@ -304,7 +425,7 @@ begin end; { get dependendent variable column } - if DepVar.Text = '' then + if DepVarEdit.Text = '' then begin MessageDlg('No dependent variable selected.', mtError, [mbOK], 0); exit; @@ -314,7 +435,7 @@ begin y_ptr := NoVars; for j := 1 to NoVariables do begin - if DepVar.Text = OS3MainFrm.DataGrid.Cells[j,0] then + if DepVarEdit.Text = OS3MainFrm.DataGrid.Cells[j,0] then begin DepVarCol := j; ColNoSelected[NoVars-1] := j; @@ -470,29 +591,58 @@ begin end; end; - DisplayReport(lReport); + FReportFrame.DisplayReport(lReport); finally lReport.Free; - pred_labels := nil; - Max_Set := nil; - Selected := nil; - ColNoSelected := nil; - IndepIndex := nil; - ColLabels := nil; - RowLabels := nil; - raw_b := nil; - xycross := nil; - variance := nil; - stddev := nil; - mean := nil; - sumx := nil; - ind_mat := nil; - cross_prod := nil; end; end; -procedure TBestRegFrm.Init; + +procedure TBestRegForm.DepInBtnClick(Sender: TObject); +var + index: integer; +begin + index := VarList.ItemIndex; + if (index > -1) and (DepVarEdit.Text = '') then + begin + DepVarEdit.Text := VarList.Items[index]; + VarList.Items.Delete(index); + end; + UpdateBtnStates; +end; + + +procedure TBestRegForm.DepOutBtnClick(Sender: TObject); +begin + if DepVarEdit.Text <> '' then + begin + VarList.Items.Add(DepVarEdit.Text); + DepVarEdit.Text := ''; + end; + UpdateBtnStates; +end; + + +procedure TBestRegForm.InBtnClick(Sender: TObject); +var + i: integer; +begin + i := 0; + while i < VarList.Items.Count do + begin + if VarList.Selected[i] then + begin + BlockList.Items.Add(VarList.Items[i]); + VarList.Items.Delete(i); + i := 0; + end else + inc(i); + end; + UpdateBtnStates; +end; + +procedure TBestRegForm.Init; var i, j: integer; begin @@ -507,7 +657,27 @@ begin end; end; -procedure TBestRegFrm.Regress(AReport: TStrings); + +procedure TBestRegForm.OutBtnClick(Sender: TObject); +var + i: integer; +begin + i := 0; + while i < BlockList.Items.Count do + begin + if BlockList.Selected[i] then + begin + VarList.Items.Add(BlockList.Items[i]); + BlockList.Items.Delete(i); + i := 0; + end else + inc(i); + end; + UpdateBtnStates; +end; + + +procedure TBestRegForm.Regress(AReport: TStrings); var i, j: integer; begin @@ -564,122 +734,33 @@ begin end; end; -procedure TBestRegFrm.BestSetStats(AReport: TStrings); -var - i, j: integer; - outline: string; -begin - AReport.Add(''); - AReport.Add('Variables entered in step %d', [sets]); - for i := 1 to sets do - begin - ii := max_set[i-1]; - selected[i-1] := max_set[i-1]; - AReport.Add('%2d %s',[max_set[i-1],ColLabels[ii-1]]); - end; - AReport.Add(''); - Regress(AReport); - - AReport.Add('Squared Multiple Correlation: %.4f', [mult_r2]); - AReport.Add('Dependent variable: %s', [ColLabels[y_ptr-1]]); - AReport.Add(''); - AReport.Add('ANOVA for Regression Effects: '); - AReport.Add('SOURCE df SS MS F Prob'); - - df_reg := sets; - df_res := round(NCases) - sets - 1; - df_tot := round(NCases) - 1; - ms_reg := ss_reg / df_reg; - ss_res := ( 1.0 - mult_R2) * ss_total ; - ms_res := ss_res / df_res ; - f_test := ms_reg / ms_res ; - prob_f := ProbF(f_test, df_reg,df_res); - - { Get variance of b coefficients } - AReport.Add('Regression %3d %14.4f %14.4f %14.4f %14.4f', [df_reg, ss_reg, ms_reg, f_test, prob_f]); - AReport.Add('Residual %3d %14.4f %14.4f', [df_res, ss_res, ms_res]); - AReport.Add('Total %3d %14.4f', [df_tot, ss_total]); - AReport.Add(''); - - AReport.Add('Variables in the equation'); - AReport.Add('VARIABLE b s.e. b Beta t prob. t'); - for i := 1 to sets do - for j := 1 to sets do - ind_mat[i-1,j-1] := ind_mat[i-1,j-1] * ms_res ; - for i := 1 to sets do - begin - ii := selected[i-1]; - pred_labels[i-1] := ColLabels[ii-1]; - outline := Format('%16s %10.5f ',[ColLabels[ii-1],raw_b[i-1]]); - seb := sqrt(ind_mat[i-1,i-1]); - t := raw_b[i-1] / seb ; - f_test := t * t ; - prob_f := probf(f_test,1,df_res); - beta := raw_b[i-1] * stddev[ii-1] / stddev[y_ptr-1] ; - outline := outline + Format('%8.4f %8.4f %6.3f %6.4f', [seb,beta,t,prob_f]); - AReport.Add(outline); - end; - - AReport.Add('(Intercept) %10.5f',[b_zero]); - AReport.Add(''); - -{ MAT_PRINT(sets,ind_mat,pred_labels,'Variance-covariance matrix of b s');} - - { Now see if the gain was significant over last step } - df1 := sets - last_set ; - f_test := ((mult_R2 - last_R2 ) / df1 ) / ( (1.0 - mult_R2) / df_res) ; - prob_f := probf(f_test, df1,df_res); - if prob_f > stop_prob then more_to_do := FALSE ; - R2_diff := mult_R2 - last_R2 ; - AReport.Add('Increase in squared R for this step: %8.6f', [R2_diff]); - AReport.Add('F: %.4f with D.F. %d and %d with Probability %.4f', [f_test, df1, df_res, prob_f]); - AReport.Add(''); - AReport.Add('----------------------------------------------------------'); - - last_set := sets; - last_R2 := mult_R2; -end; - -procedure TBestRegFrm.BumpOne; -begin - if selected[first_pt-1] < no_predictors then - selected[first_pt-1] := selected[first_pt-1] + 1 - else - begin - all_done := false; - while not all_done do - begin - first_pt := first_pt -1; - if first_pt < 1 then - all_done := true - else - begin - selected[first_pt-1] := selected[first_pt-1] + 1; - if selected[first_pt-1] < selected[first_pt] then - begin - Reset(); - first_pt := pointer; - all_done := true; - end else - selected[first_pt-1] := selected[first_pt-1] - 1; - end; - end; - end; -end; - -procedure TBestRegFrm.StartSet; +procedure TBestRegForm.Reset; var i: integer; begin - end_of_set := false; - for i := 1 to sets do - selected[i-1] := i; - first_pt := sets; - pointer := sets; + inherited; + + DepVarEdit.Clear; + BlockList.Clear; + VarList.Clear; + for i := 1 to NoVariables do + VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); + + CPChkBox.Checked := false; + CovChkBox.Checked := false; + CorrsChkBox.Checked := false; + MeansChkBox.Checked := false; + VarChkBox.Checked := false; + SDChkBox.Checked := false; + MatSaveChkBox.Checked := false; + PredictChkBox.Checked := false; + + UpdateBtnStates; end; -procedure TBestRegFrm.Reset; + +procedure TBestRegForm.ResetVars; var i: integer; begin @@ -691,117 +772,53 @@ begin selected[i-1] := selected[i-2] + 1; end; -procedure TBestRegFrm.InBtnClick(Sender: TObject); + +procedure TBestRegForm.StartSet; var i: integer; begin - i := 0; - while i < VarList.Items.Count do - begin - if VarList.Selected[i] then - begin - BlockList.Items.Add(VarList.Items[i]); - VarList.Items.Delete(i); - i := 0; - end else - inc(i); - end; - UpdateBtnStates; + end_of_set := false; + for i := 1 to sets do + selected[i-1] := i; + first_pt := sets; + pointer := sets; end; -procedure TBestRegFrm.OutBtnClick(Sender: TObject); -var - i: integer; -begin - i := 0; - while i < BlockList.Items.Count do - begin - if BlockList.Selected[i] then - begin - VarList.Items.Add(BlockList.Items[i]); - BlockList.Items.Delete(i); - i := 0; - end else - inc(i); - end; - UpdateBtnStates; -end; - -procedure TBestRegFrm.AllBtnClick(Sender: TObject); -var - index: integer; -begin - for index := 0 to VarList.Items.Count-1 do - BlockList.Items.Add(VarList.Items[index]); - VarList.Clear; - UpdateBtnStates; -end; - -procedure TBestRegFrm.DepInBtnClick(Sender: TObject); -var - index: integer; -begin - index := VarList.ItemIndex; - if (index > -1) and (DepVar.Text = '') then - begin - DepVar.Text := VarList.Items[index]; - VarList.Items.Delete(index); - end; - UpdateBtnStates; -end; - -procedure TBestRegFrm.DepOutBtnClick(Sender: TObject); -begin - if DepVar.Text <> '' then - begin - VarList.Items.Add(DepVar.Text); - DepVar.Text := ''; - end; - UpdateBtnStates; -end; - -procedure TBestRegFrm.FormActivate(Sender: TObject); -var - w: Integer; -begin - if FAutoSized then - exit; - - w := MaxValue([ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]); - ResetBtn.Constraints.MinWidth := w; - ComputeBtn.Constraints.MinWidth := w; - CloseBtn.Constraints.MinWidth := w; - - VarList.Constraints.MinHeight := AllBtn.Top + AllBtn.Height - VarList.Top; - - Constraints.MinWidth := Width; - Constraints.MinHeight := Height; - - FAutoSized := true; -end; - -procedure TBestRegFrm.FormCreate(Sender: TObject); -begin - Assert(OS3MainFrm <> nil); - InProb.Text := FormatFloat('0.00', DEFAULT_ALPHA_LEVEL); -end; - -procedure TBestRegFrm.UpdateBtnStates; + + +procedure TBestRegForm.UpdateBtnStates; begin + inherited; + InBtn.Enabled := AnySelected(VarList); OutBtn.Enabled := AnySelected(BlockList); - DepInBtn.Enabled := (VarList.ItemIndex > -1) and (DepVar.Text <= ''); - DepOutBtn.Enabled := DepVar.Text <> ''; + DepInBtn.Enabled := (VarList.ItemIndex > -1) and (DepVarEdit.Text <= ''); + DepOutBtn.Enabled := DepVarEdit.Text <> ''; end; -procedure TBestRegFrm.VarListSelectionChange(Sender: TObject; User: boolean); + +procedure TBestRegForm.VarListDblClick(Sender: TObject); +var + index: Integer; +begin + index := VarList.ItemIndex; + if index > -1 then + begin + if DepVarEdit.Text = '' then + DepVarEdit.Text := VarList.Items[index] + else + BlockList.Items.Add(VarList.Items[index]); + VarList.Items.Delete(index); + UpdateBtnStates; + end; +end; + + +procedure TBestRegForm.VarListSelectionChange(Sender: TObject; User: boolean); begin UpdateBtnStates; end; -initialization - {$I bestregunit.lrs} - end. diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/blkmregunit.lfm b/applications/lazstats/source/forms/analysis/multiple_regression/blkmregunit.lfm index 54aed8cb3..479975841 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/blkmregunit.lfm +++ b/applications/lazstats/source/forms/analysis/multiple_regression/blkmregunit.lfm @@ -1,446 +1,401 @@ -object BlkMregFrm: TBlkMregFrm - Left = 503 - Height = 451 - Top = 292 - Width = 465 +inherited BlkMregForm: TBlkMregForm + Left = 520 + Height = 415 + Top = 224 + Width = 962 HelpType = htKeyword HelpKeyword = 'html/BlockEntryMultipleRegression.htm' - AutoSize = True Caption = 'Block Entry Multiple Regression' - ClientHeight = 451 - ClientWidth = 465 - OnActivate = FormActivate - OnCreate = FormCreate - OnShow = FormShow - Position = poMainFormCenter - LCLVersion = '2.1.0.0' - object Label1: TLabel - AnchorSideLeft.Control = Owner - AnchorSideTop.Control = Bevel3 - AnchorSideTop.Side = asrBottom - Left = 8 - Height = 15 - Top = 48 - Width = 97 - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - Caption = 'Available Variables' - ParentColor = False - end - object Label2: TLabel - AnchorSideLeft.Control = DepVar - AnchorSideTop.Side = asrBottom - AnchorSideBottom.Control = DepVar - Left = 263 - Height = 15 - Top = 77 - Width = 102 - Anchors = [akLeft, akBottom] - BorderSpacing.Top = 8 - BorderSpacing.Bottom = 2 - Caption = 'Dependent Variable' - ParentColor = False - end - object Label3: TLabel - AnchorSideLeft.Control = BlockList - Left = 263 - Height = 15 - Top = 144 - Width = 166 - Caption = 'Independent Var.s for this block' - ParentColor = False - end - object Label4: TLabel - AnchorSideLeft.Control = Owner - AnchorSideTop.Control = BlockNoEdit - AnchorSideTop.Side = asrCenter - AnchorSideRight.Control = BlockNoEdit - Left = 8 - Height = 15 - Top = 12 - Width = 54 - BorderSpacing.Left = 8 - BorderSpacing.Right = 8 - Caption = 'Block No. ' - ParentColor = False - end - object Label5: TLabel - AnchorSideLeft.Control = NextBlkBtn - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = InProb - AnchorSideTop.Side = asrCenter - AnchorSideRight.Control = InProb - Left = 218 - Height = 15 - Top = 13 - Width = 187 - Alignment = taRightJustify - Anchors = [akTop, akLeft, akRight] - BorderSpacing.Right = 8 - Caption = 'Minimum Prob. to enter block:' - ParentColor = False - WordWrap = True - end - object VarList: TListBox - AnchorSideLeft.Control = Owner - AnchorSideTop.Control = Label1 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = AllBtn - AnchorSideBottom.Control = GroupBox1 - Left = 8 - Height = 220 - Top = 65 - Width = 193 - Anchors = [akTop, akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Top = 2 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Constraints.MinHeight = 220 - ItemHeight = 0 - MultiSelect = True - OnSelectionChange = VarListSelectionChange - TabOrder = 3 - end - object DepInBtn: TBitBtn - AnchorSideLeft.Control = AllBtn - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = VarList - Left = 217 - Height = 28 - Top = 69 - Width = 28 - Anchors = [akTop] - BorderSpacing.Top = 4 - Images = MainDataModule.ImageList - ImageIndex = 1 - OnClick = DepInBtnClick - Spacing = 0 - TabOrder = 4 - end - object DepOutBtn: TBitBtn - AnchorSideLeft.Control = AllBtn - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = DepInBtn - AnchorSideTop.Side = asrBottom - Left = 218 - Height = 28 - Top = 101 - Width = 28 - BorderSpacing.Top = 4 - Images = MainDataModule.ImageList - ImageIndex = 0 - OnClick = DepOutBtnClick - Spacing = 0 - TabOrder = 5 - end - object InBtn: TBitBtn - AnchorSideLeft.Control = AllBtn - AnchorSideLeft.Side = asrCenter - AnchorSideBottom.Control = OutBtn - Left = 218 - Height = 28 - Top = 174 - Width = 28 - Anchors = [akLeft, akBottom] - BorderSpacing.Bottom = 4 - Images = MainDataModule.ImageList - ImageIndex = 1 - OnClick = InBtnClick - Spacing = 0 - TabOrder = 7 - end - object OutBtn: TBitBtn - AnchorSideLeft.Control = AllBtn - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = BlockList - AnchorSideTop.Side = asrCenter - Left = 218 - Height = 28 - Top = 206 - Width = 28 - Images = MainDataModule.ImageList - ImageIndex = 0 - OnClick = OutBtnClick - Spacing = 0 - TabOrder = 8 - end - object AllBtn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = OutBtn - AnchorSideTop.Side = asrBottom - Left = 209 - Height = 25 - Top = 244 - Width = 46 - AutoSize = True - BorderSpacing.Top = 10 - Caption = 'ALL' - OnClick = AllBtnClick - Spacing = 0 - TabOrder = 9 - end - object DepVar: TEdit - AnchorSideLeft.Control = AllBtn - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = DepOutBtn - AnchorSideBottom.Side = asrBottom - Left = 263 - Height = 23 - Top = 94 - Width = 194 - Anchors = [akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Top = 2 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 12 - ReadOnly = True - TabOrder = 6 - Text = 'DepVar' - end - object BlockList: TListBox - AnchorSideLeft.Control = AllBtn - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = Label3 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = GroupBox1 - Left = 263 - Height = 119 - Top = 161 - Width = 194 - Anchors = [akTop, akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Top = 2 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - ItemHeight = 0 - MultiSelect = True - OnSelectionChange = VarListSelectionChange - TabOrder = 10 - end - object BlockNoEdit: TEdit - AnchorSideLeft.Control = Label4 - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = Owner - AnchorSideRight.Control = NextBlkBtn - Left = 70 - Height = 23 - Top = 8 - Width = 37 - Alignment = taRightJustify - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - TabOrder = 0 - Text = 'BlockNoEdit' - end - object NextBlkBtn: TButton - AnchorSideLeft.Control = BlockNoEdit - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = BlockNoEdit - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - Left = 127 - Height = 25 - Top = 8 - Width = 83 - AutoSize = True - BorderSpacing.Left = 20 - BorderSpacing.Right = 8 - Caption = 'Next Block' - OnClick = NextBlkBtnClick - TabOrder = 1 - end - object InProb: TEdit - AnchorSideTop.Control = NextBlkBtn - AnchorSideTop.Side = asrCenter - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - Left = 413 - Height = 23 - Top = 9 - Width = 44 - Alignment = taRightJustify - Anchors = [akTop, akRight] - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - TabOrder = 2 - Text = 'InProb' - end - object GroupBox1: TGroupBox - AnchorSideLeft.Control = Owner - AnchorSideBottom.Control = Bevel1 - Left = 8 - Height = 114 - Top = 288 - Width = 449 - Anchors = [akLeft, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Right = 8 - Caption = 'Options' - ChildSizing.LeftRightSpacing = 16 - ChildSizing.TopBottomSpacing = 6 - ChildSizing.HorizontalSpacing = 20 - ChildSizing.VerticalSpacing = 2 - ChildSizing.Layout = cclTopToBottomThenLeftToRight - ChildSizing.ControlsPerLine = 4 - ClientHeight = 94 - ClientWidth = 445 - TabOrder = 11 - object CPChkBox: TCheckBox - Left = 16 - Height = 19 - Top = 6 - Width = 198 - Caption = 'Show Cross-Products Matrix' - TabOrder = 0 + ClientHeight = 415 + ClientWidth = 962 + inherited ParamsPanel: TPanel + Height = 399 + Width = 442 + ClientHeight = 399 + ClientWidth = 442 + inherited CloseBtn: TButton + Left = 387 + Top = 374 + TabOrder = 15 end - object CovChkBox: TCheckBox - Left = 16 - Height = 19 - Top = 27 - Width = 198 - Caption = 'Show Variance-Covariance Matrix' + inherited ComputeBtn: TButton + Left = 303 + Top = 374 + TabOrder = 14 + end + inherited ResetBtn: TButton + Left = 241 + Top = 374 + TabOrder = 13 + end + inherited HelpBtn: TButton + Left = 182 + Top = 374 + TabOrder = 12 + end + inherited ButtonBevel: TBevel + Top = 358 + Width = 442 + end + object Label4: TLabel[5] + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = BlockNoEdit + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = BlockNoEdit + Left = 0 + Height = 15 + Top = 5 + Width = 54 + BorderSpacing.Right = 8 + Caption = 'Block No. ' + ParentColor = False + end + object Label5: TLabel[6] + AnchorSideLeft.Control = NextBlkBtn + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = InProb + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = InProb + Left = 227 + Height = 15 + Top = 5 + Width = 163 + Alignment = taRightJustify + Anchors = [akTop, akRight] + BorderSpacing.Right = 8 + Caption = 'Minimum Prob. to enter block:' + ParentColor = False + WordWrap = True + end + object BlockNoEdit: TEdit[7] + AnchorSideLeft.Control = Label4 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = NextBlkBtn + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = NextBlkBtn + Left = 62 + Height = 23 + Top = 1 + Width = 37 + Alignment = taRightJustify + BorderSpacing.Left = 8 + BorderSpacing.Right = 8 + TabOrder = 0 + Text = 'BlockNoEdit' + end + object NextBlkBtn: TButton[8] + AnchorSideLeft.Control = BlockNoEdit + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = ParamsPanel + AnchorSideRight.Control = Owner + AnchorSideRight.Side = asrBottom + Left = 119 + Height = 25 + Top = 0 + Width = 83 + AutoSize = True + BorderSpacing.Left = 20 + BorderSpacing.Right = 8 + Caption = 'Next Block' + OnClick = NextBlkBtnClick TabOrder = 1 end - object CorrsChkBox: TCheckBox - Left = 16 - Height = 19 - Top = 48 - Width = 198 - Caption = 'Show Intercorrelation Matrix' + object InProb: TEdit[9] + AnchorSideTop.Control = NextBlkBtn + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + Left = 398 + Height = 23 + Top = 1 + Width = 44 + Alignment = taRightJustify + Anchors = [akTop, akRight] + BorderSpacing.Top = 8 TabOrder = 2 + Text = 'InProb' end - object MeansChkBox: TCheckBox - Left = 16 - Height = 19 - Top = 69 - Width = 198 - Caption = 'Show Means' + object Label1: TLabel[10] + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = Bevel3 + AnchorSideTop.Side = asrBottom + Left = 0 + Height = 15 + Top = 40 + Width = 97 + BorderSpacing.Top = 8 + Caption = 'Available Variables' + ParentColor = False + end + object Label2: TLabel[11] + AnchorSideLeft.Control = DepVarEdit + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Control = DepVarEdit + Left = 247 + Height = 15 + Top = 65 + Width = 102 + Anchors = [akLeft, akBottom] + BorderSpacing.Top = 8 + BorderSpacing.Bottom = 2 + Caption = 'Dependent Variable' + ParentColor = False + end + object Label3: TLabel[12] + AnchorSideLeft.Control = BlockList + Left = 247 + Height = 15 + Top = 144 + Width = 166 + Caption = 'Independent Var.s for this block' + ParentColor = False + end + object VarList: TListBox[13] + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = Label1 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = AllBtn + AnchorSideBottom.Control = OptionsGroup + Left = 0 + Height = 179 + Top = 57 + Width = 195 + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Top = 2 + BorderSpacing.Right = 6 + BorderSpacing.Bottom = 8 + ItemHeight = 0 + MultiSelect = True + OnDblClick = VarListDblClick + OnSelectionChange = VarListSelectionChange TabOrder = 3 end - object VarChkBox: TCheckBox - Left = 234 - Height = 19 - Top = 6 - Width = 195 - Caption = 'Show Variances' + object DepInBtn: TBitBtn[14] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = VarList + Left = 208 + Height = 26 + Top = 61 + Width = 26 + BorderSpacing.Top = 4 + Images = MainDataModule.ImageList + ImageIndex = 1 + OnClick = DepInBtnClick + Spacing = 0 TabOrder = 4 end - object SDChkBox: TCheckBox - Left = 234 - Height = 19 - Top = 27 - Width = 195 - Caption = 'Show Standard Deviations' + object DepOutBtn: TBitBtn[15] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = DepInBtn + AnchorSideTop.Side = asrBottom + Left = 208 + Height = 26 + Top = 91 + Width = 26 + BorderSpacing.Top = 4 + Images = MainDataModule.ImageList + ImageIndex = 0 + OnClick = DepOutBtnClick + Spacing = 0 TabOrder = 5 end - object MatSaveChkBox: TCheckBox - Left = 234 - Height = 19 - Top = 48 - Width = 195 - Caption = 'Save Correlation Matrix' - TabOrder = 6 - end - object PredictChkBox: TCheckBox - Left = 234 - Height = 19 - Top = 69 - Width = 195 - Caption = 'Predictions,residuals,C.I.''s to Grid' + object InBtn: TBitBtn[16] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = DepOutBtn + AnchorSideTop.Side = asrBottom + Left = 208 + Height = 26 + Top = 149 + Width = 26 + BorderSpacing.Top = 32 + BorderSpacing.Bottom = 4 + Images = MainDataModule.ImageList + ImageIndex = 1 + OnClick = InBtnClick + Spacing = 0 TabOrder = 7 end + object OutBtn: TBitBtn[17] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = InBtn + AnchorSideTop.Side = asrBottom + Left = 208 + Height = 26 + Top = 179 + Width = 26 + Images = MainDataModule.ImageList + ImageIndex = 0 + OnClick = OutBtnClick + Spacing = 0 + TabOrder = 8 + end + object AllBtn: TBitBtn[18] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = OutBtn + AnchorSideTop.Side = asrBottom + Left = 201 + Height = 25 + Top = 209 + Width = 40 + AutoSize = True + BorderSpacing.Top = 4 + Caption = 'All' + OnClick = AllBtnClick + Spacing = 0 + TabOrder = 9 + end + object DepVarEdit: TEdit[19] + AnchorSideLeft.Control = AllBtn + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = DepOutBtn + AnchorSideBottom.Side = asrBottom + Left = 247 + Height = 23 + Top = 82 + Width = 195 + Anchors = [akLeft, akRight, akBottom] + BorderSpacing.Left = 6 + BorderSpacing.Top = 2 + BorderSpacing.Bottom = 12 + ReadOnly = True + TabOrder = 6 + Text = 'DepVarEdit' + end + object BlockList: TListBox[20] + AnchorSideLeft.Control = AllBtn + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = Label3 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = VarList + AnchorSideBottom.Side = asrBottom + Left = 247 + Height = 75 + Top = 161 + Width = 195 + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Left = 6 + BorderSpacing.Top = 2 + ItemHeight = 0 + MultiSelect = True + OnDblClick = BlockListDblClick + OnSelectionChange = VarListSelectionChange + TabOrder = 10 + end + object OptionsGroup: TGroupBox[21] + AnchorSideLeft.Control = ParamsPanel + AnchorSideBottom.Control = ButtonBevel + Left = 0 + Height = 114 + Top = 244 + Width = 449 + Anchors = [akLeft, akBottom] + AutoSize = True + BorderSpacing.Right = 8 + Caption = 'Options' + ChildSizing.LeftRightSpacing = 16 + ChildSizing.TopBottomSpacing = 6 + ChildSizing.HorizontalSpacing = 20 + ChildSizing.VerticalSpacing = 2 + ChildSizing.Layout = cclTopToBottomThenLeftToRight + ChildSizing.ControlsPerLine = 4 + ClientHeight = 94 + ClientWidth = 445 + TabOrder = 11 + object CPChkBox: TCheckBox + Left = 16 + Height = 19 + Top = 6 + Width = 198 + Caption = 'Show Cross-Products Matrix' + TabOrder = 0 + end + object CovChkBox: TCheckBox + Left = 16 + Height = 19 + Top = 27 + Width = 198 + Caption = 'Show Variance-Covariance Matrix' + TabOrder = 1 + end + object CorrsChkBox: TCheckBox + Left = 16 + Height = 19 + Top = 48 + Width = 198 + Caption = 'Show Intercorrelation Matrix' + TabOrder = 2 + end + object MeansChkBox: TCheckBox + Left = 16 + Height = 19 + Top = 69 + Width = 198 + Caption = 'Show Means' + TabOrder = 3 + end + object VarChkBox: TCheckBox + Left = 234 + Height = 19 + Top = 6 + Width = 195 + Caption = 'Show Variances' + TabOrder = 4 + end + object SDChkBox: TCheckBox + Left = 234 + Height = 19 + Top = 27 + Width = 195 + Caption = 'Show Standard Deviations' + TabOrder = 5 + end + object MatSaveChkBox: TCheckBox + Left = 234 + Height = 19 + Top = 48 + Width = 195 + Caption = 'Save Correlation Matrix' + TabOrder = 6 + end + object PredictChkBox: TCheckBox + Left = 234 + Height = 19 + Top = 69 + Width = 195 + Caption = 'Predictions,residuals,C.I.''s to Grid' + TabOrder = 7 + end + end + object Bevel3: TBevel[22] + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = Label5 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = CloseBtn + Left = 0 + Height = 12 + Top = 20 + Width = 442 + Anchors = [akTop, akLeft, akRight] + Shape = bsBottomLine + end end - object ResetBtn: TButton - AnchorSideRight.Control = ComputeBtn - AnchorSideBottom.Control = Owner - AnchorSideBottom.Side = asrBottom - Left = 256 - Height = 25 - Top = 418 - Width = 54 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Caption = 'Reset' - OnClick = ResetBtnClick - TabOrder = 12 + inherited ParamsSplitter: TSplitter + Left = 454 + Height = 415 end - object ComputeBtn: TButton - AnchorSideRight.Control = CloseBtn - AnchorSideBottom.Control = Owner - AnchorSideBottom.Side = asrBottom - Left = 318 - Height = 25 - Top = 418 - Width = 76 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 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 = 402 - Height = 25 - Top = 418 - 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 = 402 - Width = 465 - Anchors = [akLeft, akRight, akBottom] - Shape = bsBottomLine - end - object Bevel3: TBevel - AnchorSideLeft.Control = Owner - AnchorSideTop.Control = Label5 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = CloseBtn - Left = 0 - Height = 12 - Top = 28 - Width = 465 - Anchors = [akTop, akLeft, akRight] - Shape = bsBottomLine - end - object SaveDialog1: TSaveDialog + object SaveDialog1: TSaveDialog[2] Left = 72 Top = 112 end diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/blkmregunit.pas b/applications/lazstats/source/forms/analysis/multiple_regression/blkmregunit.pas index 6cc6c85c7..a961ca082 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/blkmregunit.pas +++ b/applications/lazstats/source/forms/analysis/multiple_regression/blkmregunit.pas @@ -9,22 +9,16 @@ unit BlkMRegUnit; interface uses - Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, - StdCtrls, Buttons, ExtCtrls, - Globals, MainUnit, MatrixLib, OutputUnit, FunctionsLib, - DataProcs, DictionaryUnit; + Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Buttons, ExtCtrls, + Globals, MainUnit, MatrixLib, FunctionsLib, DataProcs, DictionaryUnit, BasicStatsReportFormUnit; type - { TBlkMregFrm } + { TBlkMregForm } - TBlkMregFrm = class(TForm) - Bevel1: TBevel; + TBlkMregForm = class(TBasicStatsReportForm) Bevel3: TBevel; - ResetBtn: TButton; - ComputeBtn: TButton; - CloseBtn: TButton; CPChkBox: TCheckBox; CovChkBox: TCheckBox; CorrsChkBox: TCheckBox; @@ -34,7 +28,7 @@ type SDChkBox: TCheckBox; MatSaveChkBox: TCheckBox; PredictChkBox: TCheckBox; - GroupBox1: TGroupBox; + OptionsGroup: TGroupBox; InProb: TEdit; Label5: TLabel; NextBlkBtn: TButton; @@ -45,107 +39,77 @@ type Label4: TLabel; OutBtn: TBitBtn; AllBtn: TBitBtn; - DepVar: TEdit; + DepVarEdit: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; BlockList: TListBox; VarList: TListBox; procedure AllBtnClick(Sender: TObject); - procedure ComputeBtnClick(Sender: TObject); + procedure BlockListDblClick(Sender: TObject); procedure DepInBtnClick(Sender: TObject); procedure DepOutBtnClick(Sender: TObject); - procedure FormActivate(Sender: TObject); - procedure FormCreate(Sender: TObject); - procedure FormShow(Sender: TObject); procedure InBtnClick(Sender: TObject); procedure NextBlkBtnClick(Sender: TObject); procedure OutBtnClick(Sender: TObject); - procedure ResetBtnClick(Sender: TObject); + procedure VarListDblClick(Sender: TObject); procedure VarListSelectionChange(Sender: TObject; User: boolean); private - { private declarations } - FAutoSized: Boolean; BlkVarCols : IntDyneMat; NoBlocks : integer; VarsInBlk : IntDyneVec; NoVars : integer; - procedure UpdateBtnStates; - function Valid(out AMsg: String; out AControl: TWinControl): Boolean; + + 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 - BlkMregFrm: TBlkMregFrm; + BlkMregForm: TBlkMregForm; + implementation +{$R *.lfm} + uses Math, Utils, MathUnit; -{ TBlkMregFrm } -procedure TBlkMregFrm.ResetBtnClick(Sender: TObject); -var - i: integer; -begin - BlockList.Items.Clear; - VarList.Items.Clear; - BlockNoEdit.Text := '1'; - NoBlocks := 1; - for i := 1 to NoVariables do - VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); - - CPChkBox.Checked := false; - CovChkBox.Checked := false; - CorrsChkBox.Checked := true; - MeansChkBox.Checked := true; - VarChkBox.Checked := false; - SDChkBox.Checked := true; - MatSaveChkBox.Checked := false; - PredictChkBox.Checked := false; -// HeteroChk.Checked := false; - - NoVars := 0; - DepVar.Text := ''; - InProb.Text := FormatFloat('0.00', DEFAULT_ALPHA_LEVEL); - - SetLength(BlkVarCols,NoVariables,NoVariables); - SetLength(VarsInBlk,NoVariables); -end; - -procedure TBlkMregFrm.FormActivate(Sender: TObject); -var - w: Integer; -begin - if FAutoSized then - exit; - - w := MaxValue([ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]); - ResetBtn.Constraints.MinWidth := w; - ComputeBtn.Constraints.MinWidth := w; - CloseBtn.Constraints.MinWidth := w; - - Constraints.MinWidth := Width; - Constraints.MinHeight := Height; - - FAutoSized := true; -end; - -procedure TBlkMregFrm.FormCreate(Sender: TObject); +{ TBlkMregForm } + +constructor TBlkMregForm.Create(AOwner: TComponent); begin + inherited; + Assert(OS3MainFrm <> nil); if DictionaryFrm = nil then Application.CreateForm(TDictionaryFrm, DictionaryFrm); end; -procedure TBlkMregFrm.FormShow(Sender: TObject); + +procedure TBlkMregForm.AdjustConstraints; begin - ResetBtnClick(self); + inherited; + + ParamsPanel.Constraints.MinWidth := Max( + 4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left, + OptionsGroup.Width); + + ParamsPanel.Constraints.MinHeight := AllBtn.Top + AllBtn.Height + + VarList.BorderSpacing.Bottom + ButtonBevel.Height + + CloseBtn.BorderSpacing.Top + CloseBtn.Height; end; -procedure TBlkMregFrm.AllBtnClick(Sender: TObject); + +procedure TBlkMregForm.AllBtnClick(Sender: TObject); var index: integer; begin @@ -155,7 +119,22 @@ begin UpdateBtnStates; end; -procedure TBlkMregFrm.ComputeBtnClick(Sender: TObject); + +procedure TBlkMregForm.BlockListDblClick(Sender: TObject); +var + index: Integer; +begin + index := BlockList.ItemIndex; + if index > -1 then + begin + VarList.Items.Add(BlockList.Items[index]); + BlockList.Items.Delete(index); + UpdatebtnStates; + end; +end; + + +procedure TBlkMregForm.Compute; var i, j, k, errorcode: integer; NoIndepVars, DepVarCol, NEntered, StepNo : integer; @@ -182,13 +161,6 @@ var C: TWinControl; lReport: TStrings; begin - if not Valid(msg, C) then - begin - C.SetFocus; - MessageDlg(msg, mtError, [mbOK], 0); - exit; - end; - SetLength(corrs,NoVariables+1,NoVariables+1); SetLength(IndepInverse,NoVariables,NoVariables); SetLength(Means,NoVariables); @@ -211,7 +183,7 @@ begin errorcode := 0; { get dependendent variable column } - if DepVar.Text = '' then + if DepVarEdit.Text = '' then begin MessageDlg('No Dependent variable selected.', mtError, [mbOK], 0); exit; @@ -226,7 +198,7 @@ begin DepVarCol := 0; NoVars := NoVars + 1; for j := 1 to NoVariables do - if DepVar.Text = OS3MainFrm.DataGrid.Cells[j,0] then DepVarCol := j; + if DepVarEdit.Text = OS3MainFrm.DataGrid.Cells[j,0] then DepVarCol := j; R2 := 0.0; OldR2 := 0.0; @@ -300,7 +272,7 @@ begin if errorcode > 0 then begin - DisplayReport(lReport); + FReportFrame.DisplayReport(lReport); MessageDlg('A selected variable has no variability-run aborted.', mtError,[mbOK], 0); exit; end; @@ -424,7 +396,7 @@ begin lReport.Add(''); end; } - DisplayReport(lReport); + FReportFrame.DisplayReport(lReport); if MatSaveChkBox.Checked then begin @@ -439,46 +411,36 @@ begin finally lReport.Free; - ColEntered := nil; - Candidate := nil; - BetaWeights := nil; - IndColLabels := nil; - IndRowLabels := nil; - IndepIndex := nil; - StdDevs := nil; - Variances := nil; - Means := nil; - IndepInverse := nil; - corrs := nil; - VarsInBlk := nil; - BlkVarCols := nil; end; end; -procedure TBlkMregFrm.DepInBtnClick(Sender: TObject); + +procedure TBlkMregForm.DepInBtnClick(Sender: TObject); var index: integer; begin index := VarList.ItemIndex; - if (index > -1) and (DepVar.Text = '') then + if (index > -1) and (DepVarEdit.Text = '') then begin - DepVar.Text := VarList.Items[index]; + DepVarEdit.Text := VarList.Items[index]; VarList.Items.Delete(index); end; UpdateBtnStates; end; -procedure TBlkMregFrm.DepOutBtnClick(Sender: TObject); + +procedure TBlkMregForm.DepOutBtnClick(Sender: TObject); begin - if DepVar.Text <> '' then + if DepVarEdit.Text <> '' then begin - VarList.Items.Add(DepVar.Text); - DepVar.Text := ''; + VarList.Items.Add(DepVarEdit.Text); + DepVarEdit.Text := ''; end; UpdateBtnStates; end; -procedure TBlkMregFrm.InBtnClick(Sender: TObject); + +procedure TBlkMregForm.InBtnClick(Sender: TObject); var i: integer; begin @@ -496,7 +458,8 @@ begin UpdateBtnStates; end; -procedure TBlkMregFrm.NextBlkBtnClick(Sender: TObject); + +procedure TBlkMregForm.NextBlkBtnClick(Sender: TObject); var blkno, i, j, count: integer; cellstring: string; @@ -530,7 +493,8 @@ begin //BlockList.Clear; end; -procedure TBlkMregFrm.OutBtnClick(Sender: TObject); + +procedure TBlkMregForm.OutBtnClick(Sender: TObject); var i: integer; begin @@ -548,21 +512,56 @@ begin UpdateBtnStates; end; -procedure TBlkMregFrm.UpdateBtnStates; + +procedure TBlkMregForm.Reset; +var + i: integer; +begin + inherited; + + BlockList.Items.Clear; + VarList.Items.Clear; + BlockNoEdit.Text := '1'; + NoBlocks := 1; + for i := 1 to NoVariables do + VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); + + CPChkBox.Checked := false; + CovChkBox.Checked := false; + CorrsChkBox.Checked := false; + MeansChkBox.Checked := false; + VarChkBox.Checked := false; + SDChkBox.Checked := false; + MatSaveChkBox.Checked := false; + PredictChkBox.Checked := false; + + NoVars := 0; + DepVarEdit.Text := ''; + InProb.Text := FormatFloat('0.00', DEFAULT_ALPHA_LEVEL); + + SetLength(BlkVarCols, NoVariables, NoVariables); + SetLength(VarsInBlk, NoVariables); +end; + + +procedure TBlkMregForm.UpdateBtnStates; var lSelected: Boolean; begin - lSelected := AnySelected(VarList); - DepInBtn.Enabled := lSelected and (DepVar.Text = ''); - InBtn.Enabled := lSelected; + inherited; + + lSelected := AnySelected(VarList); + DepInBtn.Enabled := lSelected and (DepVarEdit.Text = ''); + InBtn.Enabled := lSelected; - DepOutBtn.Enabled := (DepVar.Text <> ''); - OutBtn.Enabled := AnySelected(BlockList); + DepOutBtn.Enabled := (DepVarEdit.Text <> ''); + OutBtn.Enabled := AnySelected(BlockList); - AllBtn.Enabled := VarList.Items.Count > 0; + AllBtn.Enabled := VarList.Items.Count > 0; end; -function TBlkMregFrm.Valid(out AMsg: String; out AControl: TWinControl): Boolean; + +function TBlkMregForm.Validate(out AMsg: String; out AControl: TWinControl): Boolean; var n: Integer; x: Double; @@ -610,14 +609,29 @@ begin Result := true; end; -procedure TBlkMregFrm.VarListSelectionChange(Sender: TObject; User: boolean); + +procedure TBlkMregForm.VarListDblClick(Sender: TObject); +var + index: Integer; +begin + index := VarList.ItemIndex; + if index > -1 then + begin + if DepVarEdit.Text = '' then + DepVarEdit.Text := VarList.Items[index] + else + BlockList.Items.Add(VarList.Items[index]); + VarList.Items.Delete(index); + UpdateBtnStates; + end; +end; + + +procedure TBlkMregForm.VarListSelectionChange(Sender: TObject; User: boolean); begin UpdateBtnStates; end; -initialization - {$I blkmregunit.lrs} - end. diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/coxregunit.lfm b/applications/lazstats/source/forms/analysis/multiple_regression/coxregunit.lfm index b84964d51..5871de490 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/coxregunit.lfm +++ b/applications/lazstats/source/forms/analysis/multiple_regression/coxregunit.lfm @@ -1,409 +1,316 @@ -object CoxRegFrm: TCoxRegFrm +inherited CoxRegForm: TCoxRegForm Left = 457 - Height = 401 + Height = 393 Top = 291 - Width = 424 + Width = 480 HelpType = htKeyword HelpKeyword = 'html/CoxProportionalHazardsSurvivalRe.htm' - AutoSize = True Caption = 'Cox Proportional Hazards Survival Regression' - ClientHeight = 401 - ClientWidth = 424 - 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 = 9 - Width = 89 - BorderSpacing.Left = 8 - BorderSpacing.Top = 9 - Caption = 'Avaialbe Variable' - ParentColor = False - end - object Label2: TLabel - AnchorSideLeft.Control = BlockList - AnchorSideTop.Control = Owner - Left = 234 - Height = 15 - Top = 8 - Width = 116 - BorderSpacing.Top = 8 - Caption = 'Independent Variables' - ParentColor = False - end - object Label3: TLabel - AnchorSideLeft.Control = DepVar - AnchorSideBottom.Control = DepVar - Left = 234 - Height = 15 - Top = 108 - Width = 114 - Anchors = [akLeft, akBottom] - BorderSpacing.Bottom = 2 - Caption = 'Survival Time Variable' - ParentColor = False - end - object Label4: TLabel - AnchorSideLeft.Control = StatusEdit - AnchorSideBottom.Control = StatusEdit - Left = 234 - Height = 15 - Top = 195 - Width = 120 - Anchors = [akLeft, akBottom] - BorderSpacing.Bottom = 2 - Caption = 'Survival Status Variable' - ParentColor = False - end - object Label5: TLabel - AnchorSideLeft.Control = GroupBox1 - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = GroupBox1 - AnchorSideTop.Side = asrCenter - Left = 219 - Height = 15 - Top = 296 - Width = 117 - BorderSpacing.Left = 40 - Caption = 'Maximum Interations:' - ParentColor = False - end - object VarList: TListBox - AnchorSideLeft.Control = Owner - AnchorSideTop.Control = Label1 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = InBtn - AnchorSideBottom.Control = GroupBox1 - Left = 8 - Height = 221 - Top = 26 - Width = 182 - Anchors = [akTop, akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Top = 2 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Constraints.MinHeight = 220 - ItemHeight = 0 - MultiSelect = True - OnSelectionChange = VarListSelectionChange - TabOrder = 0 - end - object InBtn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = VarList - Left = 198 - Height = 28 - Top = 26 - Width = 28 - Glyph.Data = { - 36040000424D3604000000000000360000002800000010000000100000000100 - 2000000000000004000064000000640000000000000000000000FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00216324B81D5E2006FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF002A702F38256929F7216324D9FFFFFF00FFFFFF00FFFFFF00FFFFFF0061BE - 6DFF5DB868FF58B162FF53A95CFF4DA156FF47994FFF419149FF3B8842FF3580 - 3BFF3F8845FF59A15EFF448B49FF216324CFFFFFFF00FFFFFF00FFFFFF0065C3 - 71FFA0D7A9FF9CD5A5FF98D3A1FF94D09DFF90CE98FF8BCB93FF87C98EFF82C6 - 89FF7EC384FF7AC180FF76BE7CFF458C4AFF216324C4FFFFFF00FFFFFF0068C7 - 74FFA5DAAEFFA2D8ABFF9ED6A7FF9AD4A3FF96D29FFF93CF9AFF8ECC95FF89CA - 90FF85C78BFF81C587FF7DC282FF4A9150FF256929C9FFFFFF00FFFFFF0068C7 - 74FF68C774FF65C371FF61BE6DFF5DB868FF58B162FF53A95CFF4DA156FF4799 - 4FFF419149FF5AA362FF559D5CFF2F7835D1FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00419149F73B8842DBFFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF0047994FBB41914906FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF - FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00 - } - Images = MainDataModule.ImageList - ImageIndex = 1 - OnClick = InBtnClick - Spacing = 0 - TabOrder = 1 - end - object OutBtn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = InBtn - AnchorSideTop.Side = asrBottom - Left = 198 - Height = 28 - Top = 58 - Width = 28 - BorderSpacing.Top = 4 - Images = MainDataModule.ImageList - ImageIndex = 0 - OnClick = OutBtnClick - Spacing = 0 - TabOrder = 2 - end - object DepInBtn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = Label3 - Left = 198 - Height = 28 - Top = 108 - Width = 28 - Images = MainDataModule.ImageList - ImageIndex = 1 - OnClick = DepInBtnClick - Spacing = 0 - TabOrder = 4 - end - object DepOutBtn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = DepInBtn - AnchorSideTop.Side = asrBottom - Left = 198 - Height = 28 - Top = 140 - Width = 28 - BorderSpacing.Top = 4 - Images = MainDataModule.ImageList - ImageIndex = 0 - OnClick = DepOutBtnClick - Spacing = 0 - TabOrder = 5 - end - object StatusInBtn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - AnchorSideBottom.Control = StatusOutBtn - Left = 198 - Height = 28 - Top = 187 - Width = 28 - Anchors = [akLeft, akBottom] - BorderSpacing.Bottom = 4 - Images = MainDataModule.ImageList - ImageIndex = 1 - OnClick = StatusInBtnClick - Spacing = 0 - TabOrder = 7 - end - object StatusOutBtn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Side = asrBottom - AnchorSideBottom.Control = VarList - AnchorSideBottom.Side = asrBottom - Left = 198 - Height = 28 - Top = 219 - Width = 28 - Anchors = [akLeft, akBottom] - Images = MainDataModule.ImageList - ImageIndex = 0 - OnClick = StatusOutBtnClick - Spacing = 0 - TabOrder = 8 - end - object BlockList: TListBox - AnchorSideLeft.Control = InBtn - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = Label2 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = Label3 - Left = 234 - Height = 67 - Top = 25 - Width = 182 - Anchors = [akTop, akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Top = 2 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 16 - ItemHeight = 0 - OnSelectionChange = VarListSelectionChange - TabOrder = 3 - end - object DepVar: TEdit - AnchorSideLeft.Control = InBtn - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = VarList - AnchorSideTop.Side = asrCenter - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - Left = 234 - Height = 23 - Top = 125 - Width = 182 - Anchors = [akTop, akLeft, akRight] - BorderSpacing.Left = 8 - BorderSpacing.Right = 8 - ReadOnly = True - TabOrder = 6 - Text = 'DepVar' - end - object StatusEdit: TEdit - AnchorSideLeft.Control = DepInBtn - AnchorSideLeft.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = StatusOutBtn - AnchorSideBottom.Side = asrBottom - Left = 234 - Height = 23 - Top = 212 - Width = 182 - Anchors = [akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 12 - ReadOnly = True - TabOrder = 9 - Text = 'StatusEdit' - end - object GroupBox1: TGroupBox - AnchorSideLeft.Control = Owner - AnchorSideBottom.Control = Bevel1 - Left = 8 - Height = 97 - Top = 255 - Width = 171 - Anchors = [akLeft, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - Caption = 'Options' - ChildSizing.LeftRightSpacing = 12 - ChildSizing.TopBottomSpacing = 6 - ChildSizing.VerticalSpacing = 2 - ClientHeight = 77 - ClientWidth = 167 - TabOrder = 10 - object DescChk: TCheckBox - Left = 12 - Height = 19 - Top = 6 + ClientHeight = 393 + ClientWidth = 480 + inherited ParamsPanel: TPanel + Height = 377 + ClientHeight = 377 + inherited CloseBtn: TButton + Top = 352 + end + inherited ComputeBtn: TButton + Top = 352 + end + inherited ResetBtn: TButton + Top = 352 + end + inherited HelpBtn: TButton + Top = 352 + end + inherited ButtonBevel: TBevel + Top = 336 + end + object Label1: TLabel[5] + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = ParamsPanel + Left = 0 + Height = 15 + Top = 0 + Width = 94 + Caption = 'Availabe Variables' + ParentColor = False + end + object Label2: TLabel[6] + AnchorSideLeft.Control = BlockList + AnchorSideTop.Control = ParamsPanel + Left = 164 + Height = 15 + Top = 8 + Width = 116 + BorderSpacing.Top = 8 + Caption = 'Independent Variables' + ParentColor = False + end + object Label3: TLabel[7] + AnchorSideLeft.Control = DepVar + AnchorSideBottom.Control = DepVar + Left = 166 + Height = 15 + Top = 80 + Width = 114 + Anchors = [akLeft, akBottom] + BorderSpacing.Bottom = 2 + Caption = 'Survival Time Variable' + ParentColor = False + end + object Label4: TLabel[8] + AnchorSideLeft.Control = StatusEdit + AnchorSideBottom.Control = StatusEdit + Left = 166 + Height = 15 + Top = 148 + Width = 120 + Anchors = [akLeft, akBottom] + BorderSpacing.Bottom = 2 + Caption = 'Survival Status Variable' + ParentColor = False + end + object Label5: TLabel[9] + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = MaxItsEdit + AnchorSideTop.Side = asrCenter + Left = 0 + Height = 15 + Top = 212 + Width = 117 + Caption = 'Maximum Interations:' + ParentColor = False + end + object VarList: TListBox[10] + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = Label1 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = InBtn + AnchorSideBottom.Control = MaxItsEdit + Left = 0 + Height = 183 + 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 = 4 + end + object InBtn: TBitBtn[11] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = VarList + Left = 132 + Height = 26 + Top = 17 + Width = 26 + Images = MainDataModule.ImageList + ImageIndex = 1 + OnClick = InBtnClick + Spacing = 0 + TabOrder = 5 + end + object OutBtn: TBitBtn[12] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = InBtn + AnchorSideTop.Side = asrBottom + Left = 132 + Height = 26 + Top = 47 + Width = 26 + BorderSpacing.Top = 4 + Images = MainDataModule.ImageList + ImageIndex = 0 + OnClick = OutBtnClick + Spacing = 0 + TabOrder = 6 + end + object DepInBtn: TBitBtn[13] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = Label3 + Left = 132 + Height = 26 + Top = 80 + Width = 26 + Images = MainDataModule.ImageList + ImageIndex = 1 + OnClick = DepInBtnClick + Spacing = 0 + TabOrder = 7 + end + object DepOutBtn: TBitBtn[14] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = DepInBtn + AnchorSideTop.Side = asrBottom + Left = 132 + Height = 26 + Top = 110 + Width = 26 + BorderSpacing.Top = 4 + Images = MainDataModule.ImageList + ImageIndex = 0 + OnClick = DepOutBtnClick + Spacing = 0 + TabOrder = 8 + end + object StatusInBtn: TBitBtn[15] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideBottom.Control = StatusOutBtn + Left = 132 + Height = 26 + Top = 144 + Width = 26 + Anchors = [akLeft, akBottom] + BorderSpacing.Bottom = 4 + Images = MainDataModule.ImageList + ImageIndex = 1 + OnClick = StatusInBtnClick + Spacing = 0 + TabOrder = 9 + end + object StatusOutBtn: TBitBtn[16] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Control = VarList + AnchorSideBottom.Side = asrBottom + Left = 132 + Height = 26 + Top = 174 + Width = 26 + Anchors = [akLeft, akBottom] + Images = MainDataModule.ImageList + ImageIndex = 0 + OnClick = StatusOutBtnClick + Spacing = 0 + TabOrder = 10 + end + object BlockList: TListBox[17] + AnchorSideLeft.Control = InBtn + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = Label2 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = Label3 + Left = 164 + Height = 39 + Top = 25 Width = 127 - Caption = 'Descriptive Statistics' - TabOrder = 0 + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Left = 6 + BorderSpacing.Top = 2 + BorderSpacing.Bottom = 16 + ItemHeight = 0 + OnDblClick = BlockListDblClick + OnSelectionChange = VarListSelectionChange + TabOrder = 11 end - object ProbsChk: TCheckBox - Left = 12 - Height = 19 - Top = 29 - Width = 143 - Caption = 'Base Survival Functions' - TabOrder = 1 + object DepVar: TEdit[18] + AnchorSideLeft.Control = InBtn + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = VarList + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + Left = 166 + Height = 23 + Top = 97 + Width = 125 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Left = 8 + ReadOnly = True + TabOrder = 12 + Text = 'DepVar' end - object ItersChk: TCheckBox - Left = 12 - Height = 19 - Top = 52 - Width = 101 - Caption = 'Show Iterations' - TabOrder = 2 + object StatusEdit: TEdit[19] + AnchorSideLeft.Control = DepInBtn + AnchorSideLeft.Side = asrBottom + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = StatusOutBtn + AnchorSideBottom.Side = asrBottom + Left = 166 + Height = 23 + Top = 165 + Width = 125 + Anchors = [akLeft, akRight, akBottom] + BorderSpacing.Left = 8 + BorderSpacing.Bottom = 12 + ReadOnly = True + TabOrder = 13 + Text = 'StatusEdit' + end + object GroupBox1: TGroupBox[20] + AnchorSideLeft.Control = ParamsPanel + AnchorSideBottom.Control = ButtonBevel + Left = 0 + Height = 97 + Top = 239 + Width = 171 + Anchors = [akLeft, akBottom] + AutoSize = True + Caption = 'Options' + ChildSizing.LeftRightSpacing = 12 + ChildSizing.TopBottomSpacing = 6 + ChildSizing.VerticalSpacing = 2 + ClientHeight = 77 + ClientWidth = 167 + TabOrder = 14 + object DescChk: TCheckBox + Left = 12 + Height = 19 + Top = 6 + Width = 127 + Caption = 'Descriptive Statistics' + TabOrder = 0 + end + object ProbsChk: TCheckBox + Left = 12 + Height = 19 + Top = 29 + Width = 143 + Caption = 'Base Survival Functions' + TabOrder = 1 + end + object ItersChk: TCheckBox + Left = 12 + Height = 19 + Top = 52 + Width = 101 + Caption = 'Show Iterations' + TabOrder = 2 + end + end + object MaxItsEdit: TEdit[21] + AnchorSideLeft.Control = Label5 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Control = GroupBox1 + Left = 125 + Height = 23 + Top = 208 + Width = 42 + Alignment = taRightJustify + Anchors = [akLeft, akBottom] + BorderSpacing.Left = 8 + BorderSpacing.Right = 8 + BorderSpacing.Bottom = 8 + TabOrder = 15 + Text = 'MaxItsEdit' end end - object MaxItsEdit: TEdit - AnchorSideLeft.Control = Label5 - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = Label5 - AnchorSideTop.Side = asrCenter - Left = 344 - Height = 23 - Top = 292 - Width = 42 - Alignment = taRightJustify - BorderSpacing.Left = 8 - BorderSpacing.Right = 8 - TabOrder = 11 - Text = 'MaxItsEdit' - end - object ResetBtn: TButton - AnchorSideRight.Control = ComputeBtn - AnchorSideBottom.Control = Owner - AnchorSideBottom.Side = asrBottom - Left = 215 - Height = 25 - Top = 368 - Width = 54 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 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 = 277 - Height = 25 - Top = 368 - Width = 76 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 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 = 361 - Height = 25 - Top = 368 - 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 = 352 - Width = 424 - Anchors = [akLeft, akRight, akBottom] - Shape = bsBottomLine + inherited ParamsSplitter: TSplitter + Height = 393 end end diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/coxregunit.pas b/applications/lazstats/source/forms/analysis/multiple_regression/coxregunit.pas index ab61549e9..a4c3a2b74 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/coxregunit.pas +++ b/applications/lazstats/source/forms/analysis/multiple_regression/coxregunit.pas @@ -5,26 +5,22 @@ unit CoxRegUnit; interface uses - Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Buttons, ExtCtrls, - Globals, MainUnit, OutputUnit; + Globals, MainUnit, BasicStatsReportFormUnit; type - { TCoxRegFrm } + { TCoxRegForm } - TCoxRegFrm = class(TForm) - Bevel1: TBevel; + TCoxRegForm = class(TBasicStatsReportForm) InBtn: TBitBtn; OutBtn: TBitBtn; DepInBtn: TBitBtn; DepOutBtn: TBitBtn; StatusInBtn: TBitBtn; StatusOutBtn: TBitBtn; - ResetBtn: TButton; - ComputeBtn: TButton; - CloseBtn: TButton; DescChk: TCheckBox; MaxItsEdit: TEdit; Label5: TLabel; @@ -39,131 +35,98 @@ type Label3: TLabel; Label4: TLabel; VarList: TListBox; - procedure ComputeBtnClick(Sender: TObject); + procedure BlockListDblClick(Sender: TObject); procedure DepInBtnClick(Sender: TObject); procedure DepOutBtnClick(Sender: TObject); - procedure FormActivate(Sender: TObject); - procedure FormCreate(Sender: TObject); - procedure FormShow(Sender: TObject); procedure InBtnClick(Sender: TObject); procedure OutBtnClick(Sender: TObject); - procedure ResetBtnClick(Sender: TObject); procedure StatusInBtnClick(Sender: TObject); procedure StatusOutBtnClick(Sender: TObject); function ChiSq(x : double; n : integer) : double; function Norm(z : double): double; function ix(j, k, nCols : integer): integer; + procedure VarListDblClick(Sender: TObject); procedure VarListSelectionChange(Sender: TObject; User: boolean); private { private declarations } - FAutoSized: Boolean; - procedure UpdateBtnStates; + + protected + procedure AdjustConstraints; override; + procedure Compute; override; + procedure UpdateBtnStates; override; + public - { public declarations } + procedure Reset; override; end; var - CoxRegFrm: TCoxRegFrm; + CoxRegForm: TCoxRegForm; implementation +{$R *.lfm} + uses Math, Utils; -{ TCoxRegFrm } +{ TCoxRegForm } -procedure TCoxRegFrm.ResetBtnClick(Sender: TObject); +procedure TCoxRegForm.AdjustConstraints; +begin + inherited; + ParamsPanel.Constraints.MinWidth := Max( + 4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left, + GroupBox1.Width); + ParamsPanel.Constraints.MinHeight := InBtn.Top + 6*InBtn.Height + 7*OutBtn.BorderSpacing.Top + + VarList.BorderSpacing.Bottom + MaxItsEdit.Height + MaxItsEdit.BorderSpacing.Bottom + + GroupBox1.Height + ButtonBevel.Height + CloseBtn.BorderSpacing.Top + CloseBtn.Height; +end; + +procedure TCoxRegForm.BlockListDblClick(Sender: TObject); var - i: integer; + index: Integer; begin - BlockList.Clear; - VarList.Clear; - for i := 1 to NoVariables do - VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); - ProbsChk.Checked := true; - DescChk.Checked := true; - DepVar.Text := ''; - StatusEdit.Text := ''; - MaxItsEdit.Text := '20'; + index := BlockList.ItemIndex; + if index > -1 then + begin + VarList.Items.Add(BlockList.Items[index]); + BlockList.Items.Delete(index); + UpdateBtnStates; + end; end; -procedure TCoxRegFrm.StatusInBtnClick(Sender: TObject); + +function TCoxRegForm.ChiSq(x: double; n: integer): double; var - index: integer; + p, t, a: double; + k: integer; begin - index := VarList.ItemIndex; - if (index > -1) and (StatusEdit.Text = '') then + p := exp(-0.5 * x); + if n mod 2 = 1 then + p := p * sqrt(2 * x / Pi); + + k := n; + while K >= 2 do begin - StatusEdit.Text := VarList.Items[index]; - VarList.Items.Delete(index); + p := p * x / k; + k := k - 2; end; - UpdateBtnStates; -end; -procedure TCoxRegFrm.StatusOutBtnClick(Sender: TObject); -begin - if (StatusEdit.Text <> '') then + t := p; + a := n; + while t > 0.000001 * p do begin - VarList.Items.Add(StatusEdit.Text); - StatusEdit.Text := ''; + a := a + 2; + t := t * x / a; + p := p + t; end; - UpdateBtnStates; + Result := (1 - p); end; -procedure TCoxRegFrm.FormActivate(Sender: TObject); -var - w: Integer; -begin - if FAutoSized then - exit; - w := MaxValue([ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]); - ResetBtn.Constraints.MinWidth := w; - ComputeBtn.Constraints.MinWidth := w; - CloseBtn.Constraints.MinWidth := w; - - Constraints.MinWidth := Width; - Constraints.MinHeight := Height; - - FAutoSized := true; -end; - -procedure TCoxRegFrm.FormCreate(Sender: TObject); -begin - Assert(OS3MainFrm <> nil); -end; - -procedure TCoxRegFrm.FormShow(Sender: TObject); -begin - ResetBtnClick(Self); -end; - -procedure TCoxRegFrm.DepInBtnClick(Sender: TObject); -var - index: integer; -begin - index := VarList.ItemIndex; - if (index > -1) and (DepVar.Text = '') then - begin - DepVar.Text := VarList.Items[index]; - VarList.Items.Delete(index); - end; - UpdateBtnStates; -end; - -procedure TCoxRegFrm.DepOutBtnClick(Sender: TObject); -begin - if DepVar.Text <> '' then - begin - VarList.Items.Add(DepVar.Text); - DepVar.Text := ''; - end; - UpdateBtnStates; -end; - -procedure TCoxRegFrm.ComputeBtnClick(Sender: TObject); +procedure TCoxRegForm.Compute; var i, j, k : integer; indx : integer; @@ -524,30 +487,40 @@ begin end; end; - DisplayReport(lReport); + FReportFrame.DisplayReport(lReport); finally lReport.Free; - - SurvT := nil; - Stat := nil; - Alpha := nil; - x := nil; - b := nil; - a := nil; - s1 := nil; - s2 := nil; - s := nil; - Av := nil; - SD := nil; - SE := nil; - RowLabels := nil; - ColLabels := nil; - ColNoSelected := nil; end; end; -procedure TCoxRegFrm.InBtnClick(Sender: TObject); + +procedure TCoxRegForm.DepInBtnClick(Sender: TObject); +var + index: integer; +begin + index := VarList.ItemIndex; + if (index > -1) and (DepVar.Text = '') then + begin + DepVar.Text := VarList.Items[index]; + VarList.Items.Delete(index); + end; + UpdateBtnStates; +end; + + +procedure TCoxRegForm.DepOutBtnClick(Sender: TObject); +begin + if DepVar.Text <> '' then + begin + VarList.Items.Add(DepVar.Text); + DepVar.Text := ''; + end; + UpdateBtnStates; +end; + + +procedure TCoxRegForm.InBtnClick(Sender: TObject); var i: integer; begin @@ -565,66 +538,87 @@ begin UpdateBtnStates; end; -procedure TCoxRegFrm.OutBtnClick(Sender: TObject); + +function TCoxRegForm.ix(j, k, nCols : integer): integer; +begin + Result := j*nCols + k; +end; + + +function TCoxRegForm.Norm(z: double): double; +begin + Result := ChiSq(z*z, 1); +end; + + +procedure TCoxRegForm.OutBtnClick(Sender: TObject); var i: integer; begin i := 0; while i < BlockList.Items.Count do begin - if BlockList.Selected[i] then + if BlockList.Selected[i] then + begin + VarList.Items.Add(BlockList.Items[i]); + BlockList.Items.Delete(i); + i := 0; + end else + i := i + 1; + UpdateBtnStates; + end; +end; + + +procedure TCoxRegForm.Reset; +var + i: integer; +begin + inherited; + + BlockList.Clear; + VarList.Clear; + for i := 1 to NoVariables do + VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); + ProbsChk.Checked := true; + DescChk.Checked := true; + DepVar.Text := ''; + StatusEdit.Text := ''; + MaxItsEdit.Text := '20'; +end; + + +procedure TCoxRegForm.StatusInBtnClick(Sender: TObject); +var + index: integer; +begin + index := VarList.ItemIndex; + if (index > -1) and (StatusEdit.Text = '') then begin - VarList.Items.Add(BlockList.Items[i]); - BlockList.Items.Delete(i); - i := 0; - end else - i := i + 1; + StatusEdit.Text := VarList.Items[index]; + VarList.Items.Delete(index); end; UpdateBtnStates; end; -function TCoxRegFrm.ChiSq(x: double; n: integer): double; -var - p, t, a: double; - k: integer; -begin - p := exp(-0.5 * x); - if n mod 2 = 1 then - p := p * sqrt(2 * x / Pi); - k := n; - while K >= 2 do +procedure TCoxRegForm.StatusOutBtnClick(Sender: TObject); +begin + if (StatusEdit.Text <> '') then begin - p := p * x / k; - k := k - 2; + VarList.Items.Add(StatusEdit.Text); + StatusEdit.Text := ''; end; - - t := p; - a := n; - while t > 0.000001 * p do - begin - a := a + 2; - t := t * x / a; - p := p + t; - end; - Result := (1 - p); + UpdateBtnStates; end; -function TCoxRegFrm.Norm(z: double): double; -begin - Result := ChiSq(z*z, 1); -end; -//------------------------------------------------------------------- -function TCoxRegFrm.ix(j, k, nCols : integer): integer; -begin - Result := j*nCols + k; -end; - -procedure TCoxRegFrm.UpdateBtnStates; +procedure TCoxRegForm.UpdateBtnStates; var lSelected: Boolean; begin + inherited; + lSelected := AnySelected(VarList); InBtn.Enabled := lSelected; DepInBtn.Enabled := lSelected and (DepVar.Text = ''); @@ -635,14 +629,27 @@ begin StatusOutBtn.Enabled := StatusEdit.Text <> ''; end; -procedure TCoxRegFrm.VarListSelectionChange(Sender: TObject; User: boolean); + +procedure TCoxRegForm.VarListDblClick(Sender: TObject); +var + index: Integer; +begin + index := VarList.ItemIndex; + if index > -1 then + begin + BlockList.Items.Add(VarList.Items[index]); + VarList.Items.Delete(index); + UpdateBtnStates; + end; +end; + + +procedure TCoxRegForm.VarListSelectionChange(Sender: TObject; User: boolean); begin UpdateBtnStates; end; -initialization - {$I coxregunit.lrs} end. diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/linprounit.lfm b/applications/lazstats/source/forms/analysis/multiple_regression/linprounit.lfm index 664904e6b..5b0b0ef41 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/linprounit.lfm +++ b/applications/lazstats/source/forms/analysis/multiple_regression/linprounit.lfm @@ -1,4 +1,4 @@ -object LinProFrm: TLinProFrm +object LinProForm: TLinProForm Left = 445 Height = 507 Top = 263 @@ -613,11 +613,11 @@ object LinProFrm: TLinProFrm TabOrder = 3 end object OpenDialog1: TOpenDialog - left = 696 - top = 136 + Left = 696 + Top = 136 end object SaveDialog1: TSaveDialog - left = 600 - top = 120 + Left = 600 + Top = 120 end end diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/linprounit.pas b/applications/lazstats/source/forms/analysis/multiple_regression/linprounit.pas index ce5a169d4..305f4a485 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/linprounit.pas +++ b/applications/lazstats/source/forms/analysis/multiple_regression/linprounit.pas @@ -11,9 +11,9 @@ uses type - { TLinProFrm } + { TLinProForm } - TLinProFrm = class(TForm) + TLinProForm = class(TForm) Bevel1: TBevel; ExitBtn: TButton; Panel1: TPanel; @@ -98,16 +98,16 @@ type end; var - LinProFrm: TLinProFrm; + LinProForm: TLinProForm; implementation uses Math; -{ TLinProFrm } +{ TLinProForm } -procedure TLinProFrm.ResetBtnClick(Sender: TObject); +procedure TLinProForm.ResetBtnClick(Sender: TObject); begin NoVarsEdit.Text := '0'; NoMaxEdit.Text := ''; @@ -139,7 +139,7 @@ begin ResultsEdit.Text := ''; end; -procedure TLinProFrm.SaveBtnClick(Sender: TObject); +procedure TLinProForm.SaveBtnClick(Sender: TObject); var F : TextFile; i, j : integer; @@ -170,7 +170,7 @@ begin end; end; -procedure TLinProFrm.FormActivate(Sender: TObject); +procedure TLinProForm.FormActivate(Sender: TObject); var w: Integer; begin @@ -188,17 +188,17 @@ begin FAutoSized := true; end; -procedure TLinProFrm.FormCreate(Sender: TObject); +procedure TLinProForm.FormCreate(Sender: TObject); begin if OutputFrm = nil then Application.CreateForm(TOutputFrm, OutputFrm); end; -procedure TLinProFrm.FormShow(Sender: TObject); +procedure TLinProForm.FormShow(Sender: TObject); begin ResetBtnClick(Self); end; -procedure TLinProFrm.LoadBtnClick(Sender: TObject); +procedure TLinProForm.LoadBtnClick(Sender: TObject); var i, j : integer; FName : string; @@ -283,7 +283,7 @@ begin ComputeBtn.SetFocus; end; -procedure TLinProFrm.CancelBtnClick(Sender: TObject); +procedure TLinProForm.CancelBtnClick(Sender: TObject); begin Coefficients := nil; EqlConstraints := nil; @@ -293,7 +293,7 @@ begin Close; end; -procedure TLinProFrm.ComputeBtnClick(Sender: TObject); +procedure TLinProForm.ComputeBtnClick(Sender: TObject); var m1, m2, m3, m, mp, n, np, nm1m2 : integer; i,icase,j : integer; @@ -415,7 +415,7 @@ begin izrov := nil; end; -procedure TLinProFrm.ExitBtnClick(Sender: TObject); +procedure TLinProForm.ExitBtnClick(Sender: TObject); begin Coefficients := nil; EqlConstraints := nil; @@ -425,7 +425,7 @@ begin Close; end; -procedure TLinProFrm.NoEqualEditExit(Sender: TObject); +procedure TLinProForm.NoEqualEditExit(Sender: TObject); VAR value : integer; begin value := StrToInt(NoEqualEdit.Text); @@ -438,12 +438,12 @@ begin SetLength(Coefficients,NoCoefs+1,NoVars+1); end; -procedure TLinProFrm.NoEqualEditKeyPress(Sender: TObject; var Key: char); +procedure TLinProForm.NoEqualEditKeyPress(Sender: TObject; var Key: char); begin if ord(Key) = 13 then ObjectiveGrid.SetFocus; end; -procedure TLinProFrm.NoMaxEditExit(Sender: TObject); +procedure TLinProForm.NoMaxEditExit(Sender: TObject); VAR value : integer; begin value := StrToInt(NoMaxEdit.Text); @@ -454,12 +454,12 @@ begin SetLength(MaxConstraints,NoMax + 1); end; -procedure TLinProFrm.NoMaxEditKeyPress(Sender: TObject; var Key: char); +procedure TLinProForm.NoMaxEditKeyPress(Sender: TObject; var Key: char); begin if ord(Key) = 13 then NoMinEdit.SetFocus; end; -procedure TLinProFrm.NoMinEditExit(Sender: TObject); +procedure TLinProForm.NoMinEditExit(Sender: TObject); VAR value : integer; begin value := StrToInt(NoMinEdit.Text); @@ -470,12 +470,12 @@ begin SetLength(MinConstraints,NoMin + 1); end; -procedure TLinProFrm.NoMinEditKeyPress(Sender: TObject; var Key: char); +procedure TLinProForm.NoMinEditKeyPress(Sender: TObject; var Key: char); begin if ord(Key) = 13 then NoEqualEdit.SetFocus; end; -procedure TLinProFrm.NoVarsEditExit(Sender: TObject); +procedure TLinProForm.NoVarsEditExit(Sender: TObject); var value : integer; begin value := StrToInt(NoVarsEdit.Text); @@ -488,12 +488,12 @@ begin SetLength(Objective,NoVars + 1); end; -procedure TLinProFrm.NoVarsEditKeyPress(Sender: TObject; var Key: char); +procedure TLinProForm.NoVarsEditKeyPress(Sender: TObject; var Key: char); begin if ord(Key) = 13 then NoMaxEdit.SetFocus; end; -PROCEDURE TLinProFrm.simplx(VAR a: DblDyneMat; m,n,mp,np,m1,m2,m3: integer; +PROCEDURE TLinProForm.simplx(VAR a: DblDyneMat; m,n,mp,np,m1,m2,m3: integer; VAR icase: integer; VAR izrov: IntDyneVec; VAR iposv: IntDyneVec); LABEL 1,2,10,20,30,99; @@ -607,7 +607,7 @@ BEGIN END; -PROCEDURE TLinProFrm.simp1(VAR a: DblDyneMat; mp,np,mm: integer; +PROCEDURE TLinProForm.simp1(VAR a: DblDyneMat; mp,np,mm: integer; ll: IntDyneVec; nll,iabf: integer; VAR kp: integer; VAR bmax: double); LABEL 99; @@ -632,7 +632,7 @@ BEGIN 99: END; -PROCEDURE TLinProFrm.simp2(VAR a: DblDyneMat; m,n,mp,np: integer; +PROCEDURE TLinProForm.simp2(VAR a: DblDyneMat; m,n,mp,np: integer; l2: IntDyneVec; nl2: integer; VAR ip: integer; kp: integer; VAR q1: double); LABEL 2,6,99; @@ -670,7 +670,7 @@ BEGIN end; -PROCEDURE TLinProFrm.simp3(VAR a: DblDyneMat; mp,np,i1,k1,ip,kp: integer); +PROCEDURE TLinProForm.simp3(VAR a: DblDyneMat; mp,np,i1,k1,ip,kp: integer); (* Programs using routine SIMP3 must define the type TYPE glmpbynp = ARRAY [1..mp,1..np] OF real; @@ -700,7 +700,7 @@ BEGIN END; -procedure TLinProFrm.LoadArrayData(Sender: TObject); +procedure TLinProForm.LoadArrayData(Sender: TObject); var i, j : integer; begin diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/logregunit.lfm b/applications/lazstats/source/forms/analysis/multiple_regression/logregunit.lfm index 31dc7a3dc..60ffdca06 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/logregunit.lfm +++ b/applications/lazstats/source/forms/analysis/multiple_regression/logregunit.lfm @@ -1,305 +1,260 @@ -object LogRegFrm: TLogRegFrm - Left = 876 - Height = 355 - Top = 245 - Width = 353 +inherited LogRegForm: TLogRegForm + Left = 566 + Height = 342 + Top = 243 + Width = 582 HelpType = htKeyword HelpKeyword = 'html/BinaryLogisticRegression.htm' - AutoSize = True Caption = 'Binary Logistic Regression' - ClientHeight = 355 - ClientWidth = 353 - 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 - BorderSpacing.Right = 8 - Caption = 'Available Variables' - ParentColor = False - end - object Label2: TLabel - AnchorSideLeft.Control = DepVar - AnchorSideBottom.Control = DepVar - Left = 198 - Height = 15 - Top = 31 - Width = 102 - Anchors = [akLeft, akBottom] - BorderSpacing.Bottom = 2 - Caption = 'Dependent Variable' - ParentColor = False - end - object Label3: TLabel - AnchorSideLeft.Control = BlockList - AnchorSideTop.Control = InBtn - Left = 198 - Height = 15 - Top = 120 - Width = 116 - Caption = 'Independent Variables' - ParentColor = False - end - object Label4: TLabel - AnchorSideLeft.Control = GroupBox1 - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = GroupBox1 - AnchorSideTop.Side = asrCenter - Left = 179 - Height = 15 - Top = 247 - Width = 107 - BorderSpacing.Left = 16 - Caption = 'Maximum Iterations' - ParentColor = False - end - object VarList: TListBox - AnchorSideLeft.Control = Owner - AnchorSideTop.Control = Label1 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = DepInBtn - AnchorSideBottom.Control = GroupBox1 - Left = 8 - Height = 170 - Top = 25 - Width = 146 - Anchors = [akTop, akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Top = 2 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - ItemHeight = 0 - MultiSelect = True - OnSelectionChange = VarListSelectionChange - TabOrder = 0 - end - object DepInBtn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = VarList - Left = 162 - Height = 28 - Top = 25 - Width = 28 - Images = MainDataModule.ImageList - ImageIndex = 1 - OnClick = DepInBtnClick - Spacing = 0 - TabOrder = 1 - end - object DepOutBtn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = DepInBtn - AnchorSideTop.Side = asrBottom - Left = 162 - Height = 28 - Top = 55 - Width = 28 - BorderSpacing.Top = 2 - Images = MainDataModule.ImageList - ImageIndex = 0 - OnClick = DepOutBtnClick - Spacing = 0 - TabOrder = 2 - end - object InBtn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - Left = 162 - Height = 28 - Top = 120 - Width = 28 - Images = MainDataModule.ImageList - ImageIndex = 1 - OnClick = InBtnClick - Spacing = 0 - TabOrder = 4 - end - object OutBtn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - Left = 162 - Height = 28 - Top = 148 - Width = 28 - Images = MainDataModule.ImageList - ImageIndex = 0 - OnClick = OutBtnClick - Spacing = 0 - TabOrder = 5 - end - object DepVar: TEdit - AnchorSideLeft.Control = DepInBtn - AnchorSideLeft.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = DepOutBtn - AnchorSideBottom.Side = asrBottom - Left = 198 - Height = 23 - Top = 48 - Width = 147 - Anchors = [akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 12 - ReadOnly = True - TabOrder = 3 - Text = 'DepVar' - end - object BlockList: TListBox - AnchorSideLeft.Control = InBtn - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = Label3 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = VarList - AnchorSideBottom.Side = asrBottom - Left = 198 - Height = 60 - Top = 135 - Width = 147 - Anchors = [akTop, akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Right = 8 - ItemHeight = 0 - MultiSelect = True - OnSelectionChange = VarListSelectionChange - TabOrder = 6 - end - object GroupBox1: TGroupBox - AnchorSideLeft.Control = Owner - AnchorSideBottom.Control = Bevel1 - Left = 8 - Height = 103 - Top = 203 - Width = 155 - Anchors = [akLeft, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - Caption = 'Options' - ChildSizing.LeftRightSpacing = 12 - ChildSizing.TopBottomSpacing = 6 - ChildSizing.VerticalSpacing = 2 - ClientHeight = 83 - ClientWidth = 151 - TabOrder = 7 - object DescChk: TCheckBox - Left = 12 - Height = 19 - Top = 6 - Width = 127 - Caption = 'Descriptive Statistics' + ClientHeight = 342 + ClientWidth = 582 + inherited ParamsPanel: TPanel + Height = 326 + ClientHeight = 326 + inherited CloseBtn: TButton + Top = 301 + TabOrder = 12 + end + inherited ComputeBtn: TButton + Top = 301 + TabOrder = 11 + end + inherited ResetBtn: TButton + Top = 301 + TabOrder = 10 + end + inherited HelpBtn: TButton + Top = 301 + TabOrder = 9 + end + inherited ButtonBevel: TBevel + Top = 285 + end + object Label1: TLabel[5] + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = ParamsPanel + Left = 0 + Height = 15 + Top = 0 + Width = 97 + BorderSpacing.Right = 8 + Caption = 'Available Variables' + ParentColor = False + end + object Label2: TLabel[6] + AnchorSideLeft.Control = DepVarEdit + AnchorSideBottom.Control = DepVarEdit + Left = 164 + Height = 15 + Top = 19 + Width = 102 + Anchors = [akLeft, akBottom] + BorderSpacing.Bottom = 2 + Caption = 'Dependent Variable' + ParentColor = False + end + object Label3: TLabel[7] + AnchorSideLeft.Control = BlockList + AnchorSideTop.Control = InBtn + Left = 164 + Height = 15 + Top = 103 + Width = 116 + Caption = 'Independent Variables' + ParentColor = False + end + object VarList: TListBox[8] + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = Label1 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = DepInBtn + AnchorSideBottom.Control = OptionsGroup + Left = 0 + Height = 157 + 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 ProbsChk: TCheckBox - Left = 12 - Height = 19 - Top = 32 - Width = 95 - Caption = 'Y Probabilities' + object DepInBtn: TBitBtn[9] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = VarList + Left = 132 + Height = 26 + Top = 17 + Width = 26 + Images = MainDataModule.ImageList + ImageIndex = 1 + OnClick = DepInBtnClick + Spacing = 0 TabOrder = 1 end - object ItersChk: TCheckBox - Left = 12 - Height = 19 - Top = 58 - Width = 101 - Caption = 'Show Iterations' + object DepOutBtn: TBitBtn[10] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = DepInBtn + AnchorSideTop.Side = asrBottom + Left = 132 + Height = 26 + Top = 45 + Width = 26 + BorderSpacing.Top = 2 + Images = MainDataModule.ImageList + ImageIndex = 0 + OnClick = DepOutBtnClick + Spacing = 0 TabOrder = 2 end + object InBtn: TBitBtn[11] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = DepOutBtn + AnchorSideTop.Side = asrBottom + Left = 132 + Height = 26 + Top = 103 + Width = 26 + BorderSpacing.Top = 32 + Images = MainDataModule.ImageList + ImageIndex = 1 + OnClick = InBtnClick + Spacing = 0 + TabOrder = 4 + end + object OutBtn: TBitBtn[12] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = InBtn + AnchorSideTop.Side = asrBottom + Left = 132 + Height = 26 + Top = 131 + Width = 26 + BorderSpacing.Top = 2 + Images = MainDataModule.ImageList + ImageIndex = 0 + OnClick = OutBtnClick + Spacing = 0 + TabOrder = 5 + end + object DepVarEdit: TEdit[13] + AnchorSideLeft.Control = DepInBtn + AnchorSideLeft.Side = asrBottom + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = DepOutBtn + AnchorSideBottom.Side = asrBottom + Left = 164 + Height = 23 + Top = 36 + Width = 127 + Anchors = [akLeft, akRight, akBottom] + BorderSpacing.Left = 6 + BorderSpacing.Bottom = 12 + ReadOnly = True + TabOrder = 3 + Text = 'DepVarEdit' + end + object BlockList: TListBox[14] + AnchorSideLeft.Control = DepInBtn + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = Label3 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = VarList + AnchorSideBottom.Side = asrBottom + Left = 164 + Height = 56 + Top = 118 + Width = 127 + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Left = 6 + ItemHeight = 0 + MultiSelect = True + OnDblClick = BlockListDblClick + OnSelectionChange = VarListSelectionChange + TabOrder = 6 + end + object MaxItsLabel: TLabel[15] + AnchorSideLeft.Control = OptionsGroup + AnchorSideLeft.Side = asrBottom + AnchorSideBottom.Control = MaxItsEdit + Left = 171 + Height = 15 + Top = 205 + Width = 107 + Anchors = [akLeft, akBottom] + BorderSpacing.Left = 16 + BorderSpacing.Bottom = 2 + Caption = 'Maximum Iterations' + ParentColor = False + end + object OptionsGroup: TGroupBox[16] + AnchorSideLeft.Control = ParamsPanel + AnchorSideBottom.Control = ButtonBevel + Left = 0 + Height = 103 + Top = 182 + Width = 155 + Anchors = [akLeft, akBottom] + AutoSize = True + Caption = 'Options' + ChildSizing.LeftRightSpacing = 12 + ChildSizing.TopBottomSpacing = 6 + ChildSizing.VerticalSpacing = 2 + ClientHeight = 83 + ClientWidth = 151 + TabOrder = 7 + object DescChk: TCheckBox + Left = 12 + Height = 19 + Top = 6 + Width = 127 + Caption = 'Descriptive Statistics' + TabOrder = 0 + end + object ProbsChk: TCheckBox + Left = 12 + Height = 19 + Top = 32 + Width = 95 + Caption = 'Y Probabilities' + TabOrder = 1 + end + object ItersChk: TCheckBox + Left = 12 + Height = 19 + Top = 58 + Width = 101 + Caption = 'Show Iterations' + TabOrder = 2 + end + end + object MaxItsEdit: TEdit[17] + AnchorSideLeft.Control = MaxItsLabel + AnchorSideTop.Control = OptionsGroup + AnchorSideTop.Side = asrCenter + AnchorSideRight.Side = asrBottom + Left = 187 + Height = 23 + Top = 222 + Width = 40 + Alignment = taRightJustify + BorderSpacing.Left = 16 + TabOrder = 8 + Text = 'MaxItsEdit' + end end - object MaxItsEdit: TEdit - AnchorSideLeft.Control = Label4 - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = Label4 - AnchorSideTop.Side = asrCenter - Left = 294 - Height = 23 - Top = 243 - Width = 38 - Alignment = taRightJustify - BorderSpacing.Left = 8 - BorderSpacing.Right = 8 - TabOrder = 8 - Text = 'MaxItsEdit' - end - object ResetBtn: TButton - AnchorSideRight.Control = ComputeBtn - AnchorSideBottom.Control = Owner - AnchorSideBottom.Side = asrBottom - Left = 140 - Height = 25 - Top = 322 - Width = 54 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 12 - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Caption = 'Reset' - OnClick = ResetBtnClick - TabOrder = 9 - end - object ComputeBtn: TButton - AnchorSideRight.Control = CloseBtn - AnchorSideBottom.Control = Owner - AnchorSideBottom.Side = asrBottom - Left = 202 - Height = 25 - Top = 322 - Width = 76 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Caption = 'Compute' - OnClick = ComputeBtnClick - TabOrder = 10 - end - object CloseBtn: TButton - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = Owner - AnchorSideBottom.Side = asrBottom - Left = 286 - Height = 25 - Top = 322 - Width = 55 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - BorderSpacing.Right = 12 - BorderSpacing.Bottom = 8 - Caption = 'Close' - ModalResult = 11 - TabOrder = 11 - end - object Bevel1: TBevel - AnchorSideLeft.Control = Owner - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = CloseBtn - Left = 0 - Height = 8 - Top = 306 - Width = 353 - Anchors = [akLeft, akRight, akBottom] - Shape = bsBottomLine + inherited ParamsSplitter: TSplitter + Height = 342 end end diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/logregunit.pas b/applications/lazstats/source/forms/analysis/multiple_regression/logregunit.pas index 83f2d6606..116c923d8 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/logregunit.pas +++ b/applications/lazstats/source/forms/analysis/multiple_regression/logregunit.pas @@ -5,92 +5,509 @@ unit LogRegUnit; interface uses - Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, - StdCtrls, Buttons, ExtCtrls, - Globals, MainUnit, OutputUnit; + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Buttons, ExtCtrls, + Globals, MainUnit, BasicStatsReportFormUnit; type - { TLogRegFrm } + { TLogRegForm } - TLogRegFrm = class(TForm) - Bevel1: TBevel; - ResetBtn: TButton; - ComputeBtn: TButton; - CloseBtn: TButton; + TLogRegForm = class(TBasicStatsReportForm) DepInBtn: TBitBtn; DepOutBtn: TBitBtn; MaxItsEdit: TEdit; InBtn: TBitBtn; - Label4: TLabel; + MaxItsLabel: TLabel; OutBtn: TBitBtn; DescChk: TCheckBox; ProbsChk: TCheckBox; ItersChk: TCheckBox; - DepVar: TEdit; - GroupBox1: TGroupBox; + DepVarEdit: TEdit; + OptionsGroup: TGroupBox; Label1: TLabel; Label2: TLabel; Label3: TLabel; BlockList: TListBox; VarList: TListBox; - procedure ComputeBtnClick(Sender: TObject); + procedure BlockListDblClick(Sender: TObject); procedure DepInBtnClick(Sender: TObject); procedure DepOutBtnClick(Sender: TObject); - procedure FormActivate(Sender: TObject); - procedure FormCreate(Sender: TObject); - procedure FormShow(Sender: TObject); procedure InBtnClick(Sender: TObject); procedure OutBtnClick(Sender: TObject); - procedure ResetBtnClick(Sender: TObject); - function ChiSq(x : double; n : integer) : double; - function Norm(z : double): double; - function ix(j, k, nCols : integer): integer; + procedure VarListDblClick(Sender: TObject); procedure VarListSelectionChange(Sender: TObject; User: boolean); private - { private declarations } - FAutoSized: Boolean; - procedure UpdateBtnStates; + + protected + procedure AdjustConstraints; override; + procedure Compute; override; + procedure UpdateBtnStates; override; + function Validate(out AMsg: String; out AControl: TWinControl): Boolean; + public - { public declarations } + procedure Reset; override; end; var - LogRegFrm: TLogRegFrm; + LogRegForm: TLogRegForm; + implementation +{$R *.lfm} + uses Math; -{ TLogRegFrm } -procedure TLogRegFrm.ResetBtnClick(Sender: TObject); -VAR i : integer; +function ix(j, k, nCols: integer): integer; begin - BlockList.Clear; - VarList.Clear; - for i := 1 to NoVariables do - begin - VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); - end; - InBtn.Enabled := true; - OutBtn.Enabled := false; - DepInBtn.Enabled := true; - DepOutBtn.Enabled := false; - ProbsChk.Checked := true; - DescChk.Checked := true; - DepVar.Text := ''; - MaxItsEdit.Text := '20'; + Result := j * nCols + k; end; -procedure TLogRegFrm.VarListSelectionChange(Sender: TObject; User: boolean); + +function ChiSq(x: double; n: integer): double; +var + p, t, a: double; + k: integer; begin + p := exp(-0.5 * x); + if n mod 2 = 1 then p := p * sqrt(2 * x / Pi); + k := n; + while K >= 2 do + begin + p := p * x / k; + k := k - 2; + end; + t := p; + a := n; + while t > 0.000001 * p do + begin + a := a + 2; + t := t * x / a; + p := p + t; + end; + Result := (1 - p); +end; + + +function Norm(z: double): double; +begin + Result := ChiSq(z*z, 1); +end; + + + +{ TLogRegForm } + +procedure TLogRegForm.AdjustConstraints; +begin + inherited; + + ParamsPanel.Constraints.MinWidth := Max( + 4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left, + OptionsGroup.Width + MaxItsLabel.Width + MaxItsLabel.BorderSpacing.Left + ); + ParamsPanel.Constraints.MinHeight := OutBtn.Top + OutBtn.Height + + VarList.BorderSpacing.Bottom + OptionsGroup.Height + ButtonBevel.Height + + CloseBtn.BorderSpacing.Top + CloseBtn.Height; +end; + + +procedure TLogRegForm.BlockListDblClick(Sender: TObject); +var + index: Integer; +begin + index := BlockList.ItemIndex; + if index > -1 then + begin + VarList.Items.Add(BlockList.Items[index]); + BlockList.Items.Delete(index); + UpdateBtnStates; + end; +end; + + +procedure TLogRegForm.Compute; +var + i, j, k : integer; + cellstring : string; + outline : string; + nR : integer; // no. independent variables + nC : integer; // no. cases + nP : integer; // total no. variables + ColNoSelected : IntDyneVec = nil; + RowLabels : StrDyneVec = nil; + ColLabels : StrDyneVec = nil; + nP1 : integer; // total no. variables plus 1 + sY0, sY1 : integer; // sum of cases with dependent of 0 or 1 + sC : integer; // total count of cases with 0 or 1 + X : DblDyneVec = nil; // data matrix for independent variables + Y0 : DblDyneVec = nil; // data array for dependent data + Y1 : DblDyneVec = nil; // data array for dependent data + xM : DblDyneVec = nil; // variable means + xSD : DblDyneVec = nil; // variable standard deviations + Par : DblDyneVec = nil; // work array + SEP : DblDyneVec = nil; // work array; + Arr : DblDyneVec = nil; // work array; + indx, indx2, indx3: integer; // indexes for arrays + value : double; + LLp, LL, LLn: double; // log likelihood + q : double; // work values + xij, s : double; // work value + CSq : double; // chi square statistic + prob : double; // probability of chi square + ORc, OR1, ORh: double; // Odds ratio values + iters : integer; + Table : array[1..3,1..3] of integer; + row, col : integer; + maxIts: Integer; + lReport: TStrings; +begin + lReport := TStringList.Create; + try + lReport.Add('LOGISTIC REGRESSION, adapted from John C. Pezzullo'); + lReport.Add('Java program at http://members.aol.com/johnp71/logistic.html'); + + // Get independent item columns + nR := BlockList.Items.Count; + nC := NoCases; + SetLength(ColNoSelected,nR + 2); + SetLength(RowLabels,nR + 2); + SetLength(ColLabels,nR + 2); + + for i := 1 to nR do + begin + cellstring := BlockList.Items.Strings[i-1]; + for j := 1 to NoVariables do + begin + if cellstring = OS3MainFrm.DataGrid.Cells[j,0] then + begin + ColNoSelected[i] := j; + RowLabels[i] := cellstring; + ColLabels[i] := cellstring; + end; + end; + end; + + // Max count of iterations + maxIts := StrToInt(MaxItsEdit.Text); + + nP := nR + 1; + nP1 := nP + 1; + for j := 1 to NoVariables do + begin + if DepVarEdit.Text = OS3MainFrm.DataGrid.Cells[j,0] then + begin + ColNoSelected[nP] := j; + RowLabels[nP] := OS3MainFrm.DataGrid.Cells[j,0]; + ColLabels[nP] := RowLabels[nP]; + end; + end; + + sY0 := 0; + sY1 := 0; + sC := 0; + SetLength(X,(nC + 1) * (nR + 1)); + SetLength(Y0,nC + 1); + SetLength(Y1,nC + 1); + SetLength(xM,nR + 2); + SetLength(xSD,nR + 2); + SetLength(Par,nP + 1); + SetLength(SEP,nP + 1); + SetLength(Arr,(nP + 1) * (nP1 + 1)); + + // Get data + for i := 0 to nC - 1 do + begin + indx := ix(i,0,nR+1); + X[indx] := 1; + for j := 1 to nR do + begin + indx := ColNoSelected[j]; + value := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[indx,i+1])); + indx := ix(i,j,nR + 1); + X[indx] := value; + end; + indx := ColNoSelected[nP]; + value := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[indx,i+1])); + if value = 0 then + begin + Y0[i] := 1; + sY0 := sY0 + 1; + end + else begin + Y1[i] := 1; + sY1 := sY1 + 1; + end; + sC := sC + round(Y0[i] + Y1[i]); + for j := 1 to nR do + begin + indx := ix(i,j,nR + 1); + value := X[indx]; + xM[j] := xM[j] + (Y0[i] + Y1[i]) * value; + xSD[j] := xSD[j] + (Y0[i] + Y1[i]) * value * value; + end; + end; // next case i + + // Print descriptive statistics + lReport.Add(''); + if DescChk.Checked then + lReport.Add('Descriptive Statistics'); + lReport.Add('%d cases have Y=0; %d cases have Y=1.', [sY0, sY1]); + lReport.Add(''); + lReport.Add('Variable Label Average Std.Dev.'); + for j := 1 to nR do + begin + xM[j] := xM[j] / sC; + xSD[j] :=xSD[j] / sC; + xSD[j] := sqrt( abs(xSD[j] - xM[j] * xM[j])); + if DescChk.Checked then + lReport.Add(' %3d %15s %10.4f %10.4f',[j,RowLabels[j],xM[j],xSD[j]]); + end; + lReport.Add('------------------------------------------------------------------'); + lReport.Add(''); + xM[0] := 0.0; + xSD[0] := 1.0; + //OutputFrm.ShowModal; + + // convert independent variable values to z scores + for i := 0 to nC - 1 do + for j := 1 to nR do + begin + indx := ix(i,j,nR + 1); + X[indx] := (X[indx] - xM[j]) / xSD[j]; + end; + + // begin iterations + iters := 0; + if ItersChk.Checked then + lReport.Add('Iteration History'); + Par[0] := ln(sY1 / sY0); + for j := 1 to nR do Par[j] := 0.0; + LLp := 2e10; + LL := 1e10; + while abs(LLp-LL) > 0.00001 do + begin + iters := iters + 1; + if iters > StrToInt(MaxItsEdit.Text) then break; + LLp := LL; + LL := 0.0; + for j := 0 to nR do + begin + for k := j to nR + 1 do + begin + indx := ix(j,k,nR+2); + Arr[indx] := 0.0; + end; + end; + for i := 0 to nC - 1 do + begin + value := Par[0]; + for j := 1 to nR do + begin + indx := ix(i,j,nR + 1); + value := value + Par[j] * X[indx]; + end; + value := 1.0 / (1.0 + exp(-value)); + q := value * (1.0 - value); + LL := LL - 2.0 * Y1[i] * ln(value) - 2.0 * Y0[i] * ln(1.0 - value); + for j := 0 to nR do + begin + indx := ix(i,j,nR + 1); + xij := X[indx]; + indx := ix(j,nR + 1, nR + 2); + Arr[indx] := Arr[indx] + xij * ( Y1[i] * (1.0 - value) + Y0[i] * (-value)); + for k := j to nR do + begin + indx := ix(j,k,nR + 2); + indx2 := ix(i,k,nR + 1); + Arr[indx] := Arr[indx] + xij * X[indx2] * q * (Y0[i] + Y1[i]); + end; + end; // next j + end; // next i + outline := format('-2 Log Likelihood = %10.4f ',[LL]); + if LLp = 1.0e10 then + begin + LLn := LL; + outline := outline + ' (Null Model)'; + end; + if ItersChk.Checked then lReport.Add(outline); + for j := 1 to nR do + begin + for k := 0 to j-1 do + begin + indx := ix(j,k,nR + 2); + indx2 := ix(k,j,nR + 2); + Arr[indx] := Arr[indx2]; + end; + end; + for i := 0 to nR do + begin + indx := ix(i,i,nR + 2); + s := Arr[indx]; + Arr[indx] := 1.0; + for k := 0 to nR + 1 do + begin + indx := ix(i,k,nR + 2); + Arr[indx] := Arr[indx] / s; + end; + for j := 0 to nR do + begin + if i <> j then + begin + indx := ix(j,i,nR + 2); + s := Arr[indx]; + Arr[indx] := 0.0; + for k := 0 to nR + 1 do + begin + indx2 := ix(j,k,nR + 2); + indx3 := ix(i,k,nR + 2); + Arr[indx2] := Arr[indx2] - s * Arr[indx3]; + end; // next k + end; // if i not equal j + end; // next j + end; // next i + for j := 0 to nR do + begin + indx := ix(j,nR + 1,nR + 2); + Par[j] := Par[j] + Arr[indx]; + end; + end; // iteration + lReport.Add('Converged'); + lReport.Add(''); + lReport.Add('------------------------------------------------------------------'); + lReport.Add(''); + + CSq := LLn - LL; + prob := ChiSq(CSq,nR); + lReport.Add('Overall Model Fit'); + lReport.Add(' Chi Square: %8.4f', [Csq]); + lReport.Add(' Degrees of freedom: %8d', [nR]); + lReport.Add(' Probability: %8.4f', [prob]); + lReport.Add(''); + lReport.Add('Coefficients and Standard Errors'); + lReport.Add('Variable Label Coeff. StdErr p'); + for j := 1 to nR do + begin + Par[j] := Par[j] / xSD[j]; + indx := ix(j,j,nP + 1); + SEP[j] := sqrt(Arr[indx]) / xSD[j]; + Par[0] := Par[0] - Par[j] * xM[j]; + prob := Norm(abs(Par[j] / SEP[j])); + lReport.Add(' %3d %15s %10.4f %10.4f %10.4f', [j, RowLabels[j], Par[j], SEP[j], prob]); + end; + lReport.Add(''); +// OutputFrm.ShowModal; + + lReport.Add('Intercept %10.4f', [Par[0]]); + lReport.Add(''); + lReport.Add('Odds Ratios and 95% Confidence Intervals...'); + lReport.Add('Variable O.R. Low -- High'); + for j := 1 to nR do + begin + ORc := exp(Par[j]); + OR1 := exp(Par[j] - 1.96 * SEP[j]); + ORh := exp(Par[j] + 1.96 * SEP[j]); + lReport.Add('%15s %10.4f %10.4f %10.4f', [RowLabels[j], ORc, OR1, ORh]); + end; + for i := 1 to 3 do + for j := 1 to 3 do Table[i,j] := 0; + lReport.Add(''); + + if ProbsChk.Checked then + begin + outline := ''; + for j := 1 to nR do outline := outline + ' X '; + outline := outline + ' Y Prob'; + lReport.Add(outline); + for i := 0 to nC - 1 do + begin + value := Par[0]; + outline := ''; + for j := 1 to nR do + begin + indx := ix(i,j,nR + 1); + xij := xM[j] + xSD[j] * X[indx]; + value := value + Par[j] * xij; + outline := outline + format(' %10.4f ',[xij]); + end; + value := 1.0 / (1.0 + exp( -value)); + outline := outline + format('%4.0f %10.4f',[Y1[i],value]); + lReport.Add(outline); + + if round(Y1[i]) = 0 then row := 1 else row := 2; + if round(value) = 0 then col := 1 else col := 2; + Table[row,col] := Table[row,col] + 1; + end; // next i + end; + for i := 1 to 2 do + for j := 1 to 2 do + begin + Table[i,3] := Table[i,3] + Table[i,j]; + Table[3,j] := Table[3,j] + Table[i,j]; + end; + for i := 1 to 2 do + Table[3,3] := Table[3,3] + Table[i,3]; + lReport.Add(''); + lReport.Add('Classification Table'); + lReport.Add(' Predicted'); + lReport.Add(' --------------- '); + lReport.Add('Observed 0 1 Total'); + lReport.Add(' --------------- '); + + for i := 1 to 2 do + begin + outline := format(' %d ',[i-1]); + for j := 1 to 3 do + outline := outline + format('| %3d ',[Table[i,j]]); + outline := outline + '|'; + lReport.Add(outline); + end; + lReport.Add(' --------------- '); + + Outline := 'Total '; + for j := 1 to 3 do + outline := outline + format('| %3d ',[Table[3,j]]); + outline := outline + ''; + lReport.Add(outline); + lReport.Add(' --------------- '); + + FReportFrame.DisplayReport(lReport); + + finally + lReport.Free; + end; +end; + + +procedure TLogRegForm.DepInBtnClick(Sender: TObject); +var + index: integer; +begin + index := VarList.ItemIndex; + if (index > -1) and (DepVarEdit.Text = '') then + begin + DepVarEdit.Text := VarList.Items[index]; + VarList.Items.Delete(index); + end; UpdateBtnStates; end; -procedure TLogRegFrm.InBtnClick(Sender: TObject); + +procedure TLogRegForm.DepOutBtnClick(Sender: TObject); +begin + if DepVarEdit.Text <> '' then + begin + VarList.Items.Add(DepVarEdit.Text); + DepVarEdit.Text := ''; + end; + UpdateBtnStates; +end; + + +procedure TLogRegForm.InBtnClick(Sender: TObject); var i: integer; begin @@ -109,439 +526,8 @@ begin UpdateBtnStates; end; -procedure TLogRegFrm.DepInBtnClick(Sender: TObject); -var - index: integer; -begin - index := VarList.ItemIndex; - if (index > -1) and (DepVar.Text = '') then - begin - DepVar.Text := VarList.Items[index]; - VarList.Items.Delete(index); - end; - UpdateBtnStates; -end; -procedure TLogRegFrm.ComputeBtnClick(Sender: TObject); -var - i, j, k : integer; - cellstring : string; - outline : string; - nR : integer; // no. independent variables - ColNoSelected : IntDyneVec; - nC : integer; // no. cases - nP : integer; // total no. variables - RowLabels, ColLabels : StrDyneVec; - nP1 : integer; // total no. variables plus 1 - sY0, sY1 : integer; // sum of cases with dependent of 0 or 1 - sC : integer; // total count of cases with 0 or 1 - X : DblDyneVec; // data matrix for independent variables - Y0, Y1 : DblDyneVec; // data array for dependent data - xM : DblDyneVec; // variable means - xSD : DblDyneVec; // variable standard deviations - Par : DblDyneVec; // work array - SEP : DblDyneVec; // work array; - Arr : DblDyneVec; // work array; - indx, indx2, indx3 : integer; // indexes for arrays - value : double; - LLp, LL, LLn : double; // log likelihood - q : double; // work values - xij, s : double; // work value - CSq : double; // chi square statistic - prob : double; // probability of chi square - ORc, OR1, ORh : double; // Odds ratio values - iters : integer; - Table : array[1..3,1..3] of integer; - row, col : integer; - maxIts: Integer; - lReport: TStrings; -begin - lReport := TStringList.Create; - try - lReport.Add('LOGISTIC REGRESSION, adapted from John C. Pezzullo'); - lReport.Add('Java program at http://members.aol.com/johnp71/logistic.html'); - - { get independent item columns } - nR := BlockList.Items.Count; - nC := NoCases; - SetLength(ColNoSelected,nR + 2); - SetLength(RowLabels,nR + 2); - SetLength(ColLabels,nR + 2); - if nR < 1 then - begin - MessageDlg('No independent variables selected.', mtError, [mbOK], 0); - exit; - end; - - for i := 1 to nR do - begin - cellstring := BlockList.Items.Strings[i-1]; - for j := 1 to NoVariables do - begin - if cellstring = OS3MainFrm.DataGrid.Cells[j,0] then - begin - ColNoSelected[i] := j; - RowLabels[i] := cellstring; - ColLabels[i] := cellstring; - end; - end; - end; - - { get dependendent variable column } - if DepVar.Text = '' then - begin - MessageDlg('No dependent variable selected.', mtError, [mbOK], 0); - exit; - end; - - if MaxItsEdit.Text = '' then begin - MaxItsEdit.Setfocus; - MessageDlg('Maximum iterations not specified.', mtError, [mbOK], 0); - exit; - end; - - if not TryStrToInt(MaxItsEdit.Text, maxIts) then - begin - MaxItsEdit.SetFocus; - MessageDlg('No valid number given for maximum iterations.', mtError, [mbOK], 0); - exit; - end; - - - nP := nR + 1; - nP1 := nP + 1; - for j := 1 to NoVariables do - begin - if DepVar.Text = OS3MainFrm.DataGrid.Cells[j,0] then - begin - ColNoSelected[nP] := j; - RowLabels[nP] := OS3MainFrm.DataGrid.Cells[j,0]; - ColLabels[nP] := RowLabels[nP]; - end; - end; - - sY0 := 0; - sY1 := 0; - sC := 0; - SetLength(X,(nC + 1) * (nR + 1)); - SetLength(Y0,nC + 1); - SetLength(Y1,nC + 1); - SetLength(xM,nR + 2); - SetLength(xSD,nR + 2); - SetLength(Par,nP + 1); - SetLength(SEP,nP + 1); - SetLength(Arr,(nP + 1) * (nP1 + 1)); - - // get data - for i := 0 to nC - 1 do - begin - indx := ix(i,0,nR+1); - X[indx] := 1; - for j := 1 to nR do - begin - indx := ColNoSelected[j]; - value := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[indx,i+1])); - indx := ix(i,j,nR + 1); - X[indx] := value; - end; - indx := ColNoSelected[nP]; - value := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[indx,i+1])); - if value = 0 then - begin - Y0[i] := 1; - sY0 := sY0 + 1; - end - else begin - Y1[i] := 1; - sY1 := sY1 + 1; - end; - sC := sC + round(Y0[i] + Y1[i]); - for j := 1 to nR do - begin - indx := ix(i,j,nR + 1); - value := X[indx]; - xM[j] := xM[j] + (Y0[i] + Y1[i]) * value; - xSD[j] := xSD[j] + (Y0[i] + Y1[i]) * value * value; - end; - end; // next case i - - // print descriptive statistics - lReport.Add(''); - if DescChk.Checked then - lReport.Add('Descriptive Statistics'); - lReport.Add('%d cases have Y=0; %d cases have Y=1.', [sY0, sY1]); - lReport.Add(''); - lReport.Add('Variable Label Average Std.Dev.'); - for j := 1 to nR do - begin - xM[j] := xM[j] / sC; - xSD[j] :=xSD[j] / sC; - xSD[j] := sqrt( abs(xSD[j] - xM[j] * xM[j])); - if DescChk.Checked then - lReport.Add(' %3d %15s %10.4f %10.4f',[j,RowLabels[j],xM[j],xSD[j]]); - end; - lReport.Add('------------------------------------------------------------------'); - lReport.Add(''); - xM[0] := 0.0; - xSD[0] := 1.0; - //OutputFrm.ShowModal; - - // convert independent variable values to z scores - for i := 0 to nC - 1 do - begin - for j := 1 to nR do - begin - indx := ix(i,j,nR + 1); - X[indx] := (X[indx] - xM[j]) / xSD[j]; - end; - end; - - // begin iterations - iters := 0; - if ItersChk.Checked then - lReport.Add('Iteration History'); - Par[0] := ln(sY1 / sY0); - for j := 1 to nR do Par[j] := 0.0; - LLp := 2e10; - LL := 1e10; - while abs(LLp-LL) > 0.00001 do - begin - iters := iters + 1; - if iters > StrToInt(MaxItsEdit.Text) then break; - LLp := LL; - LL := 0.0; - for j := 0 to nR do - begin - for k := j to nR + 1 do - begin - indx := ix(j,k,nR+2); - Arr[indx] := 0.0; - end; - end; - for i := 0 to nC - 1 do - begin - value := Par[0]; - for j := 1 to nR do - begin - indx := ix(i,j,nR + 1); - value := value + Par[j] * X[indx]; - end; - value := 1.0 / (1.0 + exp(-value)); - q := value * (1.0 - value); - LL := LL - 2.0 * Y1[i] * ln(value) - 2.0 * Y0[i] * ln(1.0 - value); - for j := 0 to nR do - begin - indx := ix(i,j,nR + 1); - xij := X[indx]; - indx := ix(j,nR + 1, nR + 2); - Arr[indx] := Arr[indx] + xij * ( Y1[i] * (1.0 - value) + Y0[i] * (-value)); - for k := j to nR do - begin - indx := ix(j,k,nR + 2); - indx2 := ix(i,k,nR + 1); - Arr[indx] := Arr[indx] + xij * X[indx2] * q * (Y0[i] + Y1[i]); - end; - end; // next j - end; // next i - outline := format('-2 Log Likelihood = %10.4f ',[LL]); - if LLp = 1.0e10 then - begin - LLn := LL; - outline := outline + ' (Null Model)'; - end; - if ItersChk.Checked then lReport.Add(outline); - for j := 1 to nR do - begin - for k := 0 to j-1 do - begin - indx := ix(j,k,nR + 2); - indx2 := ix(k,j,nR + 2); - Arr[indx] := Arr[indx2]; - end; - end; - for i := 0 to nR do - begin - indx := ix(i,i,nR + 2); - s := Arr[indx]; - Arr[indx] := 1.0; - for k := 0 to nR + 1 do - begin - indx := ix(i,k,nR + 2); - Arr[indx] := Arr[indx] / s; - end; - for j := 0 to nR do - begin - if i <> j then - begin - indx := ix(j,i,nR + 2); - s := Arr[indx]; - Arr[indx] := 0.0; - for k := 0 to nR + 1 do - begin - indx2 := ix(j,k,nR + 2); - indx3 := ix(i,k,nR + 2); - Arr[indx2] := Arr[indx2] - s * Arr[indx3]; - end; // next k - end; // if i not equal j - end; // next j - end; // next i - for j := 0 to nR do - begin - indx := ix(j,nR + 1,nR + 2); - Par[j] := Par[j] + Arr[indx]; - end; - end; // iteration - lReport.Add('Converged'); - lReport.Add(''); - lReport.Add('------------------------------------------------------------------'); - lReport.Add(''); - - CSq := LLn - LL; - prob := ChiSq(CSq,nR); - lReport.Add('Overall Model Fit... Chi Square = %8.4f with df = %3d and prob. = %8.4f', [Csq, nR, prob]); - lReport.Add(''); - lReport.Add('Coefficients and Standard Errors...'); - lReport.Add('Variable Label Coeff. StdErr p'); - for j := 1 to nR do - begin - Par[j] := Par[j] / xSD[j]; - indx := ix(j,j,nP + 1); - SEP[j] := sqrt(Arr[indx]) / xSD[j]; - Par[0] := Par[0] - Par[j] * xM[j]; - prob := Norm(abs(Par[j] / SEP[j])); - lReport.Add(' %3d %15s %10.4f %10.4f %10.4f', [j, RowLabels[j], Par[j], SEP[j], prob]); - end; - lReport.Add(''); -// OutputFrm.ShowModal; - - lReport.Add('Intercept %10.4f', [Par[0]]); - lReport.Add(''); - lReport.Add('Odds Ratios and 95% Confidence Intervals...'); - lReport.Add('Variable O.R. Low -- High'); - for j := 1 to nR do - begin - ORc := exp(Par[j]); - OR1 := exp(Par[j] - 1.96 * SEP[j]); - ORh := exp(Par[j] + 1.96 * SEP[j]); - lReport.Add('%15s %10.4f %10.4f %10.4f', [RowLabels[j], ORc, OR1, ORh]); - end; - for i := 1 to 3 do - for j := 1 to 3 do Table[i,j] := 0; - lReport.Add(''); - outline := ''; - if ProbsChk.Checked then - begin - for j := 1 to nR do outline := outline + ' X '; - outline := outline + ' Y Prob'; - lReport.Add(outline); - for i := 0 to nC - 1 do - begin - value := Par[0]; - outline := ''; - for j := 1 to nR do - begin - indx := ix(i,j,nR + 1); - xij := xM[j] + xSD[j] * X[indx]; - value := value + Par[j] * xij; - outline := outline + format(' %10.4f ',[xij]); - end; - value := 1.0 / (1.0 + exp( -value)); - outline := outline + format('%4.0f %10.4f',[Y1[i],value]); - lReport.Add(outline); - if round(Y1[i]) = 0 then row := 1 else row := 2; - if round(value) = 0 then col := 1 else col := 2; - Table[row,col] := Table[row,col] + 1; - end; // next i - end; - for i := 1 to 2 do - begin - for j := 1 to 2 do - begin - Table[i,3] := Table[i,3] + Table[i,j]; - Table[3,j] := Table[3,j] + Table[i,j]; - end; - end; - for i := 1 to 2 do Table[3,3] := Table[3,3] + Table[i,3]; - lReport.Add(''); - lReport.Add('Classification Table'); - lReport.Add(' Predicted'); - lReport.Add(' --------------- '); - lReport.Add('Observed 0 1 Total'); - lReport.Add(' --------------- '); - for i := 1 to 2 do - begin - outline := format(' %d ',[i-1]); - for j := 1 to 3 do outline := outline + format('| %3d ',[Table[i,j]]); - outline := outline + '|'; - lReport.Add(outline); - end; - lReport.Add(' --------------- '); - Outline := 'Total '; - for j := 1 to 3 do outline := outline + format('| %3d ',[Table[3,j]]); - outline := outline + ''; - lReport.Add(outline); - lReport.Add(' --------------- '); - - DisplayReport(lReport); - - finally - lReport.Free; - Arr := nil; - SEP := nil; - Par := nil; - xSD := nil; - xM := nil; - Y1 := nil; - Y0 := nil; - X := nil; - RowLabels := nil; - ColLabels := nil; - ColNoSelected := nil; - end; -end; - -procedure TLogRegFrm.DepOutBtnClick(Sender: TObject); -begin - if DepVar.Text <> '' then - begin - VarList.Items.Add(DepVar.Text); - DepVar.Text := ''; - end; - UpdateBtnStates; -end; - -procedure TLogRegFrm.FormActivate(Sender: TObject); -var - w: Integer; -begin - if FAutoSized then - exit; - - w := MaxValue([ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]); - ResetBtn.Constraints.MinWidth := w; - ComputeBtn.Constraints.MinWidth := w; - CloseBtn.Constraints.MinWidth := w; - - VarList.Constraints.MinHeight := OutBtn.Top + OutBtn.Height - VarList.Top; - - Constraints.MinHeight := Height; - Constraints.MinWidth := MaxItsEdit.Left + MaxItsEdit.Width + MaxItsEdit.BorderSpacing.Right; -// Constraints.MinWidth := Width; - - FAutoSized := true; -end; - -procedure TLogRegFrm.FormCreate(Sender: TObject); -begin - Assert(OS3MainFrm <> nil); -end; - -procedure TLogRegFrm.FormShow(Sender: TObject); -begin - ResetBtnClick(Self); -end; - -procedure TLogRegFrm.OutBtnClick(Sender: TObject); +procedure TLogRegForm.OutBtnClick(Sender: TObject); var i: integer; begin @@ -560,46 +546,34 @@ begin UpdateBtnStates; end; -function TLogRegFrm.ChiSq(x : double; n : integer) : double; + +procedure TLogRegForm.Reset; var - p, t, a : double; - k : integer; - + i: integer; begin - p := exp(-0.5 * x); - if n mod 2 = 1 then p := p * sqrt(2 * x / Pi); - k := n; - while K >= 2 do - begin - p := p * x / k; - k := k - 2; - end; - t := p; - a := n; - while t > 0.000001 * p do - begin - a := a + 2; - t := t * x / a; - p := p + t; - end; - ChiSq := (1 - p); + inherited; + + BlockList.Clear; + VarList.Clear; + for i := 1 to NoVariables do + VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); + DepVarEdit.Text := ''; + + ProbsChk.Checked := true; + DescChk.Checked := true; + MaxItsEdit.Text := '20'; + + UpdateBtnStates; end; -function TLogRegFrm.Norm(z : double): double; -begin - Norm := ChiSq(z * z, 1); -end; -function TLogRegFrm.ix(j, k, nCols : integer): integer; -begin - ix := j * nCols + k; -end; - -procedure TLogRegFrm.UpdateBtnStates; +procedure TLogRegForm.UpdateBtnStates; var i: Integer; lSelected: Boolean; begin + inherited; + lSelected := false; for i:=0 to VarList.Items.Count-1 do if VarList.Selected[i] then @@ -607,9 +581,9 @@ begin lSelected := true; break; end; - DepInBtn.Enabled := lSelected and (DepVar.Text = ''); + DepInBtn.Enabled := lSelected and (DepVarEdit.Text = ''); InBtn.Enabled := lSelected; - DepOutBtn.Enabled := DepVar.Text <> ''; + DepOutBtn.Enabled := DepVarEdit.Text <> ''; lSelected := false; for i := 0 to BlockList.Items.Count-1 do @@ -622,8 +596,65 @@ begin end; -initialization - {$I logregunit.lrs} +function TLogRegForm.Validate(out AMsg: String; out AControl: TWinControl): Boolean; +var + n: Integer; +begin + Result := false; + + if BlockList.Items.Count < 1 then + begin + AMsg := 'No independent variables selected.'; + AControl := BlockList; + exit; + end; + + if DepVarEdit.Text = '' then + begin + AMsg := 'No dependent variable selected.'; + AControl := DepVarEdit; + exit; + end; + + if MaxItsEdit.Text = '' then begin + AMsg := 'Maximum iterations not specified.'; + AControl := MaxItsEdit; + exit; + end; + + if not TryStrToInt(MaxItsEdit.Text, n) then + begin + AMsg := 'No valid number given for maximum iterations.'; + AControl := MaxItsEdit; + exit; + end; + + Result := true; +end; + + +procedure TLogRegForm.VarListDblClick(Sender: TObject); +var + index: Integer; +begin + index := VarList.ItemIndex; + if index > -1 then + begin + if DepVarEdit.Text = '' then + DepVarEdit.Text := VarList.Items[index] + else + BlockList.Items.Add(VarList.Items[index]); + VarList.Items.Delete(index); + UpdateBtnStates; + end; +end; + + +procedure TLogRegForm.VarListSelectionChange(Sender: TObject; User: boolean); +begin + UpdateBtnStates; +end; + end. diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/simultregunit.lfm b/applications/lazstats/source/forms/analysis/multiple_regression/simultregunit.lfm index 6ac4b3c0f..a48cfcea8 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/simultregunit.lfm +++ b/applications/lazstats/source/forms/analysis/multiple_regression/simultregunit.lfm @@ -1,286 +1,250 @@ -object SimultFrm: TSimultFrm - Left = 872 +inherited SimultForm: TSimultForm + Left = 619 Height = 447 - Top = 291 - Width = 437 + Top = 274 + Width = 866 HelpType = htKeyword HelpKeyword = 'html/SimultaneousMultipleRegression.htm' - AutoSize = True Caption = 'Simultaneous Multiple Regression' ClientHeight = 447 - ClientWidth = 437 - 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 = ListBox1 - AnchorSideTop.Control = Owner - Left = 249 - Height = 15 - Top = 8 - Width = 127 - BorderSpacing.Top = 8 - Caption = 'Variables to be Analyzed' - ParentColor = False - end - object VarList: TListBox - AnchorSideLeft.Control = Owner - AnchorSideTop.Control = Label1 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = AllBtn - AnchorSideBottom.Control = GroupBox1 - Left = 8 - Height = 234 - Top = 25 - Width = 179 - Anchors = [akTop, akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Top = 2 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Constraints.MinHeight = 220 - ItemHeight = 0 - MultiSelect = True - OnSelectionChange = VarListSelectionChange - TabOrder = 0 - end - object InBtn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - Left = 204 - Height = 28 - Top = 25 - Width = 28 - Images = MainDataModule.ImageList - ImageIndex = 1 - OnClick = InBtnClick - Spacing = 0 - TabOrder = 1 - end - object OutBtn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - Left = 204 - Height = 28 - Top = 65 - Width = 28 - Images = MainDataModule.ImageList - ImageIndex = 0 - OnClick = OutBtnClick - Spacing = 0 - TabOrder = 2 - end - object AllBtn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - Left = 195 - Height = 25 - Top = 112 - Width = 46 - AutoSize = True - Caption = 'ALL' - OnClick = AllBtnClick - TabOrder = 3 - end - object ListBox1: TListBox - AnchorSideLeft.Control = AllBtn - AnchorSideLeft.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = GroupBox1 - Left = 249 - Height = 235 - Top = 24 - Width = 180 - Anchors = [akTop, akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - ItemHeight = 0 - MultiSelect = True - OnSelectionChange = VarListSelectionChange - TabOrder = 4 - end - object GroupBox1: TGroupBox - AnchorSideLeft.Control = Owner - AnchorSideTop.Side = asrBottom - AnchorSideBottom.Control = Bevel1 - Left = 8 - Height = 123 - Top = 267 - Width = 417 - Anchors = [akLeft, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Caption = 'Options' - ChildSizing.LeftRightSpacing = 12 - ChildSizing.HorizontalSpacing = 16 - ChildSizing.VerticalSpacing = 2 - ChildSizing.EnlargeHorizontal = crsHomogenousChildResize - ChildSizing.Layout = cclLeftToRightThenTopToBottom - ChildSizing.ControlsPerLine = 2 - ClientHeight = 103 - ClientWidth = 413 - TabOrder = 5 - object MatInChkBox: TCheckBox - Left = 12 - Height = 19 - Top = 0 - Width = 175 - Caption = 'Get Data From a Matrix File' - TabOrder = 0 + ClientWidth = 866 + inherited ParamsPanel: TPanel + Height = 431 + Width = 407 + ClientHeight = 431 + ClientWidth = 407 + inherited CloseBtn: TButton + Left = 352 + Top = 406 + TabOrder = 9 end - object MatSaveChkBox: TCheckBox - Left = 203 - Height = 19 - Top = 0 - Width = 198 - Caption = 'Save Correlation Matrix' - TabOrder = 1 - end - object CPChkBox: TCheckBox - Left = 12 - Height = 19 - Top = 21 - Width = 175 - Caption = 'Show Cross-Products Matrix' - TabOrder = 2 - end - object CovChkBox: TCheckBox - Left = 203 - Height = 19 - Top = 21 - Width = 198 - Caption = 'Show Variance-Covariance Matrix' - TabOrder = 3 - end - object CorrsChkBox: TCheckBox - Left = 12 - Height = 19 - Top = 42 - Width = 175 - Caption = 'Show Intercorrelations Matrix' - TabOrder = 4 - end - object MeansChkBox: TCheckBox - Left = 203 - Height = 19 - Top = 42 - Width = 198 - Caption = 'Show Means' - TabOrder = 5 - end - object VarChkBox: TCheckBox - Left = 12 - Height = 19 - Top = 63 - Width = 175 - Caption = 'Show Variances' - TabOrder = 6 - end - object SDChkBox: TCheckBox - Left = 203 - Height = 19 - Top = 63 - Width = 198 - Caption = 'Show Standard Deviations' - TabOrder = 7 - end - object InvMatChkBox: TCheckBox - Left = 12 - Height = 19 - Top = 84 - Width = 175 - Caption = 'Show Inverse Matrix' + inherited ComputeBtn: TButton + Left = 268 + Top = 406 TabOrder = 8 end + inherited ResetBtn: TButton + Left = 206 + Top = 406 + TabOrder = 7 + end + inherited HelpBtn: TButton + Left = 147 + Top = 406 + TabOrder = 6 + end + inherited ButtonBevel: TBevel + Top = 390 + Width = 407 + 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 = SelList + AnchorSideTop.Control = ParamsPanel + Left = 231 + Height = 15 + Top = 0 + Width = 127 + Caption = 'Variables to be Analyzed' + ParentColor = False + end + object VarList: TListBox[7] + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = Label1 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = AllBtn + AnchorSideBottom.Control = OptionsGroup + Left = 0 + Height = 222 + Top = 17 + Width = 177 + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Top = 2 + BorderSpacing.Right = 6 + BorderSpacing.Bottom = 8 + Constraints.MinHeight = 220 + ItemHeight = 0 + MultiSelect = True + OnDblClick = VarListDblClick + OnSelectionChange = VarListSelectionChange + TabOrder = 0 + end + object InBtn: TBitBtn[8] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + Left = 190 + Height = 26 + Top = 25 + Width = 26 + Images = MainDataModule.ImageList + ImageIndex = 1 + OnClick = InBtnClick + Spacing = 0 + TabOrder = 1 + end + object OutBtn: TBitBtn[9] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + Left = 190 + Height = 26 + Top = 65 + Width = 26 + Images = MainDataModule.ImageList + ImageIndex = 0 + OnClick = OutBtnClick + Spacing = 0 + TabOrder = 2 + end + object AllBtn: TBitBtn[10] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + Left = 183 + Height = 25 + Top = 112 + Width = 40 + AutoSize = True + Caption = 'All' + OnClick = AllBtnClick + TabOrder = 3 + end + object SelList: TListBox[11] + AnchorSideLeft.Control = AllBtn + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = Label2 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = OptionsGroup + Left = 231 + Height = 222 + Top = 17 + Width = 168 + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Left = 8 + BorderSpacing.Top = 2 + BorderSpacing.Right = 8 + BorderSpacing.Bottom = 8 + ItemHeight = 0 + MultiSelect = True + OnDblClick = SelListDblClick + OnSelectionChange = VarListSelectionChange + TabOrder = 4 + end + object OptionsGroup: TGroupBox[12] + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Control = ButtonBevel + Left = 0 + Height = 135 + Top = 247 + Width = 417 + Anchors = [akLeft, akBottom] + AutoSize = True + BorderSpacing.Right = 8 + BorderSpacing.Bottom = 8 + Caption = 'Options' + ChildSizing.LeftRightSpacing = 12 + ChildSizing.TopBottomSpacing = 6 + ChildSizing.HorizontalSpacing = 16 + ChildSizing.VerticalSpacing = 2 + ChildSizing.EnlargeHorizontal = crsHomogenousChildResize + ChildSizing.Layout = cclLeftToRightThenTopToBottom + ChildSizing.ControlsPerLine = 2 + ClientHeight = 115 + ClientWidth = 413 + TabOrder = 5 + object MatInChkBox: TCheckBox + Left = 12 + Height = 19 + Top = 6 + Width = 175 + Caption = 'Get Data From a Matrix File' + TabOrder = 0 + end + object MatSaveChkBox: TCheckBox + Left = 203 + Height = 19 + Top = 6 + Width = 198 + Caption = 'Save Correlation Matrix' + TabOrder = 1 + end + object CPChkBox: TCheckBox + Left = 12 + Height = 19 + Top = 27 + Width = 175 + Caption = 'Show Cross-Products Matrix' + TabOrder = 2 + end + object CovChkBox: TCheckBox + Left = 203 + Height = 19 + Top = 27 + Width = 198 + Caption = 'Show Variance-Covariance Matrix' + TabOrder = 3 + end + object CorrsChkBox: TCheckBox + Left = 12 + Height = 19 + Top = 48 + Width = 175 + Caption = 'Show Intercorrelations Matrix' + TabOrder = 4 + end + object MeansChkBox: TCheckBox + Left = 203 + Height = 19 + Top = 48 + Width = 198 + Caption = 'Show Means' + TabOrder = 5 + end + object VarChkBox: TCheckBox + Left = 12 + Height = 19 + Top = 69 + Width = 175 + Caption = 'Show Variances' + TabOrder = 6 + end + object SDChkBox: TCheckBox + Left = 203 + Height = 19 + Top = 69 + Width = 198 + Caption = 'Show Standard Deviations' + TabOrder = 7 + end + object InvMatChkBox: TCheckBox + Left = 12 + Height = 19 + Top = 90 + Width = 175 + Caption = 'Show Inverse Matrix' + TabOrder = 8 + end + end end - object ResetBtn: TButton - AnchorSideRight.Control = ComputeBtn - AnchorSideBottom.Control = Owner - AnchorSideBottom.Side = asrBottom - Left = 228 - Height = 25 - Top = 414 - Width = 54 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Caption = 'Reset' - OnClick = ResetBtnClick - TabOrder = 6 + inherited ParamsSplitter: TSplitter + Left = 419 + Height = 447 end - object ComputeBtn: TButton - AnchorSideRight.Control = CloseBtn - AnchorSideBottom.Control = Owner - AnchorSideBottom.Side = asrBottom - Left = 290 - Height = 25 - Top = 414 - Width = 76 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Caption = 'Compute' - OnClick = ComputeBtnClick - TabOrder = 7 - end - object CloseBtn: TButton - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = Owner - AnchorSideBottom.Side = asrBottom - Left = 374 - Height = 25 - Top = 414 - Width = 55 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Caption = 'Close' - ModalResult = 11 - TabOrder = 8 - end - object Bevel1: TBevel - AnchorSideLeft.Control = Owner - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = CloseBtn - Left = 0 - Height = 8 - Top = 398 - Width = 437 - Anchors = [akLeft, akRight, akBottom] - Shape = bsBottomLine - end - object OpenDialog1: TOpenDialog + object OpenDialog1: TOpenDialog[2] Left = 88 Top = 96 end - object SaveDialog1: TSaveDialog + object SaveDialog1: TSaveDialog[3] Left = 88 Top = 160 end diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/simultregunit.pas b/applications/lazstats/source/forms/analysis/multiple_regression/simultregunit.pas index 029e1ba12..03427459d 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/simultregunit.pas +++ b/applications/lazstats/source/forms/analysis/multiple_regression/simultregunit.pas @@ -7,20 +7,16 @@ unit SimultRegUnit; interface uses - Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Buttons, ExtCtrls, - Globals, MainUnit, MatrixLib, OutputUnit, FunctionsLib, DataProcs; + Globals, MainUnit, MatrixLib, FunctionsLib, DataProcs, BasicStatsReportFormUnit; type - { TSimultFrm } + { TSimultForm } - TSimultFrm = class(TForm) - Bevel1: TBevel; + TSimultForm = class(TBasicStatsReportForm) OpenDialog1: TOpenDialog; - ResetBtn: TButton; - ComputeBtn: TButton; - CloseBtn: TButton; MatInChkBox: TCheckBox; MatSaveChkBox: TCheckBox; CPChkBox: TCheckBox; @@ -31,103 +27,91 @@ type VarChkBox: TCheckBox; SDChkBox: TCheckBox; InvMatChkBox: TCheckBox; - GroupBox1: TGroupBox; + OptionsGroup: TGroupBox; InBtn: TBitBtn; OutBtn: TBitBtn; AllBtn: TBitBtn; Label1: TLabel; Label2: TLabel; - ListBox1: TListBox; + SelList: TListBox; VarList: TListBox; procedure AllBtnClick(Sender: TObject); - procedure ComputeBtnClick(Sender: TObject); - procedure FormActivate(Sender: TObject); - procedure FormCreate(Sender: TObject); - procedure FormShow(Sender: TObject); procedure InBtnClick(Sender: TObject); procedure OutBtnClick(Sender: TObject); - procedure ResetBtnClick(Sender: TObject); + procedure SelListDblClick(Sender: TObject); + procedure VarListDblClick(Sender: TObject); procedure VarListSelectionChange(Sender: TObject; User: boolean); private - { private declarations } - procedure UpdateBtnStates; + + protected + procedure AdjustConstraints; override; + procedure Compute; override; + procedure UpdateBtnStates; override; + public - { public declarations } + procedure Reset; override; end; var - SimultFrm: TSimultFrm; + SimultForm: TSimultForm; + implementation +{$R *.lfm} + uses Math, Utils, MathUnit; -{ TSimultFrm } -procedure TSimultFrm.ResetBtnClick(Sender: TObject); -VAR i : integer; +{ TSimultForm } + +procedure TSimultForm.AdjustConstraints; begin - VarList.Clear; - ListBox1.Clear; - for i := 1 to NoVariables do - begin - VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); - end; - InBtn.Enabled := true; - OutBtn.Enabled := false; - CPChkBox.Checked := false; - CovChkBox.Checked := false; - CorrsChkBox.Checked := true; - MeansChkBox.Checked := true; - VarChkBox.Checked := false; - SDChkBox.Checked := true; - MatInChkBox.Checked := false; - MatSaveChkBox.Checked := false; + inherited; + + ParamsPanel.Constraints.MinWidth := Max( + 4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left, + OptionsGroup.Width); + + ParamsPanel.Constraints.MinHeight := AllBtn.Top + AllBtn.Height + + VarList.BorderSpacing.Bottom + OptionsGroup.Height + ButtonBevel.Height + + CloseBtn.BorderSpacing.Top + CloseBtn.Height; end; -procedure TSimultFrm.VarListSelectionChange(Sender: TObject; User: boolean); -begin - UpdateBtnStates; -end; -procedure TSimultFrm.FormShow(Sender: TObject); -begin - ResetBtnClick(Self); -end; - -procedure TSimultFrm.AllBtnClick(Sender: TObject); +procedure TSimultForm.AllBtnClick(Sender: TObject); var index: integer; begin for index := 0 to VarList.Items.Count-1 do - ListBox1.Items.Add(VarList.Items[index]); + SelList.Items.Add(VarList.Items[index]); VarList.Clear; UpdateBtnStates; end; -procedure TSimultFrm.ComputeBtnClick(Sender: TObject); +procedure TSimultForm.Compute; var NoVars, i, j, NCases, errcode: integer; StdErr, df1, df2, x, determinant : double; errorcode : boolean = false; filename : string; cellstring, valstring : string; - Corrs : DblDyneMat; - Means : DblDyneVec; - Variances : DblDyneVec; - StdDevs : DblDyneVec; - ColNoSelected : IntDyneVec; + Corrs : DblDyneMat = nil; + Means : DblDyneVec = nil; + Variances : DblDyneVec = nil; + StdDevs : DblDyneVec = nil; + ColNoSelected : IntDyneVec = nil; title : string; - RowLabels : StrDyneVec; - ColLabels : StrDyneVec; - InverseMat : DblDyneMat; - R2s : DblDyneVec; - W : DblDyneVec; - ProdMat : DblDyneMat; - FProbs : DblDyneVec; - CorrMat : DblDyneMat; + RowLabels : StrDyneVec = nil; + ColLabels : StrDyneVec = nil; + InverseMat : DblDyneMat = nil; + R2s : DblDyneVec = nil; + W : DblDyneVec = nil; + ProdMat : DblDyneMat = nil; + FProbs : DblDyneVec = nil; + CorrMat : DblDyneMat = nil; lReport: TStrings; begin @@ -165,7 +149,7 @@ begin end else begin { get variable columns } - NoVars := ListBox1.Items.Count; + NoVars := SelList.Items.Count; if NoVars < 1 then begin MessageDlg('No variables selected.',mtError, [mbOK], 0); @@ -173,7 +157,7 @@ begin end; for i := 1 to NoVars do begin - cellstring := ListBox1.Items.Strings[i-1]; + cellstring := SelList.Items.Strings[i-1]; for j := 1 to NoVariables do begin if cellstring = OS3MainFrm.DataGrid.Cells[j,0] then @@ -354,7 +338,7 @@ begin finally if lReport.Count > 0 then - DisplayReport(lReport); + FReportFrame.DisplayReport(lReport); ColNoSelected := nil; CorrMat := nil; @@ -372,25 +356,8 @@ begin end; end; -procedure TSimultFrm.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; - Constraints.MinWidth := Width; - Constraints.MinHeight := Height; -end; - -procedure TSimultFrm.FormCreate(Sender: TObject); -begin - Assert(OS3MainFrm <> nil); -end; - -procedure TSimultFrm.InBtnClick(Sender: TObject); +procedure TSimultForm.InBtnClick(Sender: TObject); var i: integer; begin @@ -399,7 +366,7 @@ begin begin if VarList.Selected[i] then begin - ListBox1.Items.Add(VarList.Items[i]); + SelList.Items.Add(VarList.Items[i]); VarList.Items.Delete(i); i := 0; end @@ -409,17 +376,18 @@ begin UpdateBtnStates; end; -procedure TSimultFrm.OutBtnClick(Sender: TObject); + +procedure TSimultForm.OutBtnClick(Sender: TObject); var i: integer; begin i := 0; - while i < Listbox1.Items.Count do + while i < SelList.Items.Count do begin - if Listbox1.Selected[i] then + if SelList.Selected[i] then begin - VarList.Items.Add(Listbox1.Items[i]); - Listbox1.Items.Delete(i); + VarList.Items.Add(SelList.Items[i]); + SelList.Items.Delete(i); i := 0; end else inc(i); @@ -427,15 +395,72 @@ begin UpdateBtnStates; end; -procedure TSimultFrm.UpdateBtnStates; + +procedure TSimultForm.Reset; +var + i: integer; begin + inherited; + + VarList.Clear; + SelList.Clear; + for i := 1 to NoVariables do + VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); + + CPChkBox.Checked := false; + CovChkBox.Checked := false; + CorrsChkBox.Checked := false; + MeansChkBox.Checked := false; + VarChkBox.Checked := false; + SDChkBox.Checked := false; + MatInChkBox.Checked := false; + MatSaveChkBox.Checked := false; + + UpdateBtnStates; +end; + + +procedure TSimultForm.SelListDblClick(Sender: TObject); +var + index: Integer; +begin + index := SelList.ItemIndex; + if index > -1 then + begin + VarList.Items.Add(SelList.Items[index]); + SelList.Items.Delete(index); + UpdateBtnStates; + end; +end; + +procedure TSimultForm.VarListDblClick(Sender: TObject); +var + index: Integer; +begin + index := VarList.ItemIndex; + if index > -1 then + begin + SelList.Items.Add(VarList.Items[index]); + VarList.Items.Delete(index); + UpdateBtnStates; + end; +end; + + +procedure TSimultForm.VarListSelectionChange(Sender: TObject; User: boolean); +begin + UpdateBtnStates; +end; + + +procedure TSimultForm.UpdateBtnStates; +begin + inherited; + InBtn.Enabled := AnySelected(VarList); - OutBtn.Enabled := AnySelected(ListBox1); + OutBtn.Enabled := AnySelected(SelList); AllBtn.Enabled := VarList.Items.Count > 0; end; -initialization - {$I simultregunit.lrs} - end. diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/twoslsunit.lfm b/applications/lazstats/source/forms/analysis/multiple_regression/twoslsunit.lfm index a5ad7b79d..e3754fdbd 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/twoslsunit.lfm +++ b/applications/lazstats/source/forms/analysis/multiple_regression/twoslsunit.lfm @@ -1,377 +1,300 @@ -object TwoSLSFrm: TTwoSLSFrm +inherited TwoSLSForm: TTwoSLSForm Left = 582 - Height = 416 + Height = 376 Top = 203 Width = 415 HelpType = htKeyword HelpKeyword = 'html/TwoStageLeastSquaresRegression.htm' - AutoSize = True Caption = 'Two Stage Least Squares Regression' - ClientHeight = 416 + ClientHeight = 376 ClientWidth = 415 - 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 = 46 - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - Caption = 'Variables' - ParentColor = False - end - object Label2: TLabel - AnchorSideLeft.Control = DepVarEdit - AnchorSideTop.Control = DepIn - AnchorSideBottom.Control = DepVarEdit - Left = 229 - Height = 15 - Top = 25 - Width = 102 - Caption = 'Dependent Variable' - ParentColor = False - end - object Label3: TLabel - AnchorSideLeft.Control = Explanatory - AnchorSideTop.Control = ExpIn - Left = 229 - Height = 15 - Top = 101 - Width = 111 - Caption = 'Explanatory Variables' - ParentColor = False - end - object Label4: TLabel - AnchorSideLeft.Control = Instrumental - AnchorSideTop.Control = Bevel2 - AnchorSideTop.Side = asrCenter - Left = 229 - Height = 15 - Top = 182 - Width = 116 - Caption = 'Instrumental Variables' - ParentColor = False - end - object VarList: TListBox - AnchorSideLeft.Control = Owner - AnchorSideTop.Control = Label1 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = DepIn - AnchorSideBottom.Control = GroupBox1 - Left = 8 - Height = 253 - Top = 25 - Width = 177 - Anchors = [akTop, akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Top = 2 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Constraints.MinHeight = 220 - ItemHeight = 0 - MultiSelect = True - OnSelectionChange = ExplanatorySelectionChange - TabOrder = 0 - end - object DepIn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = VarList - Left = 193 - Height = 28 - Top = 25 - Width = 28 - Images = MainDataModule.ImageList - ImageIndex = 1 - OnClick = DepInClick - Spacing = 0 - TabOrder = 1 - end - object DepOut: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = DepIn - AnchorSideTop.Side = asrBottom - Left = 193 - Height = 28 - Top = 57 - Width = 28 - BorderSpacing.Top = 4 - Images = MainDataModule.ImageList - ImageIndex = 0 - OnClick = DepOutClick - Spacing = 0 - TabOrder = 2 - end - object ExpIn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = DepOut - AnchorSideTop.Side = asrBottom - Left = 193 - Height = 28 - Top = 101 - Width = 28 - BorderSpacing.Top = 16 - Images = MainDataModule.ImageList - ImageIndex = 1 - OnClick = ExpInClick - Spacing = 0 - TabOrder = 4 - end - object ExpOut: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = ExpIn - AnchorSideTop.Side = asrBottom - Left = 193 - Height = 28 - Top = 133 - Width = 28 - BorderSpacing.Top = 4 - Images = MainDataModule.ImageList - ImageIndex = 0 - OnClick = ExpOutClick - Spacing = 0 - TabOrder = 5 - end - object InstIn: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = Label4 - AnchorSideBottom.Control = InstOut - Left = 193 - Height = 28 - Top = 182 - Width = 28 - BorderSpacing.Bottom = 4 - Images = MainDataModule.ImageList - ImageIndex = 1 - OnClick = InstInClick - Spacing = 0 - TabOrder = 7 - end - object InstOut: TBitBtn - AnchorSideLeft.Control = Owner - AnchorSideLeft.Side = asrCenter - AnchorSideTop.Control = InstIn - AnchorSideTop.Side = asrBottom - AnchorSideBottom.Control = VarList - AnchorSideBottom.Side = asrBottom - Left = 193 - Height = 28 - Top = 214 - Width = 28 - BorderSpacing.Top = 4 - Images = MainDataModule.ImageList - ImageIndex = 0 - OnClick = InstOutClick - Spacing = 0 - TabOrder = 8 - end - object DepVarEdit: TEdit - AnchorSideLeft.Control = DepIn - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = Label2 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = DepOut - AnchorSideBottom.Side = asrBottom - Left = 229 - Height = 23 - Top = 42 - Width = 178 - Anchors = [akTop, akLeft, akRight] - BorderSpacing.Left = 8 - BorderSpacing.Top = 2 - BorderSpacing.Right = 8 - ReadOnly = True - TabOrder = 3 - Text = 'DepVarEdit' - end - object Explanatory: TListBox - AnchorSideLeft.Control = ExpIn - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = Label3 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = Label4 - Left = 229 - Height = 40 - Top = 118 - Width = 178 - Anchors = [akTop, akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Top = 2 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 24 - ItemHeight = 0 - MultiSelect = True - OnSelectionChange = ExplanatorySelectionChange - TabOrder = 6 - end - object Instrumental: TListBox - AnchorSideLeft.Control = InstIn - AnchorSideLeft.Side = asrBottom - AnchorSideTop.Control = Label4 - AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = GroupBox1 - Left = 229 - Height = 79 - Top = 199 - Width = 178 - Anchors = [akTop, akLeft, akRight, akBottom] - BorderSpacing.Left = 8 - BorderSpacing.Top = 2 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - ItemHeight = 0 - MultiSelect = True - OnSelectionChange = ExplanatorySelectionChange - TabOrder = 9 - end - object GroupBox1: TGroupBox - AnchorSideLeft.Control = Owner - AnchorSideBottom.Control = Bevel1 - Left = 8 - Height = 73 - Top = 286 - Width = 316 - Anchors = [akLeft, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Bottom = 8 - Caption = 'Options' - ChildSizing.LeftRightSpacing = 16 - ChildSizing.TopBottomSpacing = 6 - ChildSizing.VerticalSpacing = 2 - ClientHeight = 53 - ClientWidth = 312 - TabOrder = 10 - object ProxyRegShowChk: TCheckBox - Left = 16 - Height = 19 - Top = 6 - Width = 273 - Caption = 'Show Regression Results for each Proxy Variable' + inherited ParamsPanel: TPanel + Height = 360 + Width = 315 + ClientHeight = 360 + ClientWidth = 315 + inherited CloseBtn: TButton + Left = 260 + Top = 335 + TabOrder = 14 + end + inherited ComputeBtn: TButton + Left = 176 + Top = 335 + TabOrder = 13 + end + inherited ResetBtn: TButton + Left = 114 + Top = 335 + TabOrder = 12 + end + inherited HelpBtn: TButton + Left = 55 + Top = 335 + TabOrder = 11 + end + inherited ButtonBevel: TBevel + Top = 319 + Width = 315 + end + object Label1: TLabel[5] + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = ParamsPanel + Left = 0 + Height = 15 + Top = 0 + Width = 46 + Caption = 'Variables' + ParentColor = False + end + object Label2: TLabel[6] + AnchorSideLeft.Control = DepVarEdit + AnchorSideTop.Control = DepIn + AnchorSideBottom.Control = DepVarEdit + Left = 176 + Height = 15 + Top = 17 + Width = 102 + Caption = 'Dependent Variable' + ParentColor = False + end + object Label3: TLabel[7] + AnchorSideLeft.Control = ExplanatoryList + AnchorSideTop.Control = ExpIn + Left = 176 + Height = 15 + Top = 89 + Width = 111 + Caption = 'Explanatory Variables' + ParentColor = False + end + object Label4: TLabel[8] + AnchorSideLeft.Control = InstrumentalList + AnchorSideTop.Side = asrCenter + Left = 176 + Height = 15 + Top = 182 + Width = 116 + Caption = 'Instrumental Variables' + ParentColor = False + end + object VarList: TListBox[9] + AnchorSideLeft.Control = ParamsPanel + AnchorSideTop.Control = Label1 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = DepIn + AnchorSideBottom.Control = OptionsGroup + Left = 0 + Height = 221 + Top = 17 + Width = 138 + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Top = 2 + BorderSpacing.Right = 6 + BorderSpacing.Bottom = 8 + Constraints.MinHeight = 220 + ItemHeight = 0 + MultiSelect = True + OnDblClick = VarListDblClick + OnSelectionChange = ExplanatoryListSelectionChange TabOrder = 0 end - object SaveItChk: TCheckBox - Left = 16 - Height = 19 - Top = 28 - Width = 280 - Caption = 'Save Predicted and Residuals of 2nd Stage to Grid' + object DepIn: TBitBtn[10] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = VarList + Left = 144 + Height = 26 + Top = 17 + Width = 26 + Images = MainDataModule.ImageList + ImageIndex = 1 + OnClick = DepInClick + Spacing = 0 TabOrder = 1 end + object DepOut: TBitBtn[11] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = DepIn + AnchorSideTop.Side = asrBottom + Left = 144 + Height = 26 + Top = 47 + Width = 26 + BorderSpacing.Top = 4 + Images = MainDataModule.ImageList + ImageIndex = 0 + OnClick = DepOutClick + Spacing = 0 + TabOrder = 3 + end + object ExpIn: TBitBtn[12] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = DepOut + AnchorSideTop.Side = asrBottom + Left = 144 + Height = 26 + Top = 89 + Width = 26 + BorderSpacing.Top = 16 + Images = MainDataModule.ImageList + ImageIndex = 1 + OnClick = ExpInClick + Spacing = 0 + TabOrder = 4 + end + object ExpOut: TBitBtn[13] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = ExpIn + AnchorSideTop.Side = asrBottom + Left = 144 + Height = 26 + Top = 119 + Width = 26 + BorderSpacing.Top = 4 + Images = MainDataModule.ImageList + ImageIndex = 0 + OnClick = ExpOutClick + Spacing = 0 + TabOrder = 5 + end + object InstIn: TBitBtn[14] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = Label4 + AnchorSideBottom.Control = InstOut + Left = 144 + Height = 26 + Top = 182 + Width = 26 + BorderSpacing.Bottom = 4 + Images = MainDataModule.ImageList + ImageIndex = 1 + OnClick = InstInClick + Spacing = 0 + TabOrder = 7 + end + object InstOut: TBitBtn[15] + AnchorSideLeft.Control = ParamsPanel + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = InstIn + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Control = VarList + AnchorSideBottom.Side = asrBottom + Left = 144 + Height = 26 + Top = 212 + Width = 26 + BorderSpacing.Top = 4 + Images = MainDataModule.ImageList + ImageIndex = 0 + OnClick = InstOutClick + Spacing = 0 + TabOrder = 8 + end + object DepVarEdit: TEdit[16] + AnchorSideLeft.Control = DepIn + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = Label2 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = DepOut + AnchorSideBottom.Side = asrBottom + Left = 176 + Height = 23 + Top = 34 + Width = 139 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Left = 6 + BorderSpacing.Top = 2 + ReadOnly = True + TabOrder = 2 + Text = 'DepVarEdit' + end + object ExplanatoryList: TListBox[17] + AnchorSideLeft.Control = ExpIn + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = Label3 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = Label4 + Left = 176 + Height = 52 + Top = 106 + Width = 139 + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Left = 6 + BorderSpacing.Top = 2 + BorderSpacing.Bottom = 24 + ItemHeight = 0 + MultiSelect = True + OnDblClick = ExplanatoryListDblClick + OnSelectionChange = ExplanatoryListSelectionChange + TabOrder = 6 + end + object InstrumentalList: TListBox[18] + AnchorSideLeft.Control = InstIn + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = Label4 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ParamsPanel + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = OptionsGroup + Left = 176 + Height = 39 + Top = 199 + Width = 139 + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Left = 6 + BorderSpacing.Top = 2 + BorderSpacing.Bottom = 8 + ItemHeight = 0 + MultiSelect = True + OnDblClick = InstrumentalListDblClick + OnSelectionChange = ExplanatoryListSelectionChange + TabOrder = 9 + end + object OptionsGroup: TGroupBox[19] + AnchorSideLeft.Control = ParamsPanel + Left = 0 + Height = 73 + Top = 246 + Width = 316 + Anchors = [akLeft, akBottom] + AutoSize = True + BorderSpacing.Bottom = 8 + Caption = 'Options' + ChildSizing.LeftRightSpacing = 16 + ChildSizing.TopBottomSpacing = 6 + ChildSizing.VerticalSpacing = 2 + ClientHeight = 53 + ClientWidth = 312 + TabOrder = 10 + object ProxyRegShowChk: TCheckBox + Left = 16 + Height = 19 + Top = 6 + Width = 273 + Caption = 'Show Regression Results for each Proxy Variable' + TabOrder = 0 + end + object SaveItChk: TCheckBox + Left = 16 + Height = 19 + Top = 28 + Width = 280 + Caption = 'Save Predicted and Residuals of 2nd Stage to Grid' + TabOrder = 1 + end + end end - object ResetBtn: TButton - AnchorSideRight.Control = ComputeBtn - AnchorSideBottom.Control = Owner - AnchorSideBottom.Side = asrBottom - Left = 202 - Height = 25 - Top = 383 - Width = 54 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 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 = 264 - Height = 25 - Top = 383 - Width = 76 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 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 = 348 - Height = 25 - Top = 383 - Width = 55 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 8 - BorderSpacing.Top = 8 - BorderSpacing.Right = 12 - BorderSpacing.Bottom = 8 - Caption = 'Close' - ModalResult = 11 - TabOrder = 14 - end - object HelpBtn: TButton - Tag = 153 - AnchorSideRight.Control = ResetBtn - AnchorSideBottom.Control = Owner - AnchorSideBottom.Side = asrBottom - Left = 143 - Height = 25 - Top = 383 - Width = 51 - Anchors = [akRight, akBottom] - AutoSize = True - BorderSpacing.Left = 12 - BorderSpacing.Top = 8 - BorderSpacing.Right = 8 - BorderSpacing.Bottom = 8 - Caption = 'Help' - OnClick = HelpBtnClick - TabOrder = 11 - end - object Bevel1: TBevel - AnchorSideLeft.Control = Owner - AnchorSideRight.Control = Owner - AnchorSideRight.Side = asrBottom - AnchorSideBottom.Control = CloseBtn - Left = 0 - Height = 8 - Top = 367 - Width = 415 - Anchors = [akLeft, akRight, akBottom] - Shape = bsBottomLine - end - object Bevel2: TBevel - AnchorSideLeft.Control = DepIn - AnchorSideTop.Control = ExpIn - AnchorSideRight.Control = DepIn - AnchorSideBottom.Control = VarList - AnchorSideBottom.Side = asrBottom - Left = 189 - Height = 177 - Top = 101 - Width = 4 - Anchors = [akTop, akRight, akBottom] - Shape = bsSpacer + inherited ParamsSplitter: TSplitter + Left = 327 + Height = 376 end end diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/twoslsunit.pas b/applications/lazstats/source/forms/analysis/multiple_regression/twoslsunit.pas index c305af11a..b506228b6 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/twoslsunit.pas +++ b/applications/lazstats/source/forms/analysis/multiple_regression/twoslsunit.pas @@ -1,7 +1,7 @@ // File for testing: "cansas.laz" // - dependent variable: jumpgs // - exolanatory variables: pulse, chins, situps -// - instrumental variables: pulse, chins, situps, weight, waist +// - InstrumentalList variables: pulse, chins, situps, weight, waist unit TwoSLSUnit; @@ -10,28 +10,23 @@ unit TwoSLSUnit; interface uses - Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Buttons, ExtCtrls, math, - Globals, MainUnit, MainDM, MatrixLib, DictionaryUnit, OutputUnit, ContextHelpUnit; + Globals, MainUnit, MainDM, MatrixLib, DictionaryUnit, BasicStatsReportFormUnit; type - { TTwoSLSFrm } + { TTwoSLSForm } - TTwoSLSFrm = class(TForm) - Bevel1: TBevel; + TTwoSLSForm = class(TBasicStatsReportForm) Bevel2: TBevel; - HelpBtn: TButton; - ResetBtn: TButton; - ComputeBtn: TButton; - CloseBtn: TButton; ProxyRegShowChk: TCheckBox; SaveItChk: TCheckBox; DepIn: TBitBtn; DepOut: TBitBtn; ExpIn: TBitBtn; ExpOut: TBitBtn; - GroupBox1: TGroupBox; + OptionsGroup: TGroupBox; InstIn: TBitBtn; InstOut: TBitBtn; DepVarEdit: TEdit; @@ -39,132 +34,70 @@ type Label2: TLabel; Label3: TLabel; Label4: TLabel; - Explanatory: TListBox; - Instrumental: TListBox; + ExplanatoryList: TListBox; + InstrumentalList: TListBox; VarList: TListBox; - procedure ComputeBtnClick(Sender: TObject); procedure DepInClick(Sender: TObject); procedure DepOutClick(Sender: TObject); procedure ExpInClick(Sender: TObject); - procedure ExplanatorySelectionChange(Sender: TObject; User: boolean); + procedure ExplanatoryListDblClick(Sender: TObject); + procedure ExplanatoryListSelectionChange(Sender: TObject; User: boolean); procedure ExpOutClick(Sender: TObject); - procedure FormActivate(Sender: TObject); - procedure FormCreate(Sender: TObject); - procedure FormShow(Sender: TObject); - procedure HelpBtnClick(Sender: TObject); procedure InstInClick(Sender: TObject); procedure InstOutClick(Sender: TObject); - procedure ResetBtnClick(Sender: TObject); + procedure InstrumentalListDblClick(Sender: TObject); procedure PredictIt(const ColNoSelected: IntDyneVec; NoVars: integer; Means, StdDevs, BetaWeights : DblDyneVec; StdErrEst : double; NoIndepVars : integer); + procedure VarListDblClick(Sender: TObject); private - { private declarations } - FAutoSized: boolean; - procedure UpdateBtnStates; + + protected + procedure AdjustConstraints; override; + procedure Compute; override; + procedure UpdateBtnStates; override; public - { public declarations } + constructor Create(AOwner: TComponent); override; + procedure Reset; override; end; var - TwoSLSFrm: TTwoSLSFrm; + TwoSLSForm: TTwoSLSForm; + implementation +{$R *.lfm} + uses StrUtils, Utils; -{ TTwoSLSFrm } +{ TTwoSLSForm } -procedure TTwoSLSFrm.ResetBtnClick(Sender: TObject); -var - i: integer; +constructor TTwoSLSForm.Create(AOwner: TComponent); begin - VarList.Clear; - Explanatory.Clear; - Instrumental.Clear; - DepVarEdit.Text := ''; - ProxyRegShowChk.Checked := false; - for i := 1 to NoVariables do - VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); - UpdateBtnStates; + inherited; + if DictionaryFrm = nil then Application.CreateForm(TDictionaryFrm, DictionaryFrm); end; -procedure TTwoSLSFrm.FormActivate(Sender: TObject); -var - w: Integer; + +procedure TTwoSLSForm.AdjustConstraints; begin - if FAutoSized then - exit; + inherited; - w := MaxValue([HelpBtn.Width, ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]); - HelpBtn.Constraints.MinWidth := w; - ResetBtn.Constraints.MinWidth := w; - ComputeBtn.Constraints.MinWidth := w; - CloseBtn.Constraints.MinWidth := w; + ParamsPanel.Constraints.MinWidth := Max( + 4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left, + OptionsGroup.Width); - Constraints.MinWidth := Width; - Constraints.MinHeight := Height; - - FAutoSized := True; + ParamsPanel.Constraints.MinHeight := InstOut.Top + InstOut.Height + + VarList.BorderSpacing.Bottom + OptionsGroup.Height + ButtonBevel.Height + + CloseBtn.BorderSpacing.Top + CloseBtn.Height; end; -procedure TTwoSLSFrm.FormCreate(Sender: TObject); -begin - Assert(OS3MainFrm <> nil); - if DictionaryFrm = nil then Application.CreateForm(TDictionaryFrm, DictionaryFrm); -end; -procedure TTwoSLSFrm.FormShow(Sender: TObject); -begin - ResetBtnClick(self); -end; - -procedure TTwoSLSFrm.HelpBtnClick(Sender: TObject); -begin - if ContextHelpForm = nil then - Application.CreateForm(TContextHelpForm, ContextHelpForm); - ContextHelpForm.HelpMessage((Sender as TButton).tag); -end; - -procedure TTwoSLSFrm.InstInClick(Sender: TObject); -var - i: integer; -begin - i := 0; - while (i < VarList.Items.Count) do - begin - if VarList.Selected[i] and (Instrumental.Items.IndexOf(VarList.Items[i]) = -1) then - Instrumental.Items.Add(VarList.Items[i]) - // DO NOT DELETE Items HERE. - else - i := i + 1; - end; - UpdateBtnStates; -end; - -procedure TTwoSLSFrm.InstOutClick(Sender: TObject); -var - i: Integer; -begin - i := 0; - while (i < Instrumental.Items.Count) do - begin - if Instrumental.Selected[i] then - begin - if VarList.Items.IndexOf(Instrumental.Items[i]) = -1 then - VarList.Items.Add(Instrumental.Items[i]); - Instrumental.Items.Delete(i); - i := 0; - end else - i := i + 1; - end; - UpdateBtnStates; -end; - -procedure TTwoSLSFrm.ComputeBtnClick(Sender: TObject); +procedure TTwoSLSForm.Compute; var i, j, k, DepCol, NoInst, NoExp, NoProx, Noindep : integer; IndepCols, ProxSrcCols, ExpCols, InstCols, ProxCols : IntDyneVec; @@ -187,12 +120,12 @@ begin MessageDlg('Dependent variable not selected.', mtError, [mbOK], 0); exit; end; - if Explanatory.Items.Count = 0 then + if ExplanatoryList.Items.Count = 0 then begin MessageDlg('No explanatory variables selected.', mtError, [mbOK], 0); exit; end; - if Instrumental.Items.Count = 0 then + if InstrumentalList.Items.Count = 0 then begin MessageDlg('No instrumental variables selected.', mtError, [mbOK], 0); exit; @@ -236,8 +169,8 @@ begin // Get variables to analyze NCases := NoCases; - NoInst := Instrumental.Items.Count; - NoExp := Explanatory.Items.Count; + NoInst := InstrumentalList.Items.Count; + NoExp := ExplanatoryList.Items.Count; if (NoInst < NoExp) then begin MessageDlg('The no. of Instrumental must equal or exceed the Explanatory', mtError, [mbOK], 0); @@ -254,22 +187,22 @@ begin end; for j := 0 to NoExp - 1 do begin - if (OS3MainFrm.DataGrid.Cells[i+1,0] = Explanatory.Items.Strings[j]) then + if (OS3MainFrm.DataGrid.Cells[i+1,0] = ExplanatoryList.Items.Strings[j]) then begin ExpCols[j] := i+1; // result := VarTypeChk(i+1,0); // if (result :=:= 1) goto cleanup; - ExpLabels[j] := Explanatory.Items.Strings[j]; + ExpLabels[j] := ExplanatoryList.Items.Strings[j]; end; end; // next j for j := 0 to NoInst - 1 do begin - if (OS3MainFrm.DataGrid.Cells[i+1,0] = Instrumental.Items.Strings[j]) then + if (OS3MainFrm.DataGrid.Cells[i+1,0] = InstrumentalList.Items.Strings[j]) then begin InstCols[j] := i+1; // result := VarTypeChk(i+1,0); // if (result :=:= 1) goto cleanup; - InstLabels[j] := Instrumental.Items.Strings[j]; + InstLabels[j] := InstrumentalList.Items.Strings[j]; end; end; // next j end; // next i @@ -310,7 +243,7 @@ begin lReport.Add(' ' + ProxLabels[i]); lReport.Add(''); - // Compute the prox regressions for the instrumental variables + // Compute the prox regressions for the InstrumentalList variables for i := 0 to NoProx - 1 do begin DictionaryFrm.DictGrid.ColCount := 8; @@ -382,7 +315,7 @@ begin lReport.Add('=================================================================='); lReport.Add(''); - // Compute the OLS using the Prox values and explanatory + // Compute the OLS using the Prox values and ExplanatoryList Noindep := 0; counter := 0; for i := 0 to NoExp - 1 do @@ -414,36 +347,18 @@ begin BWeights, BetaWeights, BStdErrs, Bttests, tprobs, R2, stderrest, NCases, errorcode, PrintDesc, lReport); - DisplayReport(lReport); + FReportFrame.DisplayReport(lReport); if SaveItChk.Checked then PredictIt(IndepCols, Noindep+1, Means, StdDevs, BetaWeights, stderrest, Noindep); finally lReport.Free; -// ProxVals := nil; - ProxSrcLabels := nil; - ProxSrcCols := nil; - RowLabels := nil; - IndepCols := nil; - ProxLabels := nil; - ProxCols := nil; - InstCols := nil; - InstLabels := nil; - ExpCols := nil; - ExpLabels := nil; - tprobs := nil; - Bttests := nil; - BStdErrs := nil; - BetaWeights := nil; - BWeights := nil; - StdDevs := nil; - Variances := nil; - Means := nil; end; end; -procedure TTwoSLSFrm.DepInClick(Sender: TObject); + +procedure TTwoSLSForm.DepInClick(Sender: TObject); var index: integer; begin @@ -456,7 +371,8 @@ begin UpdateBtnStates; end; -procedure TTwoSLSFrm.DepOutClick(Sender: TObject); + +procedure TTwoSLSForm.DepOutClick(Sender: TObject); begin if DepVarEdit.Text <> '' then begin @@ -466,38 +382,55 @@ begin UpdateBtnStates; end; -procedure TTwoSLSFrm.ExpInClick(Sender: TObject); + +procedure TTwoSLSForm.ExpInClick(Sender: TObject); var i: integer; begin i := 0; while (i < VarList.Items.Count) do begin - if VarList.Selected[i] and (Explanatory.Items.IndexOf(VarList.Items[i]) = -1) then - Explanatory.Items.Add(VarList.Items[i]); + if VarList.Selected[i] and (ExplanatoryList.Items.IndexOf(VarList.Items[i]) = -1) then + ExplanatoryList.Items.Add(VarList.Items[i]); // DO NOT DELETE Items HERE. i := i + 1; end; UpdateBtnStates; end; -procedure TTwoSLSFrm.ExplanatorySelectionChange(Sender: TObject; User: boolean); + +procedure TTwoSLSForm.ExplanatoryListDblClick(Sender: TObject); +var + index: Integer; +begin + index := ExplanatoryList.ItemIndex; + if index > -1 then + begin + VarList.Items.Add(ExplanatoryList.Items[index]); + ExplanatoryList.Items.Delete(index); + UpdateBtnStates; + end; +end; + + +procedure TTwoSLSForm.ExplanatoryListSelectionChange(Sender: TObject; User: boolean); begin UpdateBtnStates; end; -procedure TTwoSLSFrm.ExpOutClick(Sender: TObject); + +procedure TTwoSLSForm.ExpOutClick(Sender: TObject); var i: Integer; begin i := 0; - while (i < Explanatory.Items.Count) do + while (i < ExplanatoryList.Items.Count) do begin - if Explanatory.Selected[i] then + if ExplanatoryList.Selected[i] then begin - if (VarList.Items.IndexOf(Explanatory.Items[i]) = -1) then - VarList.Items.Add(Explanatory.Items[i]); - Explanatory.Items.Delete(i); + if (VarList.Items.IndexOf(ExplanatoryList.Items[i]) = -1) then + VarList.Items.Add(ExplanatoryList.Items[i]); + ExplanatoryList.Items.Delete(i); i := 0; end else i := i + 1; @@ -505,7 +438,59 @@ begin UpdateBtnStates; end; -procedure TTwoSLSFrm.PredictIt(const ColNoSelected: IntDyneVec; NoVars: integer; + +procedure TTwoSLSForm.InstInClick(Sender: TObject); +var + i: integer; +begin + i := 0; + while (i < VarList.Items.Count) do + begin + if VarList.Selected[i] and (InstrumentalList.Items.IndexOf(VarList.Items[i]) = -1) then + InstrumentalList.Items.Add(VarList.Items[i]) + // DO NOT DELETE Items HERE. + else + i := i + 1; + end; + UpdateBtnStates; +end; + + +procedure TTwoSLSForm.InstOutClick(Sender: TObject); +var + i: Integer; +begin + i := 0; + while (i < InstrumentalList.Items.Count) do + begin + if InstrumentalList.Selected[i] then + begin + if VarList.Items.IndexOf(InstrumentalList.Items[i]) = -1 then + VarList.Items.Add(InstrumentalList.Items[i]); + InstrumentalList.Items.Delete(i); + i := 0; + end else + i := i + 1; + end; + UpdateBtnStates; +end; + + +procedure TTwoSLSForm.InstrumentalListDblClick(Sender: TObject); +var + index: Integer; +begin + index := InstrumentalList.ItemIndex; + if index > -1 then + begin + VarList.Items.Add(InstrumentalList.Items[index]); + InstrumentalList.Items.Delete(index); + UpdateBtnStates; + end; +end; + + +procedure TTwoSLSForm.PredictIt(const ColNoSelected: IntDyneVec; NoVars: integer; Means, StdDevs, BetaWeights: DblDyneVec; StdErrEst: double; NoIndepVars: integer); var @@ -596,22 +581,57 @@ begin end; end; -procedure TTwoSLSFrm.UpdateBtnStates; + +procedure TTwoSLSForm.Reset; +var + i: integer; +begin + inherited; + + DepVarEdit.Clear; + InstrumentalList.Clear; + ExplanatoryList.Clear; + VarList.Clear; + for i := 1 to NoVariables do + VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); + ProxyRegShowChk.Checked := false; + UpdateBtnStates; +end; + + +procedure TTwoSLSForm.UpdateBtnStates; var lSelected: Boolean; begin + inherited; + lSelected := AnySelected(VarList); DepIn.Enabled := lSelected and (DepVarEdit.Text = ''); ExpIn.Enabled := lSelected; InstIn.Enabled := lSelected; DepOut.Enabled := (DepVarEdit.Text <> ''); - ExpOut.Enabled := AnySelected(Explanatory); - InstOut.Enabled := AnySelected(Instrumental); + ExpOut.Enabled := AnySelected(ExplanatoryList); + InstOut.Enabled := AnySelected(InstrumentalList); +end; + + +procedure TTwoSLSForm.VarListDblClick(Sender: TObject); +var + index: Integer; +begin + index := VarList.ItemIndex; + if index > -1 then + begin + if DepVarEdit.Text = '' then + DepVarEdit.Text := VarList.Items[index] + else + ExplanatoryList.Items.Add(VarList.Items[index]); + VarList.Items.Delete(index); + UpdateBtnStates; + end; end; -initialization - {$I twoslsunit.lrs} end. diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/wlsunit.lfm b/applications/lazstats/source/forms/analysis/multiple_regression/wlsunit.lfm index 7c872f932..5b2ef2350 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/wlsunit.lfm +++ b/applications/lazstats/source/forms/analysis/multiple_regression/wlsunit.lfm @@ -2,12 +2,12 @@ inherited WLSForm: TWLSForm Left = 288 Height = 469 Top = 171 - Width = 1024 + Width = 861 HelpType = htKeyword HelpKeyword = 'html/WeightedLeast-SquaresRegression.htm' Caption = 'Weighted Least Squares Regression' ClientHeight = 469 - ClientWidth = 1024 + ClientWidth = 861 inherited ParamsPanel: TPanel Height = 453 Width = 280 @@ -345,7 +345,7 @@ inherited WLSForm: TWLSForm Left = 301 Height = 453 Top = 8 - Width = 715 + Width = 552 ActivePage = ResidualsRegPage Align = alClient BorderSpacing.Left = 4 @@ -360,12 +360,12 @@ inherited WLSForm: TWLSForm object ResidualsRegPage: TTabSheet Caption = 'Squared Residuals Regression' ClientHeight = 425 - ClientWidth = 707 + ClientWidth = 544 object ResRegPageControl: TPageControl Left = 8 Height = 409 Top = 8 - Width = 691 + Width = 528 ActivePage = ResRegReportPage Align = alClient BorderSpacing.Around = 8 diff --git a/applications/lazstats/source/forms/mainunit.pas b/applications/lazstats/source/forms/mainunit.pas index 1cb8fd968..cc1157cc3 100644 --- a/applications/lazstats/source/forms/mainunit.pas +++ b/applications/lazstats/source/forms/mainunit.pas @@ -2044,32 +2044,33 @@ end; // Menu "Analysis" > "Multiple Regression" > "Best Combination" procedure TOS3MainFrm.mnuAnalysisMultReg_BestCombClick(Sender: TObject); begin - if BestRegFrm = nil then - Application.CreateForm(TBestRegFrm, BestRegFrm); - BestRegFrm.ShowModal; + if BestRegForm = nil then + Application.CreateForm(TBestRegForm, BestRegForm); + BestRegForm.Show; end; // Menu "Analysis" > "Multiple Regression" > "Binary Logistic" procedure TOS3MainFrm.mnuAnalysisMultReg_BinLogisticClick(Sender: TObject); begin - if LogRegFrm = nil then - Application.CreateForm(TLogRegFrm, LogRegFrm); - LogRegFrm.ShowModal; + if LogRegForm = nil then + Application.CreateForm(TLogRegForm, LogRegForm); + LogRegForm.Show; end; +// Menu "Analysis" > "Multiple Regression" > "Block Entry" procedure TOS3MainFrm.mnuAnalysisMultReg_BlockEntryClick(Sender: TObject); begin - if BlkMregFrm = nil then - Application.CreateForm(TBlkMregFrm, BlkMregFrm); - BlkMregFrm.ShowModal; + if BlkMregForm = nil then + Application.CreateForm(TBlkMregForm, BlkMregForm); + BlkMregForm.Show; end; // Menu "Analysis" > "Multiple Regression" > "Cox Proportional Hazzards Survival Regression" procedure TOS3MainFrm.mnuAnalysisMultReg_CoxSurvivalClick(Sender: TObject); begin - if CoxRegFrm = nil then - Application.CreateForm(TCoxRegFrm, CoxRegFrm); - CoxRegFrm.ShowModal; + if CoxRegForm = nil then + Application.CreateForm(TCoxRegForm, CoxRegForm); + CoxRegForm.Show; end; // Menu "Analysis" > "Multiple Regression" > "Forward Stepwise" @@ -2083,9 +2084,9 @@ end; // Menu "Analysis" > "Multiple Regression" > "Linear Programming" procedure TOS3MainFrm.mnuAnalysisMultReg_LinProgClick(Sender: TObject); begin - if LinProFrm = nil then - Application.CreateForm(TLinProFrm, LinProFrm); - LinProFrm.ShowModal; + if LinProForm = nil then + Application.CreateForm(TLinProForm, LinProForm); + LinProForm.Show; end; // Menu "Analysis" > "Multiple Regression" > "Least Squares Multiple Regression" @@ -2099,17 +2100,17 @@ end; // Menu "Analysis" > "Multiple Regression" > "Simultaneous" procedure TOS3MainFrm.mnuAnalysisMultReg_SimultClick(Sender: TObject); begin - if SimultFrm = nil then - Application.CreateForm(TSimultFrm, SimultFrm); - SimultFrm.ShowModal; + if SimultForm = nil then + Application.CreateForm(TSimultForm, SimultForm); + SimultForm.Show; end; // Menu "Analysis" > "Multiple Regression" > "Two Stage Least Squares Regression" procedure TOS3MainFrm.mnuAnalysisMultReg_TwoStageClick(Sender: TObject); begin - if TwoSLSFrm = nil then - Application.CreateForm(TTwoSLSFrm, TwoSLSFrm); - TwoSLSFrm.ShowModal; + if TwoSLSForm = nil then + Application.CreateForm(TTwoSLSForm, TwoSLSForm); + TwoSLSForm.Show; end; // Menu "Analysis" > "Multiple Regression" > "Weighted Least Squares Regression" diff --git a/applications/lazstats/source/frames/reportframeunit.lfm b/applications/lazstats/source/frames/reportframeunit.lfm index db03f7321..c8e48d3e6 100644 --- a/applications/lazstats/source/frames/reportframeunit.lfm +++ b/applications/lazstats/source/frames/reportframeunit.lfm @@ -64,13 +64,12 @@ object ReportFrame: TReportFrame TabOrder = 1 object ReportMemo: TMemo Left = 4 - Height = 194 + Height = 198 Top = 4 Width = 294 Align = alClient BorderSpacing.Left = 4 BorderSpacing.Top = 4 - BorderSpacing.Bottom = 4 BorderStyle = bsNone Color = clWhite Font.Height = -11