LazStats: Some more refactoring in RMatUnits. Misc fixes and clean-up in other units.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7868 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-11-14 12:43:20 +00:00
parent e4817b7729
commit 03cc1dfcc0
10 changed files with 149 additions and 425 deletions

View File

@ -397,7 +397,7 @@
<Unit36>
<Filename Value="forms\analysis\correlation\rmatunit.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="RMatFrm"/>
<ComponentName Value="RMatForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="RMatUnit"/>

View File

@ -1,7 +1,7 @@
inherited ABCNestedForm: TABCNestedForm
Left = 441
Left = 383
Height = 481
Top = 202
Top = 191
Width = 843
Caption = 'Three-Factor Nested ANOVA'
ClientHeight = 481

View File

@ -7,20 +7,14 @@
unit ABCNestedUnit;
{$mode objfpc}{$H+}
{.$DEFINE SHOW_OLD_PLOTS}
interface
uses
Classes, SysUtils, FileUtil, TAStyles, Forms, Controls, Graphics, Dialogs,
StdCtrls, Buttons, ExtCtrls, ComCtrls, LCLVersion,
TACustomSeries,
{$IFDEF SHOW_OLD_PLOTS}
GraphLib,
{$ENDIF}
MainUnit, Globals, ReportFrameUnit, BasicStatsReportAndChartFormUnit;
type
@ -74,12 +68,11 @@ type
ACCount, ABCount : IntDyneMat;
CellSDs, SS, SumSqr, CellMeans : DblDyneCube;
MinA, MaxA, NoALevels: Integer;
MinB, MaxB, NoBLevels: Integer; //ACol, BCol, CCol, YCol : integer;
MinB, MaxB, NoBLevels: Integer;
MinC, MaxC, NoCLevels: integer;
SSTot, SumSqrTot, TotMean, MSTot, SSA, MSA, SSB, MSB, SSW, MSW : double;
SSC, MSC, SSAC, MSAC, SSBwAC, SSAB, MSBwAC : double;
TotN, dfA, dfBwA, dfwcell, dftotal, dfC, dfAC, dfBwAC : integer;
// ColNoSelected: IntDyneVec;
AMeans, BMeans, CMeans: DblDyneVec;
ABMeans, ACMeans: DblDyneMat;
@ -92,9 +85,6 @@ type
procedure ShowResults;
procedure ReleaseMemory;
procedure TwoWayPlot;
{$IFDEF SHOW_OLD_PLOTS}
procedure OldTwoWayPlot;
{$ENDIF}
private
FMeansReportFrame: TReportFrame;
@ -147,11 +137,6 @@ begin
AddComboboxToToolbar(FChartFrame.ChartToolbar, 'Plots:', FChartCombobox);
FChartCombobox.OnSelect := @SelectPlot;
{$IFDEF SHOW_OLD_PLOTS}
if GraphFrm = nil then
Application.CreateForm(TGraphFrm, GraphFrm);
{$ENDIF}
PageControl.ActivePageIndex := 0;
end;
@ -182,6 +167,7 @@ begin
UpdateBtnStates;
end;
procedure TABCNestedForm.AOutBtnClick(Sender: TObject);
begin
if FactorAEdit.Text <> '' then
@ -192,6 +178,7 @@ begin
UpdateBtnStates;
end;
procedure TABCNestedForm.BInBtnClick(Sender: TObject);
var
index: integer;
@ -205,6 +192,7 @@ begin
UpdateBtnStates;
end;
procedure TABCNestedForm.BOutBtnClick(Sender: TObject);
begin
if FactorBEdit.Text <> '' then
@ -256,9 +244,6 @@ begin
GetResults;
ShowResults;
TwoWayPlot;
{$IFDEF SHOW_OLD_PLOTS}
OldTwoWayPlot;
{$ENDIF}
ReleaseMemory;
end;
end;
@ -657,8 +642,9 @@ begin
end;
end;
end;
// assume all cells have same n size
// get no. of levels in A
// Assume all cells have same n size
// Get number of levels in A
BLevCount := 0;
for i := 0 to NoALevels-1 do
begin
@ -681,21 +667,21 @@ begin
SSTot := SSTot - constant;
MSTot := SSTot / dftotal;
// get A Effects
// Get A Effects
SSA := 0.0;
for i := 0 to NoALevels-1 do SSA := SSA + (ASumSqr[i] / ACount[i]);
temp := SSA;
SSA := SSA - constant;
MSA := SSA / dfA;
//Get C Effects
// Get C Effects
SSC := 0.0;
for i := 0 to NoCLevels-1 do SSC := SSC + (CSumSqr[i] / CCount[i]);
temp2 := SSC;
SSC := SSC - constant;
MSC := SSC / dfC;
// get B within A
// Get B within A
SSB := 0.0;
for i := 0 to NoALevels - 1 do
begin
@ -708,7 +694,7 @@ begin
SSB := SSB - temp;
MSB := SSB / dfBwA;
// get AC interaction
// Get AC interaction
SSAC := 0.0;
for i := 0 to NoALevels-1 do
begin
@ -792,7 +778,6 @@ end;
procedure TABCNestedForm.ReleaseMemory;
begin
// ColNoSelected := nil;
ABSDs := nil;
ABCount := nil;
// ABMeans := nil;
@ -921,30 +906,6 @@ begin
end;
end;
end;
(*
GetDataIndices(ix, iy,iz);
if (ix = 1) and (iy = 2) then
begin
FSeries.ListSource.YCount := NF2Cells;
for i := 0 to NF1Cells-1 do
begin
idx := FSeries.AddXY(minF1 + i, NaN, IntToStr(minF1 + i));
item := FSeries.Source.Item[idx];
for j := 0 to NF2Cells-1 do
item^.SetY(j, wsum[i,j,iz] / ncnt[i,j,iz]);
end;
FChartFrame.SetTitle(Format('Factor "%s" x Factor "%s"' + LineEnding + '"%s" = %d', [
Factor1Edit.Text, Factor2Edit.Text, Factor3Edit.Text, MinF3 + iz]));
FChartFrame.SetXTitle(Factor1Edit.Text + ' codes');
for j := 0 to NF2Cells-1 do
with TChartStyle(FStyles.styles.Add) do
begin
Brush.Color := DATA_COLORS[j mod Length(DATA_COLORS)];
UseBrush := True;
Text := Format('%s = %s', [Factor2Edit.Text, IntToStr(MinF2 + j)]);
end;
end
else *)
if (FSeries is TBarSeries) then
begin
@ -994,216 +955,6 @@ begin
end;
{$IFDEF SHOW_OLD_PLOTS}
procedure TABCNestedForm.OldTwoWayPlot;
var
plottype, i, j, k : integer;
maxmean, XBar : double;
title, setstring : string;
XValue : DblDyneVec = nil;
begin
case OptionsGroup.ItemIndex of
0: plottype := 9;
1: plottype := 10;
2: plottype := 1;
3: plottype := 2;
end;
// Factor A first
maxmean := -1000.0;
SetLength(XValue,NoALevels);
setstring := 'FACTOR A';
GraphFrm.SetLabels[1] := setstring;
SetLength(GraphFrm.Xpoints,1,NoALevels);
SetLength(GraphFrm.Ypoints,1,NoALevels);
for i := 1 to NoALevels do
begin
GraphFrm.Ypoints[0,i-1] := AMeans[i-1];
if AMeans[i-1] > maxmean then maxmean := AMeans[i-1];
XValue[i-1] := MinA + i -1;
GraphFrm.Xpoints[0,i-1] := XValue[i-1];
end;
GraphFrm.nosets := 1;
GraphFrm.nbars := NoALevels;
GraphFrm.Heading := FactorAEdit.Text;
title := FactorAEdit.Text + ' Group Codes';
GraphFrm.XTitle := title;
GraphFrm.YTitle := 'Mean';
GraphFrm.barwideprop := 0.5;
GraphFrm.AutoScaled := false;
GraphFrm.miny := 0.0;
GraphFrm.maxy := maxmean;
GraphFrm.GraphType := plottype;
GraphFrm.BackColor := clCream;
GraphFrm.WallColor := clDkGray;
GraphFrm.FloorColor := clLtGray;
GraphFrm.ShowBackWall := true;
GraphFrm.ShowModal;
GraphFrm.Xpoints := nil;
GraphFrm.Ypoints := nil;
XValue := nil;
// Factor B next
SetLength(XValue,NoBLevels);
setstring := 'FACTOR B';
GraphFrm.SetLabels[1] := setstring;
maxmean := -1000.0;
SetLength(GraphFrm.Xpoints,1,NoBLevels);
SetLength(GraphFrm.Ypoints,1,NoBLevels);
for i := 1 to NoBLevels do
begin
GraphFrm.Ypoints[0,i-1] := BMeans[i-1];
if BMeans[i-1] > maxmean then maxmean := BMeans[i-1];
XValue[i-1] := MinB + i - 1;
GraphFrm.Xpoints[0,i-1] := XValue[i-1];
end;
GraphFrm.nosets := 1;
GraphFrm.nbars := NoBLevels;
GraphFrm.Heading := 'FACTOR B';
title := FactorBEdit.Text + ' Group Codes';
GraphFrm.XTitle := title;
GraphFrm.YTitle := 'Mean';
GraphFrm.barwideprop := 0.5;
GraphFrm.AutoScaled := false;
GraphFrm.miny := 0.0;
GraphFrm.maxy := maxmean;
GraphFrm.GraphType := plottype;
GraphFrm.BackColor := clCream;
GraphFrm.WallColor := clDkGray;
GraphFrm.FloorColor := clLtGray;
GraphFrm.ShowBackWall := true;
GraphFrm.ShowModal;
GraphFrm.Xpoints := nil;
GraphFrm.Ypoints := nil;
XValue := nil;
// Factor C next
SetLength(XValue,NoCLevels);
setstring := 'FACTOR C';
GraphFrm.SetLabels[1] := setstring;
maxmean := -1000.0;
SetLength(GraphFrm.Xpoints,1,NoCLevels);
SetLength(GraphFrm.Ypoints,1,NoCLevels);
for i := 0 to NoCLevels-1 do
begin
GraphFrm.Ypoints[0,i] := CMeans[i];
if CMeans[i] > maxmean then maxmean := CMeans[i];
XValue[i] := MinC + i - 1;
GraphFrm.Xpoints[0,i] := XValue[i];
end;
GraphFrm.nosets := 1;
GraphFrm.nbars := NoCLevels;
GraphFrm.Heading := 'FACTOR C';
title := FactorBEdit.Text + ' Group Codes';
GraphFrm.XTitle := title;
GraphFrm.YTitle := 'Mean';
GraphFrm.barwideprop := 0.5;
GraphFrm.AutoScaled := false;
GraphFrm.miny := 0.0;
GraphFrm.maxy := maxmean;
GraphFrm.GraphType := plottype;
GraphFrm.BackColor := clCream;
GraphFrm.WallColor := clDkGray;
GraphFrm.FloorColor := clLtGray;
GraphFrm.ShowBackWall := true;
GraphFrm.ShowModal;
GraphFrm.Xpoints := nil;
GraphFrm.Ypoints := nil;
XValue := nil;
// Factor A x B interaction within each slice next
SetLength(XValue,NoALevels + NoBLevels);
SetLength(GraphFrm.Ypoints,NoALevels,NoBLevels);
SetLength(GraphFrm.Xpoints,1,NoBLevels);
for k := 0 to NoCLevels-1 do
begin
maxmean := -1000.0;
for i := 0 to NoALevels-1 do
begin
setstring := 'FACTOR A ' + IntToStr(i+1);
GraphFrm.SetLabels[i+1] := setstring;
for j := 0 to NoBLevels-1 do
begin
if ABCount[i,j] > 0 then
begin
if ABMeans[i,j] > maxmean then maxmean := ABMeans[i,j];
GraphFrm.Ypoints[i,j] := ABMeans[i,j];
end;
end;
end;
for j := 0 to NoBLevels-1 do
begin
XValue[j] := MinB + j - 1;
GraphFrm.Xpoints[0,j] := XValue[j];
end;
GraphFrm.nosets := NoALevels;
GraphFrm.nbars := NoBLevels;
GraphFrm.Heading := 'FACTOR A x Factor B within C' + IntToStr(k+1);
title := FactorBEdit.Text + ' Group Codes';
GraphFrm.XTitle := title;
GraphFrm.YTitle := 'Mean';
GraphFrm.barwideprop := 0.5;
GraphFrm.AutoScaled := false;
GraphFrm.miny := 0.0;
GraphFrm.maxy := maxmean;
GraphFrm.GraphType := plottype;
GraphFrm.BackColor := clCream;
GraphFrm.WallColor := clDkGray;
GraphFrm.FloorColor := clLtGray;
GraphFrm.ShowBackWall := true;
GraphFrm.ShowModal;
end;
GraphFrm.Xpoints := nil;
GraphFrm.Ypoints := nil;
XValue := nil;
//Factor A x C Interaction within each column next
setLength(XValue,NoALevels+NoCLevels);
SetLength(GraphFrm.Xpoints,1,NoCLevels);
SetLength(GraphFrm.Ypoints,NoALevels,NoCLevels);
for j := 0 to NoBLevels-1 do
begin
maxmean := 0.0;
for i := 0 to NoALevels-1 do
begin
setstring := 'Factor A ' + IntToStr(i+1);
GraphFrm.SetLabels[i+1] := setstring;
for k := 0 to NoCLevels-1 do
begin
XBar := ACMeans[i,k];
if XBar > maxmean then maxmean := XBar;
GraphFrm.Ypoints[i,k] := XBar;
end;
end;
for k := 0 to NoCLevels-1 do
begin
XValue[k] := MinC + k - 1;
GraphFrm.Xpoints[0,k] := XValue[k];
end;
GraphFrm.nosets := NoALevels;
GraphFrm.nbars := NoCLevels;
GraphFrm.Heading := 'FACTOR A x Factor C within B ' + IntToStr(j+1);
title := FactorCEdit.Text + ' Group Codes';
GraphFrm.XTitle := title;
GraphFrm.YTitle := 'Mean';
GraphFrm.barwideprop := 0.5;
GraphFrm.AutoScaled := false;
GraphFrm.miny := 0.0;
GraphFrm.maxy := maxmean;
GraphFrm.GraphType := plottype;
GraphFrm.BackColor := clCream;
GraphFrm.WallColor := clDkGray;
GraphFrm.FloorColor := clLtGray;
GraphFrm.ShowBackWall := true;
GraphFrm.ShowModal;
end;
GraphFrm.Xpoints := nil;
GraphFrm.Ypoints := nil;
XValue := nil;
end;
{$ENDIF}
procedure TABCNestedForm.UpdateBtnStates;
begin
inherited;

