You've already forked lazarus-ccr
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:
Binary file not shown.
Binary file not shown.
@ -1,12 +1,12 @@
|
||||
object PartialsFrm: TPartialsFrm
|
||||
Left = 637
|
||||
Height = 460
|
||||
Top = 307
|
||||
Width = 412
|
||||
Left = 593
|
||||
Height = 398
|
||||
Top = 175
|
||||
Width = 361
|
||||
AutoSize = True
|
||||
Caption = 'Partial Correlation'
|
||||
ClientHeight = 460
|
||||
ClientWidth = 412
|
||||
ClientHeight = 398
|
||||
ClientWidth = 361
|
||||
OnActivate = FormActivate
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
@ -28,7 +28,7 @@ object PartialsFrm: TPartialsFrm
|
||||
AnchorSideLeft.Control = DepVar
|
||||
AnchorSideTop.Control = DepInBtn
|
||||
AnchorSideBottom.Control = DepVar
|
||||
Left = 228
|
||||
Left = 202
|
||||
Height = 15
|
||||
Top = 25
|
||||
Width = 152
|
||||
@ -37,10 +37,13 @@ object PartialsFrm: TPartialsFrm
|
||||
end
|
||||
object Label3: TLabel
|
||||
AnchorSideLeft.Control = PredList
|
||||
Left = 229
|
||||
AnchorSideTop.Control = DepOutBtn
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 203
|
||||
Height = 15
|
||||
Top = 120
|
||||
Top = 93
|
||||
Width = 144
|
||||
BorderSpacing.Top = 8
|
||||
Caption = 'Selected Predictor Variables'
|
||||
ParentColor = False
|
||||
end
|
||||
@ -48,11 +51,13 @@ object PartialsFrm: TPartialsFrm
|
||||
AnchorSideLeft.Control = PartList
|
||||
AnchorSideTop.Control = PartInBtn
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideBottom.Control = PartList
|
||||
Left = 8
|
||||
Height = 15
|
||||
Top = 289
|
||||
Top = 239
|
||||
Width = 121
|
||||
BorderSpacing.Top = 8
|
||||
BorderSpacing.Bottom = 2
|
||||
Caption = 'Variables Partialed Out:'
|
||||
ParentColor = False
|
||||
end
|
||||
@ -61,25 +66,25 @@ object PartialsFrm: TPartialsFrm
|
||||
AnchorSideTop.Control = Label1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = DepInBtn
|
||||
AnchorSideBottom.Control = Bevel3
|
||||
Left = 8
|
||||
Height = 220
|
||||
Height = 170
|
||||
Top = 25
|
||||
Width = 176
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
Width = 150
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
BorderSpacing.Left = 8
|
||||
BorderSpacing.Top = 2
|
||||
BorderSpacing.Right = 8
|
||||
Constraints.MinHeight = 220
|
||||
Constraints.MinWidth = 175
|
||||
ItemHeight = 0
|
||||
MultiSelect = True
|
||||
OnSelectionChange = VarListSelectionChange
|
||||
TabOrder = 0
|
||||
end
|
||||
object DepInBtn: TBitBtn
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideLeft.Side = asrCenter
|
||||
AnchorSideTop.Control = VarList
|
||||
Left = 192
|
||||
Left = 166
|
||||
Height = 28
|
||||
Top = 25
|
||||
Width = 28
|
||||
@ -130,7 +135,7 @@ object PartialsFrm: TPartialsFrm
|
||||
AnchorSideLeft.Side = asrCenter
|
||||
AnchorSideTop.Control = DepInBtn
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 192
|
||||
Left = 166
|
||||
Height = 28
|
||||
Top = 57
|
||||
Width = 28
|
||||
@ -180,13 +185,14 @@ object PartialsFrm: TPartialsFrm
|
||||
object PredInBtn: TBitBtn
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideLeft.Side = asrCenter
|
||||
AnchorSideBottom.Control = PredOutBtn
|
||||
Left = 192
|
||||
AnchorSideTop.Control = DepOutBtn
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideBottom.Control = Bevel4
|
||||
Left = 166
|
||||
Height = 28
|
||||
Top = 185
|
||||
Top = 122
|
||||
Width = 28
|
||||
Anchors = [akLeft, akBottom]
|
||||
BorderSpacing.Bottom = 4
|
||||
Glyph.Data = {
|
||||
36040000424D3604000000000000360000002800000010000000100000000100
|
||||
2000000000000004000064000000640000000000000000000000FFFFFF00FFFF
|
||||
@ -232,13 +238,13 @@ object PartialsFrm: TPartialsFrm
|
||||
object PredOutBtn: TBitBtn
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideLeft.Side = asrCenter
|
||||
AnchorSideBottom.Control = VarList
|
||||
AnchorSideTop.Control = Bevel4
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 192
|
||||
Left = 166
|
||||
Height = 28
|
||||
Top = 217
|
||||
Top = 154
|
||||
Width = 28
|
||||
Anchors = [akLeft, akBottom]
|
||||
Glyph.Data = {
|
||||
36040000424D3604000000000000360000002800000010000000100000000100
|
||||
2000000000000004000064000000640000000000000000000000FFFFFF00FFFF
|
||||
@ -285,9 +291,10 @@ object PartialsFrm: TPartialsFrm
|
||||
AnchorSideTop.Control = VarList
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Bevel1
|
||||
Left = 64
|
||||
AnchorSideBottom.Control = Label4
|
||||
Left = 51
|
||||
Height = 28
|
||||
Top = 253
|
||||
Top = 203
|
||||
Width = 28
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Top = 8
|
||||
@ -336,13 +343,11 @@ object PartialsFrm: TPartialsFrm
|
||||
object PartOutBtn: TBitBtn
|
||||
AnchorSideLeft.Control = Bevel1
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = VarList
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 100
|
||||
AnchorSideTop.Control = PartInBtn
|
||||
Left = 87
|
||||
Height = 28
|
||||
Top = 253
|
||||
Top = 203
|
||||
Width = 28
|
||||
BorderSpacing.Top = 8
|
||||
Glyph.Data = {
|
||||
36040000424D3604000000000000360000002800000010000000100000000100
|
||||
2000000000000004000064000000640000000000000000000000FFFFFF00FFFF
|
||||
@ -394,33 +399,37 @@ object PartialsFrm: TPartialsFrm
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = DepOutBtn
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 228
|
||||
Left = 202
|
||||
Height = 23
|
||||
Top = 42
|
||||
Width = 176
|
||||
Width = 151
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 8
|
||||
BorderSpacing.Top = 2
|
||||
BorderSpacing.Right = 8
|
||||
ReadOnly = True
|
||||
TabOrder = 3
|
||||
Text = 'DepVar'
|
||||
end
|
||||
object PredList: TListBox
|
||||
AnchorSideLeft.Control = PredInBtn
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = Label3
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = PredOutBtn
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 229
|
||||
Height = 109
|
||||
Top = 136
|
||||
Width = 175
|
||||
AnchorSideBottom.Control = Bevel3
|
||||
Left = 203
|
||||
Height = 85
|
||||
Top = 110
|
||||
Width = 150
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
BorderSpacing.Left = 9
|
||||
BorderSpacing.Top = 2
|
||||
BorderSpacing.Right = 8
|
||||
Constraints.MinWidth = 175
|
||||
ItemHeight = 0
|
||||
MultiSelect = True
|
||||
OnSelectionChange = VarListSelectionChange
|
||||
TabOrder = 6
|
||||
end
|
||||
object PartList: TListBox
|
||||
@ -431,103 +440,86 @@ object PartialsFrm: TPartialsFrm
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = Bevel2
|
||||
Left = 8
|
||||
Height = 105
|
||||
Top = 306
|
||||
Width = 176
|
||||
Height = 93
|
||||
Top = 256
|
||||
Width = 150
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
BorderSpacing.Left = 8
|
||||
BorderSpacing.Top = 2
|
||||
Constraints.MinHeight = 100
|
||||
ItemHeight = 0
|
||||
MultiSelect = True
|
||||
OnSelectionChange = VarListSelectionChange
|
||||
TabOrder = 9
|
||||
end
|
||||
object ResetBtn: TButton
|
||||
AnchorSideRight.Control = CancelBtn
|
||||
AnchorSideRight.Control = ComputeBtn
|
||||
AnchorSideBottom.Control = Owner
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 111
|
||||
Left = 152
|
||||
Height = 25
|
||||
Top = 427
|
||||
Top = 365
|
||||
Width = 54
|
||||
Anchors = [akRight, akBottom]
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 12
|
||||
BorderSpacing.Left = 8
|
||||
BorderSpacing.Top = 8
|
||||
BorderSpacing.Right = 12
|
||||
BorderSpacing.Right = 8
|
||||
BorderSpacing.Bottom = 8
|
||||
Caption = 'Reset'
|
||||
OnClick = ResetBtnClick
|
||||
TabOrder = 11
|
||||
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
|
||||
AnchorSideRight.Control = ReturnBtn
|
||||
AnchorSideRight.Control = CloseBtn
|
||||
AnchorSideBottom.Control = Owner
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 251
|
||||
Left = 214
|
||||
Height = 25
|
||||
Top = 427
|
||||
Top = 365
|
||||
Width = 76
|
||||
Anchors = [akRight, akBottom]
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 12
|
||||
BorderSpacing.Left = 8
|
||||
BorderSpacing.Top = 8
|
||||
BorderSpacing.Right = 12
|
||||
BorderSpacing.Right = 8
|
||||
BorderSpacing.Bottom = 8
|
||||
Caption = 'Compute'
|
||||
OnClick = ComputeBtnClick
|
||||
TabOrder = 13
|
||||
TabOrder = 12
|
||||
end
|
||||
object ReturnBtn: TButton
|
||||
object CloseBtn: TButton
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = Owner
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 339
|
||||
Left = 298
|
||||
Height = 25
|
||||
Top = 427
|
||||
Width = 61
|
||||
Top = 365
|
||||
Width = 55
|
||||
Anchors = [akRight, akBottom]
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 12
|
||||
BorderSpacing.Left = 8
|
||||
BorderSpacing.Top = 8
|
||||
BorderSpacing.Right = 12
|
||||
BorderSpacing.Right = 8
|
||||
BorderSpacing.Bottom = 8
|
||||
Caption = 'Return'
|
||||
ModalResult = 1
|
||||
TabOrder = 14
|
||||
Caption = 'Close'
|
||||
ModalResult = 11
|
||||
TabOrder = 13
|
||||
end
|
||||
object HelpBtn: TButton
|
||||
Tag = 136
|
||||
AnchorSideRight.Control = ResetBtn
|
||||
AnchorSideBottom.Control = Owner
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 48
|
||||
Left = 93
|
||||
Height = 25
|
||||
Top = 427
|
||||
Top = 365
|
||||
Width = 51
|
||||
Anchors = [akRight, akBottom]
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 12
|
||||
BorderSpacing.Left = 8
|
||||
BorderSpacing.Top = 8
|
||||
BorderSpacing.Right = 12
|
||||
BorderSpacing.Right = 8
|
||||
BorderSpacing.Bottom = 8
|
||||
Caption = 'Help'
|
||||
OnClick = HelpBtnClick
|
||||
@ -538,9 +530,9 @@ object PartialsFrm: TPartialsFrm
|
||||
AnchorSideLeft.Side = asrCenter
|
||||
AnchorSideTop.Control = VarList
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 92
|
||||
Left = 79
|
||||
Height = 28
|
||||
Top = 245
|
||||
Top = 195
|
||||
Width = 8
|
||||
Shape = bsSpacer
|
||||
end
|
||||
@ -548,12 +540,32 @@ object PartialsFrm: TPartialsFrm
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = ReturnBtn
|
||||
AnchorSideBottom.Control = CloseBtn
|
||||
Left = 0
|
||||
Height = 8
|
||||
Top = 411
|
||||
Width = 412
|
||||
Top = 349
|
||||
Width = 361
|
||||
Anchors = [akLeft, akRight, akBottom]
|
||||
Shape = bsBottomLine
|
||||
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
|
||||
|
@ -1,3 +1,8 @@
|
||||
// File for testing: cansas.laz
|
||||
// - Selected dependent variable --> jumps
|
||||
// - Seleckted predictor variables --> weight
|
||||
// - variables partialed out --> waist, pulse
|
||||
|
||||
unit PartialsUnit;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
@ -16,6 +21,8 @@ type
|
||||
TPartialsFrm = class(TForm)
|
||||
Bevel1: TBevel;
|
||||
Bevel2: TBevel;
|
||||
Bevel3: TBevel;
|
||||
Bevel4: TBevel;
|
||||
DepInBtn: TBitBtn;
|
||||
DepOutBtn: TBitBtn;
|
||||
HelpBtn: TButton;
|
||||
@ -24,9 +31,8 @@ type
|
||||
PartInBtn: TBitBtn;
|
||||
PartOutBtn: TBitBtn;
|
||||
ResetBtn: TButton;
|
||||
CancelBtn: TButton;
|
||||
ComputeBtn: TButton;
|
||||
ReturnBtn: TButton;
|
||||
CloseBtn: TButton;
|
||||
DepVar: TEdit;
|
||||
Label1: TLabel;
|
||||
Label2: TLabel;
|
||||
@ -47,9 +53,11 @@ type
|
||||
procedure PredInBtnClick(Sender: TObject);
|
||||
procedure PredOutBtnClick(Sender: TObject);
|
||||
procedure ResetBtnClick(Sender: TObject);
|
||||
procedure VarListSelectionChange(Sender: TObject; User: boolean);
|
||||
private
|
||||
{ private declarations }
|
||||
FAutoSized: Boolean;
|
||||
procedure UpdateBtnStates;
|
||||
public
|
||||
{ public declarations }
|
||||
end;
|
||||
@ -60,25 +68,21 @@ var
|
||||
implementation
|
||||
|
||||
uses
|
||||
Math;
|
||||
Math, Utils;
|
||||
|
||||
{ TPartialsFrm }
|
||||
|
||||
procedure TPartialsFrm.ResetBtnClick(Sender: TObject);
|
||||
VAR i : integer;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
DepVar.Text := '';
|
||||
VarList.Clear;
|
||||
PartList.Clear;
|
||||
PredList.Clear;
|
||||
DepInBtn.Enabled := true;
|
||||
DepOutBtn.Enabled := false;
|
||||
PredInBtn.Enabled := true;
|
||||
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]);
|
||||
DepVar.Text := '';
|
||||
VarList.Clear;
|
||||
PartList.Clear;
|
||||
PredList.Clear;
|
||||
for i := 1 to OS3MainFrm.DataGrid.ColCount - 1 do
|
||||
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
|
||||
UpdateBtnStates;
|
||||
end;
|
||||
|
||||
procedure TPartialsFrm.FormActivate(Sender: TObject);
|
||||
@ -88,14 +92,14 @@ begin
|
||||
if FAutoSized then
|
||||
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;
|
||||
ResetBtn.Constraints.MinWidth := w;
|
||||
CancelBtn.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;
|
||||
|
||||
FAutoSized := true;
|
||||
@ -104,7 +108,6 @@ end;
|
||||
procedure TPartialsFrm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
Assert(OS3MainFrm <> nil);
|
||||
if OutputFrm = nil then Application.CreateForm(TOutputFrm, OutputFrm);
|
||||
end;
|
||||
|
||||
procedure TPartialsFrm.FormShow(Sender: TObject);
|
||||
@ -120,178 +123,205 @@ begin
|
||||
end;
|
||||
|
||||
procedure TPartialsFrm.PartInBtnClick(Sender: TObject);
|
||||
VAR i, index : integer;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
index := VarList.Items.Count;
|
||||
i := 0;
|
||||
while i < index do
|
||||
begin
|
||||
if (VarList.Selected[i]) then
|
||||
begin
|
||||
PartList.Items.Add(VarList.Items.Strings[i]);
|
||||
VarList.Items.Delete(i);
|
||||
index := index - 1;
|
||||
i := 0;
|
||||
end
|
||||
else i := i + 1;
|
||||
end;
|
||||
PartOutBtn.Enabled := true;
|
||||
i := 0;
|
||||
while i < VarList.Items.Count do
|
||||
begin
|
||||
if VarList.Selected[i] then
|
||||
begin
|
||||
PartList.Items.Add(VarList.Items[i]);
|
||||
VarList.Items.Delete(i);
|
||||
i := 0;
|
||||
end else
|
||||
i := i + 1;
|
||||
end;
|
||||
UpdateBtnStates;
|
||||
end;
|
||||
|
||||
procedure TPartialsFrm.PartOutBtnClick(Sender: TObject);
|
||||
VAR index : integer;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
index := PartList.ItemIndex;
|
||||
VarList.Items.Add(PartList.Items.Strings[index]);
|
||||
PartList.Items.Delete(index);
|
||||
if PartList.Items.Count = 0 then PartOutBtn.Enabled := false;
|
||||
i := 0;
|
||||
while i < PartList.Items.Count do
|
||||
begin
|
||||
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;
|
||||
|
||||
procedure TPartialsFrm.PredInBtnClick(Sender: TObject);
|
||||
VAR i, index : integer;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
index := VarList.Items.Count;
|
||||
i := 0;
|
||||
while i < index do
|
||||
begin
|
||||
if (VarList.Selected[i]) then
|
||||
begin
|
||||
PredList.Items.Add(VarList.Items.Strings[i]);
|
||||
VarList.Items.Delete(i);
|
||||
index := index - 1;
|
||||
i := 0;
|
||||
end
|
||||
else i := i + 1;
|
||||
end;
|
||||
PredOutBtn.Enabled := true;
|
||||
i := 0;
|
||||
while i < VarList.Items.Count do
|
||||
begin
|
||||
if VarList.Selected[i] then
|
||||
begin
|
||||
PredList.Items.Add(VarList.Items[i]);
|
||||
VarList.Items.Delete(i);
|
||||
i := 0;
|
||||
end else
|
||||
i := i + 1;
|
||||
end;
|
||||
UpdateBtnStates;
|
||||
end;
|
||||
|
||||
procedure TPartialsFrm.PredOutBtnClick(Sender: TObject);
|
||||
VAR index : integer;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
index := PredList.ItemIndex;
|
||||
VarList.Items.Add(PredList.Items.Strings[index]);
|
||||
PredList.Items.Delete(index);
|
||||
if PredList.Items.Count = 0 then PredOutBtn.Enabled := false;
|
||||
i := 0;
|
||||
while i < PredList.Items.Count do
|
||||
begin
|
||||
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;
|
||||
|
||||
procedure TPartialsFrm.DepInBtnClick(Sender: TObject);
|
||||
VAR index : integer;
|
||||
var
|
||||
index: integer;
|
||||
begin
|
||||
index := VarList.ItemIndex;
|
||||
if index < 0 then exit;
|
||||
DepVar.Text := VarList.Items.Strings[index];
|
||||
VarList.Items.Delete(index);
|
||||
DepOutBtn.Enabled := true;
|
||||
DepInBtn.Enabled := false;
|
||||
index := VarList.ItemIndex;
|
||||
if (index > -1) and (DepVar.Text = '') then
|
||||
begin
|
||||
DepVar.Text := VarList.Items[index];
|
||||
VarList.Items.Delete(index);
|
||||
UpdateBtnStates;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TPartialsFrm.DepOutBtnClick(Sender: TObject);
|
||||
begin
|
||||
if DepVar.Text <> '' then
|
||||
begin
|
||||
VarList.Items.Add(DepVar.Text);
|
||||
DepVar.Text := '';
|
||||
UpdateBtnStates;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TPartialsFrm.ComputeBtnClick(Sender: TObject);
|
||||
var
|
||||
rmatrix, workmat: DblDyneMat;
|
||||
Means, Variances, StdDevs, W, Betas: DblDyneVec;
|
||||
R2Full, R2Cntrl, SemiPart, Partial, df1, df2, F, Prob: double;
|
||||
NoPredVars, NoCntrlVars, DepVarNo, TotNoVars, pcnt, ccnt, count: integer;
|
||||
PredVars, CntrlVars: IntDyneVec;
|
||||
MatVars: IntDyneVec;
|
||||
outline, varstring: string;
|
||||
i, j, K, L: integer;
|
||||
errorcode: boolean;
|
||||
vtimesw, W1, v: DblDyneMat;
|
||||
rmatrix, workmat: DblDyneMat;
|
||||
Means, Variances, StdDevs, W, Betas: DblDyneVec;
|
||||
R2Full, R2Cntrl, SemiPart, Partial, df1, df2, F, Prob: double;
|
||||
NoPredVars, NoCntrlVars, DepVarNo, TotNoVars, pcnt, ccnt, count: integer;
|
||||
PredVars, CntrlVars: IntDyneVec;
|
||||
MatVars: IntDyneVec;
|
||||
outline, varstring: string;
|
||||
i, j, K, L: integer;
|
||||
errorcode: boolean;
|
||||
vtimesw, W1, v: DblDyneMat;
|
||||
lReport: TStrings;
|
||||
|
||||
begin
|
||||
DepVarNo := 1;
|
||||
errorcode := false;
|
||||
DepVarNo := 1;
|
||||
errorcode := false;
|
||||
|
||||
// Get no. of predictor and control variables
|
||||
NoPredVars := PredList.Items.Count;
|
||||
NoCntrlVars := PartList.Items.Count;
|
||||
if (NoPredVars = 0) or (NoCntrlVars = 0) then
|
||||
begin
|
||||
ShowMessage('You must select at least one predictor and one control variable!');
|
||||
exit;
|
||||
end;
|
||||
TotNoVars := NoPredVars + NoCntrlVars + 1;
|
||||
count := NoCases;
|
||||
if DepVar.Text = '' then
|
||||
begin
|
||||
MessageDlg('No dependent variable selected.', mtError, [mbOK], 0);
|
||||
exit;
|
||||
end;
|
||||
|
||||
// Allocate space required
|
||||
SetLength(vtimesw,NoVariables,NoVariables);
|
||||
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);
|
||||
// Get no. of predictor and control variables
|
||||
NoPredVars := PredList.Items.Count;
|
||||
NoCntrlVars := PartList.Items.Count;
|
||||
if (NoPredVars = 0) or (NoCntrlVars = 0) then
|
||||
begin
|
||||
MessageDlg('You must select at least one predictor and one control variable.', mtError, [mbOK], 0);
|
||||
exit;
|
||||
end;
|
||||
TotNoVars := NoPredVars + NoCntrlVars + 1;
|
||||
count := NoCases;
|
||||
|
||||
OutputFrm.RichEdit.Clear;
|
||||
OutputFrm.RichEdit.Lines.Add('Partial and Semi-Partial Correlation Analysis');
|
||||
OutputFrm.RichEdit.Lines.Add('');
|
||||
// Allocate space required
|
||||
SetLength(vtimesw,NoVariables,NoVariables);
|
||||
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
|
||||
pcnt := 1;
|
||||
for i := 0 to NoPredVars - 1 do
|
||||
begin
|
||||
varstring := PredList.Items.Strings[i];
|
||||
for j := 1 to NoVariables do
|
||||
varstring := PredList.Items.Strings[i];
|
||||
for j := 1 to NoVariables do
|
||||
begin
|
||||
if varstring = OS3MainFrm.DataGrid.Cells[j,0] then
|
||||
begin
|
||||
if varstring = OS3MainFrm.DataGrid.Cells[j,0] then
|
||||
begin
|
||||
PredVars[pcnt-1] := j;
|
||||
pcnt := pcnt + 1;
|
||||
end;
|
||||
PredVars[pcnt-1] := j;
|
||||
pcnt := pcnt + 1;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
ccnt := 1;
|
||||
for i := 0 to NoCntrlVars - 1 do
|
||||
begin
|
||||
varstring := PartList.Items.Strings[i];
|
||||
for j := 1 to NoVariables do
|
||||
varstring := PartList.Items.Strings[i];
|
||||
for j := 1 to NoVariables do
|
||||
begin
|
||||
if varstring = OS3MainFrm.DataGrid.Cells[j,0] then
|
||||
begin
|
||||
if varstring = OS3MainFrm.DataGrid.Cells[j,0] then
|
||||
begin
|
||||
CntrlVars[ccnt-1] := j;
|
||||
ccnt := ccnt + 1;
|
||||
end;
|
||||
end;
|
||||
CntrlVars[ccnt-1] := j;
|
||||
ccnt := ccnt + 1;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
varstring := DepVar.Text;
|
||||
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]]);
|
||||
OutputFrm.RichEdit.Lines.Add(outline);
|
||||
OutputFrm.RichEdit.Lines.Add('');
|
||||
OutputFrm.RichEdit.Lines.Add('Predictor Variables:');
|
||||
lReport.Add('Dependent variable: %s', [OS3MainFrm.DataGrid.Cells[DepVarNo, 0]]);
|
||||
lReport.Add('');
|
||||
lReport.Add('Predictor Variables:');
|
||||
for i := 1 to NoPredVars do
|
||||
begin
|
||||
outline := format('Variable %d = %s',[i+1,OS3MainFrm.DataGrid.Cells[PredVars[i-1],0]]);
|
||||
OutputFrm.RichEdit.Lines.Add(outline);
|
||||
end;
|
||||
OutputFrm.RichEdit.Lines.Add('');
|
||||
OutputFrm.RichEdit.Lines.Add('Control Variables:');
|
||||
lReport.Add(' Variable %d: %s', [i+1, OS3MainFrm.DataGrid.Cells[PredVars[i-1], 0]]);
|
||||
lReport.Add('');
|
||||
lReport.Add('Control Variables:');
|
||||
for i := 1 to NoCntrlVars do
|
||||
begin
|
||||
outline := format('Variable %d = %s',[i+1,OS3MainFrm.DataGrid.Cells[CntrlVars[i-1],0]]);
|
||||
OutputFrm.RichEdit.Lines.Add(outline);
|
||||
end;
|
||||
OutputFrm.RichEdit.Lines.Add('');
|
||||
lReport.Add(' Variable %d: %s', [i+1, OS3MainFrm.DataGrid.Cells[CntrlVars[i-1], 0]]);
|
||||
lReport.Add('');
|
||||
if NoPredVars > 1 then
|
||||
begin
|
||||
outline := format('Higher order partialling at level = %d',[NoPredVars]);
|
||||
OutputFrm.RichEdit.Lines.Add(outline);
|
||||
OutputFrm.RichEdit.Lines.Add('');
|
||||
lReport.Add('Higher order partialling at level: %d', [NoPredVars]);
|
||||
lReport.Add('');
|
||||
end;
|
||||
if NoCntrlVars > 1 then
|
||||
begin
|
||||
outline := format('Multiple partialling with %d variables.',[NoCntrlVars]);
|
||||
OutputFrm.RichEdit.Lines.Add(outline);
|
||||
OutputFrm.RichEdit.Lines.Add('');
|
||||
lReport.Add('Multiple partialling with %d variables.', [NoCntrlVars]);
|
||||
lReport.Add('');
|
||||
end;
|
||||
|
||||
// Now, build the correlation matrix
|
||||
@ -303,61 +333,54 @@ begin
|
||||
// Now do Multiple regression models required
|
||||
// Full model first
|
||||
for i := 2 to TotNoVars do
|
||||
for j := 2 to TotNoVars do
|
||||
workmat[i-2,j-2] := rmatrix[i-1,j-1];
|
||||
for j := 2 to TotNoVars do
|
||||
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;
|
||||
for i := 1 to TotNoVars-1 do // rows
|
||||
begin
|
||||
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]);
|
||||
R2Full := R2Full + W[i-1] * rmatrix[0,i];
|
||||
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]);
|
||||
R2Full := R2Full + W[i-1] * rmatrix[0,i];
|
||||
end;
|
||||
outline := format('Squared Multiple Correlation with all variables = %6.3f',[R2Full]);
|
||||
OutputFrm.RichEdit.Lines.Add(outline);
|
||||
OutputFrm.RichEdit.Lines.Add('');
|
||||
OutputFrm.RichEdit.Lines.Add('Standardized Regression Coefficients:');
|
||||
lReport.Add('Squared Multiple Correlation with all variables: %6.3f', [R2Full]);
|
||||
lReport.Add('');
|
||||
lReport.Add('Standardized Regression Coefficients:');
|
||||
for i := 1 to TotNoVars - 1 do
|
||||
begin
|
||||
outline := format('%10s = %6.3f',[OS3MainFrm.DataGrid.Cells[MatVars[i],0],W[i-1]]);
|
||||
OutputFrm.RichEdit.Lines.Add(outline);
|
||||
end;
|
||||
OutputFrm.RichEdit.Lines.Add('');
|
||||
lReport.Add('%15s: %6.3f', [OS3MainFrm.DataGrid.Cells[MatVars[i],0], W[i-1]]);
|
||||
lReport.Add('');
|
||||
|
||||
// Now do model for Partial and Semi-partial
|
||||
for i := 1 to NoCntrlVars do
|
||||
begin
|
||||
K := i + 1 + NoPredVars;
|
||||
for j := 1 to NoCntrlVars do
|
||||
begin
|
||||
L := j + 1 + NoPredVars;
|
||||
workmat[i-1,j-1] := rmatrix[K-1,L-1];
|
||||
end;
|
||||
K := i + 1 + NoPredVars;
|
||||
for j := 1 to NoCntrlVars do
|
||||
begin
|
||||
L := j + 1 + NoPredVars;
|
||||
workmat[i-1,j-1] := rmatrix[K-1,L-1];
|
||||
end;
|
||||
end;
|
||||
matinv(workmat, vtimesw, v, W1, NoCntrlVars);
|
||||
MatInv(workmat, vtimesw, v, W1, NoCntrlVars);
|
||||
R2Cntrl := 0.0;
|
||||
for i := 1 to NoCntrlVars do
|
||||
begin
|
||||
L := i + 1 + NoPredVars;
|
||||
W[i-1] := 0.0;
|
||||
for j := 1 to NoCntrlVars do
|
||||
begin
|
||||
K := j + 1 + NoPredVars;
|
||||
W[i-1] := W[i-1] + (workmat[i-1,j-1] * rmatrix[0,K-1]);
|
||||
end;
|
||||
R2Cntrl := R2Cntrl + W[i-1] * rmatrix[0,L-1];
|
||||
L := i + 1 + NoPredVars;
|
||||
W[i-1] := 0.0;
|
||||
for j := 1 to NoCntrlVars do
|
||||
begin
|
||||
K := j + 1 + NoPredVars;
|
||||
W[i-1] := W[i-1] + (workmat[i-1,j-1] * rmatrix[0,K-1]);
|
||||
end;
|
||||
R2Cntrl := R2Cntrl + W[i-1] * rmatrix[0,L-1];
|
||||
end;
|
||||
outline := format('Squared Multiple Correlation with control variables = %6.3f',[R2Cntrl]);
|
||||
OutputFrm.RichEdit.Lines.Add(outline);
|
||||
OutputFrm.RichEdit.Lines.Add('');
|
||||
OutputFrm.RichEdit.Lines.Add('Standardized Regression Coefficients:');
|
||||
lReport.Add('Squared Multiple Correlation with control variables: %6.3f', [R2Cntrl]);
|
||||
lReport.Add('');
|
||||
lReport.Add('Standardized Regression Coefficients:');
|
||||
for i := 1 to NoCntrlVars do
|
||||
begin
|
||||
outline := format('%10s = %6.3f',[OS3MainFrm.DataGrid.Cells[MatVars[i+NoPredVars],0],W[i-1]]);
|
||||
OutputFrm.RichEdit.Lines.Add(outline);
|
||||
end;
|
||||
OutputFrm.RichEdit.Lines.Add('');
|
||||
lReport.Add('%15s: %6.3f', [OS3MainFrm.DataGrid.Cells[MatVars[i+NoPredVars],0], W[i-1]]);
|
||||
lReport.Add('');
|
||||
|
||||
SemiPart := R2Full - R2Cntrl;
|
||||
Partial := SemiPart / (1.0 - R2Cntrl);
|
||||
@ -367,18 +390,20 @@ begin
|
||||
Prob := probf(F,df1,df2);
|
||||
|
||||
// Report results
|
||||
OutputFrm.RichEdit.Lines.Add('');
|
||||
outline := format('Partial Correlation = %6.3f',[sqrt(Partial)]);
|
||||
OutputFrm.RichEdit.Lines.Add(outline);
|
||||
OutputFrm.RichEdit.Lines.Add('');
|
||||
outline := format('Semi-Partial Correlation = %6.3f',[sqrt(SemiPart)]);
|
||||
OutputFrm.RichEdit.Lines.Add(outline);
|
||||
OutputFrm.RichEdit.Lines.Add('');
|
||||
outline := format('F = %8.3f with probability = %6.4f, D.F.1 = %3.0f and D.F.2 = %3.0f',[F,Prob,df1,df2]);
|
||||
OutputFrm.RichEdit.Lines.Add(outline);
|
||||
OutputFrm.ShowModal;
|
||||
lReport.Add('');
|
||||
lReport.Add('Partial Correlation: %8.3f', [sqrt(Partial)]);
|
||||
lReport.Add('');
|
||||
lReport.Add('Semi-Partial Correlation: %8.3f', [sqrt(SemiPart)]);
|
||||
lReport.Add('');
|
||||
lReport.Add('F: %8.3f', [F]);
|
||||
lReport.Add(' with probability %8.4f', [Prob]);
|
||||
lReport.Add(' D.F.1 %8.0f', [df1]);
|
||||
lReport.Add(' D.F.2 %8.0f', [df2]);
|
||||
|
||||
// clean up the heap
|
||||
DisplayReport(lReport);
|
||||
|
||||
finally
|
||||
lReport.Free;
|
||||
MatVars := nil;
|
||||
Betas := nil;
|
||||
W := nil;
|
||||
@ -392,14 +417,26 @@ begin
|
||||
v := nil;
|
||||
W1 := nil;
|
||||
vtimesw := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TPartialsFrm.DepOutBtnClick(Sender: TObject);
|
||||
procedure TPartialsFrm.UpdateBtnStates;
|
||||
var
|
||||
lSelected: Boolean;
|
||||
begin
|
||||
VarList.Items.Add(DepVar.Text);
|
||||
DepVar.Text := '';
|
||||
DepInBtn.Enabled := true;
|
||||
DepOutBtn.Enabled := false;
|
||||
lSelected := AnySelected(VarList);
|
||||
DepInBtn.Enabled := lSelected and (DepVar.Text = '');
|
||||
PredInBtn.Enabled := lSelected;
|
||||
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;
|
||||
|
||||
|
||||
|
@ -534,6 +534,7 @@ begin
|
||||
RMatFrm.ShowModal;
|
||||
end;
|
||||
|
||||
// Menu "Correlation" > "Partial, Semipartial"
|
||||
procedure TOS3MainFrm.MenuItem72Click(Sender: TObject);
|
||||
begin
|
||||
if PartialsFrm = nil then
|
||||
|
Reference in New Issue
Block a user