LazStats: Inherit TwoCorrsUnit from TBasicStatsReportForm. Minor refactoring of TwoCorrsUnit and TwoPropUnit.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7843 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-11-04 17:53:45 +00:00
parent 7613b7da31
commit 9953cfe29b
6 changed files with 1153 additions and 910 deletions

View File

@ -307,7 +307,7 @@
<Unit25> <Unit25>
<Filename Value="forms\analysis\comparisons\twocorrsunit.pas"/> <Filename Value="forms\analysis\comparisons\twocorrsunit.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<ComponentName Value="TwoCorrsFrm"/> <ComponentName Value="TwoCorrsForm"/>
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="TwoCorrsUnit"/> <UnitName Value="TwoCorrsUnit"/>

View File

@ -5,198 +5,181 @@ unit TwoCorrsUnit;
interface interface
uses uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
ExtCtrls, StdCtrls, ExtCtrls, StdCtrls, Buttons,
MainUnit, Globals, FunctionsLib, OutputUnit, DataProcs, ContextHelpUnit; MainUnit, Globals, FunctionsLib, DataProcs, BasicStatsReportFormUnit;
type type
{ TTwoCorrsFrm } { TTwoCorrsForm }
TTwoCorrsFrm = class(TForm) TTwoCorrsForm = class(TBasicStatsReportForm)
Bevel1: TBevel; Bevel1: TBevel;
Bevel2: TBevel; Bevel5: TBevel;
HelpBtn: TButton; Notebook: TNotebook;
Notebook1: TNotebook;
Page1: TPage; Page1: TPage;
Page2: TPage; Page2: TPage;
Page3: TPage; Page3: TPage;
Panel1: TPanel;
PanelPage1: TPanel; PanelPage1: TPanel;
ResetBtn: TButton; CIntervalEdit: TEdit;
ComputeBtn: TButton;
ReturnBtn: TButton;
CInterval: TEdit;
Label14: TLabel; Label14: TLabel;
Xvar: TEdit; Var1In: TBitBtn;
Yvar: TEdit; Var2In: TBitBtn;
Zvar: TEdit; Var1Out: TBitBtn;
GroupVar: TEdit; Var3In: TBitBtn;
xlabel: TLabel; Var2Out: TBitBtn;
ylabel: TLabel; GrpIn: TBitBtn;
zlabel: TLabel; Var3Out: TBitBtn;
GroupLabel: TLabel; GrpOut: TBitBtn;
XVarEdit: TEdit;
YVarEdit: TEdit;
ZVarEdit: TEdit;
GroupVarEdit: TEdit;
XVarLabel: TLabel;
YVarLabel: TLabel;
ZVarLabel: TLabel;
GroupVarLabel: TLabel;
SelVarLabel: TLabel; SelVarLabel: TLabel;
VarList: TListBox; VarList: TListBox;
PanelPage3: TPanel; PanelPage3: TPanel;
rxy1: TEdit; Corr1Edit: TEdit;
Size1: TEdit; SampleSize1Edit: TEdit;
rxy2: TEdit; Corr2Edit: TEdit;
Size2: TEdit; Size2Edit: TEdit;
firstcorlabel: TLabel; firstcorlabel: TLabel;
size1label: TLabel; size1label: TLabel;
SecdCorLabel: TLabel; SecdCorLabel: TLabel;
Size2Label: TLabel; Size2Label: TLabel;
rxy: TEdit; CorrXYEdit: TEdit;
rxz: TEdit; CorrXZEdit: TEdit;
ryz: TEdit; CorrYZEdit: TEdit;
SampSize: TEdit; SampleSizeEdit: TEdit;
corxylabel: TLabel; corxylabel: TLabel;
corxzlabel: TLabel; corxzlabel: TLabel;
coryzlabel: TLabel; coryzlabel: TLabel;
sampsizelabel: TLabel; SampleSizeLabel: TLabel;
PanelPage2: TPanel; PanelPage2: TPanel;
RadioGroup1: TRadioGroup; DataSourceGroup: TRadioGroup;
RadioGroup2: TRadioGroup; DepIndepGroup: TRadioGroup;
procedure ComputeBtnClick(Sender: TObject); procedure DataSourceGroupClick(Sender: TObject);
procedure FormActivate(Sender: TObject); procedure DepIndepGroupClick(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure GrpInClick(Sender: TObject);
procedure FormShow(Sender: TObject); procedure GrpOutClick(Sender: TObject);
procedure HelpBtnClick(Sender: TObject); procedure Var1InClick(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject); procedure Var1OutClick(Sender: TObject);
procedure RadioGroup2Click(Sender: TObject); procedure Var2InClick(Sender: TObject);
procedure ResetBtnClick(Sender: TObject); procedure Var2OutClick(Sender: TObject);
procedure VarListClick(Sender: TObject); procedure Var3InClick(Sender: TObject);
procedure Var3OutClick(Sender: TObject);
procedure VarListDblClick(Sender: TObject);
procedure VarListSelectionChange(Sender: TObject; User: boolean);
private private
{ private declarations }
FAutoSized: Boolean;
independent: boolean; independent: boolean;
griddata: boolean; griddata: boolean;
function Validate(out AMsg: String; out AControl: TWinControl): Boolean;
protected
procedure AdjustConstraints; override;
procedure Compute; override;
procedure UpdateBtnStates; override;
function Validate(out AMsg: String; out AControl: TWinControl): Boolean; override;
public public
{ public declarations } constructor Create(AOwner: TComponent); override;
procedure Reset; override;
end; end;
var var
TwoCorrsFrm: TTwoCorrsFrm; TwoCorrsForm: TTwoCorrsForm;
implementation implementation
{$R *.lfm}
uses uses
Math, MathUnit; Math,
MathUnit, GridProcs;
{ TTwoCorrsFrm }
procedure TTwoCorrsFrm.ResetBtnClick(Sender: TObject); { TTwoCorrsForm }
var
i: integer; constructor TTwoCorrsForm.Create(AOwner: TComponent);
begin begin
CInterval.Text := FormatFloat('0.0', DEFAULT_CONFIDENCE_LEVEL_PERCENT); inherited;
CIntervalEdit.Text := FormatFloat('0.0', DEFAULT_CONFIDENCE_LEVEL_PERCENT);
RadioGroup1.ItemIndex := 0;
RadioGroup2.ItemIndex := 0;
Notebook1.PageIndex := 0;
VarList.Clear;
Xvar.Text := '';
Yvar.Text := '';
Zvar.Text := '';
rxy.Text := '';
rxz.Text := '';
ryz.Text := '';
SampSize.Text := '';
rxy1.Text := '';
rxy2.Text := '';
Size1.Text := '';
Size2.Text := '';
zlabel.Visible := false;
Zvar.Visible := false;
GroupLabel.Visible := true;
GroupVar.Text := '';
GroupVar.Visible := true;
independent := true;
griddata := false;
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
end; end;
procedure TTwoCorrsFrm.VarListClick(Sender: TObject);
var procedure TTwoCorrsForm.AdjustConstraints;
index: integer;
begin
index := VarList.ItemIndex;
if Xvar.Text = '' then
begin
Xvar.Text := VarList.Items.Strings[index];
exit;
end;
if Yvar.Text = '' then
begin
Yvar.Text := VarList.Items.Strings[index];
exit;
end;
if not independent then
begin
if Zvar.Text = '' then
begin
Zvar.Text := VarList.Items.Strings[index];
exit;
end;
end;
if independent then
begin
if GroupVar.Text = '' then
begin
GroupVar.Text := VarList.Items.Strings[index];
exit;
end;
end;
end;
procedure TTwoCorrsFrm.FormActivate(Sender: TObject);
var var
w: Integer; w: Integer;
begin begin
if FAutoSized then inherited;
exit;
w := MaxValue([HelpBtn.Width, ResetBtn.Width, ComputeBtn.Width, ReturnBtn.Width]); w := Max(DataSourceGroup.Width, DepIndepGroup.Width);
HelpBtn.Constraints.MinWidth := w; DataSourceGroup.Constraints.MinWidth := w;
ResetBtn.Constraints.MinWidth := w; DepIndepGroup.Constraints.MinWidth := w;
ComputeBtn.Constraints.MinWidth := w; ParamsPanel.Constraints.MinWidth := Max(
ReturnBtn.Constraints.MinWidth := w; CloseBtn.Width * 4 + CloseBtn.BorderSpacing.Left * 3,
w * 2 + DepIndepGroup.BorderSpacing.Left
Width := Max(
RadioGroup2.Left + RadioGroup2.Width + RadioGroup2.BorderSpacing.Right,
Width - HelpBtn.Left + HelpBtn.BorderSpacing.Left
); );
Constraints.MinWidth := Width; ParamsPanel.Constraints.MinHeight := DataSourceGroup.Height +
Constraints.MinHeight := Height; NoteBook.BorderSpacing.Top + Var3Out.Top + Var3Out.Height +
NoteBook.BorderSpacing.Bottom + CIntervalEdit.Height +
FAutoSized := true; ButtonBevel.Height + CloseBtn.BorderSpacing.Top + CloseBtn.Height;
end; end;
procedure TTwoCorrsFrm.FormCreate(Sender: TObject);
procedure TTwoCorrsForm.Reset;
var
i: integer;
begin begin
Assert(OS3MainFrm <> nil); inherited;
DataSourceGroup.ItemIndex := 0;
DepIndepGroup.ItemIndex := 0;
independent := true;
griddata := false;
Notebook.PageIndex := 0;
VarList.Clear;
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
XVarEdit.Clear;
YVarEdit.Clear;
ZVarEdit.Clear;
CorrXYEdit.Clear;
CorrXZEdit.Clear;
CorrYZEdit.Clear;
SampleSizeEdit.Clear;
Corr1Edit.Clear;
Corr2Edit.Clear;
SampleSize1Edit.Clear;
Size2Edit.Clear;
// ZVarLabel.Visible := false;
// ZVarEdit.Visible := false;
// GroupVarLabel.Visible := true;
GroupVarEdit.Clear;
// GroupVarEdit.Visible := true;
ZVarEdit.Visible := false;
ZVarLabel.Visible := ZVarEdit.Visible;
Var3In.Visible := ZVarEdit.Visible;
Var3Out.Visible := ZVarEdit.Visible;
GroupVarEdit.Visible := not ZVarEdit.Visible;
GroupVarLabel.Visible := GroupVarEdit.Visible;
GrpIn.Visible := GroupVarEdit.Visible;
GrpOut.Visible := GroupVarEdit.Visible;
end; end;
procedure TTwoCorrsFrm.FormShow(Sender: TObject);
begin
ResetBtnClick(self);
end;
procedure TTwoCorrsFrm.HelpBtnClick(Sender: TObject); procedure TTwoCorrsForm.Compute;
begin
if ContextHelpForm = nil then
Application.CreateForm(TContextHelpForm, ContextHelpForm);
ContextHelpForm.HelpMessage((Sender as TButton).tag);
end;
procedure TTwoCorrsFrm.ComputeBtnClick(Sender: TObject);
var var
lReport: TStrings; lReport: TStrings;
Corxy, Corxz, Coryz, Cor1, Cor2, alpha, tvalue, df2: double; Corxy, Corxz, Coryz, Cor1, Cor2, alpha, tvalue, df2: double;
@ -206,21 +189,11 @@ var
stddev1, stddev2, stddev3, value1, value2, value3: double; stddev1, stddev2, stddev3, value1, value2, value3: double;
meanx1, meanx2, meany1, meany2, varx1, varx2, vary1, vary2: double; meanx1, meanx2, meany1, meany2, varx1, varx2, vary1, vary2: double;
sdx1, sdx2, sdy1, sdy2: double; sdx1, sdx2, sdy1, sdy2: double;
SSize1, SSize2, SSize, v1, v2, v3, grp, ncases, NoSelected: integer; SSize1, SSize2, SSize, {v1, v2, v3, grp, }ncases: Integer; //, NoSelected: integer;
min, max, grpval, ncases1, ncases2, i: integer; min, max, grpval, ncases1, ncases2, i: integer;
cellstring: string; cellstring: string;
msg: String;
C: TWinControl;
ColNoSelected: IntDyneVec = nil; ColNoSelected: IntDyneVec = nil;
begin begin
if not Validate(msg, C) then
begin
C.SetFocus;
MessageDlg(msg, mtError, [mbOK], 0);
ModalResult := mrNone;
exit;
end;
SetLength(ColNoSelected, NoVariables); SetLength(ColNoSelected, NoVariables);
Corxy := 0.0; Corxy := 0.0;
Corxz := 0.0; Corxz := 0.0;
@ -236,7 +209,7 @@ begin
meanx1 := 0.0; meanx1 := 0.0;
meanx2 := 0.0; meanx2 := 0.0;
meany1 := 0.0; meany1 := 0.0;
ConfLevel := StrToFloat(CInterval.Text) / 100.0; ConfLevel := StrToFloat(CIntervalEdit.Text) / 100.0;
// *** USE DATA ON THE FORM *** // *** USE DATA ON THE FORM ***
if not griddata then if not griddata then
@ -244,10 +217,10 @@ begin
// read data from form and obtain results // read data from form and obtain results
if independent then if independent then
begin begin
Cor1 := StrToFloat(rxy1.Text); Cor1 := StrToFloat(Corr1Edit.Text);
Cor2 := StrToFloat(rxy2.Text); Cor2 := StrToFloat(Corr2Edit.Text);
SSize1 := StrToInt(Size1.Text); SSize1 := StrToInt(SampleSize1Edit.Text);
SSize2 := StrToInt(Size2.Text); SSize2 := StrToInt(Size2Edit.Text);
CorDif := Cor1 - Cor2; CorDif := Cor1 - Cor2;
zOne := 0.5 * ln((1.0 + Cor1) / (1.0 - Cor1)); zOne := 0.5 * ln((1.0 + Cor1) / (1.0 - Cor1));
zTwo := 0.5 * ln((1.0 + Cor2) / (1.0 - Cor2)); zTwo := 0.5 * ln((1.0 + Cor2) / (1.0 - Cor2));
@ -266,10 +239,10 @@ begin
// obtain data from form and obtain results // obtain data from form and obtain results
if not independent then if not independent then
begin begin
Corxy := StrToFloat(rxy.Text); Corxy := StrToFloat(CorrXYEdit.Text);
Corxz := StrToFloat(rxz.Text); Corxz := StrToFloat(CorrXZEdit.Text);
Coryz := StrToFloat(ryz.Text); Coryz := StrToFloat(CorrYZEdit.Text);
SSize := StrToInt(SampSize.Text); SSize := StrToInt(SampleSizeEdit.Text);
CorDif := Corxy - Corxz; CorDif := Corxy - Corxz;
alpha := (1.0 - ConfLevel) / 2.0; alpha := (1.0 - ConfLevel) / 2.0;
tvalue := CorDif * sqrt((SSize - 3.0) * (1.0 + Coryz)) / sqrt(2.0 * (1.0 - Corxy*Corxy - Corxz*Corxz - Coryz*Coryz + 2.0*Corxy*Corxz*Coryz)); tvalue := CorDif * sqrt((SSize - 3.0) * (1.0 + Coryz)) / sqrt(2.0 * (1.0 - Corxy*Corxy - Corxz*Corxz - Coryz*Coryz + 2.0*Corxy*Corxz*Coryz));
@ -279,26 +252,33 @@ begin
end; end;
end; end;
// *** USE DATA FROM THE GRID ***
if griddata then if griddata then
begin begin
v1 := 1; //v1 := 1;
v2 := 1; //v2 := 1;
grp := 1; //grp := 1;
// read grid data for independent r's // read grid data for independent r's
if independent then if independent then
begin begin
SetLength(ColNoSelected, 3);
ColNoSelected[0] := GetVariableIndex(OS3MainFrm.DataGrid, XVarEdit.Text);
ColNoSelected[1] := GetVariableIndex(OS3MainFrm.DataGrid, YVarEdit.Text);
ColNoSelected[2] := GetVariableIndex(OS3MainFrm.DataGrid, GroupVarEdit.Text);
(*
for i := 1 to NoVariables do for i := 1 to NoVariables do
begin begin
cellstring := OS3MainFrm.DataGrid.Cells[i,0]; cellstring := OS3MainFrm.DataGrid.Cells[i,0];
if cellstring = Xvar.Text then v1 := i; if cellstring = XVarEdit.Text then v1 := i;
if cellstring = Yvar.Text then v2 := i; if cellstring = YVarEdit.Text then v2 := i;
if cellstring = GroupVar.Text then grp := i; if cellstring = GroupVarEdit.Text then grp := i;
end; end;
ColNoSelected[0] := v1; ColNoSelected[0] := v1;
ColNoSelected[1] := v2; ColNoSelected[1] := v2;
ColNoSelected[2] := grp; ColNoSelected[2] := grp;
NoSelected := 3; NoSelected := 3;
*)
meanx1 := 0.0; meanx1 := 0.0;
meany1 := 0.0; meany1 := 0.0;
varx1 := 0.0; varx1 := 0.0;
@ -311,26 +291,26 @@ begin
Cor2 := 0.0; Cor2 := 0.0;
ncases1 := 0; ncases1 := 0;
ncases2 := 0; ncases2 := 0;
min := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[grp,1]))); min := MaxInt;
max := min; max := -min;
for i := 2 to NoCases do for i := 1 to NoCases do
begin begin
if not GoodRecord(i,NoSelected,ColNoSelected) then continue; if not GoodRecord(OS3MainFrm.DataGrid, i, ColNoSelected) then continue;
grpval := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[grp,i]))); grpval := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[2], i])));
if grpval > max then max := grpval; if grpval > max then max := grpval;
if grpval < min then min := grpval; if grpval < min then min := grpval;
end; end;
for i := 1 to NoCases do for i := 1 to NoCases do
begin begin
if not GoodRecord(i,NoSelected,ColNoSelected) then continue; if not GoodRecord(OS3MainFrm.DataGrid, i, ColNoSelected) then continue;
grpval := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[grp,i]))); grpval := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[2], i])));
if grpval = min then if grpval = min then
begin begin
ncases1 := ncases1 + 1; ncases1 := ncases1 + 1;
value1 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[v1,i])); value1 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[0], i]));
meanx1 := meanx1 + value1; meanx1 := meanx1 + value1;
varx1 := varx1 + (value1 * value1); varx1 := varx1 + (value1 * value1);
value2 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[v2,i])); value2 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[1], i]));
meany1 := meany1 + value2; meany1 := meany1 + value2;
vary1 := vary1 + value2 * value2; vary1 := vary1 + value2 * value2;
Cor1 := Cor1 + value1 * value2; Cor1 := Cor1 + value1 * value2;
@ -338,10 +318,10 @@ begin
if grpval = max then if grpval = max then
begin begin
ncases2 := ncases2 + 1; ncases2 := ncases2 + 1;
value1 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[v1,i])); value1 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[0], i]));
meanx2 := meanx2 + value1; meanx2 := meanx2 + value1;
varx2 := varx2 + (value1 * value1); varx2 := varx2 + (value1 * value1);
value2 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[v2,i])); value2 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[1], i]));
meany2 := meany2 + value2; meany2 := meany2 + value2;
vary2 := vary2 + value2 * value2; vary2 := vary2 + value2 * value2;
Cor2 := Cor2 + value1 * value2; Cor2 := Cor2 + value1 * value2;
@ -399,24 +379,17 @@ begin
Corxz := 0.0; Corxz := 0.0;
Coryz := 0.0; Coryz := 0.0;
ncases := 0; ncases := 0;
for i := 1 to NoVariables do SetLength(ColNoSelected, 3);
begin ColNoSelected[0] := GetVariableIndex(OS3MainFrm.DataGrid, XVarEdit.Text);
cellstring := OS3MainFrm.DataGrid.Cells[i,0]; ColNoSelected[1] := GetVariableIndex(OS3MainFrm.DataGrid, YVarEdit.Text);
if cellstring = Xvar.Text then v1 := i; ColNoSelected[2] := GetVariableIndex(OS3MainFrm.DataGrid, ZVarEdit.Text);
if cellstring = Yvar.Text then v2 := i;
if cellstring = ZVar.Text then v3 := i;
end;
ColNoSelected[0] := v1;
ColNoSelected[1] := v2;
ColNoSelected[2] := v3;
NoSelected := 3;
for i := 1 to NoCases do for i := 1 to NoCases do
begin begin
if not GoodRecord(i,NoSelected,ColNoSelected) then continue; if not GoodRecord(OS3MainFrm.DataGrid, i, ColNoSelected) then continue;
ncases := ncases + 1; ncases := ncases + 1;
value1 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[v1,i])); value1 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[0], i]));
value2 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[v2,i])); value2 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[1], i]));
value3 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[v3,i])); value3 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[2], i]));
mean1 := mean1 + value1; mean1 := mean1 + value1;
mean2 := mean2 + value2; mean2 := mean2 + value2;
mean3 := mean3 + value3; mean3 := mean3 + value3;
@ -428,22 +401,22 @@ begin
Coryz := Coryz + value2 * value3; Coryz := Coryz + value2 * value3;
end; end;
variance1 := variance1 - mean1 * mean1 / ncases; variance1 := variance1 - mean1 * mean1 / ncases;
variance1 := variance1 / (ncases - 1.0); variance1 := variance1 / (ncases - 1);
stddev1 := sqrt(variance1); stddev1 := sqrt(variance1);
variance2 := variance2 - mean2 * mean2 / ncases; variance2 := variance2 - mean2 * mean2 / ncases;
variance2 := variance2 / (ncases - 1.0); variance2 := variance2 / (ncases - 1);
stddev2 := sqrt(variance2); stddev2 := sqrt(variance2);
variance3 := variance3 - mean3 * mean3 / ncases; variance3 := variance3 - mean3 * mean3 / ncases;
variance3 := variance3 / (ncases - 1.0); variance3 := variance3 / (ncases - 1);
stddev3 := sqrt(variance3); stddev3 := sqrt(variance3);
Corxy := Corxy - mean1 * mean2 / ncases; Corxy := Corxy - mean1 * mean2 / ncases;
Corxy := Corxy / (ncases - 1.0); Corxy := Corxy / (ncases - 1);
Corxy := Corxy / (stddev1 * stddev2); Corxy := Corxy / (stddev1 * stddev2);
Corxz := Corxz - mean1 * mean3 / ncases; Corxz := Corxz - mean1 * mean3 / ncases;
Corxz := Corxz / (ncases - 1.0); Corxz := Corxz / (ncases - 1);
Corxz := Corxz / (stddev1 * stddev3); Corxz := Corxz / (stddev1 * stddev3);
Coryz := Coryz - mean2 * mean3 / ncases; Coryz := Coryz - mean2 * mean3 / ncases;
Coryz := Coryz / (ncases - 1.0); Coryz := Coryz / (ncases - 1);
Coryz := Coryz / (stddev2 * stddev3); Coryz := Coryz / (stddev2 * stddev3);
mean1 := mean1 / ncases; mean1 := mean1 / ncases;
mean2 := mean2 / ncases; mean2 := mean2 / ncases;
@ -467,11 +440,11 @@ begin
if independent then if independent then
begin begin
lReport.Add('Correlation one: %6.3f', [Cor1]); lReport.Add('Correlation one: %6.3f', [Cor1]);
lReport.Add('Sample size one: %6d', [SSize1]); lReport.Add('Sample size one: %6d', [SSize1]);
lReport.Add('Correlation two: %6.3f', [Cor2]); lReport.Add('Correlation two: %6.3f', [Cor2]);
lReport.Add('Sample size two: %6d', [SSize2]); lReport.Add('Sample size two: %6d', [SSize2]);
lReport.Add('Difference between correlations: %6.3f', [CorDif]); lReport.Add('Difference between correlations: %6.3f', [CorDif]);
lReport.Add('Confidence level selected: %6s', [CInterval.Text]); lReport.Add('Confidence level selected: %6s', [CIntervalEdit.Text]);
lReport.Add('z for Correlation One: %6.3f', [zOne]); lReport.Add('z for Correlation One: %6.3f', [zOne]);
lReport.Add('z for Correlation Two: %6.3f', [zTwo]); lReport.Add('z for Correlation Two: %6.3f', [zTwo]);
lReport.Add('z difference: %6.3f', [zDif]); lReport.Add('z difference: %6.3f', [zDif]);
@ -480,7 +453,7 @@ begin
lReport.Add('Probability > |z|: %6.3f', [zprobability]); lReport.Add('Probability > |z|: %6.3f', [zprobability]);
lReport.Add('z Required for significance: %6.3f', [zTest]); lReport.Add('z Required for significance: %6.3f', [zTest]);
lReport.Add('Note: above is a two-tailed test.'); lReport.Add('Note: above is a two-tailed test.');
lReport.Add('Confidence Limits = (%.3f ... %.3f)', [LCL, UCL]); lReport.Add('Confidence Limits: %6.3f ... %.3f', [LCL, UCL]);
lReport.Add(''); lReport.Add('');
if griddata then if griddata then
begin begin
@ -488,7 +461,7 @@ begin
lReport.Add('Mean X for group 2: %9.3f', [meanx2]); lReport.Add('Mean X for group 2: %9.3f', [meanx2]);
lReport.Add('Std.Dev. X for group 1: %9.3f', [sdx1]); lReport.Add('Std.Dev. X for group 1: %9.3f', [sdx1]);
lReport.Add('Std.Dev. X for group 2: %9.3f', [sdx2]); lReport.Add('Std.Dev. X for group 2: %9.3f', [sdx2]);
lReport.Add('Mean y for group 1; %9.3f', [meany1]); lReport.Add('Mean y for group 1: %9.3f', [meany1]);
lReport.Add('Mean Y for group 2: %9.3f', [meany2]); lReport.Add('Mean Y for group 2: %9.3f', [meany2]);
lReport.Add('Std.Dev. Y for group 1: %9.3f', [sdy1]); lReport.Add('Std.Dev. Y for group 1: %9.3f', [sdy1]);
lReport.Add('Std.Dev. Y for group 2: %9.3f', [sdy2]); lReport.Add('Std.Dev. Y for group 2: %9.3f', [sdy2]);
@ -500,8 +473,8 @@ begin
lReport.Add('Correlation x with y: %6.3f', [Corxy]); lReport.Add('Correlation x with y: %6.3f', [Corxy]);
lReport.Add('Correlation x with z: %6.3f', [Corxz]); lReport.Add('Correlation x with z: %6.3f', [Corxz]);
lReport.Add('Correlation y with z: %6.3f', [Coryz]); lReport.Add('Correlation y with z: %6.3f', [Coryz]);
lReport.Add('Sample size: %6d', [SSize]); lReport.Add('Sample size: %6d', [SSize]);
lReport.Add('Confidence Level Selected: %6s', [CInterval.Text]); lReport.Add('Confidence Level Selected: %6s', [CIntervalEdit.Text]);
lReport.Add('Difference r(x,y) - r(x,z): %6.3f', [CorDif]); lReport.Add('Difference r(x,y) - r(x,z): %6.3f', [CorDif]);
lReport.Add('t test statistic: %6.3f', [tvalue]); lReport.Add('t test statistic: %6.3f', [tvalue]);
lReport.Add('Probability > |t|: %6.3f', [tprobability]); lReport.Add('Probability > |t|: %6.3f', [tprobability]);
@ -509,83 +482,114 @@ begin
lReport.Add(''); lReport.Add('');
if griddata then if griddata then
begin begin
lReport.Add('Variable Mean Variance Std.Dev.'); lReport.Add('Variable Mean Variance Std.Dev. ');
lReport.Add(' X %9.3f %9.3f %9.3f', [mean1, variance1, stddev1]); lReport.Add('-------- ---------- ---------- ----------');
lReport.Add(' Y %9.3f %9.3f %9.3f', [mean2, variance2, stddev2]); lReport.Add(' X %10.3f %10.3f %10.3f', [mean1, variance1, stddev1]);
lReport.Add(' Z %9.3f %9.3f %9.3f', [mean3, variance3, stddev3]); lReport.Add(' Y %10.3f %10.3f %10.3f', [mean2, variance2, stddev2]);
lReport.Add(' Z %10.3f %10.3f %10.3f', [mean3, variance3, stddev3]);
end; end;
end; end;
DisplayReport(lReport); FReportFrame.DisplayReport(lReport);
finally finally
lReport.Free; lReport.Free;
ColNoSelected := nil;
end; end;
end; end;
procedure TTwoCorrsFrm.RadioGroup1Click(Sender: TObject);
procedure TTwoCorrsForm.DataSourceGroupClick(Sender: TObject);
var var
index: integer; index: integer;
begin begin
index := RadioGroup1.ItemIndex; index := DataSourceGroup.ItemIndex;
if index = 0 then if index = 0 then
begin begin
griddata := false; griddata := false;
if independent then if independent then
Notebook1.PageIndex := 0 Notebook.PageIndex := 0
else else
Notebook1.PageIndex := 1; Notebook.PageIndex := 1;
end else end else
begin begin
griddata := true; griddata := true;
Notebook1.PageIndex := 2; Notebook.PageIndex := 2;
end; end;
end; end;
procedure TTwoCorrsFrm.RadioGroup2Click(Sender: TObject);
procedure TTwoCorrsForm.DepIndepGroupClick(Sender: TObject);
var var
index1, index2: integer; index1, index2: integer;
begin begin
index1 := RadioGroup1.ItemIndex; index1 := DataSourceGroup.ItemIndex;
index2 := RadioGroup2.ItemIndex; index2 := DepIndepGroup.ItemIndex;
// form input with independent corrs // form input with independent corrs
if ((index2 = 0) and (index1 = 0)) then if ((index2 = 0) and (index1 = 0)) then
begin begin
independent := true; independent := true;
Notebook1.PageIndex := 0; Notebook.PageIndex := 0;
end; end;
// grid data for independent corrs // grid data for independent corrs
if ((index2 = 0) and (index1 = 1)) then if ((index2 = 0) and (index1 = 1)) then
begin begin
Notebook1.PageIndex := 2; Notebook.PageIndex := 2;
zlabel.Visible := false; // ZVarLabel.Visible := false;
zvar.Visible := false; ZVarEdit.Visible := false;
grouplabel.Visible := true; // GroupVarLabel.Visible := true;
groupvar.Visible := true; // GroupVarEdit.Visible := true;
end; end;
// form data for dependent corrs // form data for dependent corrs
if ((index2 = 1) and (index1 = 0)) then if ((index2 = 1) and (index1 = 0)) then
begin begin
Notebook1.PageIndex := 1; Notebook.PageIndex := 1;
end; end;
// grid data for dependent corrs // grid data for dependent corrs
if ((index2 = 1) and (index1 = 1)) then if ((index2 = 1) and (index1 = 1)) then
begin begin
Notebook1.PageIndex := 2; Notebook.PageIndex := 2;
independent := false; independent := false;
zlabel.Visible := true; // ZVarLabel.Visible := true;
Zvar.Visible := true; ZVarEdit.Visible := true;
GroupLabel.Visible := false; // GroupVarLabel.Visible := false;
GroupVar.Visible := false; // GroupVarEdit.Visible := false;
end; end;
// if Notebook.PageIndex = 2 then
// begin
ZVarLabel.Visible := ZVarEdit.Visible;
Var3In.Visible := ZVarEdit.Visible;
Var3Out.Visible := ZVarEdit.Visible;
GroupVarEdit.Visible := not ZVarEdit.Visible;
GroupVarLabel.Visible := GroupVarEdit.Visible;
GrpIn.Visible := GroupVarEdit.Visible;
GrpOut.Visible := GroupVarEdit.Visible;
// end;
end; end;
function TTwoCorrsFrm.Validate(out AMsg: String; out AControl: TWinControl): Boolean;
procedure TTwoCorrsForm.UpdateBtnStates;
begin
inherited;
Var1In.Enabled := (VarList.ItemIndex > -1) and (XVarEdit.Text = '');
Var2In.Enabled := (VarList.ItemIndex > -1) and (YVarEdit.Text = '');
Var3In.Enabled := (VarList.ItemIndex > -1) and (ZVarEdit.Text = '');
GrpIn.Enabled := (VarList.ItemIndex > -1) and (GroupVarEdit.Text = '');
Var1Out.Enabled := XVarEdit.Text <> '';
Var2Out.Enabled := YVarEdit.Text <> '';
Var3Out.Enabled := ZVarEdit.Text <> '';
GrpOut.Enabled := GroupVarEdit.Text <> '';
end;
function TTwoCorrsForm.Validate(out AMsg: String; out AControl: TWinControl): Boolean;
var var
n: Integer; n: Integer;
x: Double; x: Double;
@ -593,75 +597,75 @@ begin
Result := false; Result := false;
AControl := nil; AControl := nil;
AMsg := ''; AMsg := '';
if Notebook1.PageIndex = 0 then if Notebook.PageIndex = 0 then
begin begin
if (rxy1.Text = '') or not TryStrToFloat(rxy1.Text, x) then if (Corr1Edit.Text = '') or not TryStrToFloat(Corr1Edit.Text, x) then
begin begin
AControl := rxy1; AControl := Corr1Edit;
AMsg := 'Invalid input for first correlation'; AMsg := 'Invalid input for first correlation';
exit; exit;
end; end;
if (Size1.Text = '') or not TryStrToInt(Size1.Text, n) or (n <= 0) then if (SampleSize1Edit.Text = '') or not TryStrToInt(SampleSize1Edit.Text, n) or (n <= 0) then
begin begin
AControl := Size1; AControl := SampleSize1Edit;
AMsg := 'Invald input for size of sample 1'; AMsg := 'Invald input for size of sample 1';
exit; exit;
end; end;
if (rxy2.Text = '') or not TryStrToFloat(rxy2.Text, x) then if (Corr2Edit.Text = '') or not TryStrToFloat(Corr2Edit.Text, x) then
begin begin
AControl := rxy2; AControl := Corr2Edit;
AMsg := 'Invalid input for second correlation'; AMsg := 'Invalid input for second correlation';
exit; exit;
end; end;
if (Size2.Text = '') or not TryStrToInt(Size2.Text, n) or (n <= 0) then if (Size2Edit.Text = '') or not TryStrToInt(Size2Edit.Text, n) or (n <= 0) then
begin begin
AControl := Size2; AControl := Size2Edit;
AMsg := 'Invalud input for size of sample 2'; AMsg := 'Invalud input for size of sample 2';
exit; exit;
end; end;
end else end else
if Notebook1.PageIndex = 1 then if Notebook.PageIndex = 1 then
begin begin
if (rxy.Text = '') or not TryStrToFloat(rxy.Text, x) then if (CorrXYEdit.Text = '') or not TryStrToFloat(CorrXYEdit.Text, x) then
AControl := rxy AControl := CorrXYEdit
else else
if (rxz.Text = '') or not TryStrToFloat(rxz.Text, x) then if (CorrXZEdit.Text = '') or not TryStrToFloat(CorrXZEdit.Text, x) then
AControl := rxz AControl := CorrXZEdit
else else
if (ryz.Text = '') or not TryStrToFloat(ryz.Text, x) then if (CorrYZEdit.Text = '') or not TryStrToFloat(CorrYZEdit.Text, x) then
AControl := ryz AControl := CorrYZEdit
else else
if (SampSize.Text = '') or not TryStrToInt(SampSize.Text, n) or (n < 0) then if (SampleSizeEdit.Text = '') or not TryStrToInt(SampleSizeEdit.Text, n) or (n < 0) then
AControl := SampSize; AControl := SampleSizeEdit;
if AControl <> nil then if AControl <> nil then
begin begin
AMsg := 'Invalid input.'; AMsg := 'Invalid input.';
exit; exit;
end; end;
end else end else
if Notebook1.PageIndex = 2 then if Notebook.PageIndex = 2 then
begin begin
if XVar.Text = '' then if XVarEdit.Text = '' then
begin begin
AControl := XVar; AControl := XVarEdit;
AMsg := 'X variable not specified.'; AMsg := 'X variable not specified.';
exit; exit;
end; end;
if YVar.Text = '' then if YVarEdit.Text = '' then
begin begin
AControl := YVar; AControl := YVarEdit;
AMsg := 'Y variable not specified.'; AMsg := 'Y variable not specified.';
exit; exit;
end; end;
case RadioGroup2.ItemIndex of case DepIndepGroup.ItemIndex of
0: if (GroupVar.Text = '') then 0: if (GroupVarEdit.Text = '') then
begin begin
AControl := GroupVar; AControl := GroupVarEdit;
AMsg := 'Group variable not specified'; AMsg := 'Group variable not specified';
exit; exit;
end; end;
1: if (ZVar.Text = '') then begin 1: if (ZVarEdit.Text = '') then begin
AControl := ZVar; AControl := ZVarEdit;
AMsg := 'Z variable not specified.'; AMsg := 'Z variable not specified.';
exit; exit;
end; end;
@ -670,8 +674,156 @@ begin
Result := true; Result := true;
end; end;
initialization
{$I twocorrsunit.lrs} procedure TTwoCorrsForm.Var1InClick(Sender: TObject);
var
index: Integer;
begin
index := VarList.ItemIndex;
if index > -1 then
begin
if XVarEdit.Text = '' then
begin
XVarEdit.Text := VarList.Items[index];
VarList.Items.Delete(index);
UpdateBtnStates;
end;
end;
end;
procedure TTwoCorrsForm.Var1OutClick(Sender: TObject);
begin
if XVarEdit.Text <> '' then
begin
VarList.Items.Add(XVarEdit.Text);
XVarEdit.Text := '';
UpdateBtnStates;
end;
end;
procedure TTwoCorrsForm.Var2InClick(Sender: TObject);
var
index: Integer;
begin
index := VarList.ItemIndex;
if index > -1 then
begin
if YVarEdit.Text = '' then
begin
YVarEdit.Text := VarList.Items[index];
VarList.Items.Delete(index);
UpdateBtnStates;
end;
end;
end;
procedure TTwoCorrsForm.Var2OutClick(Sender: TObject);
begin
if YVarEdit.Text <> '' then
begin
VarList.Items.Add(YVarEdit.Text);
YVarEdit.Text := '';
UpdateBtnStates;
end;
end;
procedure TTwoCorrsForm.Var3InClick(Sender: TObject);
var
index: Integer;
begin
index := VarList.ItemIndex;
if (not independent) and (index > -1) then
begin
if ZVarEdit.Text = '' then
begin
ZVarEdit.Text := VarList.Items[index];
VarList.Items.Delete(index);
UpdateBtnStates;
end;
end;
end;
procedure TTwoCorrsForm.Var3OutClick(Sender: TObject);
begin
if (not independent) and (ZVarEdit.Text <> '') then
begin
VarList.Items.Add(ZVarEdit.Text);
ZVarEdit.Text := '';
UpdateBtnStates;
end;
end;
procedure TTwoCorrsForm.GrpInClick(Sender: TObject);
var
index: Integer;
begin
index := VarList.ItemIndex;
if independent and (index > -1) then
begin
if GroupVarEdit.Text = '' then
begin
GroupVarEdit.Text := VarList.Items[index];
VarList.Items.Delete(index);
UpdateBtnStates;
end;
end;
end;
procedure TTwoCorrsForm.GrpOutClick(Sender: TObject);
begin
if independent and (GroupVarEdit.Text <> '') then
begin
VarList.Items.Add(GroupVarEdit.Text);
GroupVarEdit.Text := '';
UpdateBtnStates;
end;
end;
procedure TTwoCorrsForm.VarListDblClick(Sender: TObject);
var
index: integer;
s: String;
begin
index := VarList.ItemIndex;
if index >-1 then
begin
s := VarList.Items[index];
if XVarEdit.Text = '' then
begin
XVarEdit.Text := s;
VarList.Items.Delete(index);
end else
if YVarEdit.Text = '' then
begin
YVarEdit.Text := s;
VarList.Items.Delete(index);
end else
if (not independent) and (ZVarEdit.Text = '') then
begin
ZVarEdit.Text := VarList.Items.Strings[index];
VarList.Items.Delete(index);
end else
if independent and (GroupVarEdit.Text = '') then
begin
GroupVarEdit.Text := VarList.Items.Strings[index];
VarList.Items.Delete(index);
end;
UpdateBtnStates;
end;
end;
procedure TTwoCorrsForm.VarListSelectionChange(Sender: TObject; User: boolean);
begin
UpdateBtnStates;
end;
end. end.