View File

@ -316,15 +316,14 @@ inherited BNestedAForm: TBNestedAForm
Left = 336
Height = 416
Width = 200
TabIndex = 2
inherited ReportPage: TTabSheet
Caption = 'ANOVA Results'
end
object MeansPage: TTabSheet[1]
Caption = 'Means'
end
inherited ChartPage: TTabSheet[2]
inherited ChartPage: TTabSheet
Caption = 'Plots'
end
object MeansPage: TTabSheet[2]
Caption = 'Means'
end
end
end

View File

@ -444,55 +444,6 @@ begin
end;
(*
var
i, group : integer;
strvalue, cellstring : string;
begin
Result := false;
DepVar := DepEdit.Text;
FactorA := ACodesEdit.Text;
FactorB := BCodesEdit.Text;
ACol := 0;
BCol := 0;
YCol := 0;
MinA := 1000;
MaxA := -1000;
MinB := 1000;
MaxB := -1000;
for i := 1 to NoVariables do
begin
strvalue := Trim(OS3MainFrm.DataGrid.Cells[i,0]);
if FactorA = strvalue then ACol := i;
if FactorB = strvalue then BCol := i;
if DepVar = strvalue then YCol := i;
end;
if (ACol = 0) or (BCol = 0) or (YCol = 0) then
begin
ErrorMsg('Select a variable for each entry box.');
exit;
end;
// Get number of levels for Factors
for i := 1 to NoCases do
begin
cellstring := Trim(OS3MainFrm.DataGrid.Cells[ACol,i]);
group := round(StrToFloat(cellstring));
if (group > MaxA) then MaxA := group;
if (group < MinA) then MinA := group;
cellstring := Trim(OS3MainFrm.DataGrid.Cells[BCol,i]);
group := round(StrToFLoat(cellstring));
if (group > MaxB) then MaxB := group;
if (group < MinB) then MinB := group;
end;
NoALevels := MaxA - MinA + 1;
NoBLevels := MaxB - MinB + 1;
Result := true;
end;
*)
procedure TBNestedAForm.ShowMeans;
var
lReport: TStrings;

