LazStats: More refactoring of blkanovaunit.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7488 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-06-23 17:41:18 +00:00
parent f8a14ebfe1
commit 6a36491ee5

View File

@@ -97,7 +97,7 @@ type
FF1, FF2, FF1F2, ProbF1, ProbF2, ProbF3, ProbF1F2, ProbF1F3 : double; FF1, FF2, FF1F2, ProbF1, ProbF2, ProbF3, ProbF1F2, ProbF1F3 : double;
FF3, FF2F3, FF1F3, FF1F2F3, ProbF2F3, ProbF1F2F3 : double; FF3, FF2F3, FF1F3, FF1F2F3, ProbF2F3, ProbF1F2F3 : double;
DepVarCol, F1Col, F2Col, F3Col, Nf1cells, Nf2cells, Nf3cells : integer; DepVarCol, F1Col, F2Col, F3Col, Nf1cells, Nf2cells, Nf3cells : integer;
MeanDep, MeanF1, MeanF2, MeanF3, X : double; MeanDep, MeanF1, MeanF2, MeanF3: double;
minf1, maxf1, minf2, maxf2, minf3, maxf3, nofactors, totcells : integer; minf1, maxf1, minf2, maxf2, minf3, maxf3, nofactors, totcells : integer;
cellcnts : DblDyneVec; // array of cell counts cellcnts : DblDyneVec; // array of cell counts
cellvars : DblDyneVec; // arrray of cell sums of squares then variances cellvars : DblDyneVec; // arrray of cell sums of squares then variances
@@ -153,7 +153,7 @@ var
implementation implementation
uses uses
Math; Math, Utils;
{ TBlksAnovaFrm } { TBlksAnovaFrm }
@@ -244,18 +244,7 @@ var
msg: String; msg: String;
C: TWinControl; C: TWinControl;
lReport: TStrings; lReport: TStrings;
procedure CleanIt;
begin begin
cellcnts := nil;
cellvars := nil;
cellsums := nil;
ColNoSelected := nil;
end;
begin
lReport := TStringList.Create;
try
// initialize values // initialize values
SetLength(ColNoSelected, NoVariables); SetLength(ColNoSelected, NoVariables);
DepVarCol := 0; DepVarCol := 0;
@@ -286,6 +275,8 @@ begin
minf3 := 0; minf3 := 0;
maxf3 := 0; maxf3 := 0;
lReport := TStringList.Create;
try
// Get column numbers of dependent variable and factors // Get column numbers of dependent variable and factors
for i := 1 to NoVariables do for i := 1 to NoVariables do
begin begin
@@ -318,12 +309,13 @@ begin
if not Validate(msg, C, DepVarCol, F1Col, F2Col, F3Col) then begin if not Validate(msg, C, DepVarCol, F1Col, F2Col, F3Col) then begin
C.SetFocus; C.SetFocus;
MessageDlg(msg, mtError, [mbOK], 0); ErrorMsg(msg);
exit; exit;
end; end;
if F2Col = 0 then nofactors := 1 else nofactors := 2; if F2Col = 0 then nofactors := 1 else nofactors := 2;
if F3Col <> 0 then nofactors := 3; if F3Col <> 0 then nofactors := 3;
allAlpha := StrToFloat(OverAllalpha.Text); allAlpha := StrToFloat(OverAllalpha.Text);
PostHocAlpha := StrToFloat(PostAlpha.Text); PostHocAlpha := StrToFloat(PostAlpha.Text);
@@ -365,11 +357,12 @@ begin
Bonferroni(cellsums, cellcnts, cellvars, minf1, maxf1, posthocAlpha, lReport); Bonferroni(cellsums, cellcnts, cellvars, minf1, maxf1, posthocAlpha, lReport);
if OrthoContrasts.Checked then if OrthoContrasts.Checked then
Contrasts(MSErr, DFErr, cellsums, cellcnts, minf1, maxf1, 0.05, lReport); Contrasts(MSErr, DFErr, cellsums, cellcnts, minf1, maxf1, 0.05, lReport);
//OutputFrm.ShowModal; if BrownForsythe.Checked then
if (PlotMeans.Checked) or (Plot2DLines.Checked) or (Plot3DLines.Checked) then BrownForsytheOneWay(lReport);
if Welch.Checked then
WelchOneWay(lReport);
if PlotMeans.Checked or Plot2DLines.Checked or Plot3DLines.Checked then
OneWayPlot; OneWayPlot;
if BrownForsythe.Checked then BrownForsytheOneWay(lReport);
if Welch.Checked then WelchOneWay(lReport);
end; end;
2 : // two-way anova 2 : // two-way anova
@@ -389,10 +382,10 @@ begin
begin begin
TwoWayTable(lReport); TwoWayTable(lReport);
TwoWayContrasts(lReport); TwoWayContrasts(lReport);
//OutputFrm.ShowModal;
if PlotMeans.Checked or Plot2DLines.Checked or Plot3DLines.Checked then if PlotMeans.Checked or Plot2DLines.Checked or Plot3DLines.Checked then
TwoWayPlot; TwoWayPlot;
end; end;
OrdMeansB := nil; OrdMeansB := nil;
OrdMeansA := nil; OrdMeansA := nil;
ColCount := nil; ColCount := nil;
@@ -420,14 +413,15 @@ begin
SetLength(ncnt, Nf1cells, Nf2cells, Nf3cells); SetLength(ncnt, Nf1cells, Nf2cells, Nf3cells);
Calc3Way; Calc3Way;
if not CompError then if not CompError then
begin begin
ThreeWayTable(lReport); ThreeWayTable(lReport);
ThreeWayContrasts(lReport); ThreeWayContrasts(lReport);
//OutputFrm.ShowModal;
if (PlotMeans.Checked) or (Plot2DLines.Checked) or (Plot3DLines.Checked) then if (PlotMeans.Checked) or (Plot2DLines.Checked) or (Plot3DLines.Checked) then
ThreeWayPlot; ThreeWayPlot;
end; end;
ncnt := nil; ncnt := nil;
wx2 := nil; wx2 := nil;
wsum := nil; wsum := nil;
@@ -447,7 +441,10 @@ begin
finally finally
lReport.Free; lReport.Free;
CleanIt; cellcnts := nil;
cellvars := nil;
cellsums := nil;
ColNoSelected := nil;
end; end;
end; end;
@@ -539,6 +536,10 @@ procedure TBlksAnovaFrm.GetLevels;
var var
i: integer; i: integer;
begin begin
Nf1cells := 0;
Nf2Cells := 0;
Nf3Cells := 0;
minf1 := MaxInt; minf1 := MaxInt;
maxf1 := -MaxInt; maxf1 := -MaxInt;
for i := 1 to NoCases do for i := 1 to NoCases do
@@ -586,6 +587,7 @@ end;
procedure TBlksAnovaFrm.Calc1Way; procedure TBlksAnovaFrm.Calc1Way;
var var
i: integer; i: integer;
X, X2: Double;
begin begin
CompError := false; CompError := false;
@@ -595,12 +597,13 @@ begin
if not GoodRecord(i,NoSelected,ColNoSelected) then continue; if not GoodRecord(i,NoSelected,ColNoSelected) then continue;
intvalue := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F1Col,i]))); intvalue := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F1Col,i])));
X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[DepVarCol,i])); X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[DepVarCol,i]));
X := X*X;
intvalue := intvalue - minf1 + 1; intvalue := intvalue - minf1 + 1;
cellcnts[intvalue-1] := cellcnts[intvalue-1] + 1; cellcnts[intvalue-1] := cellcnts[intvalue-1] + 1;
cellsums[intvalue-1] := cellsums[intvalue-1] + X; cellsums[intvalue-1] := cellsums[intvalue-1] + X;
cellvars[intvalue-1] := cellvars[intvalue-1] + (X * X); cellvars[intvalue-1] := cellvars[intvalue-1] + X2;
MeanDep := MeanDep + X; MeanDep := MeanDep + X;
SSDep := SSDep + (X * X); SSDep := SSDep + X2;
N := N + 1; N := N + 1;
end; end;
@@ -756,7 +759,7 @@ var
i, j : integer; i, j : integer;
grpA, grpB : integer; grpA, grpB : integer;
Constant, RowsTotCnt, ColsTotCnt, SSCells : double; Constant, RowsTotCnt, ColsTotCnt, SSCells : double;
X, X2: Double;
begin begin
CompError := false; CompError := false;
@@ -792,17 +795,18 @@ begin
grpA := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F1Col,i]))); grpA := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F1Col,i])));
grpB := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F2Col,i]))); grpB := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F2Col,i])));
X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[DepVarCol,i])); X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[DepVarCol,i]));
X := X*X;
grpA := grpA - minf1 + 1; grpA := grpA - minf1 + 1;
grpB := grpB - minf2 + 1; grpB := grpB - minf2 + 1;
counts[grpA-1,grpB-1] := counts[grpA-1,grpB-1] + 1; counts[grpA-1,grpB-1] := counts[grpA-1,grpB-1] + 1;
sums[grpA-1,grpB-1] := sums[grpA-1,grpB-1] + X; sums[grpA-1,grpB-1] := sums[grpA-1,grpB-1] + X;
vars[grpA-1,grpB-1] := vars[grpA-1,grpB-1] + (X * X); vars[grpA-1,grpB-1] := vars[grpA-1,grpB-1] + X2;
RowSums[GrpA-1] := RowSums[GrpA-1] + X; RowSums[GrpA-1] := RowSums[GrpA-1] + X;
ColSums[GrpB-1] := ColSums[GrpB-1] + X; ColSums[GrpB-1] := ColSums[GrpB-1] + X;
RowCount[GrpA-1] := RowCount[GrpA-1] + 1.0; RowCount[GrpA-1] := RowCount[GrpA-1] + 1.0;
ColCount[GrpB-1] := ColCount[GrpB-1] + 1.0; ColCount[GrpB-1] := ColCount[GrpB-1] + 1.0;
MeanDep := MeanDep + X; MeanDep := MeanDep + X;
SSDep := SSDep + (X * X); SSDep := SSDep + X2;
N := N + 1; N := N + 1;
end; end;
@@ -1161,7 +1165,7 @@ var
grpA, grpB, grpC : integer; grpA, grpB, grpC : integer;
Constant, RowsTotCnt, ColsTotCnt, SlcsTotCnt, SSCells : double; Constant, RowsTotCnt, ColsTotCnt, SlcsTotCnt, SSCells : double;
p, n2 : double; p, n2 : double;
X, X2: Double;
begin begin
CompError := false; CompError := false;
@@ -1169,6 +1173,7 @@ begin
NoGrpsA := maxf1 - minf1 + 1; NoGrpsA := maxf1 - minf1 + 1;
NoGrpsB := maxf2 - minf2 + 1; NoGrpsB := maxf2 - minf2 + 1;
NoGrpsC := maxf3 - minf3 + 1; NoGrpsC := maxf3 - minf3 + 1;
for i := 0 to NoGrpsA-1 do for i := 0 to NoGrpsA-1 do
begin begin
RowSums[i] := 0.0; RowSums[i] := 0.0;
@@ -1183,16 +1188,19 @@ begin
end; end;
end; end;
end; end;
for i := 0 to NoGrpsB-1 do for i := 0 to NoGrpsB-1 do
begin begin
ColCount[i] := 0.0; ColCount[i] := 0.0;
ColSums[i] := 0.0; ColSums[i] := 0.0;
end; end;
for i := 0 to NoGrpsC-1 do for i := 0 to NoGrpsC-1 do
begin begin
SlcCount[i] := 0.0; SlcCount[i] := 0.0;
SlcSums[i] := 0.0; SlcSums[i] := 0.0;
end; end;
N := 0; N := 0;
MeanDep := 0.0; MeanDep := 0.0;
SSDep := 0.0; SSDep := 0.0;
@@ -1216,12 +1224,13 @@ begin
grpB := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F2Col,i]))); grpB := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F2Col,i])));
grpC := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F3Col,i]))); grpC := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F3Col,i])));
X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[DepVarCol,i])); X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[DepVarCol,i]));
X2 := X*X;
grpA := grpA - minf1 + 1; grpA := grpA - minf1 + 1;
grpB := grpB - minf2 + 1; grpB := grpB - minf2 + 1;
grpC := grpC - minf3 + 1; grpC := grpC - minf3 + 1;
ncnt[grpA-1,grpB-1,grpC-1] := ncnt[grpA-1,grpB-1,grpC-1] + 1; ncnt[grpA-1,grpB-1,grpC-1] := ncnt[grpA-1,grpB-1,grpC-1] + 1;
wsum[grpA-1,grpB-1,grpC-1] := wsum[grpA-1,grpB-1,grpc-1] + X; wsum[grpA-1,grpB-1,grpC-1] := wsum[grpA-1,grpB-1,grpc-1] + X;
wx2[grpA-1,grpB-1,grpC-1] := wx2[grpA-1,grpB-1,grpC-1] + (X * X); wx2[grpA-1,grpB-1,grpC-1] := wx2[grpA-1,grpB-1,grpC-1] + X2;
RowSums[GrpA-1] := RowSums[GrpA-1] + X; RowSums[GrpA-1] := RowSums[GrpA-1] + X;
ColSums[GrpB-1] := ColSums[GrpB-1] + X; ColSums[GrpB-1] := ColSums[GrpB-1] + X;
SlcSums[GrpC-1] := SlcSums[GrpC-1] + X; SlcSums[GrpC-1] := SlcSums[GrpC-1] + X;
@@ -1229,12 +1238,14 @@ begin
ColCount[GrpB-1] := ColCount[GrpB-1] + 1.0; ColCount[GrpB-1] := ColCount[GrpB-1] + 1.0;
SlcCount[GrpC-1] := SlcCount[GrpC-1] + 1.0; SlcCount[GrpC-1] := SlcCount[GrpC-1] + 1.0;
MeanDep := MeanDep + X; MeanDep := MeanDep + X;
SSDep := SSDep + (X * X); SSDep := SSDep + X2;
N := N + 1; N := N + 1;
end; end;
// Calculate results // Calculate results
Constant := (MeanDep * MeanDep) / N; Constant := (MeanDep * MeanDep) / N;
// get ss for rows // get ss for rows
for i := 0 to NoGrpsA-1 do for i := 0 to NoGrpsA-1 do
begin begin
@@ -1325,10 +1336,11 @@ begin
if (SSF1 < 0.0) or (SSF2 < 0.0) or (SSF3 < 0.0) or (SSF1F2 < 0.0) or if (SSF1 < 0.0) or (SSF2 < 0.0) or (SSF3 < 0.0) or (SSF1F2 < 0.0) or
(SSF1F3 < 0.0) or (SSF2F3 < 0.0) or (SSF1F2F3 < 0.0) then (SSF1F3 < 0.0) or (SSF2F3 < 0.0) or (SSF1F2F3 < 0.0) then
begin begin
ShowMessage('ERROR! A negative SS found. Unbalanced Design? Ending analysis.'); ErrorMsg('ERROR! A negative SS found. Unbalanced Design? Ending analysis.');
CompError := true; CompError := true;
exit; exit;
end; end;
DFTot := N - 1; DFTot := N - 1;
DFF1 := NoGrpsA - 1; DFF1 := NoGrpsA - 1;
DFF2 := NoGrpsB - 1; DFF2 := NoGrpsB - 1;
@@ -1338,7 +1350,6 @@ begin
DFF2F3 := DFF2 * DFF3; DFF2F3 := DFF2 * DFF3;
DFF1F2F3 := DFF1 * DFF2 * DFF3; DFF1F2F3 := DFF1 * DFF2 * DFF3;
DFErr := DFTot - DFF1 - DFF2 - DFF3 - DFF1F2 - DFF1F3 - DFF2F3 - DFF1F2F3; DFErr := DFTot - DFF1 - DFF2 - DFF3 - DFF1F2 - DFF1F3 - DFF2F3 - DFF1F2F3;
// DFCells := N - (NoGrpsA * NoGrpsB * NoGrpsC);
MSF1 := SSF1 / DFF1; MSF1 := SSF1 / DFF1;
MSF2 := SSF2 / DFF2; MSF2 := SSF2 / DFF2;
MSF3 := SSF3 / DFF3; MSF3 := SSF3 / DFF3;
@@ -1355,13 +1366,11 @@ begin
OmegaF1F3 := (SSF1F3 - DFF1F3 * MSErr) / (SSDep + MSErr); OmegaF1F3 := (SSF1F3 - DFF1F3 * MSErr) / (SSDep + MSErr);
OmegaF2F3 := (SSF2F3 - DFF2F3 * MSErr) / (SSDep + MSErr); OmegaF2F3 := (SSF2F3 - DFF2F3 * MSErr) / (SSDep + MSErr);
OmegaF1F2F3 := (SSF1F2F3 - DFF1F2F3 * MSErr) / (SSDep + MSErr); OmegaF1F2F3 := (SSF1F2F3 - DFF1F2F3 * MSErr) / (SSDep + MSErr);
Omega := OmegaF1 + OmegaF2 + OmegaF3 + OmegaF1F2 + OmegaF1F3 + Omega := OmegaF1 + OmegaF2 + OmegaF3 + OmegaF1F2 + OmegaF1F3 + OmegaF2F3 + OmegaF1F2F3;
OmegaF2F3 + OmegaF1F2F3;
MeanDep := MeanDep / N; MeanDep := MeanDep / N;
// f tests for fixed effects // F tests for fixed effects
if (Fact1Grp.ItemIndex = 0) and (Fact2Grp.ItemIndex = 0) and if (Fact1Grp.ItemIndex = 0) and (Fact2Grp.ItemIndex = 0) and (Fact3Grp.ItemIndex = 0) then
(Fact3Grp.ItemIndex = 0) then
begin begin
FF1 := abs(MSF1 / MSErr); FF1 := abs(MSF1 / MSErr);
FF2 := abs(MSF2 / MSErr); FF2 := abs(MSF2 / MSErr);
@@ -1379,17 +1388,20 @@ begin
ProbF1F2F3 := probf(FF1F2F3,DFF1F2F3,DFErr); ProbF1F2F3 := probf(FF1F2F3,DFF1F2F3,DFErr);
end; end;
// f tests if all factors are random // F tests if all factors are random
for i := 1 to 14 do OKterms[i] := 1; // initialize as OK for i := 1 to 14 do OKterms[i] := 1; // initialize as OK
if (Fact1Grp.ItemIndex = 1) and (Fact2Grp.ItemIndex = 1) and
(Fact3Grp.ItemIndex = 1) then if (Fact1Grp.ItemIndex = 1) and (Fact2Grp.ItemIndex = 1) and (Fact3Grp.ItemIndex = 1) then
begin begin
if (MSF1F2 + MSF1F3 - MSF1F2F3) < 0.0 then OKTerms[1] := 0 else if (MSF1F2 + MSF1F3 - MSF1F2F3) < 0.0
FF1 := abs(MSF1 / (MSF1F2 + MSF1F3 - MSF1F2F3)); then OKTerms[1] := 0
if (MSF1F2 + MSF2F3 - MSF1F2F3) < 0.0 then OKTerms[2] := 0 else else FF1 := abs(MSF1 / (MSF1F2 + MSF1F3 - MSF1F2F3));
FF2 := abs(MSF2 / (MSF1F2 + MSF2F3 - MSF1F2F3)); if (MSF1F2 + MSF2F3 - MSF1F2F3) < 0.0
if (MSF1F3 + MSF2F3 - MSF1F2F3) < 0.0 then OKTerms[3] := 0 else then OKTerms[2] := 0
FF3 := abs(MSF3 / (MSF1F3 + MSF2F3 - MSF1F2F3)); else FF2 := abs(MSF2 / (MSF1F2 + MSF2F3 - MSF1F2F3));
if (MSF1F3 + MSF2F3 - MSF1F2F3) < 0.0
then OKTerms[3] := 0
else FF3 := abs(MSF3 / (MSF1F3 + MSF2F3 - MSF1F2F3));
FF1F2 := abs(MSF1F2 / MSF1F2F3); FF1F2 := abs(MSF1F2 / MSF1F2F3);
FF1F3 := abs(MSF1F3 / MSF1F2F3); FF1F3 := abs(MSF1F3 / MSF1F2F3);
FF2F3 := abs(MSF2F3 / MSF1F2F3); FF2F3 := abs(MSF2F3 / MSF1F2F3);
@@ -1403,9 +1415,8 @@ begin
probF1F2F3 := probf(FF1F2F3,DFF1F2F3,DFErr); probF1F2F3 := probf(FF1F2F3,DFF1F2F3,DFErr);
end; end;
// f test if factor A is random, B and C Fixed // F test if factor A is random, B and C Fixed
if (Fact1Grp.ItemIndex = 1) and (Fact2Grp.ItemIndex = 0) and if (Fact1Grp.ItemIndex = 1) and (Fact2Grp.ItemIndex = 0) and (Fact3Grp.ItemIndex = 0) then
(Fact3Grp.ItemIndex = 0) then
begin begin
FF1 := abs(MSF1 / MSErr); FF1 := abs(MSF1 / MSErr);
FF2 := abs(MSF2 / MSF1F2); FF2 := abs(MSF2 / MSF1F2);
@@ -1423,9 +1434,8 @@ begin
ProbF1F2F3 := probf(FF1F2F3,DFF1F2F3,DFErr); ProbF1F2F3 := probf(FF1F2F3,DFF1F2F3,DFErr);
end; end;
// f test if factor b is random and A and C are Fixed // F test if factor b is random and A and C are Fixed
if (Fact1Grp.ItemIndex = 0) and (Fact2Grp.ItemIndex = 1) and if (Fact1Grp.ItemIndex = 0) and (Fact2Grp.ItemIndex = 1) and (Fact3Grp.ItemIndex = 0) then
(Fact3Grp.ItemIndex = 0) then
begin begin
FF1 := abs(MSF1 / MSF1F2); FF1 := abs(MSF1 / MSF1F2);
FF2 := abs(MSF2 / MSErr); FF2 := abs(MSF2 / MSErr);
@@ -1443,9 +1453,8 @@ begin
ProbF1F2F3 := probf(FF1F2F3,DFF1F2F3,DFErr); ProbF1F2F3 := probf(FF1F2F3,DFF1F2F3,DFErr);
end; end;
// f test if factor c is random and A and B are Fixed // F test if factor c is random and A and B are Fixed
if (Fact1Grp.ItemIndex = 0) and (Fact2Grp.ItemIndex = 0) and if (Fact1Grp.ItemIndex = 0) and (Fact2Grp.ItemIndex = 0) and (Fact3Grp.ItemIndex = 1) then
(Fact3Grp.ItemIndex = 1) then
begin begin
FF1 := abs(MSF1 / MSF1F3); FF1 := abs(MSF1 / MSF1F3);
FF2 := abs(MSF2 / MSF2F3); FF2 := abs(MSF2 / MSF2F3);
@@ -1463,20 +1472,21 @@ begin
ProbF1F2F3 := probf(FF1F2F3,DFF1F2F3,DFErr); ProbF1F2F3 := probf(FF1F2F3,DFF1F2F3,DFErr);
end; end;
// f tests if A is fixed, B and C are random // F tests if A is fixed, B and C are random
if (Fact1Grp.ItemIndex = 0) and (Fact2Grp.ItemIndex = 1) and if (Fact1Grp.ItemIndex = 0) and (Fact2Grp.ItemIndex = 1) and (Fact3Grp.ItemIndex = 1) then
(Fact3Grp.ItemIndex = 1) then
begin begin
if (MSF1F3 + MSF1F2 - MSF1F2F3) < 0.0 then OKTerms[1] := 0 else if (MSF1F3 + MSF1F2 - MSF1F2F3) < 0.0
FF1 := abs(MSF1 / (MSF1F3 + MSF1F2 - MSF1F2F3)); then OKTerms[1] := 0
else FF1 := abs(MSF1 / (MSF1F3 + MSF1F2 - MSF1F2F3));
FF2 := abs(MSF2 / MSF2F3); FF2 := abs(MSF2 / MSF2F3);
FF3 := abs(MSF3 / MSF2F3); FF3 := abs(MSF3 / MSF2F3);
FF1F2 := abs(MSF1F2 / MSF1F2F3); FF1F2 := abs(MSF1F2 / MSF1F2F3);
FF1F3 := abs(MSF1F3 / MSF1F2F3); FF1F3 := abs(MSF1F3 / MSF1F2F3);
FF2F3 := abs(MSF2F3 / MSErr); FF2F3 := abs(MSF2F3 / MSErr);
FF1F2F3 := abs(MSF1F2F3 / MSErr); FF1F2F3 := abs(MSF1F2F3 / MSErr);
if (DFF1F3 + DFF1F2 - DFF1F2F3) <= 0 then OKTerms[8] := 0 else if (DFF1F3 + DFF1F2 - DFF1F2F3) <= 0
ProbF1 := probf(FF1,DFF1,(DFF1F3 + DFF1F2 - DFF1F2F3)); then OKTerms[8] := 0
else ProbF1 := probf(FF1,DFF1,(DFF1F3 + DFF1F2 - DFF1F2F3));
ProbF2 := probf(FF2,DFF2,DFF2F3); ProbF2 := probf(FF2,DFF2,DFF2F3);
ProbF3 := probf(FF3,DFF3,DFF2F3); ProbF3 := probf(FF3,DFF3,DFF2F3);
ProbF1F2 := probf(FF1F2,DFF1F2,DFF1F2F3); ProbF1F2 := probf(FF1F2,DFF1F2,DFF1F2F3);
@@ -1484,21 +1494,23 @@ begin
ProbF2F3 := probf(FF2F3,DFF2F3,DFErr); ProbF2F3 := probf(FF2F3,DFF2F3,DFErr);
ProbF1F2F3 := probf(FF1F2F3,DFF1F2F3,DFErr); ProbF1F2F3 := probf(FF1F2F3,DFF1F2F3,DFErr);
end; end;
// f tests if B is fixed, A and C are random
if (Fact1Grp.ItemIndex = 1) and (Fact2Grp.ItemIndex = 0) and // F tests if B is fixed, A and C are random
(Fact3Grp.ItemIndex = 1) then if (Fact1Grp.ItemIndex = 1) and (Fact2Grp.ItemIndex = 0) and (Fact3Grp.ItemIndex = 1) then
begin begin
FF1 := abs(MSF2 / MSF1F3); FF1 := abs(MSF2 / MSF1F3);
if (MSF2F3 + MSF1F2 - MSF1F2F3) <= 0.0 then OKTerms[2] := 0 else if (MSF2F3 + MSF1F2 - MSF1F2F3) <= 0.0
FF2 := abs(MSF1 / (MSF2F3 + MSF1F2 - MSF1F2F3)); then OKTerms[2] := 0
else FF2 := abs(MSF1 / (MSF2F3 + MSF1F2 - MSF1F2F3));
FF3 := abs(MSF3 / MSF1F3); FF3 := abs(MSF3 / MSF1F3);
FF1F2 := abs(MSF1F2 / MSF1F2F3); FF1F2 := abs(MSF1F2 / MSF1F2F3);
FF1F3 := abs(MSF1F3 / MSErr); FF1F3 := abs(MSF1F3 / MSErr);
FF2F3 := abs(MSF2F3 / MSF1F2F3); FF2F3 := abs(MSF2F3 / MSF1F2F3);
FF1F2F3 := abs(MSF1F2F3 / MSErr); FF1F2F3 := abs(MSF1F2F3 / MSErr);
ProbF1 := probf(FF2,DFF2,DFF1F3); ProbF1 := probf(FF2,DFF2,DFF1F3);
if (DFF2F3 + DFF1F2 - DFF1F2F3) <= 0 then OKTerms[9] := 0 else if (DFF2F3 + DFF1F2 - DFF1F2F3) <= 0
ProbF2 := probf(FF1,DFF1,(DFF2F3 + DFF1F2 - DFF1F2F3)); then OKTerms[9] := 0
else ProbF2 := probf(FF1,DFF1,(DFF2F3 + DFF1F2 - DFF1F2F3));
ProbF3 := probf(FF3,DFF3,DFF1F3); ProbF3 := probf(FF3,DFF3,DFF1F3);
ProbF1F2 := probf(FF1F2,DFF1F2,DFF1F2F3); ProbF1F2 := probf(FF1F2,DFF1F2,DFF1F2F3);
ProbF1F3 := probf(FF1F3,DFF1F3,DFErr); ProbF1F3 := probf(FF1F3,DFF1F3,DFErr);
@@ -1506,27 +1518,29 @@ begin
ProbF1F2F3 := probf(FF1F2F3,DFF1F2F3,DFErr); ProbF1F2F3 := probf(FF1F2F3,DFF1F2F3,DFErr);
end; end;
// f tests if C is fixed A and B are random // F tests if C is fixed A and B are random
if (Fact1Grp.ItemIndex = 1) and (Fact2Grp.ItemIndex = 1) and if (Fact1Grp.ItemIndex = 1) and (Fact2Grp.ItemIndex = 1) and (Fact3Grp.ItemIndex = 0) then
(Fact3Grp.ItemIndex = 0) then
begin begin
FF1 := abs(MSF1 / MSF1F2); FF1 := abs(MSF1 / MSF1F2);
FF2 := abs(MSF2 / MSF1F2); FF2 := abs(MSF2 / MSF1F2);
if (MSF2F3 + MSF1F3 - MSF1F2F3) <= 0.0 then OKTerms[3] := 0 else if (MSF2F3 + MSF1F3 - MSF1F2F3) <= 0.0
FF3 := abs(MSF3 / (MSF2F3 + MSF1F3 - MSF1F2F3)); then OKTerms[3] := 0
else FF3 := abs(MSF3 / (MSF2F3 + MSF1F3 - MSF1F2F3));
FF1F2 := abs(MSF2F3 / MSErr); FF1F2 := abs(MSF2F3 / MSErr);
FF1F3 := abs(MSF1F2 / MSF1F2F3); FF1F3 := abs(MSF1F2 / MSF1F2F3);
FF2F3 := abs(MSF1F3 / MSF1F2F3); FF2F3 := abs(MSF1F3 / MSF1F2F3);
FF1F2F3 := abs(MSF1F2F3 / MSErr); FF1F2F3 := abs(MSF1F2F3 / MSErr);
ProbF1 := probf(FF3,DFF3,DFF1F2); ProbF1 := probf(FF3,DFF3,DFF1F2);
ProbF2 := probf(FF2,DFF2,DFF1F2); ProbF2 := probf(FF2,DFF2,DFF1F2);
if (DFF2F3 + DFF1F3 - DFF1F2F3) <= 0 then OKTerms[10] := 0 else if (DFF2F3 + DFF1F3 - DFF1F2F3) <= 0
ProbF3 := probf(FF1,DFF1,(DFF2F3 + DFF1F3 - DFF1F2F3)); then OKTerms[10] := 0
else ProbF3 := probf(FF1,DFF1,(DFF2F3 + DFF1F3 - DFF1F2F3));
ProbF1F2 := probf(FF2F3,DFF2F3,DFErr); ProbF1F2 := probf(FF2F3,DFF2F3,DFErr);
ProbF1F3 := probf(FF1F2,DFF1F2,DFF1F2F3); ProbF1F3 := probf(FF1F2,DFF1F2,DFF1F2F3);
ProbF2F3 := probf(FF1F3,DFF1F3,DFF1F2F3); ProbF2F3 := probf(FF1F3,DFF1F3,DFF1F2F3);
ProbF1F2F3 := probf(FF1F2F3,DFF1F2F3,DFErr); ProbF1F2F3 := probf(FF1F2F3,DFF1F2F3,DFErr);
end; end;
if (ProbF1 > 1.0) then ProbF1 := 1.0; if (ProbF1 > 1.0) then ProbF1 := 1.0;
if (ProbF2 > 1.0) then ProbF2 := 1.0; if (ProbF2 > 1.0) then ProbF2 := 1.0;
if ProbF3 > 1.0 then ProbF3 := 1.0; if ProbF3 > 1.0 then ProbF3 := 1.0;
@@ -2439,6 +2453,7 @@ var
sumc1: double; sumc1: double;
fdegfree: double; fdegfree: double;
Fnumerator, Fdenominator, NewF: double; Fnumerator, Fdenominator, NewF: double;
X, X2: Double;
begin begin
for i := 1 to 50 do for i := 1 to 50 do
begin begin
@@ -2450,7 +2465,7 @@ begin
begin begin
if not GoodRecord(i,NoSelected,ColNoSelected) then continue; if not GoodRecord(i,NoSelected,ColNoSelected) then continue;
intvalue := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F1Col,i]))); intvalue := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F1Col,i])));
X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[DepVarCol,i])); // X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[DepVarCol,i]));
intvalue := intvalue - minf1 + 1; intvalue := intvalue - minf1 + 1;
cellcnts[intvalue-1] := 0.0; cellcnts[intvalue-1] := 0.0;
cellsums[intvalue-1] := 0.0; cellsums[intvalue-1] := 0.0;
@@ -2468,12 +2483,13 @@ begin
if not GoodRecord(i,NoSelected,ColNoSelected) then continue; if not GoodRecord(i,NoSelected,ColNoSelected) then continue;
intvalue := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F1Col,i]))); intvalue := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F1Col,i])));
X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[DepVarCol,i])); X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[DepVarCol,i]));
X2 := X*X;
intvalue := intvalue - minf1 + 1; intvalue := intvalue - minf1 + 1;
cellcnts[intvalue-1] := cellcnts[intvalue-1] + 1; cellcnts[intvalue-1] := cellcnts[intvalue-1] + 1;
cellsums[intvalue-1] := cellsums[intvalue-1] + X; cellsums[intvalue-1] := cellsums[intvalue-1] + X;
cellvars[intvalue-1] := cellvars[intvalue-1] + (X * X); cellvars[intvalue-1] := cellvars[intvalue-1] + X2;
MeanDep := MeanDep + X; MeanDep := MeanDep + X;
SSDep := SSDep + X * X; SSDep := SSDep + X2;
N := N + 1; N := N + 1;
end; end;
@@ -2572,6 +2588,7 @@ var
barxj: array[1..50] of double; barxj: array[1..50] of double;
sumc1: double; sumc1: double;
fdegfree, term1, term2, term3: double; fdegfree, term1, term2, term3: double;
X, X2: Double;
begin begin
for i := 1 to 50 do for i := 1 to 50 do
begin begin
@@ -2584,7 +2601,7 @@ begin
begin begin
if not GoodRecord(i,NoSelected,ColNoSelected) then continue; if not GoodRecord(i,NoSelected,ColNoSelected) then continue;
intvalue := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F1Col,i]))); intvalue := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F1Col,i])));
X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[DepVarCol,i])); // X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[DepVarCol,i]));
intvalue := intvalue - minf1 + 1; intvalue := intvalue - minf1 + 1;
cellcnts[intvalue-1] := 0.0; cellcnts[intvalue-1] := 0.0;
cellsums[intvalue-1] := 0.0; cellsums[intvalue-1] := 0.0;
@@ -2602,12 +2619,13 @@ begin
if not GoodRecord(i,NoSelected,ColNoSelected) then continue; if not GoodRecord(i,NoSelected,ColNoSelected) then continue;
intvalue := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F1Col,i]))); intvalue := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[F1Col,i])));
X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[DepVarCol,i])); X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[DepVarCol,i]));
X := X*X;
intvalue := intvalue - minf1 + 1; intvalue := intvalue - minf1 + 1;
cellcnts[intvalue-1] := cellcnts[intvalue-1] + 1; cellcnts[intvalue-1] := cellcnts[intvalue-1] + 1;
cellsums[intvalue-1] := cellsums[intvalue-1] + X; cellsums[intvalue-1] := cellsums[intvalue-1] + X;
cellvars[intvalue-1] := cellvars[intvalue-1] + (X * X); cellvars[intvalue-1] := cellvars[intvalue-1] + X2;
MeanDep := MeanDep + X; MeanDep := MeanDep + X;
SSDep := SSDep + (X * X); SSDep := SSDep + X2;
barxj[intvalue] := barxj[intvalue] + X; barxj[intvalue] := barxj[intvalue] + X;
N := N + 1; N := N + 1;
end; end;