View File

@ -36,7 +36,7 @@ inherited TwoPropForm: TTwoPropForm
end end
object Notebook: TNotebook[5] object Notebook: TNotebook[5]
AnchorSideLeft.Control = ParamsPanel AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = RadioGroup1 AnchorSideTop.Control = DataSourceGroup
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ParamsPanel AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
@ -60,8 +60,8 @@ inherited TwoPropForm: TTwoPropForm
Left = 0 Left = 0
Height = 15 Height = 15
Top = 0 Top = 0
Width = 83 Width = 97
Caption = 'Select Variables:' Caption = 'Available Variables'
ParentColor = False ParentColor = False
end end
object Var1Label: TLabel object Var1Label: TLabel
@ -523,7 +523,7 @@ inherited TwoPropForm: TTwoPropForm
TabOrder = 5 TabOrder = 5
Text = '95.0' Text = '95.0'
end end
object RadioGroup1: TRadioGroup[8] object DataSourceGroup: TRadioGroup[8]
AnchorSideTop.Control = ParamsPanel AnchorSideTop.Control = ParamsPanel
AnchorSideRight.Control = Bevel5 AnchorSideRight.Control = Bevel5
Left = -3 Left = -3
@ -549,7 +549,7 @@ inherited TwoPropForm: TTwoPropForm
'Values Entered on this Form' 'Values Entered on this Form'
'Values in the Data Grid' 'Values in the Data Grid'
) )
OnClick = RadioGroup1Click OnClick = DataSourceGroupClick
TabOrder = 6 TabOrder = 6
end end
object DepIndepGroup: TRadioGroup[9] object DepIndepGroup: TRadioGroup[9]