View File

@ -1,7 +1,7 @@
inherited RMatFrm: TRMatFrm
Left = 1133
inherited RMatForm: TRMatForm
Left = 690
Height = 345
Top = 254
Top = 205
Width = 840
HelpType = htKeyword
HelpKeyword = 'html/ProductMoment.htm'
@ -232,13 +232,13 @@ inherited RMatFrm: TRMatFrm
Height = 329
Top = 8
Width = 518
ActivePage = PairwisePage
ActivePage = CrossProdPage
Align = alClient
BorderSpacing.Left = 6
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
TabIndex = 4
TabIndex = 0
TabOrder = 2
object CrossProdPage: TTabSheet
Caption = 'Cross-Products'

View File

@ -15,9 +15,9 @@ uses
type
{ TRMatFrm }
{ TRMatForm }
TRMatFrm = class(TBasicStatsReportForm)
TRMatForm = class(TBasicStatsReportForm)
SaveMatrixChk: TCheckBox;
InBtn: TBitBtn;
OutBtn: TBitBtn;
@ -80,6 +80,7 @@ type
procedure Compute; override;
procedure SelectVisiblePage;
procedure UpdateBtnStates; override;
function Validate(out AMsg: String; out AControl: TWinControl): Boolean; override;
public
constructor Create(AOwner: TComponent); override;
@ -87,7 +88,7 @@ type
end;
var
RMatFrm: TRMatFrm;
RMatForm: TRMatForm;
implementation
@ -95,15 +96,18 @@ implementation
uses
Math,
Utils, MathUnit;
Utils, MathUnit, GridProcs;
{ TRMatFrm }
{ TRMatForm }
constructor TRMatFrm.Create(AOwner: TComponent);
constructor TRMatForm.Create(AOwner: TComponent);
begin
inherited;
InitToolbar(FReportFrame.ReportToolbar, tpTop);
FReportFrame.ClearBorderSpacings;
FCrossProdReportFrame := FReportFrame; // already created by ancestor
FCrossProdReportFrame.Parent := CrossProdPage;
FCrossProdReportFrame.Align := alClient;
@ -129,7 +133,7 @@ begin
end;
procedure TRMatFrm.AdjustConstraints;
procedure TRMatForm.AdjustConstraints;
begin
inherited;
ParamsPanel.Constraints.MinWidth := Max(
@ -143,7 +147,7 @@ end;
procedure TRMatFrm.AllBtnClick(Sender: TObject);
procedure TRMatForm.AllBtnClick(Sender: TObject);
var
index: Integer;
begin
@ -154,10 +158,9 @@ begin
end;
procedure TRMatFrm.Compute;
procedure TRMatForm.Compute;
var
i, j: integer;
cellstring: string;
i: integer;
NoVars: integer;
ColNoSelected: IntDyneVec = nil;
Matrix: DblDyneMat = nil;
@ -169,12 +172,6 @@ var
nGood: Integer = 0;
begin
NoVars := SelList.Items.Count;
if NoVars = 0 then
begin
MessageDlg('No variable(s) selected.', mtError, [mbOK], 0);
exit;
end;
SetLength(ColNoSelected, NoVars+1);
SetLength(Matrix, NoVars+1, NoVars+1); // 1 more for possible augmentation
SetLength(Means, NoVars+1);
@ -183,19 +180,12 @@ begin
SetLength(RowLabels, NoVars+1);
SetLength(ColLabels, NoVars+1);
// identify the included variable locations and their labels
for i := 1 to NoVars do
// Identify the included variable locations and their labels
for i := 0 to NoVars-1 do
begin
cellstring := SelList.Items.Strings[i-1];
for j := 1 to NoVariables do
begin
if cellstring = OS3MainFrm.DataGrid.Cells[j,0] then
begin
ColNoSelected[i-1] := j;
RowLabels[i-1] := cellstring;
ColLabels[i-1] := cellstring;
end;
end;
RowLabels[i] := SelList.Items[i];
ColLabels[i] := RowLabels[i];
ColNoSelected[i] := GetVariableIndex(OS3MainFrm.DataGrid, RowLabels[i]);
end;
if AugmentChk.Checked then
begin
@ -255,14 +245,13 @@ begin
end;
procedure TRMatFrm.CrossProducts(ANumVars, ANumCases: Integer;
procedure TRMatForm.CrossProducts(ANumVars, ANumCases: Integer;
const AMatrix: DblDyneMat; Augmented: Boolean;
const ARowLabels, AColLabels: StrDyneVec);
var
lReport: TStrings;
title: String;
begin
// GridXProd(ANumVars, AColNoSelected, AMatrix, Augmented, nGood);
title := 'Cross-Products Matrix';
if Augmented then
inc(ANumVars);
@ -277,7 +266,7 @@ begin
end;
procedure TRMatFrm.InterCorrelations(ANumVars: Integer; const AColNoSelected: IntDyneVec;
procedure TRMatForm.InterCorrelations(ANumVars: Integer; const AColNoSelected: IntDyneVec;
const AMatrix: DblDyneMat; const AMeans, AVars, AStdDevs: DblDyneVec;
const ARowLabels, AColLabels: StrDyneVec);
var
@ -287,7 +276,7 @@ var
hasError: Boolean = false;
i, j: Integer;
testMat: DblDyneMat = nil;
t, probR, N: double;
t, probR: double;
begin
title := 'Product-Moment Correlations Matrix';
Correlations(ANumVars, AColNoSelected, AMatrix, AMeans, AVars, AStdDevs, hasError, nGood);
@ -302,17 +291,22 @@ begin
lReport.Add('One or more correlations could not be computed due to zero variance of a variable.');
end;
N := Ngood;
if nGood <= 2 then
begin
lReport.Add('');
lReport.Add('Not enough cases to calculate t-test values.');
end else
begin
SetLength(testMat, ANumVars, ANumVars);
for i := 1 to ANumVars do
for i := 0 to ANumVars-1 do
begin
for j := i+1 to ANumVars do
for j := i+1 to ANumVars-1 do
begin
t := AMatrix[i-1, j-1] * (sqrt((N-2.0) / (1.0 - (AMatrix[i-1, j-1] * AMatrix[i-1, j-1]))));
testMat[i-1,j-1] := t;
probR := ProbT(t, N - 2);
testMat[j-1, i-1] := probR;
testMat[i-1, i-1] := 0.0;
t := AMatrix[i, j] * sqrt((nGood - 2) / (1.0 - sqr(AMatrix[i, j])));
testMat[i, j] := t;
probR := ProbT(t, nGood - 2);
testMat[j, i] := probR;
testMat[i, i] := 0.0;
end;
end;
@ -321,6 +315,7 @@ begin
title := 't-test values (upper) and probabilities of t (lower)';
MatPrint(testMat, ANumVars, ANumVars, title, ARowLabels, AColLabels, nGood, lReport);
end;
FInterCorrReportFrame.DisplayReport(lReport);
@ -330,7 +325,7 @@ begin
end;
procedure TRMatFrm.InBtnClick(Sender: TObject);
procedure TRMatForm.InBtnClick(Sender: TObject);
var
i: integer;
begin
@ -348,7 +343,8 @@ begin
UpdateBtnStates;
end;
procedure TRMatFrm.OutBtnClick(Sender: TObject);
procedure TRMatForm.OutBtnClick(Sender: TObject);
var
i: integer;
begin
@ -367,7 +363,7 @@ begin
end;
procedure TRMatFrm.PairsCalc(NoVars: integer; const ColNoSelected: IntDyneVec;
procedure TRMatForm.PairsCalc(NoVars: integer; const ColNoSelected: IntDyneVec;
const Matrix: DblDyneMat; const ColLabels: StrDyneVec);
var
lReport: TStrings;
@ -401,34 +397,34 @@ begin
for k := 1 to NoCases do
begin
if not ValidValue(k,XCol) then continue;
if not ValidValue(k,YCol) then continue;
X := StrToFloat(OS3MainFrm.DataGrid.Cells[XCol,k]);
Y := StrToFloat(OS3MainFrm.DataGrid.Cells[YCol,k]);
if not ValidValue(OS3MainFrm.DataGrid, k, XCol) then continue;
if not ValidValue(OS3MainFrm.DataGrid, k, YCol) then continue;
X := StrToFloat(OS3MainFrm.DataGrid.Cells[XCol, k]);
Y := StrToFloat(OS3MainFrm.DataGrid.Cells[YCol, k]);
pmcorr := pmcorr + (X * Y);
XMean := XMean + X;
YMean := YMean + Y;
XVar := XVar + (X * X);
YVar := YVar + (Y * Y);
Npairs := NPairs + 1;
NPairs := NPairs + 1;
end;
if CrossProdChk.Checked then
lReport.Add('CrossProducts[%d,%d]: %6.4f, N cases: %d', [i, j, pmcorr, Npairs]);
lReport.Add('CrossProducts[%d,%d]: %6.4f, N cases: %d', [i, j, pmcorr, NPairs]);
pmcorr := pmcorr - (XMean * YMean) / Npairs;
pmcorr := pmcorr - (XMean * YMean) / NPairs;
pmcorr := pmcorr / (Npairs - 1);
if VarCovarChk.Checked then
lReport.Add('Covariance[%d,%d]: %6.4f, N cases: %d', [i, j, pmcorr, Npairs]);
lReport.Add('Covariance[%d,%d]: %6.4f, N cases: %d', [i, j, pmcorr, NPairs]);
XVar := XVar - (XMean * XMean) / Npairs;
XVar := XVar / (Npairs - 1);
XVar := XVar - (XMean * XMean) / NPairs;
XVar := XVar / (NPairs - 1);
XSD := sqrt(XVar);
YVar := YVar - (YMean * YMean) / Npairs;
YVar := YVar / (Npairs - 1);
YVar := YVar / (NPairs - 1);
YSD := sqrt(YVar);
XMean := XMean / Npairs;
YMean := YMean / Npairs;
XMean := XMean / NPairs;
YMean := YMean / NPairs;
pmcorr := pmcorr / (XSD * YSD);
Matrix[i-1,j-1] := pmcorr;
Matrix[j-1,i-1] := pmcorr;
@ -444,8 +440,8 @@ begin
// z := 0.5 * ln( (1.0 + pmcorr)/(1.0 - pmcorr) );
// z := z / sqrt(1.0/N);
// rprob := probz(z);
lReport.Add('r[%d, %d]: %6.4f, N cases: %d', [i, j, pmcorr, Npairs]);
lReport.Add('t value with d.f. %d: %8.4f with Probability > t %6.4f', [Npairs - 2, z, rprob]);
lReport.Add('r[%d, %d]: %6.4f, N cases: %d', [i, j, pmcorr, NPairs]);
lReport.Add('t value with d.f. %d: %8.4f with Probability > t %6.4f', [NPairs - 2, z, rprob]);
tMatrix[i-1,j-1] := z;
tMatrix[j-1,i-1] := z;
@ -496,13 +492,13 @@ begin
if j <> i then
strout := strout + Format(' %3d ', [NMatrix[i-1,j-1]])
else begin
Npairs := 0;
NPairs := 0;
for k := 1 to NoCases do
begin
if ValidValue(k,ColNoSelected[j-1]) then
Npairs := Npairs + 1;
if ValidValue(OS3MainFrm.DataGrid, k, ColNoSelected[j-1]) then
NPairs := NPairs + 1;
end;
strout := strout + Format(' %3d ', [Npairs]);
strout := strout + Format(' %3d ', [NPairs]);
end;
end;
@ -542,7 +538,7 @@ begin
end;
procedure TRMatFrm.Reset;
procedure TRMatForm.Reset;
var
i: integer;
begin
@ -582,7 +578,7 @@ begin
end;
procedure TRMatFrm.SelectVisiblePage;
procedure TRMatForm.SelectVisiblePage;
var
i: Integer;
begin
@ -598,7 +594,7 @@ begin
end;
procedure TRMatFrm.SelListDblClick(Sender: TObject);
procedure TRMatForm.SelListDblClick(Sender: TObject);
var
index: Integer;
begin
@ -612,13 +608,13 @@ begin
end;
procedure TRMatFrm.SelListSelectionChange(Sender: TObject; User: boolean);
procedure TRMatForm.SelListSelectionChange(Sender: TObject; User: boolean);
begin
UpdateBtnStates;
end;
procedure TRMatFrm.Stats(ANumVars, ANumCases: Integer; const AMeans, AVars, AStdDevs: DblDyneVec;
procedure TRMatForm.Stats(ANumVars, ANumCases: Integer; const AMeans, AVars, AStdDevs: DblDyneVec;
const AColLabels: StrDyneVec);
var
lReport: TStrings;
@ -628,23 +624,25 @@ begin
if MeansChk.Checked then
DynVectorPrint(AMeans, ANumVars, 'Means', AColLabels, ANumCases, lReport);
if MeansChk.Checked and (VarsChk.Checked or StdDevsChk.Checked) then
if VarsChk.Checked then
begin
if MeansChk.Checked then
begin
lReport.Add(DIVIDER_SMALL_AUTO);
lReport.Add('');
end;
if VarsChk.Checked then
DynVectorPrint(AVars, ANumVars, 'Variances', AColLabels, ANumCases, lReport);
if (MeansChk.Checked or VarsChk.Checked) and StdDevsChk.Checked then
begin
lReport.Add(DIVIDER_SMALL_AUTO);
lReport.Add('');
end;
if StdDevsChk.Checked then
begin
if (MeansChk.Checked or VarsChk.Checked) then
begin
lReport.Add(DIVIDER_SMALL_AUTO);
lReport.Add('');
end;
DynVectorPrint(AStdDevs, ANumVars, 'Standard Deviations', AColLabels, ANumCases, lReport);
end;
FStatsReportFrame.DisplayReport(lReport);
finally
@ -653,7 +651,7 @@ begin
end;
procedure TRMatFrm.UpdateBtnStates;
procedure TRMatForm.UpdateBtnStates;
begin
inherited;
@ -672,7 +670,22 @@ begin
end;
procedure TRMatFrm.VarCovar(ANumVars: Integer; const AColNoSelected: IntDyneVec;
function TRMatForm.Validate(out AMsg: String; out AControl: TWinControl): Boolean;
begin
Result := false;
if SelList.Items.Count = 0 then
begin
AMsg := 'No variable(s) selected.';
AControl := SelList;
exit;
end;
Result := true;
end;
procedure TRMatForm.VarCovar(ANumVars: Integer; const AColNoSelected: IntDyneVec;
const AMatrix: DblDyneMat; const AMeans, AVars, AStdDevs: DblDyneVec;
const ARowLabels, AColLabels: StrDyneVec);
var
@ -699,7 +712,7 @@ begin
end;
procedure TRMatFrm.VarListDblClick(Sender: TObject);
procedure TRMatForm.VarListDblClick(Sender: TObject);
var
index: Integer;
begin
@ -712,7 +725,8 @@ begin
end;
end;
procedure TRMatFrm.VarListSelectionChange(Sender: TObject; User: boolean);
procedure TRMatForm.VarListSelectionChange(Sender: TObject; User: boolean);
begin
UpdateBtnStates;
end;

View File

@ -183,7 +183,7 @@ end;
procedure TSensForm.Compute;
var
NoSelected, count, half, q, tp, low, hi, col: integer;
NoSelected, count, half, q, tp, low, hi: integer;
Values: DblDyneMat = nil;
Slopes: DblDyneMat = nil;
AvgSlopes: DblDyneMat = nil;
@ -268,15 +268,10 @@ begin
lReport.Add('');
lReport.Add(DIVIDER_SMALL_AUTO);
lReport.Add('');
if j < noselected then
begin
col := Selected[j];
lReport.Add('RESULTS FOR %s', [lTitle]);
end else
begin
col := 0;
if j < noSelected then
lReport.Add('RESULTS FOR %s', [lTitle])
else
lReport.Add('RESULTS FOR AVERAGED VALUES');
end;
lReport.Add('');
if (NoSelected > 1) and StandardizeChk.Checked then

View File

@ -721,9 +721,9 @@ end;
// Menu "Correlation" > "Product-Moment"
procedure TOS3MainFrm.mnuAnalysisCorrel_ProductMomentClick(Sender: TObject);
begin
if RMatFrm = nil then
Application.CreateForm(TRMatFrm, RMatFrm);
RMatFrm.ShowModal;
if RMatForm = nil then
Application.CreateForm(TRMatForm, RMatForm);
RMatForm.Show;
end;
// Menu "Correlation" > "Partial, Semipartial"

View File

@ -6,7 +6,7 @@ interface
uses
Classes, SysUtils, Forms, Controls, ComCtrls, ExtCtrls, StdCtrls, Dialogs,
PrintersDlgs, MainDM;
PrintersDlgs, MainDM, Utils;
type
@ -34,6 +34,7 @@ type
public
constructor Create(AOwner: TComponent); override;
procedure Clear; virtual;
procedure ClearBorderSpacings;
procedure DisplayReport(AReport: TStrings; Add: Boolean = false); virtual;
procedure UpdateBtnStates; virtual;
@ -73,6 +74,19 @@ begin
end;
procedure TReportFrame.ClearBorderSpacings;
begin
with BorderSpacing do
begin
Left := 0;
Top := 0;
Right := 0;
Bottom := 0;
Around := 0;
end;
end;
procedure TReportFrame.DisplayReport(AReport: TStrings; Add: Boolean = false);
var
maxLen: Integer;