LazStats: Some refactoring of ABRAnovaUnit.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7797 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-10-24 21:21:15 +00:00
parent ea551b66f3
commit 8bdda9097d
2 changed files with 241 additions and 222 deletions

View File

@ -311,6 +311,14 @@ inherited ABRAnovaForm: TABRAnovaForm
Left = 350
Height = 336
Width = 465
ActivePage = ReportPage
TabIndex = 0
inherited ReportPage: TTabSheet
Caption = 'ANOVA Results'
end
inherited ChartPage: TTabSheet
Caption = 'Charts'
end
end
object ListChartSource_AB: TListChartSource[3]
Left = 465

View File

@ -44,7 +44,7 @@ type
procedure BOutBtnClick(Sender: TObject);
procedure CInBtnClick(Sender: TObject);
procedure CListDblClick(Sender: TObject);
procedure CListSelectionChange(Sender: TObject; User: boolean);
procedure CListSelectionChange(Sender: TObject; {%H-}User: boolean);
procedure COutBtnClick(Sender: TObject);
procedure VarListDblClick(Sender: TObject);
private
@ -309,6 +309,7 @@ begin
if FBtnBC.Down then interaction := BC;
PlotMeans(interaction);
end;
ChartPage.TabVisible := PlotChk.Checked;
end;
finally
lReport.Free;
@ -344,18 +345,13 @@ var
begin
Result := false;
SetLength(ColNoSelected,NoVariables);
ACol := 0;
BCol := 0;
for i := 1 to NoVariables do
SetLength(ColNoSelected, NoVariables);
ACol := GetVariableIndex(OS3MainFrm.DataGrid, ACodesEdit.Text);
BCol := GetVariableIndex(OS3MainFrm.DataGrid, BCodesEdit.Text);
if ((ACol = -1) or (BCol = -1)) then
begin
cellstring := OS3MainFrm.DataGrid.Cells[i,0];
if (cellstring = ACodesEdit.Text) then ACol := i;
if (cellstring = BCodesEdit.Text) then BCol := i;
end;
if ( (ACol = 0) or (BCol = 0)) then
begin
MessageDlg('Select a variable for the A and B Variable Codes.', mtError, [mbOK], 0);
// This case should already have been caught, but anyway...
ErrorMsg('Select a variable for the A and B Variable Codes.');
exit;
end;
@ -386,21 +382,21 @@ begin
if (MaxCols > MaxRows) then MaxRows := MaxCols;
// allocate storage for arrays
SetLength(ASums,NoAGrps);
SetLength(Bsums,NoBGrps);
SetLength(Csums,NoCases);
SetLength(ABSums,NoAGrps,NoBGrps);
SetLength(ACSums,NoAGrps,NoSelected);
SetLength(BCSums,NoBGrps,NoSelected);
SetLength(AMatrix,MaxRows,MaxRows);
SetLength(SumPSqr,NoCases);
SetLength(Acnt,NoAGrps);
SetLength(Bcnt,NoBGrps);
SetLength(Ccnt,MaxRows);
SetLength(RowLabels,NoSelected);
SetLength(ColLabels,NoSelected);
SetLength(ABCSums,NoAGrps,NoBGrps,NoSelected);
SetLength(ABCNcnt,NoAGrps,NoBGrps,NoSelected);
SetLength(ASums, NoAGrps);
SetLength(Bsums, NoBGrps);
SetLength(Csums, NoCases);
SetLength(ABSums, NoAGrps, NoBGrps);
SetLength(ACSums, NoAGrps, NoSelected);
SetLength(BCSums, NoBGrps, NoSelected);
SetLength(AMatrix, MaxRows, MaxRows);
SetLength(SumPSqr, NoCases);
SetLength(Acnt, NoAGrps);
SetLength(Bcnt, NoBGrps);
SetLength(Ccnt, MaxRows);
SetLength(RowLabels, NoSelected);
SetLength(ColLabels, NoSelected);
SetLength(ABCSums, NoAGrps, NoBGrps, NoSelected);
SetLength(ABCNcnt, NoAGrps, NoBGrps, NoSelected);
// initialize arrays
for i := 0 to NoAGrps-1 do
@ -409,16 +405,16 @@ begin
Acnt[i] := 0;
for j := 0 to NoBGrps-1 do
begin
ABSums[i,j] := 0.0;
ABSums[i, j] := 0.0;
for k := 0 to NoSelected-1 do
begin
ABCSums[i,j,k] := 0.0;
ABCNcnt[i,j,k] := 0;
ABCSums[i, j, k] := 0.0;
ABCNcnt[i, j, k] := 0;
end;
end;
for j := 0 to NoSelected-1 do
begin
ACSums[i,j] := 0.0;
ACSums[i, j] := 0.0;
end;
end;
for i := 0 to NoBGrps-1 do
@ -427,7 +423,7 @@ begin
Bcnt[i] := 0;
for j := 0 to NoSelected-1 do
begin
BCSums[i,j] := 0.0;
BCSums[i, j] := 0.0;
end;
end;
for i := 0 to NoSelected-1 do
@ -435,7 +431,8 @@ begin
CSums[i] := 0.0;
Ccnt[i] := 0;
end;
for i := 0 to NoCases-1 do SumPSqr[i] := 0.0;
for i := 0 to NoCases-1 do
SumPSqr[i] := 0.0;
GrandTotal := 0.0;
TotalN := 0;
SumXSqr := 0.0;
@ -450,6 +447,9 @@ begin
if TObject(Sender) is TToolButton then
TToolButton(Sender).Down := true;
if not PlotChk.Checked then
exit;
if FBtnAB.Down then
interaction := AB
else if FBtnAC.Down then
@ -458,8 +458,10 @@ begin
interaction := BC;
PlotMeans(interaction);
UpdateBtnStates;
end;
procedure TABRAnovaForm.GetData;
var
i, j, SubjA, SubjB: integer;
@ -501,157 +503,161 @@ end;
procedure TABRAnovaForm.Calculate;
var
SumA, SumB, SumC, SumAB, SumAC, SumBC, SumABC : double;
Term1, Term2, Term3, Term4, Term5, Term6, Term7, Term8, Term9, Term10 : double;
i, j, k, CountA, CountB, CountC: integer;
SumA, SumB, SumC, SumAB, SumAC, SumBC, SumABC : double;
Term1, Term2, Term3, Term4, Term5, Term6, Term7, Term8, Term9, Term10 : double;
i, j, k, CountA, CountB, CountC: integer;
begin
Term1 := (GrandTotal * GrandTotal) / TotalN;
Term2 := SumXSqr;
Term3 := 0.0;
countA := 0;
for i := 1 to NoAGrps do
Term1 := (GrandTotal * GrandTotal) / TotalN;
Term2 := SumXSqr;
Term3 := 0.0;
countA := 0;
for i := 0 to NoAGrps-1 do
begin
SumA := 0.0;
countA := countA + Acnt[i];
for j := 0 to NoBGrps-1 do
for k := 0 to NoSelected-1 do SumA := SumA + ABCSums[i, j, k];
ASums[i] := ASums[i] + SumA;
Term3 := Term3 + sqr(SumA);
end;
Term3 := Term3 / (NInGrp * NoBGrps * NoSelected);
Term4 := 0;
countB := 0;
for j := 0 to NoBGrps-1 do
begin
SumB := 0.0;
CountB := CountB + Bcnt[j];
for i := 0 to NoAGrps-1 do
for k := 0 to NoSelected-1 do SumB := SumB + ABCSums[i, j, k];
BSums[j] := BSums[j] + SumB;
Term4 := Term4 + sqr(SumB);
end;
Term4 := Term4 / (NInGrp * NoAGrps * NoSelected);
Term5 := 0.0;
countC := 0;
for k := 0 to NoSelected-1 do
begin
SumC := 0.0;
CountC := CountC + Ccnt[k];
for i := 0 to NoAGrps-1 do
for j := 0 to NoBGrps-1 do SumC := SumC + ABCSums[i, j, k];
CSums[k] := CSums[k] + SumC;
Term5 := Term5 + sqr(SumC);
end;
Term5 := Term5 / (NInGrp * NoAGrps * NoBGrps);
Term6 := 0.0;
for i := 0 to NoAGrps-1 do
begin
for j := 0 to NoBGrps-1 do
begin
SumA := 0.0;
countA := countA + Acnt[i-1];
for j := 1 to NoBGrps do
for k := 1 to NoSelected do SumA := SumA + ABCSums[i-1,j-1,k-1];
ASums[i-1] := ASums[i-1] + SumA;
Term3 := Term3 + (SumA * SumA);
SumAB := 0.0;
//CountAB := CountAB + ABcnt^[i,j];
for k := 0 to NoSelected-1 do SumAB := SumAB + ABCSums[i, j, k];
ABSums[i, j] := ABSums[i, j] + SumAB;
Term6 := Term6 + sqr(SumAB);
end;
Term3 := Term3 / (NinGrp * NoBGrps * NoSelected);
end;
Term6 := Term6 / (NInGrp * NoSelected);
Term4 := 0;
countB := 0;
for j := 1 to NoBGrps do
Term7 := 0.0;
for i := 0 to NoAGrps-1 do
begin
for k := 0 to NoSelected-1 do
begin
SumB := 0.0;
CountB := CountB + Bcnt[j-1];
for i := 1 to NoAGrps do
for k := 1 to NoSelected do SumB := SumB + ABCSums[i-1,j-1,k-1];
BSums[j-1] := BSums[j-1] + SumB;
Term4 := Term4 + (SumB * SumB);
SumAC := 0.0;
for j := 0 to NoBGrps-1 do SumAC := SumAC + ABCSums[i, j, k];
ACSums[i, k] := ACSums[i, k] + SumAC;
Term7 := Term7 + sqr(SumAC);
end;
Term4 := Term4 / (NinGrp * NoAGrps * NoSelected);
end;
Term7 := Term7 / (NInGrp * NoBGrps);
Term5 := 0.0;
countC := 0;
for k := 1 to NoSelected do
Term8 := 0.0;
for j := 0 to NoBGrps-1 do
begin
for k := 0 to NoSelected-1 do
begin
SumC := 0.0;
CountC := CountC + Ccnt[k-1];
for i := 1 to NoAGrps do
for j := 1 to NoBGrps do SumC := SumC + ABCSums[i-1,j-1,k-1];
CSums[k-1] := CSums[k-1] + SumC;
Term5 := Term5 + (SumC * SumC);
SumBC := 0.0;
for i := 0 to NoAGrps-1 do SumBC := SumBC + ABCSums[i, j, k];
BCSums[j, k] := BCSums[j, k] + SumBC;
Term8 := Term8 + sqr(SumBC);
end;
Term5 := Term5 / (NinGrp * NoAGrps * NoBGrps);
end;
Term8 := Term8 / (NInGrp * NoAGrps);
Term6 := 0.0;
for i := 1 to NoAGrps do
Term9 := 0.0;
for i := 0 to NoAGrps-1 do
begin
for j := 0 to NoBGrps-1 do
begin
for j := 1 to NoBGrps do
begin
SumAB := 0.0;
//CountAB := CountAB + ABcnt^[i,j];
for k := 1 to NoSelected do SumAB := SumAB + ABCSums[i-1,j-1,k-1];
ABSums[i-1,j-1] := ABSums[i-1,j-1] + SumAB;
Term6 := Term6 + (SumAB * SumAB);
end;
for k := 0 to NoSelected-1 do
begin
SumABC := ABCSums[i, j, k];
//CountABC := CountABC + ABCNcnt[i,j,k];
Term9 := Term9 + sqr(SumABC);
end;
end;
Term6 := Term6 / (NinGrp * NoSelected);
end;
Term9 := Term9 / NInGrp;
Term7 := 0.0;
for i := 1 to NoAGrps do
begin
for k := 1 to NoSelected do
begin
SumAC := 0.0;
for j := 1 to NoBGrps do SumAC := SumAC + ABCSums[i-1,j-1,k-1];
ACSums[i-1,k-1] := ACSums[i-1,k-1] + SumAC;
Term7 := Term7 + (SumAC * SumAC);
end;
end;
Term7 := Term7 / (NinGrp * NoBGrps);
Term10 := 0.0;
for i := 0 to NoCases-1 do Term10 := Term10 + SumPSqr[i];
Term10 := Term10 / NoSelected;
Term8 := 0.0;
for j := 1 to NoBGrps do
begin
for k := 1 to NoSelected do
begin
SumBC := 0.0;
for i := 1 to NoAGrps do SumBC := SumBC + ABCSums[i-1,j-1,k-1];
BCSums[j-1,k-1] := BCSums[j-1,k-1] + SumBC;
Term8 := Term8 + (SumBC * SumBC);
end;
end;
Term8 := Term8 / (NinGrp * NoAGrps);
//Get DF, SS, MS, F and Probabilities
DFBetween := (NInGrp * NoAGrps * NoBGrps) - 1.0;
DFA := NoAGrps - 1.0;
DFB := NoBGrps - 1.0;
DFAB := (NoAGrps - 1.0) * (NoBGrps - 1.0);
DFerrorBetween := (NoAGrps * NoBGrps) * (NInGrp - 1.0);
DFWithin := (NInGrp * NoAGrps * NoBGrps) * (NoSelected - 1.0);
DFC := NoSelected - 1.0;
DFAC := (NoAGrps - 1.0) * (NoSelected - 1.0);
DFBC := (NoBGrps - 1.0) * (NoSelected - 1.0);
DFABC := (NoAGrps - 1.0) * (NoBGrps - 1.0) * (NoSelected - 1.0);
DFerrorWithin := NoAGrps * NoBGrps * (NInGrp - 1.0) * (NoSelected - 1.0);
Term9 := 0.0;
for i := 1 to NoAGrps do
begin
for j := 1 to NoBGrps do
begin
for k := 1 to NoSelected do
begin
SumABC := ABCSums[i-1,j-1,k-1];
//CountABC := CountABC + ABCNcnt[i,j,k];
Term9 := Term9 + (SumABC * SumABC);
end;
end;
end;
Term9 := Term9 / NinGrp;
SSBetweenSubjects := Term10 - Term1;
SSA := Term3 - Term1;
SSB := Term4 - Term1;
SSAB := Term6 - Term3 - Term4 + Term1;
SSerrorBetween := Term10 - Term6;
SSWithinSubjects := Term2 - Term10;
SSC := Term5 - Term1;
SSAC := Term7 - Term3 - Term5 + Term1;
SSBC := Term8 - Term4 - Term5 + Term1;
SSABC := Term9 - Term6 - Term7 - Term8 + Term3 + Term4 + Term5 - Term1;
SSerrorWithin := Term2 - Term9 - Term10 + Term6;
Term10 := 0.0;
for i := 1 to NoCases do Term10 := Term10 + SumPSqr[i-1];
Term10 := Term10 / NoSelected;
MSA := SSA / DFA;
MSB := SSB / DFB;
MSAB := SSAB / DFAB;
MSerrorBetween := SSerrorBetween / DFerrorBetween;
MSC := SSC / DFC;
MSAC := SSAC / DFAC;
MSBC := SSBC / DFBC;
MSABC := SSABC / DFABC;
MSerrorWithin := SSerrorWithin / DFerrorWithin;
//Get DF, SS, MS, F and Probabilities
DFBetween := (NinGrp * NoAGrps * NoBGrps) - 1.0;
DFA := NoAGrps - 1.0;
DFB := NoBGrps - 1.0;
DFAB := (NoAGrps - 1.0) * (NoBGrps - 1.0);
DFerrorBetween := (NoAGrps * NoBGrps) * (NinGrp - 1.0);
DFWithin := (NinGrp * NoAGrps * NoBGrps) * (NoSelected - 1.0);
DFC := NoSelected - 1.0;
DFAC := (NoAGrps - 1.0) * (NoSelected - 1.0);
DFBC := (NoBGrps - 1.0) * (NoSelected - 1.0);
DFABC := (NoAGrps - 1.0) * (NoBGrps - 1.0) * (NoSelected - 1.0);
DFerrorWithin := NoAGrps * NoBGrps * (NinGrp - 1.0) * (NoSelected - 1.0);
SSBetweenSubjects := Term10 - Term1;
SSA := Term3 - Term1;
SSB := Term4 - Term1;
SSAB := Term6 - Term3 - Term4 + Term1;
SSerrorBetween := Term10 - Term6;
SSWithinSubjects := Term2 - Term10;
SSC := Term5 - Term1;
SSAC := Term7 - Term3 - Term5 + Term1;
SSBC := Term8 - Term4 - Term5 + Term1;
SSABC := Term9 - Term6 - Term7 - Term8 + Term3 + Term4 + Term5 - Term1;
SSerrorWithin := Term2 - Term9 - Term10 + Term6;
MSA := SSA / DFA;
MSB := SSB / DFB;
MSAB := SSAB / DFAB;
MSerrorBetween := SSerrorBetween / DFerrorBetween;
MSC := SSC / DFC;
MSAC := SSAC / DFAC;
MSBC := SSBC / DFBC;
MSABC := SSABC / DFABC;
MSerrorWithin := SSerrorWithin / DFerrorWithin;
FA := MSA / MSerrorBetween;
FB := MSB / MSerrorBetween;
FAB := MSAB / MSerrorBetween;
FC := MSC / MSerrorWithin;
FAC := MSAC / MSerrorWithin;
FBC := MSBC / MSerrorWithin;
FABC := MSABC / MSerrorWithin;
ProbA := ProbF(FA,DFA,DFerrorBetween);
ProbB := ProbF(FB,DFB,DFerrorBetween);
ProbAB := ProbF(FAB,DFAB,DFerrorBetween);
ProbC := ProbF(FC,DFC,DFerrorWithin);
ProbAC := ProbF(FAC,DFAC,DFerrorWithin);
ProbBC := ProbF(FBC,DFBC,DFerrorWithin);
ProbABC := ProbF(FABC,DFABC,DFerrorWithin);
FA := MSA / MSerrorBetween;
FB := MSB / MSerrorBetween;
FAB := MSAB / MSerrorBetween;
FC := MSC / MSerrorWithin;
FAC := MSAC / MSerrorWithin;
FBC := MSBC / MSerrorWithin;
FABC := MSABC / MSerrorWithin;
ProbA := ProbF(FA, DFA, DFerrorBetween);
ProbB := ProbF(FB, DFB, DFerrorBetween);
ProbAB := ProbF(FAB, DFAB, DFerrorBetween);
ProbC := ProbF(FC, DFC, DFerrorWithin);
ProbAC := ProbF(FAC, DFAC, DFerrorWithin);
ProbBC := ProbF(FBC, DFBC, DFerrorWithin);
ProbABC := ProbF(FABC, DFABC, DFerrorWithin);
end;
procedure TABRAnovaForm.Summarize(AReport: TStrings);
@ -757,8 +763,10 @@ procedure TABRAnovaForm.BoxTests(AReport: TStrings);
const
EPS = 1E-35;
var
XVector, XSums : DblDyneVec;
DetMat, MeanCovMat : DblDyneMat;
XVector: DblDyneVec = nil;
XSums: DblDyneVec = nil;
DetMat: DblDyneMat = nil;
MeanCovMat: DblDyneMat = nil;
M1, M2, Sum1, C1, C2, f1, f2, chi, ProbChi, X, avgvar,avgcov : double;
ColHeader, LabelStr : string;
Title : string;
@ -766,18 +774,18 @@ var
errorcode : boolean = false; // to silence the compiler
Det: Double = 0.0;
begin
SetLength(XVector,NoSelected);
SetLength(XSums,NoSelected);
SetLength(DetMat,NoSelected+1,NoSelected+1);
SetLength(MeanCovMat,NoSelected+1,NoSelected+1);
SetLength(PooledMat,NoSelected+1,NoSelected+1);
SetLength(XVector, NoSelected);
SetLength(XSums, NoSelected);
SetLength(DetMat, NoSelected+1, NoSelected+1);
SetLength(MeanCovMat, NoSelected+1, NoSelected+1);
SetLength(PooledMat, NoSelected+1, NoSelected+1);
for i := 1 to NoSelected do
for i := 0 to NoSelected-1 do
begin
LabelStr := format('C%d',[i]);
RowLabels[i-1] := LabelStr;
ColLabels[i-1] := LabelStr;
for j := 1 to NoSelected do PooledMat[i-1,j-1] := 0.0;
LabelStr := Format('C%d', [i+1]);
RowLabels[i] := LabelStr;
ColLabels[i] := LabelStr;
for j := 0 to NoSelected-1 do PooledMat[i, j] := 0.0;
end;
// get variance-covariance AMatrix for the repeated measures within
@ -794,10 +802,10 @@ begin
ColHeader := 'C Levels';
// initialize AMatrix for this combination
for k := 1 to NoSelected do
for k := 0 to NoSelected-1 do
begin
for l := 1 to NoSelected do AMatrix[k-1,0] := 0.0;
XSums[k-1] := 0.0;
for L := 0 to NoSelected-1 do AMatrix[k,0] := 0.0;
XSums[k] := 0.0;
end;
// read data and add to covariances
@ -811,35 +819,35 @@ begin
SubjB := SubjB - MinB + 1;
if ((SubjA <> i)or(SubjB <> j)) then
continue;
for k := 1 to NoSelected do
for k := 0 to NoSelected-1 do
begin
X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[k-1], row]));
XVector[k-1] := X;
XSums[k-1] := XSums[k-1] + X;
X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNoSelected[k], row]));
XVector[k] := X;
XSums[k] := XSums[k] + X;
end;
for k := 1 to NoSelected do
for k := 0 to NoSelected-1 do
begin
for l := 1 to NoSelected do
AMatrix[k-1,l-1] := AMatrix[k-1,l-1] + (XVector[k-1] * XVector[l-1]);
for L := 0 to NoSelected-1 do
AMatrix[k, L] := AMatrix[k, L] + (XVector[k] * XVector[L]);
end;
end; // next case
// convert sums of cross-products to variance-covariance
for k := 1 to NoSelected do
for k := 0 to NoSelected-1 do
begin
for l := 1 to NoSelected do
for L := 0 to NoSelected-1 do
begin
AMatrix[k-1,l-1] := AMatrix[k-1,l-1] - (XSums[k-1]*XSums[l-1] / NinGrp);
AMatrix[k-1,l-1] := AMatrix[k-1,l-1] / (NinGrp - 1);
PooledMat[k-1,l-1] := PooledMat[k-1,l-1] + AMatrix[k-1,l-1];
AMatrix[k, L] := AMatrix[k, L] - (XSums[k]*XSums[L] / NInGrp);
AMatrix[k, L] := AMatrix[k, L] / (NInGrp - 1);
PooledMat[k, L] := PooledMat[k, L] + AMatrix[k, L];
end;
end;
MatPrint(AMatrix,NoSelected,NoSelected,Title,RowLabels,ColLabels,NoCases, AReport);
for k := 1 to NoSelected do
for l := 1 to NoSelected do
DetMat[k-1,l-1] := AMatrix[k-1,l-1];
for k := 0 to NoSelected-1 do
for L := 0 to NoSelected-1 do
DetMat[k, L] := AMatrix[k, L];
Determ(DetMat,NoSelected, NoSelected, Det, errorcode);
// if (Det > 0.0e35) then // wp: What's this???
if Det > EPS then
@ -850,21 +858,20 @@ begin
end; // next A level
// get pooled variance-covariance
for i := 1 to NoSelected do
for j := 1 to NoSelected do
PooledMat[i-1,j-1] := PooledMat[i-1,j-1] / (NoAGrps * NoBGrps);
for i := 0 to NoSelected-1 do
for j := 0 to NoSelected-1 do
PooledMat[i, j] := PooledMat[i, j] / (NoAGrps * NoBGrps);
Title := 'Pooled Variance-Covariance AMatrix';
MatPrint(PooledMat,NoSelected,NoSelected,Title,RowLabels,ColLabels,NoCases, AReport);
MatPrint(PooledMat, NoSelected, NoSelected, Title, RowLabels, ColLabels, NoCases, AReport);
// calculate F-Max for variance homogeneity
// calculate Box test for covariance homogeneity
for i := 1 to NoSelected do
for j := 1 to NoSelected do
DetMat[i-1,j-1] := PooledMat[i-1,j-1];
Determ(DetMat,NoSelected,NoSelected,Det,errorcode);
//if (Det > 0.0e35) then
for i := 0 to NoSelected-1 do
for j := 0 to NoSelected-1 do
DetMat[i, j] := PooledMat[i, j];
Determ(DetMat, NoSelected, NoSelected, Det, errorcode);
if (Det > EPS) then
begin
M1 := (NinGrp*NoAGrps*NoBGrps * ln(Det)) - Sum1;
@ -876,12 +883,12 @@ begin
ProbChi := 1.0 - chisquaredprob(chi,round(f1));
AReport.Add('Test that sample covariances are from same population:');
AReport.Add('');
AReport.Add('Chi-Squared = %0.3f with %d degrees of freedom.', [chi,round(f1)]);
AReport.Add('Probability of > Chi-Squared = %0.3f', [ProbChi]);
AReport.Add('Chi-Squared %0.3f with %d degrees of freedom.', [chi,round(f1)]);
AReport.Add('Probability of > Chi-Squared: %0.3f', [ProbChi]);
AReport.Add('');
AReport.Add('');
end else
MessageDlg('Determinant of a pooled covariance AMatrix near 0.', mtError, [mbOK], 0);
ErrorMsg('Determinant of a pooled covariance AMatrix near 0.');
// test that pooled covariance has form of equal variances and equal covariances
//if (Det > 0.0e35) then // determinant of pooled covariance > 0
@ -889,16 +896,16 @@ begin
begin
M2 := Det;
avgvar := 0.0;
for i := 1 to NoSelected do
avgvar := avgvar + PooledMat[i-1,i-1];
for i := 0 to NoSelected-1 do
avgvar := avgvar + PooledMat[i, i];
avgvar := avgvar / NoSelected;
avgcov := 0.0;
for i := 1 to NoSelected-1 do
for j := i+1 to NoSelected do
avgcov := avgcov + PooledMat[i-1,j-1];
avgcov := avgcov / (NoSelected * (NoSelected - 1) / 2);
for i := 1 to NoSelected do
DetMat[i-1,i-1] := avgvar;
for i := 0 to NoSelected do
DetMat[i, i] := avgvar;
for i := 1 to NoSelected-1 do
begin
for j := i+1 to NoSelected do
@ -908,7 +915,6 @@ begin
end;
end;
Determ(DetMat,NoSelected,NoSelected,Det,errorcode);
// if (Det > 0.0e35) then
if (Det > EPS) then
begin
N := NoAGrps * NoBGrps * NinGrp;
@ -920,16 +926,15 @@ begin
C2 := C2 / (6 * (N - p) * (NoSelected - 1) * quad);
f2 := quad / 2;
chi := (1.0 - C2) * M2;
ProbChi := 1.0 - chisquaredprob(chi,round(f2));
ProbChi := 1.0 - ChiSquaredProb(chi, round(f2));
AReport.Add('Test that variance-covariances AMatrix has equal variances and equal covariances:');
AReport.Add('');
AReport.Add('Chi-Squared := %0.3f with %d degrees of freedom.', [chi, round(f2)]);
AReport.Add('Probability of > Chi-Squared := %.3f', [ProbChi]);
AReport.Add('');
end else
MessageDlg('Determinant of theoretical covariance AMatrix near zero.', mtWarning, [mbOK], 0);
ErrorMsg('Determinant of theoretical covariance AMatrix near zero.');
end;
// OutputFrm.ShowModal;
// cleanup
PooledMat := nil;
@ -943,16 +948,15 @@ end;
procedure TABRAnovaForm.PlotMeans(AInteraction: TInteraction);
const
X_TITLE: array[TInteraction] of string = (
'B TREATMENT GROUP',
'C TREATMENT (WITHIN SUBJECTS) GROUP',
'C TREATMENT (WITHIN SUBJECTS) GROUP'
'B Treatment Group',
'C Treatment (within subjects) Group',
'C Treatment (within subjects) Group'
);
SERIES_TITLE: array[TInteraction] of string = (
'A%d',
'A%d',
'B%d'
);
var
idx: Integer;
item: PChartDataItem;
@ -1032,14 +1036,21 @@ var
begin
inherited;
ListChartSource_AB.Clear;
ListChartSource_AC.Clear;
ListChartSource_BC.Clear;
ChartPage.TabVisible := false;
VarList.Items.Clear;
CList.Items.Clear;
ACodesEdit.Text := '';
BCodesEdit.Text := '';
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i, 0]);
PlotChk.Checked := false;
TestChk.Checked := false;
UpdateBtnStates;
end;