View File

@ -58,11 +58,11 @@ type
Samp20Label: TLabel; Samp20Label: TLabel;
GrpOut: TBitBtn; GrpOut: TBitBtn;
VarList: TListBox; VarList: TListBox;
RadioGroup1: TRadioGroup; DataSourceGroup: TRadioGroup;
DepIndepGroup: TRadioGroup; DepIndepGroup: TRadioGroup;
procedure GrpInClick(Sender: TObject); procedure GrpInClick(Sender: TObject);
procedure GrpOutClick(Sender: TObject); procedure GrpOutClick(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject); procedure DataSourceGroupClick(Sender: TObject);
procedure DepIndepGroupClick(Sender: TObject); procedure DepIndepGroupClick(Sender: TObject);
procedure Var1InClick(Sender: TObject); procedure Var1InClick(Sender: TObject);
procedure Var1OutClick(Sender: TObject); procedure Var1OutClick(Sender: TObject);
@ -94,7 +94,8 @@ implementation
{$R *.lfm} {$R *.lfm}
uses uses
Math; Math,
GridProcs;
{ TTwoPropForm } { TTwoPropForm }
@ -107,13 +108,20 @@ end;
procedure TTwoPropForm.AdjustConstraints; procedure TTwoPropForm.AdjustConstraints;
var
w: Integer;
begin begin
inherited; inherited;
w := Max(DataSourceGroup.Width, DepIndepGroup.Width);
DataSourceGroup.Constraints.MinWidth := w;
DepIndepGroup.Constraints.MinWidth := w;
ParamsPanel.Constraints.MinWidth := Max( ParamsPanel.Constraints.MinWidth := Max(
4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left, 4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left,
RadioGroup1.Width + Bevel5.Width + DepIndepGroup.Width 2*w + Bevel5.Width
); );
ParamsPanel.Constraints.MinHeight := GrpOut.Top + GrpOut.Height + ParamsPanel.Constraints.MinHeight := DataSourceGroup.Height +
Notebook.BorderSpacing.Top + Var2Out.Top + Var2Out.Height +
Notebook.BorderSpacing.Bottom + CIntervalEdit.Height + ButtonBevel.Height + Notebook.BorderSpacing.Bottom + CIntervalEdit.Height + ButtonBevel.Height +
CloseBtn.BorderSpacing.Top + CloseBtn.Height; CloseBtn.BorderSpacing.Top + CloseBtn.Height;
end; end;
@ -124,7 +132,8 @@ var
ConfInt, Prop1, Prop2, zstatistic, zprobability: double; ConfInt, Prop1, Prop2, zstatistic, zprobability: double;
PropDif, stderr, UCL, LCL, value1, value2, ztest: double; PropDif, stderr, UCL, LCL, value1, value2, ztest: double;
P, Q: double; P, Q: double;
i, v1, v2, NoSelected, f1, f2, f3, f4, ncases1, ncases2: integer; i: Integer; //, v1, v2, NoSelected,
f1, f2, f3, f4, ncases1, ncases2: integer;
min, max, group, AB, AC, CD, BD: integer; min, max, group, AB, AC, CD, BD: integer;
ColNoSelected: IntDyneVec = nil; ColNoSelected: IntDyneVec = nil;
lReport: TStrings; lReport: TStrings;
@ -132,12 +141,12 @@ begin
// Initialize output form // Initialize output form
stderr := 0.0; stderr := 0.0;
PropDif := 0.0; PropDif := 0.0;
v2 := 0; // v2 := 0;
ztest := 0.0; ztest := 0.0;
Prop1 := 0.0; Prop1 := 0.0;
Prop2 := 0.0; Prop2 := 0.0;
NoSelected := 0; // NoSelected := 0;
v1 := 0; // v1 := 0;
zstatistic := 0.0; zstatistic := 0.0;
zprobability := 0.0; zprobability := 0.0;
UCL := 0.0; UCL := 0.0;
@ -147,6 +156,7 @@ begin
ConfInt := (100.0 - StrToFloat(CIntervalEdit.Text)) / 2.0 ; ConfInt := (100.0 - StrToFloat(CIntervalEdit.Text)) / 2.0 ;
ConfInt := (100.0 - ConfInt) / 100.0; // one tail ConfInt := (100.0 - ConfInt) / 100.0; // one tail
ncases1 := 0; ncases1 := 0;
ncases2 := 0; ncases2 := 0;
f1 := 0; f1 := 0;
@ -158,6 +168,10 @@ begin
if griddata then // data read from grid if griddata then // data read from grid
begin begin
SetLength(ColNoSelected, 2);
ColNoSelected[0] := GetVariableIndex(OS3MainFrm.DataGrid, Var1Edit.Text);
ColNoSelected[1] := GetVariableIndex(OS3MainFrm.DataGrid, Var2Edit.Text);
{
for i := 1 to NoVariables do for i := 1 to NoVariables do
begin begin
if Var1Edit.Text = OS3MainFrm.DataGrid.Cells[i,0] then if Var1Edit.Text = OS3MainFrm.DataGrid.Cells[i,0] then
@ -172,30 +186,34 @@ begin
ColNoSelected[1] := i; ColNoSelected[1] := i;
end; end;
end; // next variable end; // next variable
}
f1 := 0;
f2 := 0;
nCases1 := 0;
if not independent then // correlated data if not independent then // correlated data
begin begin
for i := 1 to NoCases do for i := 1 to NoCases do
begin begin
if not GoodRecord(i,NoSelected,ColNoSelected) then continue; if not GoodRecord(OS3MainFrm.DataGrid, i, ColNoSelected) then continue;
ncases1 := ncases1 + 1; nCases1 := nCases1 + 1;
value1 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[v1,i])); value1 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[0], i]));
value2 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[v2,i])); value2 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[1], i]));
f1 := f1 + round(value1); f1 := f1 + round(value1);
f2 := f2 + round(value2); f2 := f2 + round(value2);
end; // next case end; // next case
f3 := ncases1 - f1; f3 := nCases1 - f1;
f4 := ncases1 - f2; f4 := nCases1 - f2;
AB := f1 + f2; AB := f1 + f2;
AC := f1 + f3; AC := f1 + f3;
CD := f3 + f4; CD := f3 + f4;
BD := f2 + f4; BD := f2 + f4;
Prop1 := BD / ncases1; Prop1 := BD / nCases1;
Prop2 := AB / ncases1; Prop2 := AB / nCases1;
stderr := sqrt((f1 / ncases1 + f4 / ncases1) / ncases1); stderr := sqrt((f1 / nCases1 + f4 / nCases1) / nCases1);
PropDif := Prop1 - Prop2; PropDif := Prop1 - Prop2;
zstatistic := PropDif / stderr; zstatistic := PropDif / stderr;
ztest := inversez(ConfInt); ztest := InverseZ(ConfInt);
zprobability := 1.0 - ProbZ(abs(zstatistic)); zprobability := 1.0 - ProbZ(abs(zstatistic));
UCL := PropDif + stderr * ztest; UCL := PropDif + stderr * ztest;
LCL := PropDif - stderr * ztest; LCL := PropDif - stderr * ztest;
@ -203,21 +221,21 @@ begin
if independent then if independent then
begin begin
min := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[v2,1]))); min := MaxInt;
max := min; max := min;
for i := 2 to NoCases do for i := 1 to NoCases do
begin begin
if not GoodRecord(i,NoSelected,ColNoSelected) then continue; if not GoodRecord(OS3MainFrm.DataGrid, i, ColNoSelected) then continue;
group := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[v2,i]))); group := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[1], i])));
if group < min then min := group; if group < min then min := group;
if group > max then max := group; if group > max then max := group;
end; end;
for i := 1 to NoCases do for i := 1 to NoCases do
begin begin
if not GoodRecord(i,NoSelected,ColNoSelected) then continue; if not GoodRecord(OS3MainFrm.DataGrid, i, ColNoSelected) then continue;
value1 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[v1,i])); value1 := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[0], i]));
group := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[v2,i]))); group := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[1], i])));
if group = min then if group = min then
begin begin
f1 := f1 + round(value1); f1 := f1 + round(value1);
@ -307,8 +325,10 @@ begin
lReport.Add(' --------|-------|------'); lReport.Add(' --------|-------|------');
lReport.Add(' sum | %5d %5d %5d |', [AC, BD, ncases1]); lReport.Add(' sum | %5d %5d %5d |', [AC, BD, ncases1]);
lReport.Add(''); lReport.Add('');
lReport.Add('Confidence Level selected: %s', [CIntervalEdit.Text]); lReport.Add('Confidence Level selected: %9s', [CIntervalEdit.Text]);
lReport.Add('Proportion 1 = %.3f and Proportion 2 = %.3f with %d cases', [Prop1, Prop2, ncases1]); lReport.Add('Proportion 1: %9.3f', [Prop1]);
lReport.Add('Proportion 2: %9.3f', [Prop2]);
lReport.Add('Number of cases: %9d', [nCases1]);
lReport.Add('Difference in proportions: %9.3f', [PropDif]); lReport.Add('Difference in proportions: %9.3f', [PropDif]);
lReport.Add('Standard Error of Difference: %9.3f', [stderr]); lReport.Add('Standard Error of Difference: %9.3f', [stderr]);
lReport.Add('z test statistic: %9.3f', [zStatistic]); lReport.Add('z test statistic: %9.3f', [zStatistic]);
@ -323,14 +343,14 @@ begin
lReport.Add(''); lReport.Add('');
lReport.Add('Entered Values'); lReport.Add('Entered Values');
lReport.Add(''); lReport.Add('');
lReport.Add('Sample 1: Frequency = %5d for %5d cases.', [f1, ncases1]); lReport.Add('Sample 1: Frequency %5d for %5d cases.', [f1, ncases1]);
lReport.Add('Sample 2: Frequency = %5d for %5d cases.', [f2, ncases2]); lReport.Add('Sample 2: Frequency %5d for %5d cases.', [f2, ncases2]);
lReport.Add(''); lReport.Add('');
lReport.Add('Proportion 1: %9.3f', [Prop1]); lReport.Add('Proportion 1: %9.3f', [Prop1]);
lReport.Add('Proportion 2: %9.3f', [Prop2]); lReport.Add('Proportion 2: %9.3f', [Prop2]);
lReport.Add('Difference: %9.3f', [PropDif]); lReport.Add('Difference: %9.3f', [PropDif]);
lReport.Add('Standard Error of Difference: %9.3f', [stderr]); lReport.Add('Standard Error of Difference: %9.3f', [stderr]);
lReport.Add('Confidence Level selected: %-9s', [CIntervalEdit.Text]); lReport.Add('Confidence Level selected: %9s', [CIntervalEdit.Text]);
lReport.Add('z test statistic: %9.3f', [zStatistic]); lReport.Add('z test statistic: %9.3f', [zStatistic]);
lReport.Add(' with probability %9.4f', [zProbability]); lReport.Add(' with probability %9.4f', [zProbability]);
lReport.Add('z value for confidence interval: %9.3f', [ztest]); lReport.Add('z value for confidence interval: %9.3f', [ztest]);
@ -370,9 +390,9 @@ begin
end; end;
procedure TTwoPropForm.RadioGroup1Click(Sender: TObject); procedure TTwoPropForm.DataSourceGroupClick(Sender: TObject);
begin begin
griddata := (RadioGroup1.ItemIndex = 1); griddata := (DataSourceGroup.ItemIndex = 1);
DepIndepGroupClick(nil); DepIndepGroupClick(nil);
end; end;
@ -415,7 +435,7 @@ var
begin begin
inherited; inherited;
RadioGroup1.ItemIndex := 0; DataSourceGroup.ItemIndex := 0;
DepIndepGroup.ItemIndex := 0; DepIndepGroup.ItemIndex := 0;
VarList.Clear; VarList.Clear;
@ -600,20 +620,20 @@ begin
begin begin
s := VarList.Items[index]; s := VarList.Items[index];
if Var1Edit.Text = '' then if Var1Edit.Text = '' then
Var1Edit.Text := s
else
begin begin
if independent then Var1Edit.Text := s;
begin VarList.Items.Delete(index);
if GrpEdit.Text = '' then end else
GrpEdit.Text := s; if independent and (GrpEdit.Text = '') then
end else begin
begin GrpEdit.Text := s;
if Var2Edit.Text = '' then VarList.Items.Delete(index);
Var2Edit.Text := s; end else
end; if (not independent) and (Var2Edit.Text = '') then
begin
Var2Edit.Text := s;
VarList.Items.Delete(index);
end; end;
UpdateBtnStates; UpdateBtnStates;
end; end;
end; end;

View File

@ -1087,9 +1087,9 @@ end;
// Menu "Analysis" > "Comparisons" > "Difference Between Correlations" // Menu "Analysis" > "Comparisons" > "Difference Between Correlations"
procedure TOS3MainFrm.mnuAnalysisComp_CorrDiffClick(Sender: TObject); procedure TOS3MainFrm.mnuAnalysisComp_CorrDiffClick(Sender: TObject);
begin begin
if TwoCorrsFrm = nil then if TwoCorrsForm = nil then
Application.CreateForm(TTwoCorrsFrm, TwoCorrsFrm); Application.CreateForm(TTwoCorrsForm, TwoCorrsForm);
TwoCorrsFrm.ShowModal; TwoCorrsForm.Show;
end; end;
// Menu "Analysis" > "Multivariate" > "mnuAnalysisMulti_Correspondence Analysis" // Menu "Analysis" > "Multivariate" > "mnuAnalysisMulti_Correspondence Analysis"