LazStats: Refactor PartialsUnit. Add pdf help text to chm help.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7401 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-04-24 22:19:30 +00:00
parent a9b903fb75
commit 8c760eb862
5 changed files with 341 additions and 291 deletions

View File

@@ -1,12 +1,12 @@
object PartialsFrm: TPartialsFrm object PartialsFrm: TPartialsFrm
Left = 637 Left = 593
Height = 460 Height = 398
Top = 307 Top = 175
Width = 412 Width = 361
AutoSize = True AutoSize = True
Caption = 'Partial Correlation' Caption = 'Partial Correlation'
ClientHeight = 460 ClientHeight = 398
ClientWidth = 412 ClientWidth = 361
OnActivate = FormActivate OnActivate = FormActivate
OnCreate = FormCreate OnCreate = FormCreate
OnShow = FormShow OnShow = FormShow
@@ -28,7 +28,7 @@ object PartialsFrm: TPartialsFrm
AnchorSideLeft.Control = DepVar AnchorSideLeft.Control = DepVar
AnchorSideTop.Control = DepInBtn AnchorSideTop.Control = DepInBtn
AnchorSideBottom.Control = DepVar AnchorSideBottom.Control = DepVar
Left = 228 Left = 202
Height = 15 Height = 15
Top = 25 Top = 25
Width = 152 Width = 152
@@ -37,10 +37,13 @@ object PartialsFrm: TPartialsFrm
end end
object Label3: TLabel object Label3: TLabel
AnchorSideLeft.Control = PredList AnchorSideLeft.Control = PredList
Left = 229 AnchorSideTop.Control = DepOutBtn
AnchorSideTop.Side = asrBottom
Left = 203
Height = 15 Height = 15
Top = 120 Top = 93
Width = 144 Width = 144
BorderSpacing.Top = 8
Caption = 'Selected Predictor Variables' Caption = 'Selected Predictor Variables'
ParentColor = False ParentColor = False
end end
@@ -48,11 +51,13 @@ object PartialsFrm: TPartialsFrm
AnchorSideLeft.Control = PartList AnchorSideLeft.Control = PartList
AnchorSideTop.Control = PartInBtn AnchorSideTop.Control = PartInBtn
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideBottom.Control = PartList
Left = 8 Left = 8
Height = 15 Height = 15
Top = 289 Top = 239
Width = 121 Width = 121
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Bottom = 2
Caption = 'Variables Partialed Out:' Caption = 'Variables Partialed Out:'
ParentColor = False ParentColor = False
end end
@@ -61,25 +66,25 @@ object PartialsFrm: TPartialsFrm
AnchorSideTop.Control = Label1 AnchorSideTop.Control = Label1
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = DepInBtn AnchorSideRight.Control = DepInBtn
AnchorSideBottom.Control = Bevel3
Left = 8 Left = 8
Height = 220 Height = 170
Top = 25 Top = 25
Width = 176 Width = 150
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 8 BorderSpacing.Left = 8
BorderSpacing.Top = 2 BorderSpacing.Top = 2
BorderSpacing.Right = 8 BorderSpacing.Right = 8
Constraints.MinHeight = 220
Constraints.MinWidth = 175
ItemHeight = 0 ItemHeight = 0
MultiSelect = True MultiSelect = True
OnSelectionChange = VarListSelectionChange
TabOrder = 0 TabOrder = 0
end end
object DepInBtn: TBitBtn object DepInBtn: TBitBtn
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = VarList AnchorSideTop.Control = VarList
Left = 192 Left = 166
Height = 28 Height = 28
Top = 25 Top = 25
Width = 28 Width = 28
@@ -130,7 +135,7 @@ object PartialsFrm: TPartialsFrm
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = DepInBtn AnchorSideTop.Control = DepInBtn
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 192 Left = 166
Height = 28 Height = 28
Top = 57 Top = 57
Width = 28 Width = 28
@@ -180,13 +185,14 @@ object PartialsFrm: TPartialsFrm
object PredInBtn: TBitBtn object PredInBtn: TBitBtn
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideBottom.Control = PredOutBtn AnchorSideTop.Control = DepOutBtn
Left = 192 AnchorSideTop.Side = asrBottom
AnchorSideBottom.Control = Bevel4
Left = 166
Height = 28 Height = 28
Top = 185 Top = 122
Width = 28 Width = 28
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
BorderSpacing.Bottom = 4
Glyph.Data = { Glyph.Data = {
36040000424D3604000000000000360000002800000010000000100000000100 36040000424D3604000000000000360000002800000010000000100000000100
2000000000000004000064000000640000000000000000000000FFFFFF00FFFF 2000000000000004000064000000640000000000000000000000FFFFFF00FFFF
@@ -232,13 +238,13 @@ object PartialsFrm: TPartialsFrm
object PredOutBtn: TBitBtn object PredOutBtn: TBitBtn
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideBottom.Control = VarList AnchorSideTop.Control = Bevel4
AnchorSideTop.Side = asrBottom
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 192 Left = 166
Height = 28 Height = 28
Top = 217 Top = 154
Width = 28 Width = 28
Anchors = [akLeft, akBottom]
Glyph.Data = { Glyph.Data = {
36040000424D3604000000000000360000002800000010000000100000000100 36040000424D3604000000000000360000002800000010000000100000000100
2000000000000004000064000000640000000000000000000000FFFFFF00FFFF 2000000000000004000064000000640000000000000000000000FFFFFF00FFFF
@@ -285,9 +291,10 @@ object PartialsFrm: TPartialsFrm
AnchorSideTop.Control = VarList AnchorSideTop.Control = VarList
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Bevel1 AnchorSideRight.Control = Bevel1
Left = 64 AnchorSideBottom.Control = Label4
Left = 51
Height = 28 Height = 28
Top = 253 Top = 203
Width = 28 Width = 28
Anchors = [akTop, akRight] Anchors = [akTop, akRight]
BorderSpacing.Top = 8 BorderSpacing.Top = 8
@@ -336,13 +343,11 @@ object PartialsFrm: TPartialsFrm
object PartOutBtn: TBitBtn object PartOutBtn: TBitBtn
AnchorSideLeft.Control = Bevel1 AnchorSideLeft.Control = Bevel1
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = VarList AnchorSideTop.Control = PartInBtn
AnchorSideTop.Side = asrBottom Left = 87
Left = 100
Height = 28 Height = 28
Top = 253 Top = 203
Width = 28 Width = 28
BorderSpacing.Top = 8
Glyph.Data = { Glyph.Data = {
36040000424D3604000000000000360000002800000010000000100000000100 36040000424D3604000000000000360000002800000010000000100000000100
2000000000000004000064000000640000000000000000000000FFFFFF00FFFF 2000000000000004000064000000640000000000000000000000FFFFFF00FFFF
@@ -394,33 +399,37 @@ object PartialsFrm: TPartialsFrm
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = DepOutBtn AnchorSideBottom.Control = DepOutBtn
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 228 Left = 202
Height = 23 Height = 23
Top = 42 Top = 42
Width = 176 Width = 151
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 8 BorderSpacing.Left = 8
BorderSpacing.Top = 2 BorderSpacing.Top = 2
BorderSpacing.Right = 8 BorderSpacing.Right = 8
ReadOnly = True
TabOrder = 3 TabOrder = 3
Text = 'DepVar' Text = 'DepVar'
end end
object PredList: TListBox object PredList: TListBox
AnchorSideLeft.Control = PredInBtn AnchorSideLeft.Control = PredInBtn
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Label3
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = PredOutBtn AnchorSideBottom.Control = Bevel3
AnchorSideBottom.Side = asrBottom Left = 203
Left = 229 Height = 85
Height = 109 Top = 110
Top = 136 Width = 150
Width = 175
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 9 BorderSpacing.Left = 9
BorderSpacing.Top = 2
BorderSpacing.Right = 8 BorderSpacing.Right = 8
Constraints.MinWidth = 175
ItemHeight = 0 ItemHeight = 0
MultiSelect = True
OnSelectionChange = VarListSelectionChange
TabOrder = 6 TabOrder = 6
end end
object PartList: TListBox object PartList: TListBox
@@ -431,103 +440,86 @@ object PartialsFrm: TPartialsFrm
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Bevel2 AnchorSideBottom.Control = Bevel2
Left = 8 Left = 8
Height = 105 Height = 93
Top = 306 Top = 256
Width = 176 Width = 150
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 8 BorderSpacing.Left = 8
BorderSpacing.Top = 2 BorderSpacing.Top = 2
Constraints.MinHeight = 100
ItemHeight = 0 ItemHeight = 0
MultiSelect = True
OnSelectionChange = VarListSelectionChange
TabOrder = 9 TabOrder = 9
end end
object ResetBtn: TButton object ResetBtn: TButton
AnchorSideRight.Control = CancelBtn AnchorSideRight.Control = ComputeBtn
AnchorSideBottom.Control = Owner AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 111 Left = 152
Height = 25 Height = 25
Top = 427 Top = 365
Width = 54 Width = 54
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Left = 12 BorderSpacing.Left = 8
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 12 BorderSpacing.Right = 8
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Reset' Caption = 'Reset'
OnClick = ResetBtnClick OnClick = ResetBtnClick
TabOrder = 11 TabOrder = 11
end end
object CancelBtn: TButton
AnchorSideRight.Control = ComputeBtn
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 177
Height = 25
Top = 427
Width = 62
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 12
BorderSpacing.Top = 8
BorderSpacing.Right = 12
BorderSpacing.Bottom = 8
Caption = 'Cancel'
ModalResult = 2
TabOrder = 12
end
object ComputeBtn: TButton object ComputeBtn: TButton
AnchorSideRight.Control = ReturnBtn AnchorSideRight.Control = CloseBtn
AnchorSideBottom.Control = Owner AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 251 Left = 214
Height = 25 Height = 25
Top = 427 Top = 365
Width = 76 Width = 76
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Left = 12 BorderSpacing.Left = 8
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 12 BorderSpacing.Right = 8
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Compute' Caption = 'Compute'
OnClick = ComputeBtnClick OnClick = ComputeBtnClick
TabOrder = 13 TabOrder = 12
end end
object ReturnBtn: 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 = 298
Height = 25 Height = 25
Top = 427 Top = 365
Width = 61 Width = 55
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Left = 12 BorderSpacing.Left = 8
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 12 BorderSpacing.Right = 8
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Return' Caption = 'Close'
ModalResult = 1 ModalResult = 11
TabOrder = 14 TabOrder = 13
end end
object HelpBtn: TButton object HelpBtn: TButton
Tag = 136 Tag = 136
AnchorSideRight.Control = ResetBtn AnchorSideRight.Control = ResetBtn
AnchorSideBottom.Control = Owner AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 48 Left = 93
Height = 25 Height = 25
Top = 427 Top = 365
Width = 51 Width = 51
Anchors = [akRight, akBottom] Anchors = [akRight, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Left = 12 BorderSpacing.Left = 8
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 12 BorderSpacing.Right = 8
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Help' Caption = 'Help'
OnClick = HelpBtnClick OnClick = HelpBtnClick
@@ -538,9 +530,9 @@ object PartialsFrm: TPartialsFrm
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = VarList AnchorSideTop.Control = VarList
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 92 Left = 79
Height = 28 Height = 28
Top = 245 Top = 195
Width = 8 Width = 8
Shape = bsSpacer Shape = bsSpacer
end end
@@ -548,12 +540,32 @@ object PartialsFrm: TPartialsFrm
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideRight.Control = Owner AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ReturnBtn AnchorSideBottom.Control = CloseBtn
Left = 0 Left = 0
Height = 8 Height = 8
Top = 411 Top = 349
Width = 412 Width = 361
Anchors = [akLeft, akRight, akBottom] Anchors = [akLeft, akRight, akBottom]
Shape = bsBottomLine Shape = bsBottomLine
end end
object Bevel3: TBevel
AnchorSideTop.Control = Owner
AnchorSideTop.Side = asrCenter
Left = 8
Height = 8
Top = 195
Width = 40
Shape = bsSpacer
end
object Bevel4: TBevel
AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = PredList
AnchorSideTop.Side = asrCenter
Left = 160
Height = 4
Top = 150
Width = 40
Shape = bsSpacer
end
end end

View File

@@ -1,3 +1,8 @@
// File for testing: cansas.laz
// - Selected dependent variable --> jumps
// - Seleckted predictor variables --> weight
// - variables partialed out --> waist, pulse
unit PartialsUnit; unit PartialsUnit;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
@@ -16,6 +21,8 @@ type
TPartialsFrm = class(TForm) TPartialsFrm = class(TForm)
Bevel1: TBevel; Bevel1: TBevel;
Bevel2: TBevel; Bevel2: TBevel;
Bevel3: TBevel;
Bevel4: TBevel;
DepInBtn: TBitBtn; DepInBtn: TBitBtn;
DepOutBtn: TBitBtn; DepOutBtn: TBitBtn;
HelpBtn: TButton; HelpBtn: TButton;
@@ -24,9 +31,8 @@ type
PartInBtn: TBitBtn; PartInBtn: TBitBtn;
PartOutBtn: TBitBtn; PartOutBtn: TBitBtn;
ResetBtn: TButton; ResetBtn: TButton;
CancelBtn: TButton;
ComputeBtn: TButton; ComputeBtn: TButton;
ReturnBtn: TButton; CloseBtn: TButton;
DepVar: TEdit; DepVar: TEdit;
Label1: TLabel; Label1: TLabel;
Label2: TLabel; Label2: TLabel;
@@ -47,9 +53,11 @@ type
procedure PredInBtnClick(Sender: TObject); procedure PredInBtnClick(Sender: TObject);
procedure PredOutBtnClick(Sender: TObject); procedure PredOutBtnClick(Sender: TObject);
procedure ResetBtnClick(Sender: TObject); procedure ResetBtnClick(Sender: TObject);
procedure VarListSelectionChange(Sender: TObject; User: boolean);
private private
{ private declarations } { private declarations }
FAutoSized: Boolean; FAutoSized: Boolean;
procedure UpdateBtnStates;
public public
{ public declarations } { public declarations }
end; end;
@@ -60,25 +68,21 @@ var
implementation implementation
uses uses
Math; Math, Utils;
{ TPartialsFrm } { TPartialsFrm }
procedure TPartialsFrm.ResetBtnClick(Sender: TObject); procedure TPartialsFrm.ResetBtnClick(Sender: TObject);
VAR i : integer; var
i: integer;
begin begin
DepVar.Text := ''; DepVar.Text := '';
VarList.Clear; VarList.Clear;
PartList.Clear; PartList.Clear;
PredList.Clear; PredList.Clear;
DepInBtn.Enabled := true; for i := 1 to OS3MainFrm.DataGrid.ColCount - 1 do
DepOutBtn.Enabled := false; VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
PredInBtn.Enabled := true; UpdateBtnStates;
PredOutBtn.Enabled := false;
PartInBtn.Enabled := true;
PartOutBtn.Enabled := false;
for i := 1 to OS3MainFrm.DataGrid.ColCount - 1 do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
end; end;
procedure TPartialsFrm.FormActivate(Sender: TObject); procedure TPartialsFrm.FormActivate(Sender: TObject);
@@ -88,14 +92,14 @@ begin
if FAutoSized then if FAutoSized then
exit; exit;
w := MaxValue([HelpBtn.Width, ResetBtn.Width, CancelBtn.Width, ComputeBtn.Width, ReturnBtn.Width]); w := MaxValue([HelpBtn.Width, ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]);
HelpBtn.Constraints.MinWidth := w; HelpBtn.Constraints.MinWidth := w;
ResetBtn.Constraints.MinWidth := w; ResetBtn.Constraints.MinWidth := w;
CancelBtn.Constraints.MinWidth := w;
ComputeBtn.Constraints.MinWidth := w; ComputeBtn.Constraints.MinWidth := w;
ReturnBtn.Constraints.MinWidth := w; CloseBtn.Constraints.MinWidth := w;
Constraints.MinWidth := Width; w := 2 * Max(Label2.Width, Label3.Width) + DepInBtn.Width + 4 * VarList.BorderSpacing.Left;
Constraints.MinWidth := w; //Max(Width, w);
Constraints.MinHeight := Height; Constraints.MinHeight := Height;
FAutoSized := true; FAutoSized := true;
@@ -104,7 +108,6 @@ end;
procedure TPartialsFrm.FormCreate(Sender: TObject); procedure TPartialsFrm.FormCreate(Sender: TObject);
begin begin
Assert(OS3MainFrm <> nil); Assert(OS3MainFrm <> nil);
if OutputFrm = nil then Application.CreateForm(TOutputFrm, OutputFrm);
end; end;
procedure TPartialsFrm.FormShow(Sender: TObject); procedure TPartialsFrm.FormShow(Sender: TObject);
@@ -120,178 +123,205 @@ begin
end; end;
procedure TPartialsFrm.PartInBtnClick(Sender: TObject); procedure TPartialsFrm.PartInBtnClick(Sender: TObject);
VAR i, index : integer; var
i: integer;
begin begin
index := VarList.Items.Count; i := 0;
i := 0; while i < VarList.Items.Count do
while i < index do begin
begin if VarList.Selected[i] then
if (VarList.Selected[i]) then begin
begin PartList.Items.Add(VarList.Items[i]);
PartList.Items.Add(VarList.Items.Strings[i]); VarList.Items.Delete(i);
VarList.Items.Delete(i); i := 0;
index := index - 1; end else
i := 0; i := i + 1;
end end;
else i := i + 1; UpdateBtnStates;
end;
PartOutBtn.Enabled := true;
end; end;
procedure TPartialsFrm.PartOutBtnClick(Sender: TObject); procedure TPartialsFrm.PartOutBtnClick(Sender: TObject);
VAR index : integer; var
i: integer;
begin begin
index := PartList.ItemIndex; i := 0;
VarList.Items.Add(PartList.Items.Strings[index]); while i < PartList.Items.Count do
PartList.Items.Delete(index); begin
if PartList.Items.Count = 0 then PartOutBtn.Enabled := false; if PartList.Selected[i] then
begin
VarList.Items.Add(PartList.Items[i]);
PartList.Items.Delete(i);
i := 0;
end else
i := i + 1;
end;
UpdateBtnStates;
end; end;
procedure TPartialsFrm.PredInBtnClick(Sender: TObject); procedure TPartialsFrm.PredInBtnClick(Sender: TObject);
VAR i, index : integer; var
i: integer;
begin begin
index := VarList.Items.Count; i := 0;
i := 0; while i < VarList.Items.Count do
while i < index do begin
begin if VarList.Selected[i] then
if (VarList.Selected[i]) then begin
begin PredList.Items.Add(VarList.Items[i]);
PredList.Items.Add(VarList.Items.Strings[i]); VarList.Items.Delete(i);
VarList.Items.Delete(i); i := 0;
index := index - 1; end else
i := 0; i := i + 1;
end end;
else i := i + 1; UpdateBtnStates;
end;
PredOutBtn.Enabled := true;
end; end;
procedure TPartialsFrm.PredOutBtnClick(Sender: TObject); procedure TPartialsFrm.PredOutBtnClick(Sender: TObject);
VAR index : integer; var
i: integer;
begin begin
index := PredList.ItemIndex; i := 0;
VarList.Items.Add(PredList.Items.Strings[index]); while i < PredList.Items.Count do
PredList.Items.Delete(index); begin
if PredList.Items.Count = 0 then PredOutBtn.Enabled := false; if PredList.Selected[i] then
begin
VarList.Items.Add(PredList.Items[i]);
PredList.Items.Delete(i);
i := 0;
end else
i := i + 1;
end;
UpdateBtnStates;
end; end;
procedure TPartialsFrm.DepInBtnClick(Sender: TObject); procedure TPartialsFrm.DepInBtnClick(Sender: TObject);
VAR index : integer; var
index: integer;
begin begin
index := VarList.ItemIndex; index := VarList.ItemIndex;
if index < 0 then exit; if (index > -1) and (DepVar.Text = '') then
DepVar.Text := VarList.Items.Strings[index]; begin
VarList.Items.Delete(index); DepVar.Text := VarList.Items[index];
DepOutBtn.Enabled := true; VarList.Items.Delete(index);
DepInBtn.Enabled := false; UpdateBtnStates;
end;
end;
procedure TPartialsFrm.DepOutBtnClick(Sender: TObject);
begin
if DepVar.Text <> '' then
begin
VarList.Items.Add(DepVar.Text);
DepVar.Text := '';
UpdateBtnStates;
end;
end; end;
procedure TPartialsFrm.ComputeBtnClick(Sender: TObject); procedure TPartialsFrm.ComputeBtnClick(Sender: TObject);
var var
rmatrix, workmat: DblDyneMat; rmatrix, workmat: DblDyneMat;
Means, Variances, StdDevs, W, Betas: DblDyneVec; Means, Variances, StdDevs, W, Betas: DblDyneVec;
R2Full, R2Cntrl, SemiPart, Partial, df1, df2, F, Prob: double; R2Full, R2Cntrl, SemiPart, Partial, df1, df2, F, Prob: double;
NoPredVars, NoCntrlVars, DepVarNo, TotNoVars, pcnt, ccnt, count: integer; NoPredVars, NoCntrlVars, DepVarNo, TotNoVars, pcnt, ccnt, count: integer;
PredVars, CntrlVars: IntDyneVec; PredVars, CntrlVars: IntDyneVec;
MatVars: IntDyneVec; MatVars: IntDyneVec;
outline, varstring: string; outline, varstring: string;
i, j, K, L: integer; i, j, K, L: integer;
errorcode: boolean; errorcode: boolean;
vtimesw, W1, v: DblDyneMat; vtimesw, W1, v: DblDyneMat;
lReport: TStrings;
begin begin
DepVarNo := 1; DepVarNo := 1;
errorcode := false; errorcode := false;
// Get no. of predictor and control variables if DepVar.Text = '' then
NoPredVars := PredList.Items.Count; begin
NoCntrlVars := PartList.Items.Count; MessageDlg('No dependent variable selected.', mtError, [mbOK], 0);
if (NoPredVars = 0) or (NoCntrlVars = 0) then exit;
begin end;
ShowMessage('You must select at least one predictor and one control variable!');
exit;
end;
TotNoVars := NoPredVars + NoCntrlVars + 1;
count := NoCases;
// Allocate space required // Get no. of predictor and control variables
SetLength(vtimesw,NoVariables,NoVariables); NoPredVars := PredList.Items.Count;
SetLength(v,NoVariables,NoVariables); NoCntrlVars := PartList.Items.Count;
SetLength(W1,NoVariables,NoVariables); if (NoPredVars = 0) or (NoCntrlVars = 0) then
SetLength(rmatrix,NoVariables+1,NoVariables+1); // augmented begin
SetLength(workmat,NoVariables+1,NoVariables+1); // augmented MessageDlg('You must select at least one predictor and one control variable.', mtError, [mbOK], 0);
SetLength(PredVars,NoVariables); exit;
SetLength(CntrlVars,NoVariables); end;
SetLength(Means,NoVariables); TotNoVars := NoPredVars + NoCntrlVars + 1;
SetLength(Variances,NoVariables); count := NoCases;
SetLength(StdDevs,NoVariables);
SetLength(W,NoVariables);
SetLength(Betas,NoVariables);
SetLength(MatVars,NoVariables);
OutputFrm.RichEdit.Clear; // Allocate space required
OutputFrm.RichEdit.Lines.Add('Partial and Semi-Partial Correlation Analysis'); SetLength(vtimesw,NoVariables,NoVariables);
OutputFrm.RichEdit.Lines.Add(''); SetLength(v,NoVariables,NoVariables);
SetLength(W1,NoVariables,NoVariables);
SetLength(rmatrix,NoVariables+1,NoVariables+1); // augmented
SetLength(workmat,NoVariables+1,NoVariables+1); // augmented
SetLength(PredVars,NoVariables);
SetLength(CntrlVars,NoVariables);
SetLength(Means,NoVariables);
SetLength(Variances,NoVariables);
SetLength(StdDevs,NoVariables);
SetLength(W,NoVariables);
SetLength(Betas,NoVariables);
SetLength(MatVars,NoVariables);
lReport := TStringList.Create;
try
lReport.Add('PARTIAL AND SEMI-PARTIAL CORRELATION ANALYSIS');
lReport.Add('');
// Get column numbers of dependent, predictor and control variables // Get column numbers of dependent, predictor and control variables
pcnt := 1; pcnt := 1;
for i := 0 to NoPredVars - 1 do for i := 0 to NoPredVars - 1 do
begin begin
varstring := PredList.Items.Strings[i]; varstring := PredList.Items.Strings[i];
for j := 1 to NoVariables do for j := 1 to NoVariables do
begin
if varstring = OS3MainFrm.DataGrid.Cells[j,0] then
begin begin
if varstring = OS3MainFrm.DataGrid.Cells[j,0] then PredVars[pcnt-1] := j;
begin pcnt := pcnt + 1;
PredVars[pcnt-1] := j;
pcnt := pcnt + 1;
end;
end; end;
end;
end; end;
ccnt := 1; ccnt := 1;
for i := 0 to NoCntrlVars - 1 do for i := 0 to NoCntrlVars - 1 do
begin begin
varstring := PartList.Items.Strings[i]; varstring := PartList.Items.Strings[i];
for j := 1 to NoVariables do for j := 1 to NoVariables do
begin
if varstring = OS3MainFrm.DataGrid.Cells[j,0] then
begin begin
if varstring = OS3MainFrm.DataGrid.Cells[j,0] then CntrlVars[ccnt-1] := j;
begin ccnt := ccnt + 1;
CntrlVars[ccnt-1] := j; end;
ccnt := ccnt + 1; end;
end;
end;
end; end;
varstring := DepVar.Text; varstring := DepVar.Text;
for i := 1 to NoVariables do for i := 1 to NoVariables do
if varstring = OS3MainFrm.DataGrid.Cells[i,0] then DepVarNo := i; if varstring = OS3MainFrm.DataGrid.Cells[i,0] then DepVarNo := i;
outline := format('Dependent variable = %s',[OS3MainFrm.DataGrid.Cells[DepVarNo,0]]); lReport.Add('Dependent variable: %s', [OS3MainFrm.DataGrid.Cells[DepVarNo, 0]]);
OutputFrm.RichEdit.Lines.Add(outline); lReport.Add('');
OutputFrm.RichEdit.Lines.Add(''); lReport.Add('Predictor Variables:');
OutputFrm.RichEdit.Lines.Add('Predictor Variables:');
for i := 1 to NoPredVars do for i := 1 to NoPredVars do
begin lReport.Add(' Variable %d: %s', [i+1, OS3MainFrm.DataGrid.Cells[PredVars[i-1], 0]]);
outline := format('Variable %d = %s',[i+1,OS3MainFrm.DataGrid.Cells[PredVars[i-1],0]]); lReport.Add('');
OutputFrm.RichEdit.Lines.Add(outline); lReport.Add('Control Variables:');
end;
OutputFrm.RichEdit.Lines.Add('');
OutputFrm.RichEdit.Lines.Add('Control Variables:');
for i := 1 to NoCntrlVars do for i := 1 to NoCntrlVars do
begin lReport.Add(' Variable %d: %s', [i+1, OS3MainFrm.DataGrid.Cells[CntrlVars[i-1], 0]]);
outline := format('Variable %d = %s',[i+1,OS3MainFrm.DataGrid.Cells[CntrlVars[i-1],0]]); lReport.Add('');
OutputFrm.RichEdit.Lines.Add(outline);
end;
OutputFrm.RichEdit.Lines.Add('');
if NoPredVars > 1 then if NoPredVars > 1 then
begin begin
outline := format('Higher order partialling at level = %d',[NoPredVars]); lReport.Add('Higher order partialling at level: %d', [NoPredVars]);
OutputFrm.RichEdit.Lines.Add(outline); lReport.Add('');
OutputFrm.RichEdit.Lines.Add('');
end; end;
if NoCntrlVars > 1 then if NoCntrlVars > 1 then
begin begin
outline := format('Multiple partialling with %d variables.',[NoCntrlVars]); lReport.Add('Multiple partialling with %d variables.', [NoCntrlVars]);
OutputFrm.RichEdit.Lines.Add(outline); lReport.Add('');
OutputFrm.RichEdit.Lines.Add('');
end; end;
// Now, build the correlation matrix // Now, build the correlation matrix
@@ -303,61 +333,54 @@ begin
// Now do Multiple regression models required // Now do Multiple regression models required
// Full model first // Full model first
for i := 2 to TotNoVars do for i := 2 to TotNoVars do
for j := 2 to TotNoVars do for j := 2 to TotNoVars do
workmat[i-2,j-2] := rmatrix[i-1,j-1]; workmat[i-2,j-2] := rmatrix[i-1,j-1];
matinv(workmat, vtimesw, v, W1, TotNoVars-1); MatInv(workmat, vtimesw, v, W1, TotNoVars-1);
R2Full := 0.0; R2Full := 0.0;
for i := 1 to TotNoVars-1 do // rows for i := 1 to TotNoVars-1 do // rows
begin begin
W[i-1] := 0.0; W[i-1] := 0.0;
for j := 1 to TotNoVars - 1 do W[i-1] := W[i-1] + (workmat[i-1,j-1] * rmatrix[0,j]); for j := 1 to TotNoVars - 1 do
R2Full := R2Full + W[i-1] * rmatrix[0,i]; W[i-1] := W[i-1] + (workmat[i-1,j-1] * rmatrix[0,j]);
R2Full := R2Full + W[i-1] * rmatrix[0,i];
end; end;
outline := format('Squared Multiple Correlation with all variables = %6.3f',[R2Full]); lReport.Add('Squared Multiple Correlation with all variables: %6.3f', [R2Full]);
OutputFrm.RichEdit.Lines.Add(outline); lReport.Add('');
OutputFrm.RichEdit.Lines.Add(''); lReport.Add('Standardized Regression Coefficients:');
OutputFrm.RichEdit.Lines.Add('Standardized Regression Coefficients:');
for i := 1 to TotNoVars - 1 do for i := 1 to TotNoVars - 1 do
begin lReport.Add('%15s: %6.3f', [OS3MainFrm.DataGrid.Cells[MatVars[i],0], W[i-1]]);
outline := format('%10s = %6.3f',[OS3MainFrm.DataGrid.Cells[MatVars[i],0],W[i-1]]); lReport.Add('');
OutputFrm.RichEdit.Lines.Add(outline);
end;
OutputFrm.RichEdit.Lines.Add('');
// Now do model for Partial and Semi-partial // Now do model for Partial and Semi-partial
for i := 1 to NoCntrlVars do for i := 1 to NoCntrlVars do
begin begin
K := i + 1 + NoPredVars; K := i + 1 + NoPredVars;
for j := 1 to NoCntrlVars do for j := 1 to NoCntrlVars do
begin begin
L := j + 1 + NoPredVars; L := j + 1 + NoPredVars;
workmat[i-1,j-1] := rmatrix[K-1,L-1]; workmat[i-1,j-1] := rmatrix[K-1,L-1];
end; end;
end; end;
matinv(workmat, vtimesw, v, W1, NoCntrlVars); MatInv(workmat, vtimesw, v, W1, NoCntrlVars);
R2Cntrl := 0.0; R2Cntrl := 0.0;
for i := 1 to NoCntrlVars do for i := 1 to NoCntrlVars do
begin begin
L := i + 1 + NoPredVars; L := i + 1 + NoPredVars;
W[i-1] := 0.0; W[i-1] := 0.0;
for j := 1 to NoCntrlVars do for j := 1 to NoCntrlVars do
begin begin
K := j + 1 + NoPredVars; K := j + 1 + NoPredVars;
W[i-1] := W[i-1] + (workmat[i-1,j-1] * rmatrix[0,K-1]); W[i-1] := W[i-1] + (workmat[i-1,j-1] * rmatrix[0,K-1]);
end; end;
R2Cntrl := R2Cntrl + W[i-1] * rmatrix[0,L-1]; R2Cntrl := R2Cntrl + W[i-1] * rmatrix[0,L-1];
end; end;
outline := format('Squared Multiple Correlation with control variables = %6.3f',[R2Cntrl]); lReport.Add('Squared Multiple Correlation with control variables: %6.3f', [R2Cntrl]);
OutputFrm.RichEdit.Lines.Add(outline); lReport.Add('');
OutputFrm.RichEdit.Lines.Add(''); lReport.Add('Standardized Regression Coefficients:');
OutputFrm.RichEdit.Lines.Add('Standardized Regression Coefficients:');
for i := 1 to NoCntrlVars do for i := 1 to NoCntrlVars do
begin lReport.Add('%15s: %6.3f', [OS3MainFrm.DataGrid.Cells[MatVars[i+NoPredVars],0], W[i-1]]);
outline := format('%10s = %6.3f',[OS3MainFrm.DataGrid.Cells[MatVars[i+NoPredVars],0],W[i-1]]); lReport.Add('');
OutputFrm.RichEdit.Lines.Add(outline);
end;
OutputFrm.RichEdit.Lines.Add('');
SemiPart := R2Full - R2Cntrl; SemiPart := R2Full - R2Cntrl;
Partial := SemiPart / (1.0 - R2Cntrl); Partial := SemiPart / (1.0 - R2Cntrl);
@@ -367,18 +390,20 @@ begin
Prob := probf(F,df1,df2); Prob := probf(F,df1,df2);
// Report results // Report results
OutputFrm.RichEdit.Lines.Add(''); lReport.Add('');
outline := format('Partial Correlation = %6.3f',[sqrt(Partial)]); lReport.Add('Partial Correlation: %8.3f', [sqrt(Partial)]);
OutputFrm.RichEdit.Lines.Add(outline); lReport.Add('');
OutputFrm.RichEdit.Lines.Add(''); lReport.Add('Semi-Partial Correlation: %8.3f', [sqrt(SemiPart)]);
outline := format('Semi-Partial Correlation = %6.3f',[sqrt(SemiPart)]); lReport.Add('');
OutputFrm.RichEdit.Lines.Add(outline); lReport.Add('F: %8.3f', [F]);
OutputFrm.RichEdit.Lines.Add(''); lReport.Add(' with probability %8.4f', [Prob]);
outline := format('F = %8.3f with probability = %6.4f, D.F.1 = %3.0f and D.F.2 = %3.0f',[F,Prob,df1,df2]); lReport.Add(' D.F.1 %8.0f', [df1]);
OutputFrm.RichEdit.Lines.Add(outline); lReport.Add(' D.F.2 %8.0f', [df2]);
OutputFrm.ShowModal;
// clean up the heap DisplayReport(lReport);
finally
lReport.Free;
MatVars := nil; MatVars := nil;
Betas := nil; Betas := nil;
W := nil; W := nil;
@@ -392,14 +417,26 @@ begin
v := nil; v := nil;
W1 := nil; W1 := nil;
vtimesw := nil; vtimesw := nil;
end;
end; end;
procedure TPartialsFrm.DepOutBtnClick(Sender: TObject); procedure TPartialsFrm.UpdateBtnStates;
var
lSelected: Boolean;
begin begin
VarList.Items.Add(DepVar.Text); lSelected := AnySelected(VarList);
DepVar.Text := ''; DepInBtn.Enabled := lSelected and (DepVar.Text = '');
DepInBtn.Enabled := true; PredInBtn.Enabled := lSelected;
DepOutBtn.Enabled := false; PartInBtn.Enabled := lSelected;
DepOutBtn.Enabled := DepVar.Text <> '';
PredOutBtn.Enabled := AnySelected(PredList);
PartOutBtn.Enabled := AnySelected(Partlist);
end;
procedure TPartialsFrm.VarListSelectionChange(Sender: TObject; User: boolean);
begin
UpdateBtnStates;
end; end;

View File

@@ -534,6 +534,7 @@ begin
RMatFrm.ShowModal; RMatFrm.ShowModal;
end; end;
// Menu "Correlation" > "Partial, Semipartial"
procedure TOS3MainFrm.MenuItem72Click(Sender: TObject); procedure TOS3MainFrm.MenuItem72Click(Sender: TObject);
begin begin
if PartialsFrm = nil then if PartialsFrm = nil then