TwoSLSUnit: Apply usual changes.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7355 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-04-04 11:25:29 +00:00
parent 56bfa8c993
commit a1d5e0fab0
6 changed files with 282 additions and 199 deletions

View File

@ -40,7 +40,7 @@
<PackageName Value="LCL"/> <PackageName Value="LCL"/>
</Item4> </Item4>
</RequiredPackages> </RequiredPackages>
<Units Count="170"> <Units Count="171">
<Unit0> <Unit0>
<Filename Value="LazStats.lpr"/> <Filename Value="LazStats.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
@ -1382,6 +1382,11 @@
<ResourceBaseClass Value="DataModule"/> <ResourceBaseClass Value="DataModule"/>
<UnitName Value="MainDM"/> <UnitName Value="MainDM"/>
</Unit169> </Unit169>
<Unit170>
<Filename Value="units\utils.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="Utils"/>
</Unit170>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>

View File

@ -8,7 +8,7 @@ uses
{$ENDIF}{$ENDIF} {$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset Interfaces, // this includes the LCL widgetset
Forms, Forms,
Globals, LicenseUnit, OptionsUnit, MainDM, MainUnit; Globals, LicenseUnit, OptionsUnit, MainDM, MainUnit, utils;
{$R LazStats.res} {$R LazStats.res}

View File

@ -74,6 +74,7 @@ object TwoSLSFrm: TTwoSLSFrm
Constraints.MinHeight = 220 Constraints.MinHeight = 220
ItemHeight = 0 ItemHeight = 0
MultiSelect = True MultiSelect = True
OnSelectionChange = ExplanatorySelectionChange
TabOrder = 0 TabOrder = 0
end end
object DepIn: TBitBtn object DepIn: TBitBtn
@ -168,6 +169,7 @@ object TwoSLSFrm: TTwoSLSFrm
BorderSpacing.Top = 4 BorderSpacing.Top = 4
Images = MainDataModule.ImageList Images = MainDataModule.ImageList
ImageIndex = 0 ImageIndex = 0
OnClick = InstOutClick
Spacing = 0 Spacing = 0
TabOrder = 8 TabOrder = 8
end end
@ -188,6 +190,7 @@ object TwoSLSFrm: TTwoSLSFrm
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 = 'DepVarEdit' Text = 'DepVarEdit'
end end
@ -210,6 +213,7 @@ object TwoSLSFrm: TTwoSLSFrm
BorderSpacing.Bottom = 24 BorderSpacing.Bottom = 24
ItemHeight = 0 ItemHeight = 0
MultiSelect = True MultiSelect = True
OnSelectionChange = ExplanatorySelectionChange
TabOrder = 6 TabOrder = 6
end end
object Instrumental: TListBox object Instrumental: TListBox
@ -230,6 +234,8 @@ object TwoSLSFrm: TTwoSLSFrm
BorderSpacing.Right = 8 BorderSpacing.Right = 8
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
ItemHeight = 0 ItemHeight = 0
MultiSelect = True
OnSelectionChange = ExplanatorySelectionChange
TabOrder = 9 TabOrder = 9
end end
object GroupBox1: TGroupBox object GroupBox1: TGroupBox
@ -238,20 +244,20 @@ object TwoSLSFrm: TTwoSLSFrm
Left = 8 Left = 8
Height = 73 Height = 73
Top = 286 Top = 286
Width = 308 Width = 316
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Left = 8 BorderSpacing.Left = 8
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Options' Caption = 'Options'
ChildSizing.LeftRightSpacing = 12 ChildSizing.LeftRightSpacing = 16
ChildSizing.TopBottomSpacing = 6 ChildSizing.TopBottomSpacing = 6
ChildSizing.VerticalSpacing = 2 ChildSizing.VerticalSpacing = 2
ClientHeight = 53 ClientHeight = 53
ClientWidth = 304 ClientWidth = 312
TabOrder = 10 TabOrder = 10
object ProxyRegShowChk: TCheckBox object ProxyRegShowChk: TCheckBox
Left = 12 Left = 16
Height = 19 Height = 19
Top = 6 Top = 6
Width = 273 Width = 273
@ -259,7 +265,7 @@ object TwoSLSFrm: TTwoSLSFrm
TabOrder = 0 TabOrder = 0
end end
object SaveItChk: TCheckBox object SaveItChk: TCheckBox
Left = 12 Left = 16
Height = 19 Height = 19
Top = 28 Top = 28
Width = 280 Width = 280
@ -268,84 +274,66 @@ object TwoSLSFrm: TTwoSLSFrm
end end
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 = 114 Left = 202
Height = 25 Height = 25
Top = 383 Top = 383
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 = 12 TabOrder = 12
end end
object CancelBtn: TButton
AnchorSideRight.Control = ComputeBtn
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 180
Height = 25
Top = 383
Width = 62
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 12
BorderSpacing.Top = 8
BorderSpacing.Right = 12
BorderSpacing.Bottom = 8
Caption = 'Cancel'
ModalResult = 2
TabOrder = 13
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 = 254 Left = 264
Height = 25 Height = 25
Top = 383 Top = 383
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 = 14 TabOrder = 13
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 = 342 Left = 348
Height = 25 Height = 25
Top = 383 Top = 383
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 = 12
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Return' Caption = 'Close'
ModalResult = 1 ModalResult = 11
TabOrder = 15 TabOrder = 14
end end
object HelpBtn: TButton object HelpBtn: TButton
Tag = 153 Tag = 153
AnchorSideRight.Control = ResetBtn AnchorSideRight.Control = ResetBtn
AnchorSideBottom.Control = Owner AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom AnchorSideBottom.Side = asrBottom
Left = 51 Left = 143
Height = 25 Height = 25
Top = 383 Top = 383
Width = 51 Width = 51
@ -353,7 +341,7 @@ object TwoSLSFrm: TTwoSLSFrm
AutoSize = True AutoSize = True
BorderSpacing.Left = 12 BorderSpacing.Left = 12
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
@ -363,7 +351,7 @@ object TwoSLSFrm: TTwoSLSFrm
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 = 367 Top = 367

View File

@ -1,3 +1,8 @@
// File for testing: "cansas.laz"
// - dependent variable: jumpgs
// - exolanatory variables: pulse, chins, situps
// - instrumental variables: pulse, chins, situps, weight, waist
unit TwoSLSUnit; unit TwoSLSUnit;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
@ -18,9 +23,8 @@ type
Bevel2: TBevel; Bevel2: TBevel;
HelpBtn: TButton; HelpBtn: TButton;
ResetBtn: TButton; ResetBtn: TButton;
CancelBtn: TButton;
ComputeBtn: TButton; ComputeBtn: TButton;
ReturnBtn: TButton; CloseBtn: TButton;
ProxyRegShowChk: TCheckBox; ProxyRegShowChk: TCheckBox;
SaveItChk: TCheckBox; SaveItChk: TCheckBox;
DepIn: TBitBtn; DepIn: TBitBtn;
@ -42,20 +46,23 @@ type
procedure DepInClick(Sender: TObject); procedure DepInClick(Sender: TObject);
procedure DepOutClick(Sender: TObject); procedure DepOutClick(Sender: TObject);
procedure ExpInClick(Sender: TObject); procedure ExpInClick(Sender: TObject);
procedure ExplanatorySelectionChange(Sender: TObject; User: boolean);
procedure ExpOutClick(Sender: TObject); procedure ExpOutClick(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 InstInClick(Sender: TObject); procedure InstInClick(Sender: TObject);
procedure InstOutClick(Sender: TObject);
procedure ResetBtnClick(Sender: TObject); procedure ResetBtnClick(Sender: TObject);
procedure PredictIt(ColNoSelected : IntDyneVec; NoVars : integer; procedure PredictIt(const ColNoSelected: IntDyneVec; NoVars: integer;
Means, StdDevs, BetaWeights : DblDyneVec; Means, StdDevs, BetaWeights : DblDyneVec;
StdErrEst : double; NoIndepVars : integer); StdErrEst : double; NoIndepVars : integer);
private private
{ private declarations } { private declarations }
FAutoSized: boolean; FAutoSized: boolean;
procedure UpdateBtnStates;
public public
{ public declarations } { public declarations }
@ -66,24 +73,23 @@ var
implementation implementation
uses
StrUtils, Utils;
{ TTwoSLSFrm } { TTwoSLSFrm }
procedure TTwoSLSFrm.ResetBtnClick(Sender: TObject); procedure TTwoSLSFrm.ResetBtnClick(Sender: TObject);
VAR i : integer; var
i: integer;
begin begin
VarList.Clear; VarList.Clear;
Explanatory.Clear; Explanatory.Clear;
Instrumental.Clear; Instrumental.Clear;
DepVarEdit.Text := ''; DepVarEdit.Text := '';
ProxyRegShowChk.Checked := false; ProxyRegShowChk.Checked := false;
DepIn.Enabled := true; for i := 1 to NoVariables do
DepOut.Enabled := false; VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
ExpIn.Enabled := true; UpdateBtnStates;
ExpOut.Enabled := false;
InstIn.Enabled := true;
InstOut.Enabled := false;
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
end; end;
procedure TTwoSLSFrm.FormActivate(Sender: TObject); procedure TTwoSLSFrm.FormActivate(Sender: TObject);
@ -93,12 +99,11 @@ 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; Constraints.MinWidth := Width;
Constraints.MinHeight := Height; Constraints.MinHeight := Height;
@ -109,7 +114,6 @@ end;
procedure TTwoSLSFrm.FormCreate(Sender: TObject); procedure TTwoSLSFrm.FormCreate(Sender: TObject);
begin begin
Assert(OS3MainFrm <> nil); Assert(OS3MainFrm <> nil);
if OutputFrm = nil then Application.CreateForm(TOutputFrm, OutputFrm);
if DictionaryFrm = nil then Application.CreateForm(TDictionaryFrm, DictionaryFrm); if DictionaryFrm = nil then Application.CreateForm(TDictionaryFrm, DictionaryFrm);
end; end;
@ -126,64 +130,89 @@ begin
end; end;
procedure TTwoSLSFrm.InstInClick(Sender: TObject); procedure TTwoSLSFrm.InstInClick(Sender: TObject);
VAR i : integer; var
i: integer;
begin begin
if (VarList.Items.Count < 1) then exit; i := 0;
i := 0; while (i < VarList.Items.Count) do
while (i < VarList.Items.Count) do begin
begin if VarList.Selected[i] and (Instrumental.Items.IndexOf(VarList.Items[i]) = -1) then
if (VarList.Selected[i]) then Instrumental.Items.Add(VarList.Items[i])
begin // DO NOT DELETE Items HERE.
Instrumental.Items.Add(VarList.Items.Strings[i]); else
end; i := i + 1;
i := i + 1; end;
end; UpdateBtnStates;
InstOut.Enabled := true;
if (VarList.Items.Count < 1) then InstIn.Enabled := false;
end; end;
procedure TTwoSLSFrm.DepInClick(Sender: TObject); procedure TTwoSLSFrm.InstOutClick(Sender: TObject);
VAR index : integer; var
i: Integer;
begin begin
if (VarList.Items.Count < 1) then exit; i := 0;
index := VarList.ItemIndex; while (i < Instrumental.Items.Count) do
DepVarEdit.Text := VarList.Items.Strings[index]; begin
VarList.Items.Delete(index); if Instrumental.Selected[i] then
DepOut.Enabled := true; begin
DepIn.Enabled := false; if VarList.Items.IndexOf(Instrumental.Items[i]) = -1 then
VarList.Items.Add(Instrumental.Items[i]);
Instrumental.Items.Delete(i);
i := 0;
end else
i := i + 1;
end;
UpdateBtnStates;
end; end;
procedure TTwoSLSFrm.ComputeBtnClick(Sender: TObject); procedure TTwoSLSFrm.ComputeBtnClick(Sender: TObject);
label cleanup; var
VAR
i, j, k, DepCol, NoInst, NoExp, NoProx, Noindep : integer; i, j, k, DepCol, NoInst, NoExp, NoProx, Noindep : integer;
IndepCols, ProxSrcCols, ExpCols, InstCols, ProxCols : IntDyneVec; IndepCols, ProxSrcCols, ExpCols, InstCols, ProxCols : IntDyneVec;
DepProx, NCases, col, counter : integer; DepProx, NCases, col, counter : integer;
ExpLabels, InstLabels, ProxLabels, RowLabels, ProxSrcLabels : StrDyneVec; ExpLabels, InstLabels, ProxLabels, RowLabels, ProxSrcLabels : StrDyneVec;
outstr : string; X, Y : double;
R2, stderrest, X, Y : double;
Means, Variances, StdDevs, BWeights : DblDyneVec; Means, Variances, StdDevs, BWeights : DblDyneVec;
BetaWeights, BStdErrs, Bttests, tprobs : DblDyneVec; BetaWeights, BStdErrs, Bttests, tprobs : DblDyneVec;
ProxVals : DblDyneMat; // ProxVals : DblDyneMat;
errorcode, PrintDesc, PrintCorrs, PrintInverse, PrintCoefs, SaveCorrs : boolean; PrintDesc: Boolean;
// PrintCorrs, PrintInverse, PrintCoefs, SaveCorrs : boolean;
found : boolean; found : boolean;
lReport: TStrings;
errorcode: Boolean = false;
R2: Double = 0.0;
stdErrEst: Double = 0.0;
begin begin
if DepVarEdit.Text = '' then
begin
MessageDlg('Dependent variable not selected.', mtError, [mbOK], 0);
exit;
end;
if Explanatory.Items.Count = 0 then
begin
MessageDlg('No explanatory variables selected.', mtError, [mbOK], 0);
exit;
end;
if Instrumental.Items.Count = 0 then
begin
MessageDlg('No instrumental variables selected.', mtError, [mbOK], 0);
exit;
end;
if (ProxyRegShowChk.Checked) then if (ProxyRegShowChk.Checked) then
begin begin
PrintDesc := true; PrintDesc := true;
PrintCorrs := true; // PrintCorrs := true;
PrintInverse := false; // PrintInverse := false;
PrintCoefs := true; // PrintCoefs := true;
SaveCorrs := false; // SaveCorrs := false;
end end
else else
begin begin
PrintDesc := false; PrintDesc := false;
PrintCorrs := false; // PrintCorrs := false;
PrintInverse := false; // PrintInverse := false;
PrintCoefs := false; // PrintCoefs := false;
SaveCorrs := false; // SaveCorrs := false;
end; end;
SetLength(Means,NoVariables+2); SetLength(Means,NoVariables+2);
SetLength(Variances,NoVariables+2); SetLength(Variances,NoVariables+2);
@ -203,7 +232,7 @@ begin
SetLength(RowLabels,NoVariables); SetLength(RowLabels,NoVariables);
SetLength(ProxSrcCols,NoVariables); SetLength(ProxSrcCols,NoVariables);
SetLength(ProxSrcLabels,NoVariables); SetLength(ProxSrcLabels,NoVariables);
SetLength(ProxVals,NoCases,NoVariables); // SetLength(ProxVals,NoCases,NoVariables);
// Get variables to analyze // Get variables to analyze
NCases := NoCases; NCases := NoCases;
@ -211,9 +240,10 @@ begin
NoExp := Explanatory.Items.Count; NoExp := Explanatory.Items.Count;
if (NoInst < NoExp) then if (NoInst < NoExp) then
begin begin
ShowMessage('The no. of Instrumental must equal or exceed the Explanatory'); MessageDlg('The no. of Instrumental must equal or exceed the Explanatory', mtError, [mbOK], 0);
goto cleanup; exit;
end; end;
for i := 0 to NoVariables - 1 do for i := 0 to NoVariables - 1 do
begin begin
if (OS3MainFrm.DataGrid.Cells[i+1,0] = DepVarEdit.Text) then if (OS3MainFrm.DataGrid.Cells[i+1,0] = DepVarEdit.Text) then
@ -260,22 +290,29 @@ begin
end; end;
end; end;
// Output Parameters of the Analysis lReport := TStringList.Create;
OutputFrm.RichEdit.Clear; try
OutputFrm.RichEdit.Lines.Add('FILE: ' + OS3MainFrm.FileNameEdit.Text); // Output Parameters of the Analysis
OutputFrm.RichEdit.Lines.Add(''); lReport.Add('FILE: ' + OS3MainFrm.FileNameEdit.Text);
OutputFrm.RichEdit.Lines.Add('Dependent := ' + DepVarEdit.Text); lReport.Add('');
OutputFrm.RichEdit.Lines.Add('Explanatory Variables:'); lReport.Add('Dependent: ' + DepVarEdit.Text);
for i := 0 to NoExp - 1 do OutputFrm.RichEdit.Lines.Add(ExpLabels[i]); lReport.Add('');
OutputFrm.RichEdit.Lines.Add('Instrumental Variables:'); lReport.Add('Explanatory Variables:');
for i := 0 to NoInst - 1 do OutputFrm.RichEdit.Lines.Add(InstLabels[i]); for i := 0 to NoExp - 1 do
OutputFrm.RichEdit.Lines.Add('Proxy Variables:'); lReport.Add(' ' + ExpLabels[i]);
for i := 0 to NoProx - 1 do OutputFrm.RichEdit.Lines.Add(ProxLabels[i]); lReport.Add('');
OutputFrm.RichEdit.Lines.Add(''); lReport.Add('Instrumental Variables:');
for i := 0 to NoInst - 1 do
lReport.Add(' ' + InstLabels[i]);
lReport.Add('');
lReport.Add('Proxy Variables:');
for i := 0 to NoProx - 1 do
lReport.Add(' ' + ProxLabels[i]);
lReport.Add('');
// Compute the prox regressions for the instrumental variables // Compute the prox regressions for the instrumental variables
for i := 0 to NoProx - 1 do for i := 0 to NoProx - 1 do
begin begin
DictionaryFrm.DictGrid.ColCount := 8; DictionaryFrm.DictGrid.ColCount := 8;
col := NoVariables + 1; col := NoVariables + 1;
// NoVariables := col; // NoVariables := col;
@ -307,14 +344,23 @@ begin
end; end;
end; end;
IndepCols[Noindep] := DepProx; IndepCols[Noindep] := DepProx;
OutputFrm.RichEdit.Lines.Add('Analysis for ' + ProxLabels[i]); lReport.Add('');
OutputFrm.RichEdit.Lines.Add('Dependent: ' + ProxSrcLabels[i]); lReport.Add('==================================================================');
OutputFrm.RichEdit.Lines.Add('Independent: '); lReport.Add('');
for j := 0 to Noindep - 1 do OutputFrm.RichEdit.Lines.Add(RowLabels[j]); lReport.Add('Analysis for ' + ProxLabels[i]);
lReport.Add('-------------' + DupeString('-', Length(ProxLabels[i])));
lReport.Add('Dependent: ' + ProxSrcLabels[i]);
lReport.Add('');
lReport.Add('Independent: ');
for j := 0 to Noindep - 1 do
lReport.Add(' ' + RowLabels[j]);
lReport.Add('');
// OutputFrm.ShowModal(); // OutputFrm.ShowModal();
mreg(Noindep, IndepCols, DepProx, RowLabels, Means, Variances, StdDevs, MReg(Noindep, IndepCols, DepProx, RowLabels, Means, Variances, StdDevs,
BWeights, BetaWeights, BStdErrs, Bttests, tprobs, R2, stderrest, BWeights, BetaWeights, BStdErrs, Bttests, tprobs, R2, stderrest,
NCases, errorcode, PrintDesc); NCases, errorcode, PrintDesc, lReport);
// save predicted scores at column := NoVariables and in ProxVals array // save predicted scores at column := NoVariables and in ProxVals array
for j := 1 to NoCases do for j := 1 to NoCases do
begin begin
@ -327,17 +373,20 @@ begin
end; end;
Y := Y + BWeights[Noindep]; // intercept Y := Y + BWeights[Noindep]; // intercept
col := NoVariables; col := NoVariables;
outstr := format('%12.5f',[Y]); OS3MainFrm.DataGrid.Cells[col,j] := Format('%12.5f', [Y]);
OS3MainFrm.DataGrid.Cells[col,j] := outstr;
end; // next case end; // next case
end; // next proxy end; // next proxy
// OutputFrm.ShowModal(); // OutputFrm.ShowModal();
// Compute the OLS using the Prox values and explanatory lReport.Add('');
Noindep := 0; lReport.Add('==================================================================');
counter := 0; lReport.Add('');
for i := 0 to NoExp - 1 do
begin // Compute the OLS using the Prox values and explanatory
Noindep := 0;
counter := 0;
for i := 0 to NoExp - 1 do
begin
for j := 0 to NoInst - 1 do for j := 0 to NoInst - 1 do
begin begin
if (ExpLabels[i] = InstLabels[j]) then // use proxy if (ExpLabels[i] = InstLabels[j]) then // use proxy
@ -354,88 +403,115 @@ begin
end; end;
end; end;
Noindep := Noindep + 1; Noindep := Noindep + 1;
end; end;
PrintDesc := true; PrintDesc := true;
PrintCorrs := true; // PrintCorrs := true;
PrintInverse := false; // PrintInverse := false;
PrintCoefs := true; // PrintCoefs := true;
SaveCorrs := false; // SaveCorrs := false;
IndepCols[Noindep] := DepCol; IndepCols[Noindep] := DepCol;
mreg(Noindep, IndepCols, DepCol, RowLabels, Means, Variances, StdDevs, MReg(Noindep, IndepCols, DepCol, RowLabels, Means, Variances, StdDevs,
BWeights, BetaWeights, BStdErrs, Bttests, tprobs, R2, stderrest, BWeights, BetaWeights, BStdErrs, Bttests, tprobs, R2, stderrest,
NCases, errorcode, PrintDesc); NCases, errorcode, PrintDesc, lReport);
OutputFrm.ShowModal;
if (SaveItChk.Checked) then
begin
PredictIt(IndepCols, Noindep+1, Means, StdDevs, BetaWeights, stderrest, Noindep);
end;
// cleanup DisplayReport(lReport);
cleanup:
ProxVals := nil; if SaveItChk.Checked then
ProxSrcLabels := nil; PredictIt(IndepCols, Noindep+1, Means, StdDevs, BetaWeights, stderrest, Noindep);
ProxSrcCols := nil;
RowLabels := nil; finally
IndepCols := nil; lReport.Free;
ProxLabels := nil; // ProxVals := nil;
ProxCols := nil; ProxSrcLabels := nil;
InstCols := nil; ProxSrcCols := nil;
InstLabels := nil; RowLabels := nil;
ExpCols := nil; IndepCols := nil;
ExpLabels := nil; ProxLabels := nil;
tprobs := nil; ProxCols := nil;
Bttests := nil; InstCols := nil;
BStdErrs := nil; InstLabels := nil;
BetaWeights := nil; ExpCols := nil;
BWeights := nil; ExpLabels := nil;
StdDevs := nil; tprobs := nil;
Variances := nil; Bttests := nil;
Means := nil; BStdErrs := nil;
BetaWeights := nil;
BWeights := nil;
StdDevs := nil;
Variances := nil;
Means := nil;
end;
end;
procedure TTwoSLSFrm.DepInClick(Sender: TObject);
var
index: integer;
begin
index := VarList.ItemIndex;
if (index > -1) and (DepVarEdit.Text = '') then
begin
DepVarEdit.Text := VarList.Items[index];
VarList.Items.Delete(index);
end;
UpdateBtnStates;
end; end;
procedure TTwoSLSFrm.DepOutClick(Sender: TObject); procedure TTwoSLSFrm.DepOutClick(Sender: TObject);
begin begin
if (DepVarEdit.Text = '') then exit; if DepVarEdit.Text <> '' then
VarList.Items.Add(DepVarEdit.Text); begin
DepVarEdit.Text := ''; VarList.Items.Add(DepVarEdit.Text);
DepIn.Enabled := true; DepVarEdit.Text := '';
DepOut.Enabled := false; end;
UpdateBtnStates;
end; end;
procedure TTwoSLSFrm.ExpInClick(Sender: TObject); procedure TTwoSLSFrm.ExpInClick(Sender: TObject);
VAR i : integer; var
i: integer;
begin begin
if (VarList.Items.Count < 1) then exit; i := 0;
i := 0; while (i < VarList.Items.Count) do
while (i < VarList.Items.Count) do begin
begin if VarList.Selected[i] and (Explanatory.Items.IndexOf(VarList.Items[i]) = -1) then
if (VarList.Selected[i]) then Explanatory.Items.Add(VarList.Items[i]);
begin // DO NOT DELETE Items HERE.
Explanatory.Items.Add(VarList.Items.Strings[i]); i := i + 1;
end; end;
i := i + 1; UpdateBtnStates;
end; end;
ExpOut.Enabled := true;
if (VarList.Items.Count < 1) then ExpIn.Enabled := false; procedure TTwoSLSFrm.ExplanatorySelectionChange(Sender: TObject; User: boolean);
begin
UpdateBtnStates;
end; end;
procedure TTwoSLSFrm.ExpOutClick(Sender: TObject); procedure TTwoSLSFrm.ExpOutClick(Sender: TObject);
VAR index : integer; var
i: Integer;
begin begin
index := Explanatory.ItemIndex; i := 0;
Explanatory.Items.Delete(index); while (i < Explanatory.Items.Count) do
ExpIn.Enabled := true; begin
if (Explanatory.Items.Count < 1) then ExpOut.Enabled := false; if Explanatory.Selected[i] then
begin
if (VarList.Items.IndexOf(Explanatory.Items[i]) = -1) then
VarList.Items.Add(Explanatory.Items[i]);
Explanatory.Items.Delete(i);
i := 0;
end else
i := i + 1;
end;
UpdateBtnStates;
end; end;
procedure TTwoSLSFrm.PredictIt(ColNoSelected : IntDyneVec; NoVars : integer; procedure TTwoSLSFrm.PredictIt(const ColNoSelected: IntDyneVec; NoVars: integer;
Means, StdDevs, BetaWeights : DblDyneVec; Means, StdDevs, BetaWeights: DblDyneVec;
StdErrEst : double; NoIndepVars : integer); StdErrEst: double; NoIndepVars: integer);
VAR var
col, i, j, k, Index: integer; col, i, j, k, Index: integer;
predicted, zpredicted, z1, z2, resid, residsqr : double; predicted, zpredicted, z1, z2, resid, residsqr: double;
astring : string; astring: string;
begin begin
// routine obtains predicted raw and standardized scores and their // routine obtains predicted raw and standardized scores and their
// residuals. It is assumed that the dependent variable is last in the // residuals. It is assumed that the dependent variable is last in the
@ -520,6 +596,20 @@ begin
end; end;
end; end;
procedure TTwoSLSFrm.UpdateBtnStates;
var
lSelected: Boolean;
begin
lSelected := AnySelected(VarList);
DepIn.Enabled := lSelected and (DepVarEdit.Text = '');
ExpIn.Enabled := lSelected;
InstIn.Enabled := lSelected;
DepOut.Enabled := (DepVarEdit.Text <> '');
ExpOut.Enabled := AnySelected(Explanatory);
InstOut.Enabled := AnySelected(Instrumental);
end;
initialization initialization
{$I twoslsunit.lrs} {$I twoslsunit.lrs}