LazStats: Improved layout of LogLinScreenUnit. Pdf to Chm (partially because calculation crashes).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7412 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-04-27 20:51:12 +00:00
parent 82eea5cf08
commit 977021871d
3 changed files with 319 additions and 461 deletions

View File

@@ -1,160 +1,132 @@
object LogLinScreenFrm: TLogLinScreenFrm object LogLinScreenFrm: TLogLinScreenFrm
Left = 456 Left = 417
Height = 584 Height = 379
Top = 135 Top = 130
Width = 402 Width = 662
AutoSize = True AutoSize = True
Caption = 'Cross-Classification Log Linear Screen' Caption = 'Cross-Classification Log Linear Screen'
ClientHeight = 584 ClientHeight = 379
ClientWidth = 402 ClientWidth = 662
OnActivate = FormActivate OnActivate = FormActivate
OnCreate = FormCreate OnCreate = FormCreate
OnShow = FormShow OnShow = FormShow
Position = poMainFormCenter
LCLVersion = '2.1.0.0' LCLVersion = '2.1.0.0'
object Label1: TLabel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = CountVarChk
AnchorSideTop.Side = asrBottom
Left = 8
Height = 15
Top = 39
Width = 337
BorderSpacing.Left = 8
BorderSpacing.Top = 12
BorderSpacing.Right = 16
Caption = '1. Select the variables of the Grid that define your classifications'
ParentColor = False
end
object Label2: TLabel object Label2: TLabel
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Panel1 AnchorSideTop.Control = Owner
AnchorSideTop.Side = asrBottom
Left = 8 Left = 8
Height = 15 Height = 15
Top = 208 Top = 8
Width = 97 Width = 97
BorderSpacing.Left = 8 BorderSpacing.Left = 8
BorderSpacing.Top = 12 BorderSpacing.Top = 8
Caption = 'Available Variables' Caption = 'Available Variables'
ParentColor = False ParentColor = False
end end
object Label3: TLabel object Label3: TLabel
AnchorSideLeft.Control = SelectList AnchorSideLeft.Control = SelectList
AnchorSideTop.Control = Label2 AnchorSideTop.Control = Label2
Left = 232 Left = 255
Height = 15 Height = 15
Top = 208 Top = 8
Width = 44 Width = 44
Caption = 'Selected' Caption = 'Selected'
ParentColor = False ParentColor = False
end end
object CountVarChk: TCheckBox object CountVarChk: TCheckBox
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = SelectList
AnchorSideTop.Control = Owner AnchorSideRight.Side = asrBottom
Left = 8 AnchorSideBottom.Control = GroupBox1
Left = 255
Height = 19 Height = 19
Top = 8 Top = 252
Width = 247 Width = 247
BorderSpacing.Left = 8 Anchors = [akLeft, akBottom]
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Last Variable Selected is a Frequency Count' Caption = 'Last Variable Selected is a Frequency Count'
TabOrder = 0 OnChange = CountVarChkChange
end TabOrder = 4
object Step2Btn: TButton
AnchorSideLeft.Control = Label10
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Label10
AnchorSideTop.Side = asrCenter
Left = 234
Height = 25
Top = 55
Width = 52
AutoSize = True
BorderSpacing.Left = 16
Caption = 'Click'
OnClick = Step2BtnClick
TabOrder = 1
end end
object VarList: TListBox object VarList: TListBox
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Label2 AnchorSideTop.Control = Label2
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = AllBtn AnchorSideRight.Control = AllBtn
AnchorSideBottom.Control = GroupBox1 AnchorSideBottom.Control = CountVarChk
AnchorSideBottom.Side = asrBottom
Left = 8 Left = 8
Height = 230 Height = 246
Top = 225 Top = 25
Width = 162 Width = 185
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 8 BorderSpacing.Left = 8
BorderSpacing.Top = 2 BorderSpacing.Top = 2
BorderSpacing.Right = 8 BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Constraints.MinHeight = 220
ItemHeight = 0 ItemHeight = 0
MultiSelect = True MultiSelect = True
OnSelectionChange = VarListSelectionChange OnSelectionChange = VarListSelectionChange
TabOrder = 3 TabOrder = 0
end end
object InBtn: TBitBtn object InBtn: TBitBtn
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Bevel2
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = VarList AnchorSideTop.Control = VarList
Left = 187 Left = 210
Height = 28 Height = 28
Top = 225 Top = 25
Width = 28 Width = 28
Images = MainDataModule.ImageList Images = MainDataModule.ImageList
ImageIndex = 1 ImageIndex = 1
OnClick = InBtnClick OnClick = InBtnClick
Spacing = 0 Spacing = 0
TabOrder = 4 TabOrder = 1
end end
object OutBtn: TBitBtn object OutBtn: TBitBtn
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Bevel2
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = InBtn AnchorSideTop.Control = InBtn
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 187 Left = 210
Height = 28 Height = 28
Top = 257 Top = 57
Width = 28 Width = 28
BorderSpacing.Top = 4 BorderSpacing.Top = 4
Images = MainDataModule.ImageList Images = MainDataModule.ImageList
ImageIndex = 0 ImageIndex = 0
OnClick = OutBtnClick OnClick = OutBtnClick
Spacing = 0 Spacing = 0
TabOrder = 5 TabOrder = 2
end end
object AllBtn: TBitBtn object AllBtn: TBitBtn
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Bevel2
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = OutBtn AnchorSideTop.Control = OutBtn
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 178 AnchorSideBottom.Side = asrBottom
Left = 201
Height = 25 Height = 25
Top = 289 Top = 89
Width = 46 Width = 46
AutoSize = True AutoSize = True
BorderSpacing.Top = 4 BorderSpacing.Top = 4
BorderSpacing.Bottom = 24
Caption = 'ALL' Caption = 'ALL'
OnClick = AllBtnClick OnClick = AllBtnClick
Spacing = 0 Spacing = 0
TabOrder = 6 TabOrder = 3
end end
object SelectList: TListBox object SelectList: TListBox
AnchorSideLeft.Control = AllBtn AnchorSideLeft.Control = AllBtn
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = VarList AnchorSideTop.Control = VarList
AnchorSideRight.Control = Owner AnchorSideRight.Control = MinMaxGrid
AnchorSideRight.Side = asrBottom AnchorSideBottom.Control = CountVarChk
AnchorSideBottom.Control = VarList Left = 255
AnchorSideBottom.Side = asrBottom Height = 219
Left = 232 Top = 25
Height = 230 Width = 185
Top = 225
Width = 162
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 8 BorderSpacing.Left = 8
BorderSpacing.Right = 8 BorderSpacing.Right = 8
@@ -162,154 +134,40 @@ object LogLinScreenFrm: TLogLinScreenFrm
OnSelectionChange = SelectListSelectionChange OnSelectionChange = SelectListSelectionChange
TabOrder = 7 TabOrder = 7
end end
object Panel1: TPanel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Label11
AnchorSideTop.Side = asrBottom
Left = 24
Height = 85
Top = 111
Width = 244
AutoSize = True
BorderSpacing.Left = 24
BevelOuter = bvNone
ClientHeight = 85
ClientWidth = 244
TabOrder = 2
object Label7: TLabel
AnchorSideTop.Control = VarNoEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = VarNoEdit
Left = 137
Height = 15
Top = 12
Width = 44
Anchors = [akTop, akRight]
BorderSpacing.Right = 8
Caption = 'Variable:'
ParentColor = False
end
object Label8: TLabel
AnchorSideTop.Control = MinEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = MinEdit
Left = 98
Height = 15
Top = 39
Width = 87
Anchors = [akTop, akRight]
BorderSpacing.Right = 4
Caption = 'Minimum Value:'
ParentColor = False
end
object Label9: TLabel
AnchorSideTop.Control = MaxEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = MaxEdit
Left = 92
Height = 15
Top = 66
Width = 89
Anchors = [akTop, akRight]
BorderSpacing.Right = 8
Caption = 'Maximum Value:'
ParentColor = False
end
object ScrollBar1: TScrollBar
AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = VarNoEdit
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label7
Left = 0
Height = 17
Top = 11
Width = 121
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Right = 16
PageSize = 0
TabOrder = 0
OnChange = ScrollBar1Change
end
object VarNoEdit: TEdit
AnchorSideTop.Control = Panel1
AnchorSideRight.Control = Panel1
AnchorSideRight.Side = asrBottom
Left = 189
Height = 23
Top = 8
Width = 55
Alignment = taRightJustify
Anchors = [akTop, akRight]
BorderSpacing.Top = 8
TabOrder = 1
Text = 'VarNoEdit'
end
object MinEdit: TEdit
AnchorSideLeft.Control = VarNoEdit
AnchorSideTop.Control = VarNoEdit
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Panel1
AnchorSideRight.Side = asrBottom
Left = 189
Height = 23
Top = 35
Width = 55
Alignment = taRightJustify
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 4
OnKeyPress = MinEditKeyPress
TabOrder = 2
Text = 'MinEdit'
end
object MaxEdit: TEdit
AnchorSideLeft.Control = VarNoEdit
AnchorSideTop.Control = MinEdit
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Panel1
AnchorSideRight.Side = asrBottom
Left = 189
Height = 23
Top = 62
Width = 55
Alignment = taRightJustify
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 4
OnKeyPress = MaxEditKeyPress
TabOrder = 3
Text = 'MaxEdit'
end
end
object GroupBox1: TGroupBox object GroupBox1: TGroupBox
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Bevel1 AnchorSideBottom.Control = Bevel1
Left = 8 Left = 8
Height = 72 Height = 51
Top = 463 Top = 279
Width = 241 Width = 390
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Left = 8 BorderSpacing.Left = 8
BorderSpacing.Right = 8
Caption = 'Options' Caption = 'Options'
ChildSizing.LeftRightSpacing = 12 ChildSizing.LeftRightSpacing = 12
ChildSizing.TopBottomSpacing = 6 ChildSizing.TopBottomSpacing = 6
ChildSizing.HorizontalSpacing = 20
ChildSizing.VerticalSpacing = 2 ChildSizing.VerticalSpacing = 2
ChildSizing.Layout = cclLeftToRightThenTopToBottom ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1 ChildSizing.ControlsPerLine = 2
ClientHeight = 52 ClientHeight = 31
ClientWidth = 237 ClientWidth = 386
TabOrder = 8 TabOrder = 6
object MarginsChk: TCheckBox object MarginsChk: TCheckBox
Left = 12 Left = 12
Height = 19 Height = 19
Top = 6 Top = 6
Width = 213 Width = 129
Caption = 'Print Marginal Totals' Caption = 'Print Marginal Totals'
TabOrder = 0 TabOrder = 0
end end
object GenlModelChk: TCheckBox object GenlModelChk: TCheckBox
Left = 12 Left = 161
Height = 19 Height = 19
Top = 27 Top = 6
Width = 213 Width = 213
Caption = 'Print General Linear Modle Estimates' Caption = 'Print General Linear Modle Estimates'
TabOrder = 1 TabOrder = 1
@@ -319,9 +177,9 @@ object LogLinScreenFrm: TLogLinScreenFrm
AnchorSideRight.Control = ComputeBtn AnchorSideRight.Control = ComputeBtn
AnchorSideBottom.Control = Owner AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 193 Left = 453
Height = 25 Height = 25
Top = 551 Top = 346
Width = 54 Width = 54
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
AutoSize = True AutoSize = True
@@ -331,15 +189,15 @@ object LogLinScreenFrm: TLogLinScreenFrm
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Reset' Caption = 'Reset'
OnClick = ResetBtnClick OnClick = ResetBtnClick
TabOrder = 10 TabOrder = 9
end end
object ComputeBtn: TButton object ComputeBtn: TButton
AnchorSideRight.Control = CloseBtn AnchorSideRight.Control = CloseBtn
AnchorSideBottom.Control = Owner AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 255 Left = 515
Height = 25 Height = 25
Top = 551 Top = 346
Width = 76 Width = 76
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
AutoSize = True AutoSize = True
@@ -349,16 +207,16 @@ object LogLinScreenFrm: TLogLinScreenFrm
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Compute' Caption = 'Compute'
OnClick = ComputeBtnClick OnClick = ComputeBtnClick
TabOrder = 11 TabOrder = 10
end end
object CloseBtn: TButton object CloseBtn: TButton
AnchorSideRight.Control = Owner AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 339 Left = 599
Height = 25 Height = 25
Top = 551 Top = 346
Width = 55 Width = 55
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
AutoSize = True AutoSize = True
@@ -368,17 +226,16 @@ object LogLinScreenFrm: TLogLinScreenFrm
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Close' Caption = 'Close'
ModalResult = 11 ModalResult = 11
OnClick = CloseBtnClick TabOrder = 11
TabOrder = 12
end end
object HelpBtn: TButton object HelpBtn: TButton
Tag = 131 Tag = 131
AnchorSideRight.Control = ResetBtn AnchorSideRight.Control = ResetBtn
AnchorSideBottom.Control = Owner AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 134 Left = 394
Height = 25 Height = 25
Top = 551 Top = 346
Width = 51 Width = 51
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
AutoSize = True AutoSize = True
@@ -388,7 +245,7 @@ object LogLinScreenFrm: TLogLinScreenFrm
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Help' Caption = 'Help'
OnClick = HelpBtnClick OnClick = HelpBtnClick
TabOrder = 9 TabOrder = 8
end end
object Bevel1: TBevel object Bevel1: TBevel
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
@@ -397,38 +254,69 @@ object LogLinScreenFrm: TLogLinScreenFrm
AnchorSideBottom.Control = CloseBtn AnchorSideBottom.Control = CloseBtn
Left = 0 Left = 0
Height = 8 Height = 8
Top = 535 Top = 330
Width = 402 Width = 662
Anchors = [akLeft, akRight, akBottom] Anchors = [akLeft, akRight, akBottom]
Shape = bsBottomLine Shape = bsBottomLine
end end
object Label10: TLabel object MinMaxGrid: TStringGrid
AnchorSideLeft.Control = Label1 AnchorSideLeft.Control = SelectList
AnchorSideTop.Control = Label1 AnchorSideLeft.Side = asrBottom
AnchorSideTop.Side = asrBottom AnchorSideTop.Control = SelectList
Left = 8
Height = 15
Top = 60
Width = 210
BorderSpacing.Top = 6
Caption = '2. Click here when variables are selected'
ParentColor = False
end
object Label11: TLabel
AnchorSideLeft.Control = Label1
AnchorSideTop.Control = Label10
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
Left = 8 AnchorSideBottom.Control = SelectList
Height = 30 AnchorSideBottom.Side = asrBottom
Top = 81 Left = 448
Width = 386 Height = 219
Anchors = [akTop, akLeft, akRight] Top = 25
BorderSpacing.Top = 6 Width = 206
Anchors = [akTop, akRight, akBottom]
AutoFillColumns = True
BorderSpacing.Left = 8
BorderSpacing.Right = 8 BorderSpacing.Right = 8
Caption = '3. For each variable complete the specifications below. Press the ENTER key following each entry.' ColCount = 3
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goColSizing, goEditing, goSmoothScroll]
RowCount = 1
TabOrder = 5
ColWidths = (
64
69
69
)
Cells = (
3
0
0
'Variable'
1
0
'Minimum'
2
0
'Maximum'
)
end
object Label1: TLabel
AnchorSideLeft.Control = MinMaxGrid
AnchorSideTop.Control = Label2
AnchorSideBottom.Control = MinMaxGrid
Left = 448
Height = 15
Top = 8
Width = 142
Caption = 'Min/Max for each variable:'
ParentColor = False ParentColor = False
WordWrap = True end
object Bevel2: TBevel
AnchorSideLeft.Control = VarList
AnchorSideRight.Control = SelectList
AnchorSideRight.Side = asrBottom
Left = 8
Height = 4
Top = 2
Width = 432
Anchors = [akTop, akLeft, akRight]
Shape = bsSpacer
end end
end end

View File

@@ -16,7 +16,7 @@ interface
uses uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, Buttons, ExtCtrls, StdCtrls, Buttons, ExtCtrls, Grids,
Globals, MainUnit, FunctionsLib, OutputUnit, DataProcs, ContextHelpUnit; Globals, MainUnit, FunctionsLib, OutputUnit, DataProcs, ContextHelpUnit;
type type
@@ -25,10 +25,10 @@ type
TLogLinScreenFrm = class(TForm) TLogLinScreenFrm = class(TForm)
Bevel1: TBevel; Bevel1: TBevel;
Bevel2: TBevel;
HelpBtn: TButton; HelpBtn: TButton;
InBtn: TBitBtn; InBtn: TBitBtn;
Label10: TLabel; Label1: TLabel;
Label11: TLabel;
OutBtn: TBitBtn; OutBtn: TBitBtn;
AllBtn: TBitBtn; AllBtn: TBitBtn;
ResetBtn: TButton; ResetBtn: TButton;
@@ -37,53 +37,37 @@ type
MarginsChk: TCheckBox; MarginsChk: TCheckBox;
GenlModelChk: TCheckBox; GenlModelChk: TCheckBox;
GroupBox1: TGroupBox; GroupBox1: TGroupBox;
MaxEdit: TEdit;
MinEdit: TEdit;
Label8: TLabel;
Label9: TLabel;
VarNoEdit: TEdit;
Label2: TLabel; Label2: TLabel;
Label3: TLabel; Label3: TLabel;
Label7: TLabel;
Panel1: TPanel;
ScrollBar1: TScrollBar;
SelectList: TListBox; SelectList: TListBox;
MinMaxGrid: TStringGrid;
VarList: TListBox; VarList: TListBox;
Step2Btn: TButton;
CountVarChk: TCheckBox; CountVarChk: TCheckBox;
Label1: TLabel;
procedure AllBtnClick(Sender: TObject); procedure AllBtnClick(Sender: TObject);
procedure ComputeBtnClick(Sender: TObject); procedure ComputeBtnClick(Sender: TObject);
procedure CountVarChkChange(Sender: TObject);
procedure FormActivate(Sender: TObject); procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject); procedure FormShow(Sender: TObject);
procedure HelpBtnClick(Sender: TObject); procedure HelpBtnClick(Sender: TObject);
procedure InBtnClick(Sender: TObject); procedure InBtnClick(Sender: TObject);
procedure MaxEditKeyPress(Sender: TObject; var Key: char);
procedure MinEditKeyPress(Sender: TObject; var Key: char);
procedure OutBtnClick(Sender: TObject); procedure OutBtnClick(Sender: TObject);
procedure ResetBtnClick(Sender: TObject); procedure ResetBtnClick(Sender: TObject);
procedure CloseBtnClick(Sender: TObject);
procedure ScrollBar1Change(Sender: TObject);
procedure SelectListSelectionChange(Sender: TObject; User: boolean); procedure SelectListSelectionChange(Sender: TObject; User: boolean);
procedure Step2BtnClick(Sender: TObject); function ArrayPosition(NumDims: integer; const Data: DblDyneVec;
function ArrayPosition(Sender: TObject; NoDims : integer; const Subscripts, DimSize: IntDyneVec): integer;
VAR Data : DblDyneVec; procedure Marginals(NumDims, ArraySize: integer; const Indexes: IntDyneMat;
VAR Subscripts : IntDyneVec; const Data: DblDyneVec; const Margins: IntDyneMat);
VAR DimSize : IntDyneVec) : integer;
procedure Marginals(Sender: TObject;
NoDims : integer;
ArraySize : integer;
VAR Indexes : IntDyneMat;
VAR Data : DblDyneVec;
VAR Margins : IntDyneMat);
procedure VarListSelectionChange(Sender: TObject; User: boolean); procedure VarListSelectionChange(Sender: TObject; User: boolean);
private private
{ private declarations } { private declarations }
FAutoSized: Boolean; FAutoSized: Boolean;
procedure UpdateBtnStates; procedure UpdateBtnStates;
procedure Screen(VAR NVAR : integer; procedure UpdateMinMaxGrid;
procedure Screen(VAR NVAR : integer;
VAR MP : integer; VAR MM : integer; VAR MP : integer; VAR MM : integer;
VAR NTAB : integer; VAR TABLE : DblDyneVec; VAR NTAB : integer; VAR TABLE : DblDyneVec;
VAR DIM : IntDyneVec; VAR GSQ : DblDyneVec; VAR DIM : IntDyneVec; VAR GSQ : DblDyneVec;
@@ -96,35 +80,35 @@ type
VAR X : DblDyneVec; VAR Y : DblDyneVec; VAR X : DblDyneVec; VAR Y : DblDyneVec;
VAR IFAULT : integer); VAR IFAULT : integer);
procedure CONF(VAR N : integer; VAR M : integer; procedure CONF(VAR N : integer; VAR M : integer;
VAR MP : integer; VAR MP : integer;
VAR MM : integer; VAR MM : integer;
VAR ISET : IntDyneVec; VAR JSET : IntDyneVec; VAR ISET : IntDyneVec; VAR JSET : IntDyneVec;
VAR IP : IntDyneMat; VAR IM : IntDyneMat; VAR NP : integer); VAR IP : IntDyneMat; VAR IM : IntDyneMat; VAR NP : integer);
procedure COMBO(VAR ISET : IntDyneVec; procedure COMBO(VAR ISET : IntDyneVec;
N, M : Integer; N, M : Integer;
VAR LAST : boolean); VAR LAST : boolean);
procedure EVAL(VAR IAR : IntDyneMat; procedure EVAL(VAR IAR : IntDyneMat;
NC, NV, IBEG, NVAR, MAX : integer; NC, NV, IBEG, NVAR, MAX : integer;
VAR CONFIG : IntDyneMat; VAR CONFIG : IntDyneMat;
VAR DIM : IntDyneVec; VAR DF : integer); VAR DIM : IntDyneVec; VAR DF : integer);
procedure RESET(VAR FIT : DblDyneVec; NTAB : Integer; procedure RESET(VAR FIT : DblDyneVec; NTAB : Integer;
AVG : Double); AVG : Double);
procedure LIKE(VAR GSQ : Double; VAR FIT : DblDyneVec; procedure LIKE(VAR GSQ : Double; VAR FIT : DblDyneVec;
VAR TABLE : DblDyneVec; NTAB : integer); VAR TABLE : DblDyneVec; NTAB : integer);
procedure LOGFIT(NVAR, NTAB, NCON : integer; procedure LOGFIT(NVAR, NTAB, NCON : integer;
VAR DIM : IntDyneVec; VAR DIM : IntDyneVec;
VAR CONFIG : IntDyneMat; VAR TABLE : DblDyneVec; VAR CONFIG : IntDyneMat; VAR TABLE : DblDyneVec;
VAR FIT : DblDyneVec; VAR SIZE : IntDyneVec; VAR FIT : DblDyneVec; VAR SIZE : IntDyneVec;
VAR COORD : IntDyneVec; VAR X : DblDyneVec; VAR COORD : IntDyneVec; VAR X : DblDyneVec;
VAR Y : DblDyneVec); VAR Y : DblDyneVec);
procedure MaxCombos(NoDims : integer; VAR MM : integer; VAR MP : integer); procedure MaxCombos(NumDims: integer; out MM, MP: integer);
public public
{ public declarations } { public declarations }
@@ -132,53 +116,23 @@ type
var var
LogLinScreenFrm: TLogLinScreenFrm; LogLinScreenFrm: TLogLinScreenFrm;
Minimums : IntDyneVec;
Maximums : IntDyneVec;
Response : BoolDyneVec;
Interact : BoolDyneVec;
NoDims : integer;
implementation implementation
uses uses
Math, Utils; Math, LCLIntf, LCLType, Utils;
{ TLogLinScreenFrm } { TLogLinScreenFrm }
procedure TLogLinScreenFrm.ResetBtnClick(Sender: TObject); procedure TLogLinScreenFrm.ResetBtnClick(Sender: TObject);
VAR i : integer; var
i : integer;
begin begin
Panel1.Visible := false; VarList.Clear;
VarList.Clear; for i := 1 to NoVariables do VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
SelectList.Clear; SelectList.Clear;
VarNoEdit.Text := '1'; UpdateBtnStates;
MaxEdit.Text := ''; UpdateMinMaxGrid;
MinEdit.Text := '';
InBtn.Enabled := true;
OutBtn.Enabled := false;
NoDims := 0;
Minimums := nil;
Maximums := nil;
Response := nil;
Interact := nil;
ScrollBar1.Min := 1;
ScrollBar1.Max := 1;
ScrollBar1.Position := 1;
for i := 1 to NoVariables do VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
end;
procedure TLogLinScreenFrm.CloseBtnClick(Sender: TObject);
begin
Maximums := nil;
Minimums := nil;
Response := nil;
Interact := nil;
Close;
end;
procedure TLogLinScreenFrm.ScrollBar1Change(Sender: TObject);
begin
VarNoEdit.Text := IntToStr(ScrollBar1.Position);
end; end;
procedure TLogLinScreenFrm.SelectListSelectionChange(Sender: TObject; procedure TLogLinScreenFrm.SelectListSelectionChange(Sender: TObject;
@@ -187,21 +141,6 @@ begin
UpdateBtnStates; UpdateBtnStates;
end; end;
procedure TLogLinScreenFrm.Step2BtnClick(Sender: TObject);
begin
if CountVarChk.Checked then
begin
NoDims := NoDims - 1;
ScrollBar1.Max := NoDims;
end;
Panel1.Visible := true;
setLength(Maximums,NoDims);
SetLength(Minimums,NoDims);
SetLength(Response,NoDims);
SetLength(Interact,NoDims);
MaxEdit.SetFocus;
end;
procedure TLogLinScreenFrm.InBtnClick(Sender: TObject); procedure TLogLinScreenFrm.InBtnClick(Sender: TObject);
var var
i: integer; i: integer;
@@ -213,37 +152,14 @@ begin
begin begin
SelectList.Items.Add(VarList.Items[i]); SelectList.Items.Add(VarList.Items[i]);
VarList.Items.Delete(i); VarList.Items.Delete(i);
NoDims := NoDims + 1;
i := 0; i := 0;
end else end else
i := i + 1; i := i + 1;
end; end;
Scrollbar1.Max := NoDims; UpdateMinMaxGrid;
UpdateBtnStates; UpdateBtnStates;
end; end;
procedure TLogLinScreenFrm.MaxEditKeyPress(Sender: TObject; var Key: char);
VAR DimNo : integer;
begin
if ord(Key) = 13 then // return key
begin
DimNo := StrToInt(VarNoEdit.Text);
Maximums[DimNo-1] := StrToInt(MaxEdit.Text);
ScrollBar1.SetFocus;
end;
end;
procedure TLogLinScreenFrm.MinEditKeyPress(Sender: TObject; var Key: char);
VAR DimNo : integer;
begin
if ord(Key) = 13 then // return key
begin
DimNo := StrToInt(VarNoEdit.Text);
Minimums[DimNo-1] := StrToInt(MinEdit.Text);
MaxEdit.SetFocus;
end;
end;
procedure TLogLinScreenFrm.FormActivate(Sender: TObject); procedure TLogLinScreenFrm.FormActivate(Sender: TObject);
var var
w: Integer; w: Integer;
@@ -257,8 +173,14 @@ begin
ComputeBtn.Constraints.MinWidth := w; ComputeBtn.Constraints.MinWidth := w;
CloseBtn.Constraints.MinWidth := w; CloseBtn.Constraints.MinWidth := w;
Constraints.MinWidth := Width; MinMaxGrid.ClientWidth := 3 * MinMaxGrid.Canvas.TextWidth('Maximum ') + 6*varCellPadding;
Constraints.MinWidth := MinMaxGrid.Width * 3 + AllBtn.Width + 4 * VarList.BorderSpacing.Left;
Constraints.MinHeight := Height; Constraints.MinHeight := Height;
AutoSize := false;
Height := 2*Height;
Position := poMainFormCenter;
FAutoSized := true; FAutoSized := true;
end; end;
@@ -287,9 +209,8 @@ begin
for i := 0 to VarList.Items.Count-1 do for i := 0 to VarList.Items.Count-1 do
SelectList.Items.Add(VarList.Items[i]); SelectList.Items.Add(VarList.Items[i]);
VarList.Clear; VarList.Clear;
NoDims := SelectList.Items.Count;
ScrollBar1.Max := NoDims;
UpdateBtnStates; UpdateBtnStates;
UpdateMinMaxGrid;
end; end;
procedure TLogLinScreenFrm.ComputeBtnClick(Sender: TObject); procedure TLogLinScreenFrm.ComputeBtnClick(Sender: TObject);
@@ -308,7 +229,6 @@ var
WorkVec : IntDyneVec; WorkVec : IntDyneVec;
Indexes : IntDyneMat; Indexes : IntDyneMat;
LogM : DblDyneVec; LogM : DblDyneVec;
NSize : IntDyneVec;
M : DblDyneMat; M : DblDyneMat;
astr, HeadStr : string; astr, HeadStr : string;
MaxDim, MP, MM : integer; MaxDim, MP, MM : integer;
@@ -333,30 +253,53 @@ var
IFAULT : integer; IFAULT : integer;
TABLE : DblDyneVec; TABLE : DblDyneVec;
DIM : IntDyneVec; DIM : IntDyneVec;
NoDims: Integer;
Minimums: IntDyneVec;
Maximums: IntDyneVec;
// Response: BoolDyneVec;
// Interact: BoolDyneVec;
lReport: TStrings; lReport: TStrings;
begin begin
lReport := TStringList.Create; lReport := TStringList.Create;
try try
// Allocate space for labels, DimSize and SubScripts // Allocate space for labels, DimSize and SubScripts
NoDims := MinMaxGrid.RowCount - 1;
NoVars := SelectList.Items.Count; NoVars := SelectList.Items.Count;
SetLength(Labels,NoVars);
SetLength(DimSize,NoDims); SetLength(Labels, NoVars);
SetLength(Subscripts,NoDims); SetLength(GridPos, NoVars);
SetLength(GridPos,NoVars); SetLength(Minimums, NoDims);
SetLength(Maximums, NoDims);
SetLength(DimSize, NoDims);
SetLength(Subscripts, NoDims);
for i := 1 to NoDims do
begin
if not TryStrToInt(MinMaxGrid.Cells[1, i], Minimums[i-1]) then
begin
MessageDlg('Integer number > 0 expected.', mtError, [mbOK], 0);
exit;
end;
if not TryStrToInt(MinMaxGrid.Cells[2, i], Maximums[i-1]) then
begin
MessageDlg('Integer number > 0 expected.', mtError, [mbOK], 0);
exit;
end;
end;
// get variable labels and column positions // get variable labels and column positions
for i := 1 to NoVars do for i := 1 to NoVars do
begin begin
astr := SelectList.Items.Strings[i-1]; astr := SelectList.Items.Strings[i-1];
for j := 1 to NoVariables do for j := 1 to NoVariables do
begin begin
if OS3MainFrm.DataGrid.Cells[j,0] = astr then if OS3MainFrm.DataGrid.Cells[j,0] = astr then
begin begin
Labels[i-1] := astr; Labels[i-1] := astr;
GridPos[i-1] := j; GridPos[i-1] := j;
break; break;
end; end;
end; end;
end; end;
// Get no. of categories for each dimension (DimSize) // Get no. of categories for each dimension (DimSize)
@@ -364,9 +307,9 @@ begin
ArraySize := 1; ArraySize := 1;
for i := 0 to NoDims - 1 do for i := 0 to NoDims - 1 do
begin begin
DimSize[i] := Maximums[i] - Minimums[i] + 1; DimSize[i] := Maximums[i] - Minimums[i] + 1;
if DimSize[i] > MaxDim then MaxDim := DimSize[i]; if DimSize[i] > MaxDim then MaxDim := DimSize[i];
ArraySize := ArraySize * DimSize[i]; ArraySize := ArraySize * DimSize[i];
end; end;
// Allocate space for Data and marginals // Allocate space for Data and marginals
@@ -377,46 +320,49 @@ begin
SetLength(Indexes,ArraySize+1,NoDims); SetLength(Indexes,ArraySize+1,NoDims);
SetLength(LogM,ArraySize); SetLength(LogM,ArraySize);
SetLength(M,ArraySize,NoDims); SetLength(M,ArraySize,NoDims);
SetLength(NSize,NoDims);
// Initialize data and margins arrays // Initialize data and margins arrays
for i := 1 to NoDims do for i := 1 to NoDims do
for j := 1 to MaxDim do for j := 1 to MaxDim do
Margins[i-1,j-1] := 0; Margins[i-1,j-1] := 0;
for i := 1 to ArraySize do Data[i-1] := 0; for i := 1 to ArraySize do
N := 0; Data[i-1] := 0;
// Read and store frequencies in Data // Read and store frequencies in Data
for i := 1 to NoCases do for i := 1 to NoCases do
begin begin
if GoodRecord(i, NoVars, GridPos) then // casewise check if GoodRecord(i, NoVars, GridPos) then // casewise check
begin begin
for j := 1 to NoDims do // get cell subscripts // get cell subscripts
begin for j := 1 to NoDims do
index := StrToInt(OS3MainFrm.DataGrid.Cells[GridPos[j-1],i]); begin
index := index - Minimums[j-1] + 1; index := StrToInt(OS3MainFrm.DataGrid.Cells[GridPos[j-1],i]);
Subscripts[j-1] := index; index := index - Minimums[j-1] + 1;
end; Subscripts[j-1] := index;
end;
index := ArrayPosition(Self, NoDims, Data, Subscripts, DimSize); index := ArrayPosition(NoDims, Data, Subscripts, DimSize);
for j := 1 to NoDims do // save subscripts for later use // save subscripts for later use
Indexes[index,j-1] := Subscripts[j-1]; for j := 1 to NoDims do
Indexes[index,j-1] := Subscripts[j-1];
if CountVarChk.Checked then if CountVarChk.Checked then
begin begin
k := GridPos[NoVars-1]; k := GridPos[NoVars-1];
Data[index] := Data[index] + StrToInt(OS3MainFrm.DataGrid.Cells[k,i]); Data[index] := Data[index] + StrToInt(OS3MainFrm.DataGrid.Cells[k,i]);
end end else
else Data[index] := Data[index] + 1; Data[index] := Data[index] + 1;
end; end;
end; end;
// get total N // get total N
for i := 1 to ArraySize do N := N + Round(Data[i-1]); N := 0;
for i := 1 to ArraySize do
N := N + Round(Data[i-1]);
// Get marginal frequencies // Get marginal frequencies
Marginals(Self,NoDims,ArraySize,Indexes,Data,Margins); Marginals(NoDims, ArraySize, Indexes, Data, Margins);
// Print Marginal totals if requested // Print Marginal totals if requested
if MarginsChk.Checked then if MarginsChk.Checked then
@@ -472,10 +418,10 @@ begin
astr := astr + format('%10.0f %10.2f %10.3f',[Data[i-1],Expected[i-1],LogM[i-1]]); astr := astr + format('%10.0f %10.2f %10.3f',[Data[i-1],Expected[i-1],LogM[i-1]]);
lReport.Add(astr); lReport.Add(astr);
end; end;
chi2 := 0.0;
G2 := 0.0;
// Calculate chi-squared and G squared statistics // Calculate chi-squared and G squared statistics
chi2 := 0.0;
G2 := 0.0;
for i := 1 to ArraySize do for i := 1 to ArraySize do
begin begin
chi2 := chi2 + Sqr(Data[i-1] - Expected[i-1]) / Expected[i-1]; chi2 := chi2 + Sqr(Data[i-1] - Expected[i-1]) / Expected[i-1];
@@ -484,10 +430,10 @@ begin
G2 := 2.0 * G2; G2 := 2.0 * G2;
DF := 1; DF := 1;
for i := 1 to NoDims do DF := DF * (DimSize[i-1]-1); for i := 1 to NoDims do DF := DF * (DimSize[i-1]-1);
ProbChi2 := 1.0 - Chisquaredprob(chi2,DF); ProbChi2 := 1.0 - ChiSquaredProb(chi2,DF);
ProbG2 := 1.0 - Chisquaredprob(G2,DF); ProbG2 := 1.0 - ChiSquaredProb(G2,DF);
lReport.Add('Chisquare: %10.3f with probability %10.3f (DF = %d)',[chi2, ProbChi2, DF]); lReport.Add('Chisquare: %10.3f with probability %10.3f (DF = %d)', [chi2, ProbChi2, DF]);
lReport.Add('G squared: %10.3f with probability %10.3f (DF = %d)',[G2, ProbG2, DF]); lReport.Add('G squared: %10.3f with probability %10.3f (DF = %d)', [G2, ProbG2, DF]);
lReport.Add(''); lReport.Add('');
lReport.Add('U (mu) for general loglinear model: %10.2f', [U]); lReport.Add('U (mu) for general loglinear model: %10.2f', [U]);
@@ -647,7 +593,6 @@ begin
PART := nil; PART := nil;
DGFR := nil; DGFR := nil;
GSQ := nil; GSQ := nil;
NSize := nil;
M := nil; M := nil;
LogM := nil; LogM := nil;
Indexes := nil; Indexes := nil;
@@ -674,12 +619,11 @@ begin
VarList.Items.Add(SelectList.Items[i]); VarList.Items.Add(SelectList.Items[i]);
SelectList.Items.Delete(i); SelectList.Items.Delete(i);
i := 0; i := 0;
NoDims := NoDims - 1;
end else end else
i := i + 1; i := i + 1;
end; end;
if NoDims > 0 then ScrollBar1.Max := NoDims else ScrollBar1.Max := 1;
UpdateBtnStates; UpdateBtnStates;
UpdateMinMaxGrid;
end; end;
procedure TLogLinScreenFrm.Screen(var NVAR: integer; var MP: integer; procedure TLogLinScreenFrm.Screen(var NVAR: integer; var MP: integer;
@@ -880,6 +824,11 @@ begin
GOTO 120; GOTO 120;
end; end;
procedure TLogLinScreenFrm.CountVarChkChange(Sender: TObject);
begin
UpdateMinMaxGrid;
end;
procedure TLogLinScreenFrm.COMBO(var ISET: IntDyneVec; N, M: Integer; procedure TLogLinScreenFrm.COMBO(var ISET: IntDyneVec; N, M: Integer;
var LAST: boolean); var LAST: boolean);
label 100, 110, 130, 150; label 100, 110, 130, 150;
@@ -1121,67 +1070,70 @@ begin
end; // 230 CONTINUE end; // 230 CONTINUE
end; end;
procedure TLogLinScreenFrm.MaxCombos(NoDims: integer; var MM: integer; procedure TLogLinScreenFrm.MaxCombos(NumDims: integer; out MM, MP: integer);
var MP: integer);
var var
combos : integer; combos: integer;
i,j : integer; i,j: integer;
begin begin
MM := 0; MM := 0;
MP := 0; MP := 0;
for i := 1 to NoDims do for i := 1 to NumDims do
begin begin
combos := 1; combos := 1;
// get numerator factorial products down to i
for j := NoDims downto i + 1 do // get numerator factorial products down to i
combos := combos * j; for j := NumDims downto i + 1 do
// divide by factorial of NoDims - i; combos := combos * j;
for j := (NoDims - i) downto 2 do
combos := combos div j; // divide by factorial of NumDims - i;
if combos > MP then MP := combos; for j := (NumDims - i) downto 2 do
if i * combos > MM then MM := i * combos; combos := combos div j;
end;
if combos > MP then
MP := combos;
if i * combos > MM then
MM := i * combos;
end;
end; end;
function TLogLinScreenFrm.ArrayPosition(Sender: TObject; NoDims : integer; function TLogLinScreenFrm.ArrayPosition(NumDims: integer;
VAR Data : DblDyneVec; const Data: DblDyneVec; const Subscripts, DimSize: IntDyneVec): integer;
VAR Subscripts : IntDyneVec;
VAR DimSize : IntDyneVec) : integer;
var var
Pos : integer; Pos : integer;
i, j : integer; i, j : integer;
PriorSizes : IntDyneVec; PriorSizes : IntDyneVec;
begin begin
// allocate space for PriorSizes // allocate space for PriorSizes
SetLength(PriorSizes,NoDims); SetLength(PriorSizes, NumDims);
// calculate PriorSizes values
for i := 0 to NoDims - 2 do PriorSizes[i] := 1; // initialize // calculate PriorSizes values
for i := NoDims - 2 downto 0 do for i := 0 to NumDims - 2 do
for j := 0 to i do PriorSizes[i] := PriorSizes[i] * DimSize[j]; PriorSizes[i] := 1; // initialize
Pos := Subscripts[0] - 1;
for i := 0 to NoDims - 2 do for i := NumDims - 2 downto 0 do
Pos := Pos + (PriorSizes[i] * (Subscripts[i+1]-1)); for j := 0 to i do PriorSizes[i] := PriorSizes[i] * DimSize[j];
Result := Pos;
PriorSizes := nil; Pos := Subscripts[0] - 1;
for i := 0 to NumDims - 2 do
Pos := Pos + (PriorSizes[i] * (Subscripts[i+1]-1));
Result := Pos;
PriorSizes := nil;
end; end;
procedure TLogLinScreenFrm.Marginals(Sender: TObject; NoDims: integer; procedure TLogLinScreenFrm.Marginals(NumDims, ArraySize: integer;
ArraySize: integer; var Indexes: IntDyneMat; var Data: DblDyneVec; const Indexes: IntDyneMat; const Data: DblDyneVec; const Margins: IntDyneMat);
var Margins: IntDyneMat); var
var i, j, category : integer; i, j, category: integer;
begin begin
for i := 1 to ArraySize do for i := 1 to ArraySize do
begin begin
for j := 1 to NoDims do for j := 1 to NumDims do
begin begin
category := Indexes[i-1,j-1]; category := Indexes[i-1,j-1];
Margins[j-1,category-1] := Margins[j-1,category-1] + Round(Data[i-1]); Margins[j-1,category-1] := Margins[j-1,category-1] + Round(Data[i-1]);
end; end;
end; end;
end; end;
procedure TLogLinScreenFrm.UpdateBtnStates; procedure TLogLinScreenFrm.UpdateBtnStates;
@@ -1191,6 +1143,24 @@ begin
AllBtn.Enabled := VarList.Items.Count > 0; AllBtn.Enabled := VarList.Items.Count > 0;
end; end;
procedure TLogLinScreenFrm.UpdateMinMaxGrid;
var
NumDims, j: Integer;
begin
if CountVarChk.Checked then
NumDims := SelectList.Count - 1
else
NumDims := SelectList.Count;
if NumDims < 0 then NumDims := 0;
MinMaxGrid.RowCount := NumDims + 1;
for j := 1 to MinMaxGrid.RowCount-1 do
begin
MinMaxGrid.Cells[0, j] := SelectList.Items[j-1];
MinMaxGrid.Cells[1, j] := '';
MinMaxGrid.Cells[2, j] := '';
end;
end;
procedure TLogLinScreenFrm.VarListSelectionChange(Sender: TObject; User: boolean); procedure TLogLinScreenFrm.VarListSelectionChange(Sender: TObject; User: boolean);
begin begin
UpdateBtnStates; UpdateBtnStates;