diff --git a/applications/lazstats/data/LatinGreco.laz b/applications/lazstats/data/LatinGreco.laz new file mode 100644 index 000000000..e62bbc31b --- /dev/null +++ b/applications/lazstats/data/LatinGreco.laz @@ -0,0 +1,259 @@ +36 +5 +A +VARIABLE 1 +1 +I +0 +99999 +L +B +VARIABLE 2 +1 +I +0 +99999 +L +Latin +VARIABLE 3 +1 +I +0 +99999 +L +Greek +VARIABLE 4 +1 +I +0 +99999 +L +DepVar +VARIABLE 5 +5 +F +3 +99999 +L +Case 0 +A +B +Latin +Greek +DepVar +Case 1 +1 +1 +1 +1 +2.00 +Case 2 +1 +1 +1 +1 +3.00 +Case 3 +1 +1 +1 +1 +5.00 +Case 4 +1 +1 +1 +1 +6.00 +Case 5 +1 +2 +2 +2 +4.00 +Case 6 +1 +2 +2 +2 +5.00 +Case 7 +1 +2 +2 +2 +7.00 +Case 8 +1 +2 +2 +2 +8.00 +Case 9 +1 +3 +3 +3 +5.00 +Case 10 +1 +3 +3 +3 +6.00 +Case 11 +1 +3 +3 +3 +8.00 +Case 12 +1 +3 +3 +3 +9.00 +Case 13 +2 +1 +2 +3 +4.00 +Case 14 +2 +1 +2 +3 +5.00 +Case 15 +2 +1 +2 +3 +7.00 +Case 16 +2 +1 +2 +3 +8.00 +Case 17 +2 +2 +3 +1 +10.00 +Case 18 +2 +2 +3 +1 +11.00 +Case 19 +2 +2 +3 +1 +13.00 +Case 20 +2 +2 +3 +1 +14.00 +Case 21 +2 +3 +1 +2 +6.00 +Case 22 +2 +3 +1 +2 +7.00 +Case 23 +2 +3 +1 +2 +9.00 +Case 24 +2 +3 +1 +2 +10.00 +Case 25 +3 +1 +3 +2 +5.00 +Case 26 +3 +1 +3 +2 +6.00 +Case 27 +3 +1 +3 +2 +8.00 +Case 28 +3 +1 +3 +2 +9.00 +Case 29 +3 +2 +1 +3 +6.00 +Case 30 +3 +2 +1 +3 +7.00 +Case 31 +3 +2 +1 +3 +9.00 +Case 32 +3 +2 +1 +3 +10.00 +Case 33 +3 +3 +2 +1 +8.00 +Case 34 +3 +3 +2 +1 +9.00 +Case 35 +3 +3 +2 +1 +11.00 +Case 36 +3 +3 +2 +1 +12.00 diff --git a/applications/lazstats/data/LatinPlan5.laz b/applications/lazstats/data/LatinPlan5.laz new file mode 100644 index 000000000..7534e0d0f --- /dev/null +++ b/applications/lazstats/data/LatinPlan5.laz @@ -0,0 +1,259 @@ +36 +5 +A (Col) +VARIABLE 1 +1 +I +0 +99999 +L +B (Cell) +VARIABLE 2 +1 +I +0 +99999 +L +Group (row) +VARIABLE 3 +1 +I +0 +99999 +L +Subject +VARIABLE 4 +1 +I +0 +99999 +L +DepVar +VARIABLE 5 +4 +F +2 +99999 +L +Case 0 +A (Col) +B (Cell) +Group (row) +Subject +DepVar +Case 1 +1 +3 +1 +1 +4.00 +Case 2 +1 +3 +1 +2 +5.00 +Case 3 +1 +3 +1 +3 +2.00 +Case 4 +1 +3 +1 +4 +3.00 +Case 5 +1 +1 +2 +1 +3.00 +Case 6 +1 +1 +2 +2 +6.00 +Case 7 +1 +1 +2 +3 +2.00 +Case 8 +1 +1 +2 +4 +4.00 +Case 9 +1 +2 +3 +1 +4.00 +Case 10 +1 +2 +3 +2 +2.00 +Case 11 +1 +2 +3 +3 +5.00 +Case 12 +1 +2 +3 +4 +3.00 +Case 13 +2 +1 +1 +1 +4.00 +Case 14 +2 +1 +1 +2 +4.00 +Case 15 +2 +1 +1 +3 +6.00 +Case 16 +2 +1 +1 +4 +5.00 +Case 17 +2 +2 +2 +1 +3.00 +Case 18 +2 +2 +2 +2 +5.00 +Case 19 +2 +2 +2 +3 +4.00 +Case 20 +2 +2 +2 +4 +6.00 +Case 21 +2 +3 +3 +1 +5.00 +Case 22 +2 +3 +3 +2 +4.00 +Case 23 +2 +3 +3 +3 +6.00 +Case 24 +2 +3 +3 +4 +6.00 +Case 25 +3 +2 +1 +1 +5.00 +Case 26 +3 +2 +1 +2 +2.00 +Case 27 +3 +2 +1 +3 +5.00 +Case 28 +3 +2 +1 +4 +6.00 +Case 29 +3 +3 +2 +1 +4.00 +Case 30 +3 +3 +2 +2 +3.00 +Case 31 +3 +3 +2 +3 +4.00 +Case 32 +3 +3 +2 +4 +5.00 +Case 33 +3 +1 +3 +1 +4.00 +Case 34 +3 +1 +3 +2 +3.00 +Case 35 +3 +1 +3 +3 +6.00 +Case 36 +3 +1 +3 +4 +5.00 diff --git a/applications/lazstats/data/LatinPlan6.laz b/applications/lazstats/data/LatinPlan6.laz new file mode 100644 index 000000000..3eb57c651 --- /dev/null +++ b/applications/lazstats/data/LatinPlan6.laz @@ -0,0 +1,259 @@ +36 +5 +A (Col) +VARIABLE 1 +4 +F +2 +99999 +L +B (Cell) +VARIABLE 2 +4 +F +2 +99999 +L +Subject +VARIABLE 3 +4 +F +2 +99999 +L +Group+C +VARIABLE 4 +4 +F +2 +99999 +L +DepVar +VARIABLE 5 +4 +F +2 +99999 +L +Case 0 +A (Col) +B (Cell) +Subject +Group+C +DepVar +Case 1 +1.00 +3.00 +1.00 +1.00 +4.00 +Case 2 +1.00 +3.00 +2.00 +1.00 +6.00 +Case 3 +1.00 +3.00 +3.00 +1.00 +5.00 +Case 4 +1.00 +3.00 +4.00 +1.00 +8.00 +Case 5 +2.00 +1.00 +1.00 +1.00 +7.00 +Case 6 +2.00 +1.00 +2.00 +1.00 +4.00 +Case 7 +2.00 +1.00 +3.00 +1.00 +2.00 +Case 8 +2.00 +1.00 +4.00 +1.00 +3.00 +Case 9 +3.00 +2.00 +1.00 +1.00 +5.00 +Case 10 +3.00 +2.00 +2.00 +1.00 +4.00 +Case 11 +3.00 +2.00 +3.00 +1.00 +6.00 +Case 12 +3.00 +2.00 +4.00 +1.00 +7.00 +Case 13 +1.00 +1.00 +1.00 +2.00 +5.00 +Case 14 +1.00 +1.00 +2.00 +2.00 +4.00 +Case 15 +1.00 +1.00 +3.00 +2.00 +6.00 +Case 16 +1.00 +1.00 +4.00 +2.00 +7.00 +Case 17 +2.00 +2.00 +1.00 +2.00 +3.00 +Case 18 +2.00 +2.00 +2.00 +2.00 +4.00 +Case 19 +2.00 +2.00 +3.00 +2.00 +2.00 +Case 20 +2.00 +2.00 +4.00 +2.00 +5.00 +Case 21 +3.00 +3.00 +1.00 +2.00 +4.00 +Case 22 +3.00 +3.00 +2.00 +2.00 +5.00 +Case 23 +3.00 +3.00 +3.00 +2.00 +6.00 +Case 24 +3.00 +3.00 +4.00 +2.00 +3.00 +Case 25 +1.00 +2.00 +1.00 +3.00 +7.00 +Case 26 +1.00 +2.00 +2.00 +3.00 +8.00 +Case 27 +1.00 +2.00 +3.00 +3.00 +5.00 +Case 28 +1.00 +2.00 +4.00 +3.00 +4.00 +Case 29 +2.00 +3.00 +1.00 +3.00 +5.00 +Case 30 +2.00 +3.00 +2.00 +3.00 +6.00 +Case 31 +2.00 +3.00 +3.00 +3.00 +2.00 +Case 32 +2.00 +3.00 +4.00 +3.00 +8.00 +Case 33 +3.00 +1.00 +1.00 +3.00 +6.00 +Case 34 +3.00 +1.00 +2.00 +3.00 +5.00 +Case 35 +3.00 +1.00 +3.00 +3.00 +4.00 +Case 36 +3.00 +1.00 +4.00 +3.00 +6.00 diff --git a/applications/lazstats/data/LatinPlan7.laz b/applications/lazstats/data/LatinPlan7.laz new file mode 100644 index 000000000..a94ec7545 --- /dev/null +++ b/applications/lazstats/data/LatinPlan7.laz @@ -0,0 +1,303 @@ +36 +6 +A (Col) +VARIABLE 1 +4 +F +2 +99999 +L +B (Cell) +VARIABLE 2 +4 +F +2 +99999 +L +C (Cell) +VARIABLE 3 +4 +F +2 +99999 +L +Subject +VARIABLE 4 +4 +F +2 +99999 +L +Group +VARIABLE 5 +4 +F +2 +99999 +L +DepVar +VARIABLE 6 +4 +F +2 +99999 +L +Case 0 +A (Col) +B (Cell) +C (Cell) +Subject +Group +DepVar +Case 1 +1.00 +1.00 +1.00 +1.00 +1.00 +4.00 +Case 2 +1.00 +1.00 +1.00 +2.00 +1.00 +6.00 +Case 3 +1.00 +1.00 +1.00 +3.00 +1.00 +5.00 +Case 4 +1.00 +1.00 +1.00 +4.00 +1.00 +8.00 +Case 5 +2.00 +2.00 +3.00 +1.00 +1.00 +7.00 +Case 6 +2.00 +2.00 +3.00 +2.00 +1.00 +4.00 +Case 7 +2.00 +2.00 +3.00 +3.00 +1.00 +2.00 +Case 8 +2.00 +2.00 +3.00 +4.00 +1.00 +3.00 +Case 9 +3.00 +3.00 +2.00 +1.00 +1.00 +5.00 +Case 10 +3.00 +3.00 +2.00 +2.00 +1.00 +4.00 +Case 11 +3.00 +3.00 +2.00 +3.00 +1.00 +6.00 +Case 12 +3.00 +3.00 +2.00 +4.00 +1.00 +7.00 +Case 13 +1.00 +2.00 +2.00 +1.00 +2.00 +5.00 +Case 14 +1.00 +2.00 +2.00 +2.00 +2.00 +4.00 +Case 15 +1.00 +2.00 +2.00 +3.00 +2.00 +6.00 +Case 16 +1.00 +2.00 +2.00 +4.00 +2.00 +7.00 +Case 17 +2.00 +3.00 +1.00 +1.00 +2.00 +3.00 +Case 18 +2.00 +3.00 +1.00 +2.00 +2.00 +4.00 +Case 19 +2.00 +3.00 +1.00 +3.00 +2.00 +2.00 +Case 20 +2.00 +3.00 +1.00 +4.00 +2.00 +5.00 +Case 21 +3.00 +1.00 +3.00 +1.00 +2.00 +4.00 +Case 22 +3.00 +1.00 +3.00 +2.00 +2.00 +5.00 +Case 23 +3.00 +1.00 +3.00 +3.00 +2.00 +6.00 +Case 24 +3.00 +1.00 +3.00 +4.00 +2.00 +3.00 +Case 25 +1.00 +3.00 +3.00 +1.00 +3.00 +7.00 +Case 26 +1.00 +3.00 +3.00 +2.00 +3.00 +8.00 +Case 27 +1.00 +3.00 +3.00 +3.00 +3.00 +5.00 +Case 28 +1.00 +3.00 +3.00 +4.00 +3.00 +4.00 +Case 29 +2.00 +1.00 +2.00 +1.00 +3.00 +5.00 +Case 30 +2.00 +1.00 +2.00 +2.00 +3.00 +6.00 +Case 31 +2.00 +1.00 +2.00 +3.00 +3.00 +2.00 +Case 32 +2.00 +1.00 +2.00 +4.00 +3.00 +8.00 +Case 33 +3.00 +2.00 +1.00 +1.00 +3.00 +6.00 +Case 34 +3.00 +2.00 +1.00 +2.00 +3.00 +5.00 +Case 35 +3.00 +2.00 +1.00 +3.00 +3.00 +4.00 +Case 36 +3.00 +2.00 +1.00 +4.00 +3.00 +6.00 diff --git a/applications/lazstats/data/LatinPlan8.laz b/applications/lazstats/data/LatinPlan8.laz new file mode 100644 index 000000000..fea4b996a --- /dev/null +++ b/applications/lazstats/data/LatinPlan8.laz @@ -0,0 +1,555 @@ +72 +6 +Factor A +VARIABLE 1 +4 +F +2 +99999 +L +Factor B +VARIABLE 2 +4 +F +2 +99999 +L +Factor C +VARIABLE 3 +4 +F +2 +99999 +L +Subject +VARIABLE 4 +5 +F +3 +99999 +L +Group +VARIABLE 5 +4 +F +2 +99999 +L +DepVar +VARIABLE 6 +4 +F +2 +99999 +L +Case 0 +Factor A +Factor B +Factor C +Subject +Group +DepVar +Case 1 +1.00 +1.00 +1.00 +1.00 +1.00 +1.00 +Case 2 +1.00 +1.00 +1.00 +2.00 +1.00 +2.00 +Case 3 +1.00 +1.00 +1.00 +3.00 +1.00 +3.00 +Case 4 +1.00 +1.00 +1.00 +4.00 +1.00 +4.00 +Case 5 +2.00 +2.00 +1.00 +1.00 +1.00 +2.00 +Case 6 +2.00 +2.00 +1.00 +2.00 +1.00 +3.00 +Case 7 +2.00 +2.00 +1.00 +3.00 +1.00 +4.00 +Case 8 +2.00 +2.00 +1.00 +4.00 +1.00 +5.00 +Case 9 +3.00 +3.00 +1.00 +1.00 +1.00 +3.00 +Case 10 +3.00 +3.00 +1.00 +2.00 +1.00 +4.00 +Case 11 +3.00 +3.00 +1.00 +3.00 +1.00 +5.00 +Case 12 +3.00 +3.00 +1.00 +4.00 +1.00 +6.00 +Case 13 +1.00 +2.00 +1.00 +5.00 +2.00 +2.00 +Case 14 +1.00 +2.00 +1.00 +6.00 +2.00 +3.00 +Case 15 +1.00 +2.00 +1.00 +7.00 +2.00 +4.00 +Case 16 +1.00 +2.00 +1.00 +8.00 +2.00 +5.00 +Case 17 +2.00 +3.00 +1.00 +5.00 +2.00 +3.00 +Case 18 +2.00 +3.00 +1.00 +6.00 +2.00 +4.00 +Case 19 +2.00 +3.00 +1.00 +7.00 +2.00 +5.00 +Case 20 +2.00 +3.00 +1.00 +8.00 +2.00 +6.00 +Case 21 +3.00 +1.00 +1.00 +5.00 +2.00 +4.00 +Case 22 +3.00 +1.00 +1.00 +6.00 +2.00 +5.00 +Case 23 +3.00 +1.00 +1.00 +7.00 +2.00 +6.00 +Case 24 +3.00 +1.00 +1.00 +8.00 +2.00 +7.00 +Case 25 +1.00 +3.00 +1.00 +9.00 +3.00 +1.00 +Case 26 +1.00 +3.00 +1.00 +10.00 +3.00 +2.00 +Case 27 +1.00 +3.00 +1.00 +11.00 +3.00 +3.00 +Case 28 +1.00 +3.00 +1.00 +12.00 +3.00 +4.00 +Case 29 +2.00 +1.00 +1.00 +9.00 +3.00 +2.00 +Case 30 +2.00 +1.00 +1.00 +10.00 +3.00 +3.00 +Case 31 +2.00 +1.00 +1.00 +11.00 +3.00 +4.00 +Case 32 +2.00 +1.00 +1.00 +12.00 +3.00 +5.00 +Case 33 +3.00 +2.00 +1.00 +9.00 +3.00 +3.00 +Case 34 +3.00 +2.00 +1.00 +10.00 +3.00 +4.00 +Case 35 +3.00 +2.00 +1.00 +11.00 +3.00 +5.00 +Case 36 +3.00 +2.00 +1.00 +12.00 +3.00 +6.00 +Case 37 +1.00 +2.00 +2.00 +13.00 +4.00 +3.00 +Case 38 +1.00 +2.00 +2.00 +14.00 +4.00 +4.00 +Case 39 +1.00 +2.00 +2.00 +15.00 +4.00 +5.00 +Case 40 +1.00 +2.00 +2.00 +16.00 +4.00 +6.00 +Case 41 +2.00 +3.00 +2.00 +13.00 +4.00 +4.00 +Case 42 +2.00 +3.00 +2.00 +14.00 +4.00 +5.00 +Case 43 +2.00 +3.00 +2.00 +15.00 +4.00 +6.00 +Case 44 +2.00 +3.00 +2.00 +16.00 +4.00 +7.00 +Case 45 +3.00 +1.00 +2.00 +13.00 +4.00 +5.00 +Case 46 +3.00 +1.00 +2.00 +14.00 +4.00 +6.00 +Case 47 +3.00 +1.00 +2.00 +15.00 +4.00 +7.00 +Case 48 +3.00 +1.00 +2.00 +16.00 +4.00 +8.00 +Case 49 +1.00 +1.00 +2.00 +17.00 +5.00 +4.00 +Case 50 +1.00 +1.00 +2.00 +18.00 +5.00 +5.00 +Case 51 +1.00 +1.00 +2.00 +19.00 +5.00 +6.00 +Case 52 +1.00 +1.00 +2.00 +20.00 +5.00 +7.00 +Case 53 +2.00 +2.00 +2.00 +17.00 +5.00 +4.00 +Case 54 +2.00 +2.00 +2.00 +18.00 +5.00 +5.00 +Case 55 +2.00 +2.00 +2.00 +19.00 +5.00 +6.00 +Case 56 +2.00 +2.00 +2.00 +20.00 +5.00 +7.00 +Case 57 +3.00 +3.00 +2.00 +17.00 +5.00 +5.00 +Case 58 +3.00 +3.00 +2.00 +18.00 +5.00 +6.00 +Case 59 +3.00 +3.00 +2.00 +19.00 +5.00 +7.00 +Case 60 +3.00 +3.00 +2.00 +20.00 +5.00 +8.00 +Case 61 +1.00 +3.00 +2.00 +21.00 +6.00 +3.00 +Case 62 +1.00 +3.00 +2.00 +22.00 +6.00 +4.00 +Case 63 +1.00 +3.00 +2.00 +23.00 +6.00 +5.00 +Case 64 +1.00 +3.00 +2.00 +24.00 +6.00 +6.00 +Case 65 +2.00 +1.00 +2.00 +21.00 +6.00 +4.00 +Case 66 +2.00 +1.00 +2.00 +22.00 +6.00 +5.00 +Case 67 +2.00 +1.00 +2.00 +23.00 +6.00 +6.00 +Case 68 +2.00 +1.00 +2.00 +24.00 +6.00 +7.00 +Case 69 +3.00 +2.00 +2.00 +21.00 +6.00 +5.00 +Case 70 +3.00 +2.00 +2.00 +22.00 +6.00 +6.00 +Case 71 +3.00 +2.00 +2.00 +23.00 +6.00 +7.00 +Case 72 +3.00 +2.00 +2.00 +24.00 +6.00 +8.00 diff --git a/applications/lazstats/data/LatinPlan8Rev.laz b/applications/lazstats/data/LatinPlan8Rev.laz new file mode 100644 index 000000000..46b9a0dda --- /dev/null +++ b/applications/lazstats/data/LatinPlan8Rev.laz @@ -0,0 +1,555 @@ +72 +6 +Factor A +VARIABLE 1 +4 +F +2 +99999 +L +Factor B +VARIABLE 2 +4 +F +2 +99999 +L +Factor C +VARIABLE 3 +4 +F +2 +99999 +L +Subject +VARIABLE 4 +4 +F +2 +99999 +L +Group +VARIABLE 5 +4 +F +2 +99999 +L +DepVar +VARIABLE 6 +4 +F +2 +99999 +L +Case 0 +Factor A +Factor B +Factor C +Subject +Group +DepVar +Case 1 +1.00 +1.00 +1.00 +1.00 +1.00 +1.00 +Case 2 +1.00 +1.00 +1.00 +2.00 +1.00 +2.00 +Case 3 +1.00 +1.00 +1.00 +3.00 +1.00 +3.00 +Case 4 +1.00 +1.00 +1.00 +4.00 +1.00 +4.00 +Case 5 +2.00 +2.00 +1.00 +1.00 +1.00 +2.00 +Case 6 +2.00 +2.00 +1.00 +2.00 +1.00 +3.00 +Case 7 +2.00 +2.00 +1.00 +3.00 +1.00 +4.00 +Case 8 +2.00 +2.00 +1.00 +4.00 +1.00 +5.00 +Case 9 +3.00 +3.00 +1.00 +1.00 +1.00 +3.00 +Case 10 +3.00 +3.00 +1.00 +2.00 +1.00 +4.00 +Case 11 +3.00 +3.00 +1.00 +3.00 +1.00 +5.00 +Case 12 +3.00 +3.00 +1.00 +4.00 +1.00 +6.00 +Case 13 +1.00 +2.00 +1.00 +1.00 +2.00 +2.00 +Case 14 +1.00 +2.00 +1.00 +2.00 +2.00 +3.00 +Case 15 +1.00 +2.00 +1.00 +3.00 +2.00 +4.00 +Case 16 +1.00 +2.00 +1.00 +4.00 +2.00 +5.00 +Case 17 +2.00 +3.00 +1.00 +1.00 +2.00 +3.00 +Case 18 +2.00 +3.00 +1.00 +2.00 +2.00 +4.00 +Case 19 +2.00 +3.00 +1.00 +3.00 +2.00 +5.00 +Case 20 +2.00 +3.00 +1.00 +4.00 +2.00 +6.00 +Case 21 +3.00 +1.00 +1.00 +1.00 +2.00 +4.00 +Case 22 +3.00 +1.00 +1.00 +2.00 +2.00 +5.00 +Case 23 +3.00 +1.00 +1.00 +3.00 +2.00 +6.00 +Case 24 +3.00 +1.00 +1.00 +4.00 +2.00 +7.00 +Case 25 +1.00 +3.00 +1.00 +1.00 +3.00 +1.00 +Case 26 +1.00 +3.00 +1.00 +2.00 +3.00 +2.00 +Case 27 +1.00 +3.00 +1.00 +3.00 +3.00 +3.00 +Case 28 +1.00 +3.00 +1.00 +4.00 +3.00 +4.00 +Case 29 +2.00 +1.00 +1.00 +1.00 +3.00 +2.00 +Case 30 +2.00 +1.00 +1.00 +2.00 +3.00 +3.00 +Case 31 +2.00 +1.00 +1.00 +3.00 +3.00 +4.00 +Case 32 +2.00 +1.00 +1.00 +4.00 +3.00 +5.00 +Case 33 +3.00 +2.00 +1.00 +1.00 +3.00 +3.00 +Case 34 +3.00 +2.00 +1.00 +2.00 +3.00 +4.00 +Case 35 +3.00 +2.00 +1.00 +3.00 +3.00 +5.00 +Case 36 +3.00 +2.00 +1.00 +4.00 +3.00 +6.00 +Case 37 +1.00 +2.00 +2.00 +1.00 +1.00 +3.00 +Case 38 +1.00 +2.00 +2.00 +2.00 +1.00 +4.00 +Case 39 +1.00 +2.00 +2.00 +3.00 +1.00 +5.00 +Case 40 +1.00 +2.00 +2.00 +4.00 +1.00 +6.00 +Case 41 +2.00 +3.00 +2.00 +1.00 +1.00 +4.00 +Case 42 +2.00 +3.00 +2.00 +2.00 +1.00 +5.00 +Case 43 +2.00 +3.00 +2.00 +3.00 +1.00 +6.00 +Case 44 +2.00 +3.00 +2.00 +4.00 +1.00 +7.00 +Case 45 +3.00 +1.00 +2.00 +1.00 +1.00 +5.00 +Case 46 +3.00 +1.00 +2.00 +2.00 +1.00 +6.00 +Case 47 +3.00 +1.00 +2.00 +3.00 +1.00 +7.00 +Case 48 +3.00 +1.00 +2.00 +4.00 +1.00 +8.00 +Case 49 +1.00 +1.00 +2.00 +1.00 +2.00 +4.00 +Case 50 +1.00 +1.00 +2.00 +2.00 +2.00 +5.00 +Case 51 +1.00 +1.00 +2.00 +3.00 +2.00 +6.00 +Case 52 +1.00 +1.00 +2.00 +4.00 +2.00 +7.00 +Case 53 +2.00 +2.00 +2.00 +1.00 +2.00 +4.00 +Case 54 +2.00 +2.00 +2.00 +2.00 +2.00 +5.00 +Case 55 +2.00 +2.00 +2.00 +3.00 +2.00 +6.00 +Case 56 +2.00 +2.00 +2.00 +4.00 +2.00 +7.00 +Case 57 +3.00 +3.00 +2.00 +1.00 +2.00 +5.00 +Case 58 +3.00 +3.00 +2.00 +2.00 +2.00 +6.00 +Case 59 +3.00 +3.00 +2.00 +3.00 +2.00 +7.00 +Case 60 +3.00 +3.00 +2.00 +4.00 +2.00 +8.00 +Case 61 +1.00 +3.00 +2.00 +1.00 +3.00 +3.00 +Case 62 +1.00 +3.00 +2.00 +2.00 +3.00 +4.00 +Case 63 +1.00 +3.00 +2.00 +3.00 +3.00 +5.00 +Case 64 +1.00 +3.00 +2.00 +4.00 +3.00 +6.00 +Case 65 +2.00 +1.00 +2.00 +1.00 +3.00 +4.00 +Case 66 +2.00 +1.00 +2.00 +2.00 +3.00 +5.00 +Case 67 +2.00 +1.00 +2.00 +3.00 +3.00 +6.00 +Case 68 +2.00 +1.00 +2.00 +4.00 +3.00 +7.00 +Case 69 +3.00 +2.00 +2.00 +1.00 +3.00 +5.00 +Case 70 +3.00 +2.00 +2.00 +2.00 +3.00 +6.00 +Case 71 +3.00 +2.00 +2.00 +3.00 +3.00 +7.00 +Case 72 +3.00 +2.00 +2.00 +4.00 +3.00 +8.00 diff --git a/applications/lazstats/data/LatinPlan9.laz b/applications/lazstats/data/LatinPlan9.laz new file mode 100644 index 000000000..a6bbac561 --- /dev/null +++ b/applications/lazstats/data/LatinPlan9.laz @@ -0,0 +1,429 @@ +54 +6 +FactorA +VARIABLE 1 +4 +F +2 +99999 +L +FactorB +VARIABLE 2 +4 +F +2 +99999 +L +FactorC +VARIABLE 3 +4 +F +2 +99999 +L +Person +VARIABLE 4 +5 +F +3 +99999 +L +Group +VARIABLE 5 +4 +F +2 +99999 +L +DepVar +VARIABLE 6 +4 +F +2 +99999 +L +Case 0 +FactorA +FactorB +FactorC +Person +Group +DepVar +Case 1 +1.00 +2.00 +1.00 +1.00 +1.00 +2.00 +Case 2 +2.00 +3.00 +1.00 +1.00 +1.00 +2.00 +Case 3 +3.00 +1.00 +1.00 +1.00 +1.00 +3.00 +Case 4 +1.00 +2.00 +1.00 +2.00 +1.00 +1.00 +Case 5 +2.00 +3.00 +1.00 +2.00 +1.00 +1.00 +Case 6 +3.00 +1.00 +1.00 +2.00 +1.00 +7.00 +Case 7 +1.00 +2.00 +2.00 +3.00 +4.00 +5.00 +Case 8 +2.00 +3.00 +2.00 +3.00 +4.00 +8.00 +Case 9 +3.00 +1.00 +2.00 +3.00 +4.00 +1.00 +Case 10 +1.00 +2.00 +2.00 +4.00 +4.00 +9.00 +Case 11 +2.00 +3.00 +2.00 +4.00 +4.00 +12.00 +Case 12 +3.00 +1.00 +2.00 +4.00 +4.00 +7.00 +Case 13 +1.00 +2.00 +3.00 +5.00 +7.00 +5.00 +Case 14 +2.00 +3.00 +3.00 +5.00 +7.00 +4.00 +Case 15 +3.00 +1.00 +3.00 +5.00 +7.00 +6.00 +Case 16 +1.00 +2.00 +3.00 +6.00 +7.00 +7.00 +Case 17 +2.00 +3.00 +3.00 +6.00 +7.00 +5.00 +Case 18 +3.00 +1.00 +3.00 +6.00 +7.00 +9.00 +Case 19 +1.00 +1.00 +1.00 +7.00 +2.00 +5.00 +Case 20 +2.00 +2.00 +1.00 +7.00 +2.00 +4.00 +Case 21 +3.00 +3.00 +1.00 +7.00 +2.00 +7.00 +Case 22 +1.00 +1.00 +1.00 +8.00 +2.00 +8.00 +Case 23 +2.00 +2.00 +1.00 +8.00 +2.00 +5.00 +Case 24 +3.00 +3.00 +1.00 +8.00 +2.00 +8.00 +Case 25 +1.00 +1.00 +2.00 +9.00 +5.00 +8.00 +Case 26 +2.00 +2.00 +2.00 +9.00 +5.00 +10.00 +Case 27 +3.00 +3.00 +2.00 +9.00 +5.00 +4.00 +Case 28 +1.00 +1.00 +2.00 +10.00 +5.00 +10.00 +Case 29 +2.00 +2.00 +2.00 +10.00 +5.00 +14.00 +Case 30 +3.00 +3.00 +2.00 +10.00 +5.00 +6.00 +Case 31 +1.00 +1.00 +3.00 +11.00 +8.00 +10.00 +Case 32 +2.00 +2.00 +3.00 +11.00 +8.00 +10.00 +Case 33 +3.00 +3.00 +3.00 +11.00 +8.00 +8.00 +Case 34 +1.00 +1.00 +3.00 +12.00 +8.00 +7.00 +Case 35 +2.00 +2.00 +3.00 +12.00 +8.00 +3.00 +Case 36 +3.00 +3.00 +3.00 +12.00 +8.00 +9.00 +Case 37 +1.00 +3.00 +1.00 +13.00 +3.00 +3.00 +Case 38 +2.00 +1.00 +1.00 +13.00 +3.00 +2.00 +Case 39 +3.00 +2.00 +1.00 +13.00 +3.00 +5.00 +Case 40 +1.00 +3.00 +1.00 +14.00 +3.00 +6.00 +Case 41 +2.00 +1.00 +1.00 +14.00 +3.00 +4.00 +Case 42 +3.00 +2.00 +1.00 +14.00 +3.00 +9.00 +Case 43 +1.00 +3.00 +2.00 +15.00 +6.00 +8.00 +Case 44 +2.00 +1.00 +2.00 +15.00 +6.00 +9.00 +Case 45 +3.00 +2.00 +2.00 +15.00 +6.00 +6.00 +Case 46 +1.00 +3.00 +2.00 +16.00 +6.00 +10.00 +Case 47 +2.00 +1.00 +2.00 +16.00 +6.00 +10.00 +Case 48 +3.00 +2.00 +2.00 +16.00 +6.00 +5.00 +Case 49 +1.00 +3.00 +3.00 +17.00 +9.00 +12.00 +Case 50 +2.00 +1.00 +3.00 +17.00 +9.00 +6.00 +Case 51 +3.00 +2.00 +3.00 +17.00 +9.00 +10.00 +Case 52 +1.00 +3.00 +3.00 +18.00 +9.00 +8.00 +Case 53 +2.00 +1.00 +3.00 +18.00 +9.00 +8.00 +Case 54 +3.00 +2.00 +3.00 +18.00 +9.00 +2.00 diff --git a/applications/lazstats/data/LatinSquare.Llaz b/applications/lazstats/data/LatinSquare.laz similarity index 100% rename from applications/lazstats/data/LatinSquare.Llaz rename to applications/lazstats/data/LatinSquare.laz diff --git a/applications/lazstats/docs/HelpNDoc/LazStats.hnd b/applications/lazstats/docs/HelpNDoc/LazStats.hnd index 9f8a59d07..52b1e118f 100644 Binary files a/applications/lazstats/docs/HelpNDoc/LazStats.hnd and b/applications/lazstats/docs/HelpNDoc/LazStats.hnd differ diff --git a/applications/lazstats/source/forms/analysis/comparisons/latinspecsunit.lfm b/applications/lazstats/source/forms/analysis/comparisons/latinspecsunit.lfm index fe17d0ad9..87274def9 100644 --- a/applications/lazstats/source/forms/analysis/comparisons/latinspecsunit.lfm +++ b/applications/lazstats/source/forms/analysis/comparisons/latinspecsunit.lfm @@ -31,9 +31,9 @@ object LatinSpecsFrm: TLatinSpecsFrm Left = 8 Height = 15 Top = 491 - Width = 66 + Width = 99 BorderSpacing.Left = 8 - Caption = 'No. per cell: ' + Caption = 'No. Cases per cell: ' ParentColor = False end object VarList: TListBox @@ -45,13 +45,14 @@ object LatinSpecsFrm: TLatinSpecsFrm Left = 8 Height = 445 Top = 25 - Width = 232 + Width = 240 Anchors = [akTop, akLeft, akRight, akBottom] BorderSpacing.Left = 8 BorderSpacing.Top = 2 BorderSpacing.Right = 8 Constraints.MinWidth = 150 ItemHeight = 0 + OnSelectionChange = VarListSelectionChange TabOrder = 0 end object ResetBtn: TButton @@ -116,12 +117,13 @@ object LatinSpecsFrm: TLatinSpecsFrm AnchorSideTop.Control = OKBtn AnchorSideTop.Side = asrCenter AnchorSideRight.Side = asrBottom - Left = 82 + Left = 115 Height = 23 Top = 487 Width = 48 Alignment = taRightJustify BorderSpacing.Left = 8 + BorderSpacing.Right = 12 TabOrder = 2 Text = 'nPerCellEdit' end @@ -143,10 +145,10 @@ object LatinSpecsFrm: TLatinSpecsFrm AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom AnchorSideBottom.Control = Bevel1 - Left = 248 + Left = 256 Height = 440 Top = 25 - Width = 164 + Width = 156 Anchors = [akTop, akRight] AutoSize = True BorderSpacing.Right = 8 @@ -157,18 +159,18 @@ object LatinSpecsFrm: TLatinSpecsFrm ChildSizing.Layout = cclLeftToRightThenTopToBottom ChildSizing.ControlsPerLine = 1 ClientHeight = 440 - ClientWidth = 164 + ClientWidth = 156 TabOrder = 1 object PanelA: TPanel AnchorSideRight.Side = asrBottom Left = 0 Height = 60 Top = 0 - Width = 164 + Width = 156 AutoSize = True BevelOuter = bvNone ClientHeight = 60 - ClientWidth = 164 + ClientWidth = 156 TabOrder = 0 object ACodeLabel: TLabel AnchorSideLeft.Control = ACodeEdit @@ -220,10 +222,11 @@ object LatinSpecsFrm: TLatinSpecsFrm Left = 37 Height = 23 Top = 25 - Width = 127 + Width = 119 Anchors = [akLeft, akRight, akBottom] BorderSpacing.Left = 8 BorderSpacing.Bottom = 12 + NumbersOnly = True TabOrder = 2 Text = 'ACodeEdit' end @@ -232,11 +235,11 @@ object LatinSpecsFrm: TLatinSpecsFrm Left = 0 Height = 60 Top = 76 - Width = 164 + Width = 156 AutoSize = True BevelOuter = bvNone ClientHeight = 60 - ClientWidth = 164 + ClientWidth = 156 TabOrder = 1 object BCodeLabel: TLabel AnchorSideLeft.Control = BCodeEdit @@ -289,23 +292,24 @@ object LatinSpecsFrm: TLatinSpecsFrm Left = 37 Height = 23 Top = 25 - Width = 127 + Width = 119 Anchors = [akLeft, akRight, akBottom] BorderSpacing.Left = 8 BorderSpacing.Bottom = 12 + NumbersOnly = True TabOrder = 2 - Text = 'Edit1' + Text = 'BCodeEdit' end end object PanelC: TPanel Left = 0 Height = 60 Top = 152 - Width = 164 + Width = 156 AutoSize = True BevelOuter = bvNone ClientHeight = 60 - ClientWidth = 164 + ClientWidth = 156 TabOrder = 2 object CCodeLabel: TLabel AnchorSideLeft.Control = CCodeEdit @@ -357,33 +361,33 @@ object LatinSpecsFrm: TLatinSpecsFrm Left = 37 Height = 23 Top = 25 - Width = 127 + Width = 119 Anchors = [akLeft, akRight, akBottom] BorderSpacing.Left = 8 BorderSpacing.Bottom = 12 + NumbersOnly = True TabOrder = 2 - Text = 'Edit1' + Text = 'CCodeEdit' end end object PanelD: TPanel Left = 0 Height = 60 Top = 228 - Width = 164 + Width = 156 AutoSize = True BevelOuter = bvNone ClientHeight = 60 - ClientWidth = 164 + ClientWidth = 156 TabOrder = 3 object DCodeLabel: TLabel AnchorSideLeft.Control = DCodeEdit AnchorSideBottom.Control = DCodeEdit - Left = 45 + Left = 37 Height = 15 Top = 8 Width = 119 Anchors = [akLeft, akBottom] - BorderSpacing.Left = 8 BorderSpacing.Bottom = 2 Caption = 'Factor D Code Variable' ParentColor = False @@ -426,23 +430,24 @@ object LatinSpecsFrm: TLatinSpecsFrm Left = 37 Height = 23 Top = 25 - Width = 127 + Width = 119 Anchors = [akLeft, akRight, akBottom] BorderSpacing.Left = 8 BorderSpacing.Bottom = 12 + NumbersOnly = True TabOrder = 2 - Text = 'Edit1' + Text = 'DCodeEdit' end end object PanelGrp: TPanel Left = 0 Height = 60 Top = 304 - Width = 164 + Width = 156 AutoSize = True BevelOuter = bvNone ClientHeight = 60 - ClientWidth = 164 + ClientWidth = 156 TabOrder = 4 object GrpCodeLabel: TLabel AnchorSideLeft.Control = GrpCodeEdit @@ -494,23 +499,24 @@ object LatinSpecsFrm: TLatinSpecsFrm Left = 37 Height = 23 Top = 25 - Width = 127 + Width = 119 Anchors = [akLeft, akRight, akBottom] BorderSpacing.Left = 8 BorderSpacing.Bottom = 12 + NumbersOnly = True TabOrder = 2 - Text = 'Edit1' + Text = 'GrpCodeEdit' end end object PanelDep: TPanel Left = 0 Height = 60 Top = 380 - Width = 164 + Width = 156 AutoSize = True BevelOuter = bvNone ClientHeight = 60 - ClientWidth = 164 + ClientWidth = 156 TabOrder = 5 object DepVarLabel: TLabel AnchorSideLeft.Control = DepVarEdit @@ -562,12 +568,13 @@ object LatinSpecsFrm: TLatinSpecsFrm Left = 37 Height = 23 Top = 25 - Width = 127 + Width = 119 Anchors = [akLeft, akRight, akBottom] BorderSpacing.Left = 8 BorderSpacing.Bottom = 12 + NumbersOnly = True TabOrder = 2 - Text = 'Edit1' + Text = 'DepVarEdit' end end end diff --git a/applications/lazstats/source/forms/analysis/comparisons/latinspecsunit.pas b/applications/lazstats/source/forms/analysis/comparisons/latinspecsunit.pas index 9e1dffe5f..b5a9936d8 100644 --- a/applications/lazstats/source/forms/analysis/comparisons/latinspecsunit.pas +++ b/applications/lazstats/source/forms/analysis/comparisons/latinspecsunit.pas @@ -70,12 +70,15 @@ type procedure GrpOutBtnClick(Sender: TObject); procedure OKBtnClick(Sender: TObject); procedure ResetBtnClick(Sender: TObject); + procedure VarListSelectionChange(Sender: TObject; User: boolean); private { private declarations } FAutoSized: Boolean; function Validate(out AMsg: String; out AControl: TWinControl): Boolean; + procedure UpdateBtnStates; public { public declarations } + procedure PrepareForPlan(APlan: integer); end; var @@ -85,17 +88,65 @@ implementation uses Math, - LatinSqrsUnit; + Utils, LatinSqrsUnit; { TLatinSpecsFrm } -procedure TLatinSpecsFrm.ResetBtnClick(Sender: TObject); -VAR i : integer; +procedure TLatinSpecsFrm.PrepareForPlan(APlan: Integer); begin - VarList.Clear; - for i := 1 to NoVariables do - VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); + ResetBtnClick(nil); + case APlan of + 1: begin + PanelD.Visible := false; + PanelGrp.Visible := false; + end; + 2: begin + PanelD.Visible := true; + PanelGrp.Visible := false; + end; + 3: begin + PanelD.Visible := true; + PanelGrp.Visible := false; + end; + 4: begin + PanelD.Visible := true; + PanelGrp.Visible := false; + end; + 5: begin + PanelD.Visible := false; + PanelGrp.Visible := true; + end; + 6: begin + PanelD.Visible := false; + PanelGrp.Visible := true; + end; + 7: begin + PanelD.Visible := true; + PanelGrp.Visible := true; + end; + 9: begin + PanelD.Visible := true; + PanelGrp.Visible := true; + end; + end; +end; + +procedure TLatinSpecsFrm.ResetBtnClick(Sender: TObject); +var + i: integer; +begin + VarList.Clear; + for i := 1 to NoVariables do + VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); + ACodeEdit.Text := ''; + BCodeEdit.Text := ''; + CCodeEdit.Text := ''; + DCodeEdit.Text := ''; + GrpCodeEdit.Text := ''; + DepVarEdit.Text := ''; + nPerCellEdit.Text := ''; + UpdatebtnStates; end; procedure TLatinSpecsFrm.FormActivate(Sender: TObject); @@ -127,112 +178,142 @@ begin ResetBtnClick(Self); end; -procedure TLatinSpecsFrm.GrpInBtnClick(Sender: TObject); -VAR index : integer; -begin - index := VarList.ItemIndex; - GrpCodeEdit.Text := VarList.Items.Strings[index]; - VarList.Items.Delete(index); - GrpInBtn.Enabled := false; - GrpOutBtn.Enabled := true; -end; - -procedure TLatinSpecsFrm.GrpOutBtnClick(Sender: TObject); -begin - VarList.Items.Add(GrpCodeEdit.Text); - GrpCodeEdit.Text := ''; - GrpInBtn.Enabled := true; - GrpOutBtn.Enabled := false; -end; - procedure TLatinSpecsFrm.AInBtnClick(Sender: TObject); -VAR index : integer; +var + index: integer; begin - index := VarList.ItemIndex; - ACodeEdit.Text := VarList.Items.Strings[index]; - VarList.Items.Delete(index); - AinBtn.Enabled := false; - AOutBtn.Enabled := true; + index := VarList.ItemIndex; + if (index > -1) and (ACodeEdit.Text = '') then + begin + ACodeEdit.Text := VarList.Items[index]; + VarList.Items.Delete(index); + UpdateBtnStates; + end; end; procedure TLatinSpecsFrm.AOutBtnClick(Sender: TObject); begin - VarList.Items.Add(ACodeEdit.Text); - ACodeEdit.Text := ''; - AinBtn.Enabled := true; - AOutBtn.Enabled := false; + if ACodeEdit.Text <> '' then + begin + VarList.Items.Add(ACodeEdit.Text); + ACodeEdit.Text := ''; + UpdateBtnStates; + end; end; procedure TLatinSpecsFrm.BInBtnClick(Sender: TObject); -VAR index : integer; +var + index: integer; begin - index := VarList.ItemIndex; - BCodeEdit.Text := VarList.Items.Strings[index]; - VarList.Items.Delete(index); - BinBtn.Enabled := false; - BOutBtn.Enabled := true; + index := VarList.ItemIndex; + if (index > -1) and (BCodeEdit.Text = '') then + begin + BCodeEdit.Text := VarList.Items[index]; + VarList.Items.Delete(index); + UpdateBtnStates; + end; end; procedure TLatinSpecsFrm.BOutBtnClick(Sender: TObject); begin - VarList.Items.Add(BCodeEdit.Text); - BCodeEdit.Text := ''; - BinBtn.Enabled := true; - BOutBtn.Enabled := false; + if BCodeEdit.Text <> '' then + begin + VarList.Items.Add(BCodeEdit.Text); + BCodeEdit.Text := ''; + UpdateBtnStates; + end; end; procedure TLatinSpecsFrm.CInBtnClick(Sender: TObject); -VAR index : integer; +var + index: integer; begin - index := VarList.ItemIndex; - CCodeEdit.Text := VarList.Items.Strings[index]; - VarList.Items.Delete(index); - CinBtn.Enabled := false; - COutBtn.Enabled := true; + index := VarList.ItemIndex; + if (index > -1) and (CCodeEdit.Text = '') then + begin + CCodeEdit.Text := VarList.Items[index]; + VarList.Items.Delete(index); + UpdateBtnStates; + end; end; procedure TLatinSpecsFrm.COutBtnClick(Sender: TObject); begin - VarList.Items.Add(CCodeEdit.Text); - CCodeEdit.Text := ''; - CinBtn.Enabled := true; - COutBtn.Enabled := false; + if CCodeEdit.Text <> '' then + begin + VarList.Items.Add(CCodeEdit.Text); + CCodeEdit.Text := ''; + UpdateBtnStates; + end; end; procedure TLatinSpecsFrm.DataInBtnClick(Sender: TObject); -VAR index : integer; +var + index: integer; begin - index := VarList.ItemIndex; - DepVarEdit.Text := VarList.Items.Strings[index]; - VarList.Items.Delete(index); - DataInBtn.Enabled := false; - DataOutBtn.Enabled := true; + index := VarList.ItemIndex; + if (index > -1) and (DepVarEdit.Text = '') then + begin + DepVarEdit.Text := VarList.Items[index]; + VarList.Items.Delete(index); + UpdateBtnStates; + end; end; procedure TLatinSpecsFrm.DataOutBtnClick(Sender: TObject); begin - VarList.Items.Add(DepVarEdit.Text); - DepVarEdit.Text := ''; - DataInBtn.Enabled := true; - DataOutBtn.Enabled := false; + if DepVarEdit.Text <> '' then + begin + VarList.Items.Add(DepVarEdit.Text); + DepVarEdit.Text := ''; + UpdateBtnStates; + end; end; procedure TLatinSpecsFrm.DInBtnClick(Sender: TObject); -VAR index : integer; +var + index: integer; begin - index := VarList.ItemIndex; - DCodeEdit.Text := VarList.Items.Strings[index]; - VarList.Items.Delete(index); - DinBtn.Enabled := false; - DOutBtn.Enabled := true; + index := VarList.ItemIndex; + if (index > -1) and (DCodeEdit.Text = '') then + begin + DCodeEdit.Text := VarList.Items[index]; + VarList.Items.Delete(index); + UpdateBtnStates; + end; end; procedure TLatinSpecsFrm.DOutBtnClick(Sender: TObject); begin - VarList.Items.Add(DCodeEdit.Text); - DCodeEdit.Text := ''; - DinBtn.Enabled := true; - DOutBtn.Enabled := false; + if DCodeEdit.Text <> '' then + begin + VarList.Items.Add(DCodeEdit.Text); + DCodeEdit.Text := ''; + UpdateBtnStates; + end; +end; + +procedure TLatinSpecsFrm.GrpInBtnClick(Sender: TObject); +var + index: integer; +begin + index := VarList.ItemIndex; + if (index > -1) and (GrpCodeEdit.Text = '') then + begin + GrpCodeEdit.Text := VarList.Items[index]; + VarList.Items.Delete(index); + UpdateBtnStates; + end; +end; + +procedure TLatinSpecsFrm.GrpOutBtnClick(Sender: TObject); +begin + if GrpCodeEdit.Text <> '' then + begin + VarList.Items.Add(GrpCodeEdit.Text); + GrpCodeEdit.Text := ''; + UpdateBtnStates; + end; end; procedure TLatinSpecsFrm.OKBtnClick(Sender: TObject); @@ -242,29 +323,90 @@ var begin if not Validate(msg, C) then begin C.SetFocus; - MessageDlg(msg, mtError, [mbOK], 0); + ErrorMsg(msg); ModalResult := mrNone; end; end; +procedure TLatinSpecsFrm.UpdateBtnStates; +begin + AInBtn.Enabled := (VarList.ItemIndex > -1) and (ACodeEdit.Text = ''); + BInBtn.Enabled := (VarList.ItemIndex > -1) and (BCodeEdit.Text = ''); + CInBtn.Enabled := (VarList.ItemIndex > -1) and (CCodeEdit.Text = ''); + DInBtn.Enabled := (VarList.ItemIndex > -1) and (DCodeEdit.Text = ''); + GrpInBtn.Enabled := (VarList.ItemIndex > -1) and (GrpCodeEdit.Text = ''); + DataInBtn.Enabled := (VarList.ItemIndex > -1) and (DepVarEdit.Text = ''); + + AOutBtn.Enabled := (ACodeEdit.Text <> ''); + BOutBtn.Enabled := (BCodeEdit.Text <> ''); + COutBtn.Enabled := (CCodeEdit.Text <> ''); + DOutBtn.Enabled := (DCodeEdit.Text <> ''); + GrpOutBtn.Enabled := (GrpCodeEdit.Text <> ''); + DataOutBtn.Enabled := (DepVarEdit.Text <> ''); +end; + function TLatinSpecsFrm.Validate(out AMsg: String; out AControl: TWinControl): Boolean; var n: Integer; begin Result := false; + if (nPerCellEdit.Text = '') then begin AMsg := 'Please specify the number of cases per cell.'; AControl := nPercellEdit; exit; end; - if not TryStrToInt(nPercellEdit.Text, n) or (n <= 0) then begin - AMsg := 'Please specify a valid number for the cases per cell.'; + if not TryStrToInt(nPerCellEdit.Text, n) or (n <= 0) then begin + AMsg := 'Please specify a valid (positive) number for the cases per cell.'; AControl := nPercellEdit; exit; end; + + if PanelA.Visible and (ACodeEdit.Text = '') then + begin + AMsg := 'Factor A code variable is not specified.'; + AControl := ACodeEdit; + exit; + end; + if PanelB.Visible and (BCodeEdit.Text = '') then + begin + AMsg := 'Factor B code variable is not specified.'; + Acontrol := BCodeEdit; + exit; + end; + if PanelC.Visible and (CCodeEdit.Text = '') then + begin + AMsg := 'Factor C code variable is not specified.'; + Acontrol := CCodeEdit; + exit; + end; + if PanelD.Visible and (DCodeEdit.Text = '') then + begin + AMsg := 'Factor D code variable is not specified.'; + Acontrol := DCodeEdit; + exit; + end; + if PanelGrp.Visible and (GrpCodeEdit.Text = '') then + begin + AMsg := 'Group code variable is not specified.'; + Acontrol := GrpCodeEdit; + exit; + end; + if PanelDep.Visible and (DepVarEdit.Text = '') then + begin + AMsg := 'Dependent variable is not specified.'; + Acontrol := DepVarEdit; + exit; + end; + Result := true; end; +procedure TLatinSpecsFrm.VarListSelectionChange(Sender: TObject; User: boolean); +begin + UpdateBtnStates; +end; + initialization {$I latinspecsunit.lrs} diff --git a/applications/lazstats/source/forms/analysis/comparisons/latinsqrsunit.lfm b/applications/lazstats/source/forms/analysis/comparisons/latinsqrsunit.lfm index aa77da113..b1fef2f17 100644 --- a/applications/lazstats/source/forms/analysis/comparisons/latinsqrsunit.lfm +++ b/applications/lazstats/source/forms/analysis/comparisons/latinsqrsunit.lfm @@ -13,41 +13,40 @@ object LatinSqrsFrm: TLatinSqrsFrm OnCreate = FormCreate Position = poMainFormCenter LCLVersion = '2.1.0.0' - object CancelBtn: TButton + object ComputeBtn: TButton AnchorSideLeft.Side = asrCenter AnchorSideTop.Control = Plan AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = OKBtn - Left = 399 + AnchorSideRight.Control = CloseBtn + Left = 372 Height = 25 Top = 214 - Width = 62 + Width = 76 Anchors = [akTop, akRight] AutoSize = True BorderSpacing.Top = 8 BorderSpacing.Right = 12 BorderSpacing.Bottom = 8 - Caption = 'Cancel' - ModalResult = 2 + Caption = 'Compute' + OnClick = ComputeBtnClick TabOrder = 2 end - object OKBtn: TButton + object CloseBtn: TButton AnchorSideTop.Control = Plan AnchorSideTop.Side = asrBottom AnchorSideRight.Control = Owner AnchorSideRight.Side = asrBottom - Left = 473 + Left = 460 Height = 25 Top = 214 - Width = 42 + Width = 55 Anchors = [akTop, akRight] AutoSize = True BorderSpacing.Top = 8 BorderSpacing.Right = 8 BorderSpacing.Bottom = 8 - Caption = 'OK' - ModalResult = 1 - OnClick = OKBtnClick + Caption = 'Close' + ModalResult = 11 TabOrder = 3 end object Plan: TRadioGroup @@ -84,15 +83,14 @@ object LatinSqrsFrm: TLatinSqrsFrm 'Plan 7. Plan 5 with superimposing of an orthogonal Latin square.' 'Plan 9. AxBxC (same square used for all levels of Factor C.)' ) - OnClick = PlanClick TabOrder = 0 end object HelpBtn: TButton Tag = 130 AnchorSideTop.Control = Plan AnchorSideTop.Side = asrBottom - AnchorSideRight.Control = CancelBtn - Left = 340 + AnchorSideRight.Control = ComputeBtn + Left = 313 Height = 25 Top = 214 Width = 51 diff --git a/applications/lazstats/source/forms/analysis/comparisons/latinsqrsunit.pas b/applications/lazstats/source/forms/analysis/comparisons/latinsqrsunit.pas index 3b31b575b..85ad0c0eb 100644 --- a/applications/lazstats/source/forms/analysis/comparisons/latinsqrsunit.pas +++ b/applications/lazstats/source/forms/analysis/comparisons/latinsqrsunit.pas @@ -15,27 +15,25 @@ type { TLatinSqrsFrm } TLatinSqrsFrm = class(TForm) - CancelBtn: TButton; + ComputeBtn: TButton; HelpBtn: TButton; - OKBtn: TButton; + CloseBtn: TButton; Plan: TRadioGroup; + procedure ComputeBtnClick(Sender: TObject); procedure FormActivate(Sender: TObject); procedure FormCreate(Sender: TObject); procedure HelpBtnClick(Sender: TObject); - procedure OKBtnClick(Sender: TObject); - procedure PlanClick(Sender: TObject); private { private declarations } - Btn : integer; - procedure Plan1(Sender: TObject); - procedure Plan2(Sender: TObject); - procedure Plan3(Sender: TObject); - procedure Plan4(Sender: TObject); - procedure Plan5(Sender: TObject); - procedure Plan6(Sender: TObject); - procedure Plan7(Sender: TObject); -// procedure Plan8(Sender: TObject); - procedure Plan9(Sender: TObject); + procedure Plan1; + procedure Plan2; + procedure Plan3; + procedure Plan4; + procedure Plan5; + procedure Plan6; + procedure Plan7; +// procedure Plan8; + procedure Plan9; public { public declarations } @@ -47,49 +45,35 @@ var implementation uses - Math; + Math, Utils; { TLatinSqrsFrm } -procedure TLatinSqrsFrm.OKBtnClick(Sender: TObject); +procedure TLatinSqrsFrm.ComputeBtnClick(Sender: TObject); +var + btn: Integer; begin - case Btn of - 1 : begin - Plan1(Self); - end; - 2 : begin - Plan2(Self); - end; - 3 : begin - Plan3(Self); - end; - 4 : begin - Plan4(Self); - end; - 5 : begin - Plan5(Self); - end; - 6 : begin - Plan6(Self); - end; - 7 : begin - Plan7(Self); - end; - 8 : begin - Plan9(Self); - end; - end; - Close; + btn := Plan.ItemIndex + 1; + case btn of + 1: Plan1; + 2: Plan2; + 3: Plan3; + 4: Plan4; + 5: Plan5; + 6: Plan6; + 7: Plan7; + 8: Plan9; + end; end; procedure TLatinSqrsFrm.FormActivate(Sender: TObject); var w: Integer; begin - w := MaxValue([HelpBtn.Width, CancelBtn.Width, OKBtn.Width]); + w := MaxValue([HelpBtn.Width, ComputeBtn.Width, CloseBtn.Width]); HelpBtn.Constraints.MinWidth := w; - CancelBtn.Constraints.MinWidth := w; - OKBtn.Constraints.MinWidth := w; + ComputeBtn.Constraints.MinWidth := w; + CloseBtn.Constraints.MinWidth := w; end; procedure TLatinSqrsFrm.FormCreate(Sender: TObject); @@ -97,8 +81,6 @@ begin Assert(OS3MainFrm <> nil); if LatinSpecsFrm = nil then Application.CreateForm(TLatinSpecsFrm, LatinSpecsFrm); - if OutputFrm = nil then - Application.CreateForm(TOutputFrm, OutputFrm); end; procedure TLatinSqrsFrm.HelpBtnClick(Sender: TObject); @@ -108,839 +90,743 @@ begin ContextHelpForm.HelpMessage((Sender as TButton).tag); end; -procedure TLatinSqrsFrm.PlanClick(Sender: TObject); -begin - Btn := Plan.ItemIndex + 1; -end; - -procedure TLatinSqrsFrm.Plan1(Sender: TObject); -label cleanup; +procedure TLatinSqrsFrm.Plan1; var - NoFactors : integer; - n : integer; // no. of subjects per cell - Acol, Bcol, Ccol, DataCol : integer; // variable columns in grid - FactorA : string; - FactorB : string; - FactorC : string; - DataVar : string; - cellstring : string; - i, j, minA, minB, minC, maxA, maxB, maxC, rangeA, rangeB, rangeC : integer; - value : integer; - cellcnts : IntDyneMat; - celltotals : DblDyneMat; - Ctotals : DblDyneVec; - design : StrDyneMat; - G, term1, term2, term3, term4, term5, term6, sumxsqr : double; - sumAsqr, sumBsqr, sumCsqr, sumABCsqr, SSA, SSB, SSC : double; - SSbetween, SSwithin, SSres, SStotal : double; - MSa, MSb, MSc, MSres, MSwithin : double; - data, GrandMean : double; - p, row, col, slice : integer; - dfa, dfb, dfc, dfres, dfwithin, dftotal, fa, fb, fc, fpartial : double; - proba, probb, probc, probpartial : double; + n: integer; // no. of subjects per cell + Acol, Bcol, Ccol, DataCol: integer; // variable columns in grid + FactorA: string; + FactorB: string; + FactorC: string; + DataVar: string; + cellstring: string; + i, j, minA, minB, minC, maxA, maxB, maxC, rangeA, rangeB, rangeC: integer; + value: integer; + cellcnts: IntDyneMat; + celltotals: DblDyneMat; + Ctotals: DblDyneVec; + design: StrDyneMat; + G, term1, term2, term3, term4, term5, term6, sumxsqr: double; + sumAsqr, sumBsqr, sumCsqr, sumABCsqr, SSA, SSB, SSC: double; + SSwithin, SSres, SStotal: double; + MSa, MSb, MSc, MSres, MSwithin: double; + data, GrandMean: double; + p, row, col, slice: integer; + dfa, dfb, dfc, dfres, dfwithin, dftotal, fa, fb, fc, fpartial: double; + proba, probb, probc, probpartial: double; + lReport: TStrings; begin - NoFactors := 3; - LatinSpecsFrm.PanelD.Visible := false; - LatinSpecsFrm.PanelGrp.Visible := false; - LatinSpecsFrm.AinBtn.Enabled := true; - LatinSpecsFrm.AoutBtn.Enabled := false; - LatinSpecsFrm.BinBtn.Enabled := true; - LatinSpecsFrm.BoutBtn.Enabled := false; - LatinSpecsFrm.CinBtn.Enabled := true; - LatinSpecsFrm.CoutBtn.Enabled := false; -// LatinSpecsFrm.DCodeLabel.Visible := false; -// LatinSpecsFrm.GrpCodeLabel.Visible := false; -// LatinSpecsFrm.DinBtn.Visible := false; -// LatinSpecsFrm.DoutBtn.Visible := false; - LatinSpecsFrm.ACodeEdit.Text := ''; - LatinSpecsFrm.BCodeEdit.Text := ''; - LatinSpecsFrm.CCodeEdit.Text := ''; - LatinSpecsFrm.DCodeEdit.Text := ''; - LatinSpecsFrm.GrpCodeEdit.Text := ''; - LatinSpecsFrm.DepVarEdit.Text := ''; - LatinSpecsFrm.nPerCellEdit.Text := ''; -// LatinSpecsFrm.DCodeEdit.Visible := false; -// LatinSpecsFrm.GrpInBtn.Visible := false; -// LatinSpecsFrm.GrpOutBtn.Visible := false; -// LatinSpecsFrm.GrpCodeEdit.Visible := false; - LatinSpecsFrm.DataInBtn.Enabled := true; - LatinSpecsFrm.DataOutBtn.Enabled := false; + LatinSpecsFrm.PrepareForPlan(1); + if LatinSpecsFrm.ShowModal <> mrOK then + exit; - if LatinSpecsFrm.ShowModal = mrCancel then - exit; + n := StrToInt(LatinSpecsFrm.nPerCellEdit.Text); + FactorA := LatinSpecsFrm.ACodeEdit.Text; + FactorB := LatinSpecsFrm.BCodeEdit.Text; + FactorC := LatinSpecsFrm.CCodeEdit.Text; + DataVar := LatinSpecsFrm.DepVarEdit.Text; - n := StrToInt(LatinSpecsFrm.nPerCellEdit.Text); - FactorA := LatinSpecsFrm.ACodeEdit.Text; - FactorB := LatinSpecsFrm.BCodeEdit.Text; - FactorC := LatinSpecsFrm.CCodeEdit.Text; - DataVar := LatinSpecsFrm.DepVarEdit.Text; - for i := 1 to NoVariables do + for i := 1 to NoVariables do + begin + cellstring := OS3MainFrm.DataGrid.Cells[i,0]; + if (cellstring = FactorA) then ACol := i; + if (cellstring = FactorB) then BCol := i; + if (cellstring = FactorC) then Ccol := i; + if (cellstring = DataVar) then DataCol := i; + end; + + // determine no. of levels in A, B and C + minA := MaxInt; + minB := MaxInt; + minC := MaxInt; + maxA := -MaxInt; + maxB := -MaxInt; + maxC := -MaxInt; + for i := 1 to NoCases do + begin + value := StrToInt(OS3MainFrm.DataGrid.Cells[ACol,i]); + if value < minA then minA := value; + if value > maxA then maxA := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[BCol,i]); + if value < minB then minB := value; + if value > maxB then maxB := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); + if value < minC then minC := value; + if value > maxC then maxC := value; + end; + rangeA := maxA - minA + 1; + rangeB := maxB - minB + 1; + rangeC := maxC - minC + 1; + + // check for squareness + if (rangeA <> rangeB) or (rangeA <> rangeC) or (rangeB <> rangeC) then + begin + ErrorMsg('In a Latin square the range of values should all be equal.'); + exit; + end; + p := rangeA; + + // set up an array for cell counts and for cell sums and marginal sums + SetLength(cellcnts, rangeA+1, rangeB+1); + SetLength(celltotals, rangeA+1, rangeB+1); + SetLength(Ctotals, rangeC+1); + SetLength(Design, rangeA, rangeB); + + // initialize arrays and values + for i := 0 to rangeA do + for j := 0 to rangeB do begin - cellstring := OS3MainFrm.DataGrid.Cells[i,0]; - if (cellstring = FactorA) then ACol := i; - if (cellstring = FactorB) then BCol := i; - if (cellstring = FactorC) then Ccol := i; - if (cellstring = DataVar) then DataCol := i; + cellcnts[i,j] := 0; + celltotals[i,j] := 0.0; end; - // determine no. of levels in A, B and C - minA := 1000; - minB := 1000; - minC := 1000; - maxA := -1000; - maxB := -1000; - maxC := -1000; - for i := 1 to NoCases do - begin - value := StrToInt(OS3MainFrm.DataGrid.Cells[ACol,i]); - if value < minA then minA := value; - if value > maxA then maxA := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[BCol,i]); - if value < minB then minB := value; - if value > maxB then maxB := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); - if value < minC then minC := value; - if value > maxC then maxC := value; - end; - rangeA := maxA - minA + 1; - rangeB := maxB - minB + 1; - rangeC := maxC - minC + 1; + for i := 0 to rangeC-1 do + Ctotals[i] := 0; - // check for squareness - if ( (rangeA <> rangeB) or (rangeA <> rangeC) or (rangeB <> rangeC)) then - begin - ShowMessage('ERROR! In a Latin square the range of values should all be equal!'); - exit; - end; - p := rangeA; + G := 0.0; + sumxsqr := 0.0; + sumAsqr := 0.0; + sumBsqr := 0.0; + sumCsqr := 0.0; + sumABCsqr := 0.0; + term1 := 0.0; + term2 := 0.0; + term3 := 0.0; + term4 := 0.0; + term5 := 0.0; + term6 := 0.0; + GrandMean := 0.0; - // set up an array for cell counts and for cell sums and marginal sums - SetLength(cellcnts,rangeA+1,rangeB+1); - SetLength(celltotals,rangeA+1,rangeB+1); - SetLength(Ctotals,rangeC+1); - SetLength(Design,rangeA,rangeB); + // Read in the data + for i := 1 to NoCases do + begin + row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); + col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); + slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); + data := StrToFloat(OS3MainFrm.DataGrid.Cells[DataCol,i]); + cellcnts[row-1,col-1] := cellcnts[row-1,col-1] + 1; + celltotals[row-1,col-1] := celltotals[row-1,col-1] + data; + Ctotals[slice-1] := Ctotals[slice-1] + data; + sumxsqr := sumxsqr + (data * data); + GrandMean := GrandMean + data; + end; - // initialize arrays and values - for i := 0 to rangeA do + // check for equal cell counts + for i := 0 to p-1 do + for j := 0 to p-1 do begin - for j := 0 to rangeB do - begin - cellcnts[i,j] := 0; - celltotals[i,j] := 0.0; - end; - end; - for i := 0 to rangeC-1 do Ctotals[i] := 0; - G := 0.0; - sumxsqr := 0.0; - sumAsqr := 0.0; - sumBsqr := 0.0; - sumCsqr := 0.0; - sumABCsqr := 0.0; - term1 := 0.0; - term2 := 0.0; - term3 := 0.0; - term4 := 0.0; - term5 := 0.0; - term6 := 0.0; - GrandMean := 0.0; - - // Read in the data - for i := 1 to NoCases do - begin - row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); - col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); - slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); - data := StrToFloat(OS3MainFrm.DataGrid.Cells[DataCol,i]); - cellcnts[row-1,col-1] := cellcnts[row-1,col-1] + 1; - celltotals[row-1,col-1] := celltotals[row-1,col-1] + data; - Ctotals[slice-1] := Ctotals[slice-1] + data; - sumxsqr := sumxsqr + (data * data); - GrandMean := GrandMean + data; + if cellcnts[i,j] <> n then + begin + ErrorMsg('Cell sizes are not equal.'); + exit; + end; end; - // check for equal cell counts - for i := 0 to p-1 do + // calculate values + for i := 0 to p - 1 do // get row and column sums + begin + for j := 0 to p-1 do begin - for j := 0 to p-1 do - begin - if cellcnts[i,j] <> n then - begin - ShowMessage('cell sizes are not equal!'); - goto cleanup; - end; - end; + celltotals[i,p] := celltotals[i,p] + celltotals[i,j]; + celltotals[p,j] := celltotals[p,j] + celltotals[i,j]; + sumABCsqr := sumABCsqr + (celltotals[i,j] * celltotals[i,j]); end; + end; - // calculate values - for i := 0 to p - 1 do // get row and column sums - begin - for j := 0 to p-1 do - begin - celltotals[i,p] := celltotals[i,p] + celltotals[i,j]; - celltotals[p,j] := celltotals[p,j] + celltotals[i,j]; - sumABCsqr := sumABCsqr + (celltotals[i,j] * celltotals[i,j]); - end; - end; - for i := 0 to p-1 do G := G + Ctotals[i]; - term1 := (G * G) / (n * p * p); - term2 := sumxsqr; - for i := 0 to p-1 do // sum of squared A's - sumAsqr := sumAsqr + (celltotals[i,p] * celltotals[i,p]); - for i := 0 to p-1 do // sum of squared B's - sumBsqr := sumBsqr + (celltotals[p,i] * celltotals[p,i]); - for i := 0 to p-1 do // sum of squared C's - sumCsqr := sumCsqr + (Ctotals[i] * Ctotals[i]); - term3 := sumAsqr / (n * p); - term4 := sumBsqr / (n * p); - term5 := sumCsqr / (n * p); - term6 := sumABCsqr / n; - SSA := term3 - term1; - SSB := term4 - term1; - SSC := term5 - term1; - SSbetween := term6 - term1; - SSwithin := term2 - term6; - SSres := term6 - term3 - term4 - term5 + 2 * term1; - SStotal := SSA + SSB + SSC + SSres + SSwithin; - dfa := p-1; - dfb := p-1; - dfc := p-1; - dfres := (p-1) * (p-2); - dfwithin := (p * p) * (n - 1); - dftotal := n * p * p - 1; - MSa := SSA / dfa; - MSb := SSB / dfb; - MSc := SSC / dfc; - MSres := SSres / dfres; - MSwithin := SSwithin / dfwithin; - fa := MSa / MSwithin; - fb := MSb / MSwithin; - fc := MSc / MSwithin; - fpartial := MSres / MSwithin; - proba := probf(fa,dfa,dfwithin); - probb := probf(fb,dfb,dfwithin); - probc := probf(fc,dfc,dfwithin); - probpartial := probf(fpartial,dfres,dfwithin); + for i := 0 to p-1 do + G := G + Ctotals[i]; - // show ANOVA table results - OutputFrm.RichEdit.Clear; - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Latin Square Analysis Plan 1 Results'); - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); - OutputFrm.RichEdit.Lines.Add('Source SS DF MS F Prob.>F'); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); - cellstring := 'Factor A '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSA,dfa,MSa,fa,proba]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Factor B '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSB,dfb,MSb,fb,probb]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Factor C '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSC,dfc,MSc,fc,probc]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Residual '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSres,dfres,MSres,fpartial,probpartial]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Within '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f',[SSwithin, dfwithin, MSwithin]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Total '; - cellstring := cellstring + format('%9.3f %9.0f',[SStotal, dftotal]); - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); + term1 := (G * G) / (n * p * p); + term2 := sumxsqr; + + for i := 0 to p-1 do // sum of squared A's + sumAsqr := sumAsqr + (celltotals[i,p] * celltotals[i,p]); + for i := 0 to p-1 do // sum of squared B's + sumBsqr := sumBsqr + (celltotals[p,i] * celltotals[p,i]); + for i := 0 to p-1 do // sum of squared C's + sumCsqr := sumCsqr + (Ctotals[i] * Ctotals[i]); + + term3 := sumAsqr / (n * p); + term4 := sumBsqr / (n * p); + term5 := sumCsqr / (n * p); + term6 := sumABCsqr / n; + SSA := term3 - term1; + SSB := term4 - term1; + SSC := term5 - term1; + SSwithin := term2 - term6; + SSres := term6 - term3 - term4 - term5 + 2 * term1; + SStotal := SSA + SSB + SSC + SSres + SSwithin; + dfa := p-1; + dfb := p-1; + dfc := p-1; + dfres := (p-1) * (p-2); + dfwithin := (p * p) * (n - 1); + dftotal := n * p * p - 1; + MSa := SSA / dfa; + MSb := SSB / dfb; + MSc := SSC / dfc; + MSres := SSres / dfres; + MSwithin := SSwithin / dfwithin; + fa := MSa / MSwithin; + fb := MSb / MSwithin; + fc := MSc / MSwithin; + fpartial := MSres / MSwithin; + proba := probf(fa,dfa,dfwithin); + probb := probf(fb,dfb,dfwithin); + probc := probf(fc,dfc,dfwithin); + probpartial := probf(fpartial,dfres,dfwithin); + + // show ANOVA table results + lReport := TStringList.Create; + try + lReport.Add('LATIN SQUARE ANALYSIS PLAN 1 RESULTS'); + lReport.Add(''); + lReport.Add('-----------------------------------------------------------'); + lReport.Add('Source SS DF MS F Prob.>F'); + lReport.Add('-----------------------------------------------------------'); + lReport.Add('Factor A %9.3f %9.0f %9.3f %9.3f %9.3f', [SSA, dfa, MSa, fa, proba]); + lReport.Add('Factor B %9.3f %9.0f %9.3f %9.3f %9.3f', [SSB, dfb, MSb, fb, probb]); + lReport.Add('Factor C %9.3f %9.0f %9.3f %9.3f %9.3f', [SSC, dfc, MSc, fc, probc]); + lReport.Add('Residual %9.3f %9.0f %9.3f %9.3f %9.3f',[SSres, dfres, MSres, fpartial, probpartial]); + lReport.Add('Within %9.3f %9.0f %9.3f', [SSwithin, dfwithin, MSwithin]); + lReport.Add('Total %9.3f %9.0f', [SStotal, dftotal]); + lReport.Add('-----------------------------------------------------------'); // show design - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Experimental Design'); + lReport.Add(''); + lReport.Add('Experimental Design'); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorB]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := Format('%10s', [FactorB]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ',[i]); + lReport.Add(cellstring); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + lReport.Add('%10s', [FactorA]); for i := 1 to NoCases do begin - row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); - col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); - slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); - Design[row-1,col-1] := 'C' + IntToStr(slice); + row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); + col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); + slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); + Design[row-1, col-1] := 'C' + IntToStr(slice); end; for i := 0 to p - 1 do begin - cellstring := format(' %3d ',[i+1]); - for j := 0 to p - 1 do - begin - cellstring := cellstring + format('%5s',[Design[i,j]]); - end; - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := Format(' %3d ',[i+1]); + for j := 0 to p - 1 do + cellstring := cellstring + Format('%5s', [Design[i,j]]); + lReport.Add(cellstring); end; cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); // show table cell means for i := 0 to p-1 do - for j := 0 to p-1 do - celltotals[i,j] := celltotals[i,j] / n; + for j := 0 to p-1 do + celltotals[i,j] := celltotals[i,j] / n; for i := 0 to p-1 do begin - celltotals[i,p] := celltotals[i,p] / (p * n); - celltotals[p,i] := celltotals[p,i] / (p * n); + celltotals[i,p] := celltotals[i,p] / (p * n); + celltotals[p,i] := celltotals[p,i] / (p * n); end; GrandMean := GrandMean / (p * p * n); - for i := 0 to p-1 do Ctotals[i] := Ctotals[i] / (p * n); + for i := 0 to p-1 do + Ctotals[i] := Ctotals[i] / (p * n); - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Cell means and totals'); + lReport.Add(''); + lReport.Add(''); + lReport.Add('Cell means and totals'); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorB]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + cellstring := format('%10s', [FactorB]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := Format('%10s', [FactorA]); + lReport.Add(cellstring); for i := 0 to p-1 do begin - cellstring := format(' %3d ',[i+1]); - for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[celltotals[i,j]]); - end; - cellstring := cellstring + format(' %8.3f ',[celltotals[i,p]]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := Format(' %3d ', [i+1]); + for j := 0 to p - 1 do + cellstring := cellstring + Format(' %8.3f ', [celltotals[i,j]]); + cellstring := cellstring + Format(' %8.3f ', [celltotals[i,p]]); + lReport.Add(cellstring); end; cellstring := 'Total '; for j := 0 to p-1 do - cellstring := cellstring + format(' %8.3f ',[celltotals[p,j]]); - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [celltotals[p,j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); // show category means - OutputFrm.RichEdit.Lines.Add(''); + lReport.Add(''); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorC]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + cellstring := Format('%10s', [FactorC]); + for i := 1 to p do + cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Ctotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Ctotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellString); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); - OutputFrm.ShowModal; + DisplayReport(lReport); + finally + lReport.Free; -cleanup: Design := nil; Ctotals := nil; celltotals := nil; cellcnts := nil; + end; end; -procedure TLatinSqrsFrm.Plan2(Sender: TObject); -label cleanup; +procedure TLatinSqrsFrm.Plan2; var - NoFactors : integer; - n : integer; // no. of subjects per cell - Acol, Bcol, Ccol, Dcol, DataCol : integer; // variable columns in grid - FactorA : string; - FactorB : string; - FactorC : string; - FactorD : string; - DataVar : string; - cellstring : string; - i, j, k, minA, minB, minC, maxA, maxB, maxC : integer; - minD, maxD, rangeD, rangeA, rangeB, rangeC : integer; - value : integer; - cellcnts : IntDyneCube; - celltotals : DblDyneCube; - Ctotals : DblDyneVec; - design : StrDyneMat; - G, term1, term2, term3, term4, term5, term6, term7, term8 : double; - term9, sumxsqr : double; - sumAsqr, sumBsqr, sumCsqr, sumDsqr, SSA, SSB, SSC, SSD : double; - sumADsqr, sumBDsqr, sumCDsqr : double; - ADmat, BDmat, CDmat : DblDyneMat; - SSAD, SSBD, SSCD, SSwithin, SSres, SStotal : double; - MSa, MSb, MSc, MSd, MSAD, MSBD, MSCD, MSres, MSwithin : double; - data, GrandMean : double; - p, row, col, slice, block : integer; - dfa, dfb, dfc, dfres, dfwithin, dftotal, fa, fb, fc, fpartial : double; - dfd, fd, fad, fbd, fcd, dfad, dfbd, dfcd : double; - proba, probb, probc, probd, probpartial : double; - probad, probbd, probcd: double; + n: integer; // no. of subjects per cell + Acol, Bcol, Ccol, Dcol, DataCol: integer; // variable columns in grid + FactorA: string; + FactorB: string; + FactorC: string; + FactorD: string; + DataVar: string; + cellstring: string; + i, j, k, minA, minB, minC, maxA, maxB, maxC: integer; + minD, maxD, rangeD, rangeA, rangeB, rangeC: integer; + value: integer; + cellcnts: IntDyneCube; + celltotals: DblDyneCube; + Ctotals: DblDyneVec; + design: StrDyneMat; + G, term1, term2, term3, term4, term5, term6, term7, term8: double; + term9, sumxsqr: double; + sumAsqr, sumBsqr, sumCsqr, sumDsqr, SSA, SSB, SSC, SSD: double; + sumADsqr, sumBDsqr, sumCDsqr: double; + ADmat, BDmat, CDmat: DblDyneMat; + SSAD, SSBD, SSCD, SSwithin, SSres, SStotal: double; + MSa, MSb, MSc, MSd, MSAD, MSBD, MSCD, MSres, MSwithin: double; + data, GrandMean: double; + p, row, col, slice, block: integer; + dfa, dfb, dfc, dfres, dfwithin, dftotal, fa, fb, fc, fpartial: double; + dfd, fd, fad, fbd, fcd, dfad, dfbd, dfcd: double; + proba, probb, probc, probd, probpartial: double; + probad, probbd, probcd: double; + lReport: TStrings; begin - NoFactors := 4; - LatinSpecsFrm.PanelD.Visible := true; - LatinSpecsFrm.PanelGrp.Visible := false; - LatinSpecsFrm.AinBtn.Enabled := true; - LatinSpecsFrm.AoutBtn.Enabled := false; - LatinSpecsFrm.BinBtn.Enabled := true; - LatinSpecsFrm.BoutBtn.Enabled := false; - LatinSpecsFrm.CinBtn.Enabled := true; - LatinSpecsFrm.CoutBtn.Enabled := false; - LatinSpecsFrm.DCodeEdit.Visible := true; - LatinSpecsFrm.ACodeEdit.Text := ''; - LatinSpecsFrm.BCodeEdit.Text := ''; - LatinSpecsFrm.CCodeEdit.Text := ''; - LatinSpecsFrm.DCodeEdit.Text := ''; - LatinSpecsFrm.GrpCodeEdit.Text := ''; - LatinSpecsFrm.DepVarEdit.Text := ''; - LatinSpecsFrm.nPerCellEdit.Text := ''; - LatinSpecsFrm.DinBtn.Enabled := true; - LatinSpecsFrm.DoutBtn.Enabled := false; - LatinSpecsFrm.DataInBtn.Enabled := true; - LatinSpecsFrm.DataOutBtn.Enabled := false; - LatinSpecsFrm.ShowModal; - if LatinSpecsFrm.ModalResult = mrCancel then exit; - n := StrToInt(LatinSpecsFrm.nPerCellEdit.Text); - if n <= 0 then - begin - ShowMessage('Please specify the number of cases per cell.'); - exit; - end; - FactorA := LatinSpecsFrm.ACodeEdit.Text; - FactorB := LatinSpecsFrm.BCodeEdit.Text; - FactorC := LatinSpecsFrm.CCodeEdit.Text; - FactorD := LatinSpecsFrm.DCodeEdit.Text; - DataVar := LatinSpecsFrm.DepVarEdit.Text; - for i := 1 to NoVariables do - begin - cellstring := OS3MainFrm.DataGrid.Cells[i,0]; - if (cellstring = FactorA) then ACol := i; - if (cellstring = FactorB) then BCol := i; - if (cellstring = FactorC) then Ccol := i; - if (cellstring = FactorD) then Dcol := i; - if (cellstring = DataVar) then DataCol := i; - end; - // determine no. of levels in A, B and C - minA := 1000; - minB := 1000; - minC := 1000; - minD := 1000; - maxA := -1000; - maxB := -1000; - maxC := -1000; - maxD := -1000; - for i := 1 to NoCases do - begin - value := StrToInt(OS3MainFrm.DataGrid.Cells[ACol,i]); - if value < minA then minA := value; - if value > maxA then maxA := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[BCol,i]); - if value < minB then minB := value; - if value > maxB then maxB := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); - if value < minC then minC := value; - if value > maxC then maxC := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol,i]); - if value < minD then minD := value; - if value > maxD then maxD := value; - end; - rangeA := maxA - minA + 1; - rangeB := maxB - minB + 1; - rangeC := maxC - minC + 1; - rangeD := maxD - minD + 1; + LatinSpecsFrm.PrepareForPlan(2); + if LatinSpecsFrm.ShowModal <> mrOK then + exit; - // check for squareness - if ( (rangeA <> rangeB) or (rangeA <> rangeC) or (rangeB <> rangeC)) then - begin - ShowMessage('ERROR! In a Latin square the range of values should all be equal!'); - exit; - end; - p := rangeA; + n := StrToInt(LatinSpecsFrm.nPerCellEdit.Text); + FactorA := LatinSpecsFrm.ACodeEdit.Text; + FactorB := LatinSpecsFrm.BCodeEdit.Text; + FactorC := LatinSpecsFrm.CCodeEdit.Text; + FactorD := LatinSpecsFrm.DCodeEdit.Text; + DataVar := LatinSpecsFrm.DepVarEdit.Text; - // set up an array for cell counts and for cell sums and marginal sums - SetLength(cellcnts,rangeA+1,rangeB+1,rangeD+1); - SetLength(celltotals,rangeA+1,rangeB+1,rangeD+1); - SetLength(ADmat,rangeA+1,rangeD+1); - SetLength(BDmat,rangeB+1,rangeD+1); - SetLength(CDmat,rangeC+1,rangeD+1); - SetLength(Ctotals,rangeC+1); - SetLength(Design,rangeA,rangeB); + for i := 1 to NoVariables do + begin + cellstring := OS3MainFrm.DataGrid.Cells[i,0]; + if (cellstring = FactorA) then ACol := i; + if (cellstring = FactorB) then BCol := i; + if (cellstring = FactorC) then Ccol := i; + if (cellstring = FactorD) then Dcol := i; + if (cellstring = DataVar) then DataCol := i; + end; - // initialize arrays and values - for i := 0 to rangeA do - begin - for j := 0 to rangeB do + // determine no. of levels in A, B and C + minA := MaxInt; + minB := MaxInt; + minC := MaxInt; + minD := MaxInt; + maxA := -MaxInt; + maxB := -MaxInt; + maxC := -MaxInt; + maxD := -MaxInt; + for i := 1 to NoCases do + begin + value := StrToInt(OS3MainFrm.DataGrid.Cells[ACol,i]); + if value < minA then minA := value; + if value > maxA then maxA := value; + value := StrToInt(OS3MainFrm.DataGrid.Cells[BCol,i]); + if value < minB then minB := value; + if value > maxB then maxB := value; + value := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); + if value < minC then minC := value; + if value > maxC then maxC := value; + value := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol,i]); + if value < minD then minD := value; + if value > maxD then maxD := value; + end; + rangeA := maxA - minA + 1; + rangeB := maxB - minB + 1; + rangeC := maxC - minC + 1; + rangeD := maxD - minD + 1; + + // check for squareness + if (rangeA <> rangeB) or (rangeA <> rangeC) or (rangeB <> rangeC) then + begin + ErrorMsg('In a Latin square the range of values should all be equal.'); + exit; + end; + p := rangeA; + + // set up an array for cell counts and for cell sums and marginal sums + SetLength(cellcnts, rangeA+1, rangeB+1, rangeD+1); + SetLength(celltotals, rangeA+1, rangeB+1, rangeD+1); + SetLength(ADmat, rangeA+1, rangeD+1); + SetLength(BDmat, rangeB+1, rangeD+1); + SetLength(CDmat, rangeC+1, rangeD+1); + SetLength(Ctotals, rangeC+1); + SetLength(Design, rangeA, rangeB); + + // initialize arrays and values + for i := 0 to rangeA do + for j := 0 to rangeB do + for k := 0 to rangeD do + begin + cellcnts[i, j, k] := 0; + celltotals[i, j, k] := 0.0; + end; + for i := 0 to rangeA do + for j := 0 to rangeD do + ADmat[i,j] := 0.0; + for i := 0 to rangeB do + for j := 0 to rangeD do + BDmat[i,j] := 0.0; + for i := 0 to rangeC do + for j := 0 to rangeD do + CDmat[i,j] := 0.0; + for i := 0 to rangeC-1 do + Ctotals[i] := 0; + G := 0.0; + sumxsqr := 0.0; + sumAsqr := 0.0; + sumBsqr := 0.0; + sumCsqr := 0.0; + sumDsqr := 0.0; + sumADsqr := 0.0; + sumBDsqr := 0.0; + sumCDsqr := 0.0; + term1 := 0.0; + term2 := 0.0; + term3 := 0.0; + term4 := 0.0; + term5 := 0.0; + term6 := 0.0; + term7 := 0.0; + term8 := 0.0; + term9 := 0.0; + GrandMean := 0.0; + SSwithin := 0.0; + + // Read in the data + for i := 1 to NoCases do + begin + row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); + col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); + slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); + block := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol,i]); + data := StrToFloat(OS3MainFrm.DataGrid.Cells[DataCol,i]); + cellcnts[row-1,col-1,block-1] := cellcnts[row-1,col-1,block-1] + 1; + celltotals[row-1,col-1,block-1] := celltotals[row-1,col-1,block-1] + data; + ADmat[row-1,block-1] := ADmat[row-1,block-1] + data; + BDmat[col-1,block-1] := BDmat[col-1,block-1] + data; + CDmat[slice-1,block-1] := CDmat[slice-1,block-1] + data; + Ctotals[slice-1] := Ctotals[slice-1] + data; + sumxsqr := sumxsqr + (data * data); + GrandMean := GrandMean + data; + end; + + // check for equal cell counts + for i := 0 to p-1 do + for j := 0 to p-1 do + for k := 0 to rangeD - 1 do + if cellcnts[i,j,k] <> n then begin - for k := 0 to rangeD do - begin - cellcnts[i,j,k] := 0; - celltotals[i,j,k] := 0.0; - end; + ErrorMsg('Cell sizes are not equal.'); + exit; end; - end; - for i := 0 to rangeA do - for j := 0 to rangeD do - ADmat[i,j] := 0.0; - for i := 0 to rangeB do - for j := 0 to rangeD do - BDmat[i,j] := 0.0; - for i := 0 to rangeC do - for j := 0 to rangeD do - CDmat[i,j] := 0.0; - for i := 0 to rangeC-1 do Ctotals[i] := 0; - G := 0.0; - sumxsqr := 0.0; - sumAsqr := 0.0; - sumBsqr := 0.0; - sumCsqr := 0.0; - sumDsqr := 0.0; - sumADsqr := 0.0; - sumBDsqr := 0.0; - sumCDsqr := 0.0; - term1 := 0.0; - term2 := 0.0; - term3 := 0.0; - term4 := 0.0; - term5 := 0.0; - term6 := 0.0; - term7 := 0.0; - term8 := 0.0; - term9 := 0.0; - GrandMean := 0.0; - SSwithin := 0.0; - // Read in the data - for i := 1 to NoCases do + // calculate values + for i := 0 to p - 1 do // get row, column and block sums + for j := 0 to p-1 do + for k := 0 to rangeD - 1 do + begin + celltotals[i,p,k] := celltotals[i,p,k] + celltotals[i,j,k]; + celltotals[p,j,k] := celltotals[p,j,k] + celltotals[i,j,k]; + celltotals[i,j,rangeD] :=celltotals[i,j,rangeD] + celltotals[i,j,k]; + end; + + // get interaction AD + for i := 0 to rangeA-1 do + for j := 0 to rangeD-1 do begin - row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); - col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); - slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); - block := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol,i]); - data := StrToFloat(OS3MainFrm.DataGrid.Cells[DataCol,i]); - cellcnts[row-1,col-1,block-1] := cellcnts[row-1,col-1,block-1] + 1; - celltotals[row-1,col-1,block-1] := celltotals[row-1,col-1,block-1] + data; - ADmat[row-1,block-1] := ADmat[row-1,block-1] + data; - BDmat[col-1,block-1] := BDmat[col-1,block-1] + data; - CDmat[slice-1,block-1] := CDmat[slice-1,block-1] + data; - Ctotals[slice-1] := Ctotals[slice-1] + data; - sumxsqr := sumxsqr + (data * data); - GrandMean := GrandMean + data; + sumADsqr := sumADsqr + (ADmat[i,j] * ADmat[i,j]); + ADmat[i,rangeD] := ADmat[i,rangeD] + ADmat[i,j]; + ADmat[rangeA,j] := ADmat[rangeA,j] + ADmat[i,j]; end; + for i := 0 to rangeA-1 do + sumAsqr := sumAsqr + (ADmat[i,rangeD] * ADmat[i,rangeD]); + for i := 0 to rangeD-1 do + sumDsqr := sumDsqr + (ADmat[rangeA,i] * ADmat[rangeA,i]); - // check for equal cell counts - for i := 0 to p-1 do + // get interaction BD + for i := 0 to rangeB-1 do + for j := 0 to rangeD-1 do begin - for j := 0 to p-1 do - begin - for k := 0 to rangeD - 1 do - begin - if cellcnts[i,j,k] <> n then - begin - ShowMessage('cell sizes are not equal!'); - goto cleanup; - end; - end; - end; + sumBDsqr := sumBDsqr + (BDmat[i,j] * BDmat[i,j]); + BDmat[i,rangeD] := BDmat[i,rangeD] + BDmat[i,j]; + BDmat[rangeB,j] := BDmat[rangeB,j] + BDmat[i,j]; end; + for i := 0 to rangeB-1 do + sumBsqr := sumBsqr + (BDmat[i,rangeD] * BDmat[i,rangeD]); - // calculate values - for i := 0 to p - 1 do // get row, column and block sums + // get interaction CD + for i := 0 to rangeC-1 do + for j := 0 to rangeD-1 do begin - for j := 0 to p-1 do - begin - for k := 0 to rangeD - 1 do - begin - celltotals[i,p,k] := celltotals[i,p,k] + celltotals[i,j,k]; - celltotals[p,j,k] := celltotals[p,j,k] + celltotals[i,j,k]; - celltotals[i,j,rangeD] :=celltotals[i,j,rangeD] + celltotals[i,j,k]; - end; - end; + sumCDsqr := sumCDsqr + (CDmat[i,j] * CDmat[i,j]); + CDmat[i,rangeD] := CDmat[i,rangeD] + CDmat[i,j]; + CDmat[rangeC,j] := CDmat[rangeC,j] + CDmat[i,j]; end; - // get interaction AD - for i := 0 to rangeA-1 do - begin - for j := 0 to rangeD-1 do - begin - sumADsqr := sumADsqr + (ADmat[i,j] * ADmat[i,j]); - ADmat[i,rangeD] := ADmat[i,rangeD] + ADmat[i,j]; - ADmat[rangeA,j] := ADmat[rangeA,j] + ADmat[i,j]; - end; - end; - for i := 0 to rangeA-1 do - sumAsqr := sumAsqr + (ADmat[i,rangeD] * ADmat[i,rangeD]); - for i := 0 to rangeD-1 do - sumDsqr := sumDsqr + (ADmat[rangeA,i] * ADmat[rangeA,i]); + for i := 0 to rangeC-1 do + sumCsqr := sumCsqr + (CDmat[i,rangeD] * CDmat[i,rangeD]); - // get interaction BD - for i := 0 to rangeB-1 do - begin - for j := 0 to rangeD-1 do - begin - sumBDsqr := sumBDsqr + (BDmat[i,j] * BDmat[i,j]); - BDmat[i,rangeD] := BDmat[i,rangeD] + BDmat[i,j]; - BDmat[rangeB,j] := BDmat[rangeB,j] + BDmat[i,j]; - end; - end; - for i := 0 to rangeB-1 do - sumBsqr := sumBsqr + (BDmat[i,rangeD] * BDmat[i,rangeD]); + G := GrandMean; + term1 := (G * G) / (n * p * p * rangeD); + term2 := sumxsqr; + term3 := sumAsqr / (n * p * rangeD); + term4 := sumBsqr / (n * p * rangeD); + term5 := sumCsqr / (n * p * rangeD); + term6 := sumADsqr / (n * p); + term7 := SumBDsqr / (n * p); + term8 := SumCDsqr / (n * p); + term9 := sumDsqr / (n * p * p); + SSA := term3 - term1; + SSD := term9 - term1; + SSAD := term6 - term3 - term9 + term1; + SSB := term4 - term1; + SSBD := term7 - term4 - term9 + term1; + SSC := term5 - term1; + SSCD := term8 - term5 - term9 + term1; - // get interaction CD - for i := 0 to rangeC-1 do - begin - for j := 0 to rangeD-1 do - begin - sumCDsqr := sumCDsqr + (CDmat[i,j] * CDmat[i,j]); - CDmat[i,rangeD] := CDmat[i,rangeD] + CDmat[i,j]; - CDmat[rangeC,j] := CDmat[rangeC,j] + CDmat[i,j]; - end; - end; - for i := 0 to rangeC-1 do - sumCsqr := sumCsqr + (CDmat[i,rangeD] * CDmat[i,rangeD]); + // get ss within + for i := 0 to rangeA - 1 do + for j := 0 to rangeB - 1 do + for k := 0 to rangeD - 1 do + SSwithin := SSwithin + (celltotals[i,j,k] * celltotals[i,j,k]); + SSwithin := sumXsqr - (SSwithin / n); - G := GrandMean; - term1 := (G * G) / (n * p * p * rangeD); - term2 := sumxsqr; - term3 := sumAsqr / (n * p * rangeD); - term4 := sumBsqr / (n * p * rangeD); - term5 := sumCsqr / (n * p * rangeD); - term6 := sumADsqr / (n * p); - term7 := SumBDsqr / (n * p); - term8 := SumCDsqr / (n * p); - term9 := sumDsqr / (n * p * p); - SSA := term3 - term1; - SSD := term9 - term1; - SSAD := term6 - term3 - term9 + term1; - SSB := term4 - term1; - SSBD := term7 - term4 - term9 + term1; - SSC := term5 - term1; - SSCD := term8 - term5 - term9 + term1; + // get SS residual + SStotal := sumXsqr - term1; + SSres := SStotal - SSA - SSB - SSC - SSD - SSAD - SSBD - SSCD - SSwithin; + dfa := p-1; + dfb := p-1; + dfc := p-1; + dfd := rangeD - 1; + dfad := (p-1) * (rangeD - 1); + dfbd := dfad; + dfcd := dfad; + dfres := rangeD * (p-1) * (p-2); + dfwithin := (p * p) * rangeD * (n - 1); + dftotal := n * p * p * rangeD - 1; + MSa := SSA / dfa; + MSb := SSB / dfb; + MSc := SSC / dfc; + MSd := SSD / dfd; + MSad := SSAD / dfad; + MSbd := SSBD / dfbd; + MScd := SSCD / dfcd; + MSres := SSres / dfres; + MSwithin := SSwithin / dfwithin; + fa := MSa / MSwithin; + fb := MSb / MSwithin; + fc := MSc / MSwithin; + fd := MSd / MSwithin; + fad := MSad / MSwithin; + fbd := MSbd / MSwithin; + fcd := MScd / MSwithin; + fpartial := MSres / MSwithin; + proba := ProbF(fa, dfa, dfwithin); + probb := ProbF(fb, dfb, dfwithin); + probc := ProbF(fc, dfc, dfwithin); + probd := ProbF(fd, dfd, dfwithin); + probad := ProbF(fad, dfad, dfwithin); + probbd := ProbF(fbd, dfbd, dfwithin); + probcd := ProbF(fcd, dfcd, dfwithin); + probpartial := ProbF(fpartial, dfres, dfwithin); - // get ss within - for i := 0 to rangeA - 1 do - for j := 0 to rangeB - 1 do - for k := 0 to rangeD - 1 do - SSwithin := SSwithin + (celltotals[i,j,k] * celltotals[i,j,k]); - SSwithin := sumXsqr - (SSwithin / n); - - // get SS residual - SStotal := sumXsqr - term1; - SSres := SStotal - SSA - SSB - SSC - SSD - SSAD - SSBD - SSCD - SSwithin; - dfa := p-1; - dfb := p-1; - dfc := p-1; - dfd := rangeD - 1; - dfad := (p-1) * (rangeD - 1); - dfbd := dfad; - dfcd := dfad; - dfres := rangeD * (p-1) * (p-2); - dfwithin := (p * p) * rangeD * (n - 1); - dftotal := n * p * p * rangeD - 1; - MSa := SSA / dfa; - MSb := SSB / dfb; - MSc := SSC / dfc; - MSd := SSD / dfd; - MSad := SSAD / dfad; - MSbd := SSBD / dfbd; - MScd := SSCD / dfcd; - MSres := SSres / dfres; - MSwithin := SSwithin / dfwithin; - fa := MSa / MSwithin; - fb := MSb / MSwithin; - fc := MSc / MSwithin; - fd := MSd / MSwithin; - fad := MSad / MSwithin; - fbd := MSbd / MSwithin; - fcd := MScd / MSwithin; - fpartial := MSres / MSwithin; - proba := probf(fa,dfa,dfwithin); - probb := probf(fb,dfb,dfwithin); - probc := probf(fc,dfc,dfwithin); - probd := probf(fd,dfd,dfwithin); - probad := probf(fad,dfad,dfwithin); - probbd := probf(fbd,dfbd,dfwithin); - probcd := probf(fcd,dfcd,dfwithin); - probpartial := probf(fpartial,dfres,dfwithin); - - // show ANOVA table results - OutputFrm.RichEdit.Clear; - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Latin Square Analysis Plan 2 Results'); - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); - OutputFrm.RichEdit.Lines.Add('Source SS DF MS F Prob.>F'); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); - cellstring := 'Factor A '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSA,dfa,MSa,fa,proba]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Factor B '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSB,dfb,MSb,fb,probb]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Factor C '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSC,dfc,MSc,fc,probc]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Factor D '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSD,dfd,MSd,fd,probd]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'A x D '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSAD,dfad,MSad,fad,probad]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'B x D '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSBD,dfbd,MSbd,fbd,probbd]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'C x D '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSCD,dfcd,MScd,fcd,probcd]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Residual '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSres,dfres,MSres,fpartial,probpartial]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Within '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f',[SSwithin, dfwithin, MSwithin]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Total '; - cellstring := cellstring + format('%9.3f %9.0f',[SStotal, dftotal]); - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); + // show ANOVA table results + lReport := TStringList.Create; + try + lReport.Add(''); + lReport.Add('LATIN SQUARE ANALYSIS PLAN 2 RESULTS'); + lReport.Add(''); + lReport.Add('-----------------------------------------------------------'); + lReport.Add('Source SS DF MS F Prob.>F'); + lReport.Add('-----------------------------------------------------------'); + lReport.Add('Factor A %9.3f %9.0f %9.3f %9.3f %9.3f', [SSA, dfa, MSa, fa, proba]); + lReport.Add('Factor B %9.3f %9.0f %9.3f %9.3f %9.3f', [SSB, dfb, MSb, fb, probb]); + lReport.Add('Factor C %9.3f %9.0f %9.3f %9.3f %9.3f', [SSC, dfc, MSc, fc, probc]); + lReport.Add('Factor D %9.3f %9.0f %9.3f %9.3f %9.3f', [SSD, dfd, MSd, fd, probd]); + lReport.Add('A x D %9.3f %9.0f %9.3f %9.3f %9.3f', [SSAD, dfad, MSad, fad, probad]); + lReport.Add('B x D %9.3f %9.0f %9.3f %9.3f %9.3f', [SSBD, dfbd, MSbd, fbd, probbd]); + lReport.Add('C x D %9.3f %9.0f %9.3f %9.3f %9.3f', [SSCD, dfcd, MScd, fcd, probcd]); + lReport.Add('Residual %9.3f %9.0f %9.3f %9.3f %9.3f', [SSres, dfres, MSres, fpartial, probpartial]); + lReport.Add('Within %9.3f %9.0f %9.3f', [SSwithin, dfwithin, MSwithin]); + lReport.Add('Total %9.3f %9.0f', [SStotal, dftotal]); + lReport.Add('-----------------------------------------------------------'); // show design for each block for k := 0 to rangeD - 1 do begin - OutputFrm.RichEdit.Lines.Add(''); - cellstring := 'Experimental Design for block ' + format('%d',[k+1]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorB]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - OutputFrm.RichEdit.Lines.Add(cellstring); - for i := 1 to NoCases do - begin - row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); - col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); - slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); - block := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol,i]); - if block = minD + k then - Design[row-1,col-1] := 'C' + IntToStr(slice); - end; - for i := 0 to p - 1 do - begin - cellstring := format(' %3d ',[i+1]); - for j := 0 to p - 1 do - begin - cellstring := cellstring + format('%5s',[Design[i,j]]); - end; - OutputFrm.RichEdit.Lines.Add(cellstring); - end; - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(''); + lReport.Add('Experimental Design for block %d', [k+1]); + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '-----'; + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorB]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ',[i]); + lReport.Add(cellstring); + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '-----'; + lReport.Add(cellstring); + + lReport.Add('%10s', [FactorA]); + for i := 1 to NoCases do + begin + row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol, i]); + col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol, i]); + slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol, i]); + block := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol, i]); + if block = minD + k then + Design[row-1, col-1] := 'C' + IntToStr(slice); + end; + for i := 0 to p - 1 do + begin + cellstring := Format(' %3d ', [i+1]); + for j := 0 to p - 1 do + cellstring := cellstring + Format('%5s', [Design[i,j]]); + lReport.Add(cellstring); + end; + cellstring := '----------'; + for i := 1 to p + 1 do + cellstring := cellstring + '-----'; + lReport.Add(cellstring); end; // get cell means for i := 0 to p-1 do - for j := 0 to p-1 do - for k := 0 to rangeD - 1 do - celltotals[i,j,k] := celltotals[i,j,k] / n; + for j := 0 to p-1 do + for k := 0 to rangeD - 1 do + celltotals[i,j,k] := celltotals[i,j,k] / n; for i := 0 to p-1 do - begin - for k := 0 to rangeD - 1 do - begin - celltotals[i,p,k] := celltotals[i,p,k] / (p * n); - celltotals[p,i,k] := celltotals[p,i,k] / (p * n); - end; - end; + for k := 0 to rangeD - 1 do + begin + celltotals[i,p,k] := celltotals[i,p,k] / (p * n); + celltotals[p,i,k] := celltotals[p,i,k] / (p * n); + end; GrandMean := GrandMean / (p * p * n * rangeD); - for i := 0 to p-1 do Ctotals[i] := Ctotals[i] / (p * n * rangeD); + for i := 0 to p-1 do + Ctotals[i] := Ctotals[i] / (p * n * rangeD); // show table of means for each block for k := 0 to rangeD-1 do begin - OutputFrm.RichEdit.Lines.Add(''); - cellstring := format('BLOCK %d',[k+1]); - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Cell means and totals'); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorB]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); - cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - OutputFrm.RichEdit.Lines.Add(cellstring); - for i := 0 to p-1 do - begin - cellstring := format(' %3d ',[i+1]); - for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[celltotals[i,j,k]]); - end; - cellstring := cellstring + format(' %8.3f ',[celltotals[i,p,k]]); - OutputFrm.RichEdit.Lines.Add(cellstring); - end; - cellstring := 'Total '; - for j := 0 to p-1 do - cellstring := cellstring + format(' %8.3f ',[celltotals[p,j,k]]); - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(''); + lReport.Add('BLOCK %d', [k+1]); + lReport.Add(''); + lReport.Add('Cell means and totals'); + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '----------'; + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorB]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ',[i]); + cellstring := cellstring + ' Total'; + lReport.Add(cellstring); + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '----------'; + lReport.Add(cellstring); + cellstring := Format('%10s', [FactorA]); + lReport.Add(cellstring); + for i := 0 to p-1 do + begin + cellstring := Format(' %3d ', [i+1]); + for j := 0 to p - 1 do + cellstring := cellstring + Format(' %8.3f ', [celltotals[i, j, k]]); + cellstring := cellstring + Format(' %8.3f ', [celltotals[i, p, k]]); + lReport.Add(cellstring); + end; + + cellstring := 'Total '; + for j := 0 to p-1 do + cellstring := cellstring + Format(' %8.3f ', [celltotals[p, j, k]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '----------'; + lReport.Add(cellstring); end; // show category means - OutputFrm.RichEdit.Lines.Add(''); + lReport.Add(''); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorC]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorC]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Ctotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Ctotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); - OutputFrm.ShowModal; + DisplayReport(lReport); + + finally + lReport.Free; -cleanup: Design := nil; Ctotals := nil; CDmat := nil; @@ -948,623 +834,575 @@ cleanup: ADmat := nil; celltotals := nil; cellcnts := nil; + end; end; -procedure TLatinSqrsFrm.Plan3(Sender: TObject); -label cleanup; +procedure TLatinSqrsFrm.Plan3; var - NoFactors : integer; - n : integer; // no. of subjects per cell - Acol, Bcol, Ccol, Dcol, DataCol : integer; // variable columns in grid - FactorA : string; - FactorB : string; - FactorC : string; - FactorD : string; - DataVar : string; - cellstring : string; - i, j, k, m, minA, minB, minC, maxA, maxB, maxC : integer; - minD, maxD, rangeA, rangeB, rangeC, rangeD : integer; - value : integer; - cellcnts : IntDyneCube; - celltotals : DblDyneQuad; - ABmat, ACmat, BCmat : DblDyneMat; - ABCmat : DblDyneCube; - Atotals : DblDyneVec; - Btotals : DblDyneVec; - Ctotals : DblDyneVec; - Dtotals : DblDyneVec; - design : StrDyneMat; - G, term1, term2, term3, term4, term5, term6, term7, term8 : double; - term9, term10, sumxsqr : double; - sumAsqr, sumBsqr, sumCsqr, sumDsqr, SSA, SSB, SSC, SSD : double; - sumABsqr, sumACsqr, sumBCsqr, sumABCsqr : double; - SSAB, SSAC, SSBC, SSABC, SSwithin, SStotal : double; - MSa, MSb, MSc, MSd, MSAB, MSAC, MSBC, MSABC, MSwithin : double; - data, GrandMean : double; - p, row, col, slice, block : integer; - dfa, dfb, dfc, dfwithin, dftotal, fa, fb, fc: double; - dfd, fd, fab, fac, fbc, fabc, dfab, dfac, dfbc, dfabc : double; - proba, probb, probc, probd: double; - probab, probac, probbc, probabc : double; - + n : integer; // no. of subjects per cell + Acol, Bcol, Ccol, Dcol, DataCol: integer; // variable columns in grid + FactorA: string; + FactorB: string; + FactorC: string; + FactorD: string; + DataVar: string; + cellstring: string; + i, j, k, m, minA, minB, minC, maxA, maxB, maxC: integer; + minD, maxD, rangeA, rangeB, rangeC, rangeD: integer; + value: integer; + cellcnts: IntDyneCube; + celltotals: DblDyneQuad; + ABmat, ACmat, BCmat: DblDyneMat; + ABCmat: DblDyneCube; + Atotals: DblDyneVec; + Btotals: DblDyneVec; + Ctotals: DblDyneVec; + Dtotals: DblDyneVec; + design: StrDyneMat; + G, term1, term2, term3, term4, term5, term6, term7, term8: double; + term9, term10, sumxsqr: double; + sumAsqr, sumBsqr, sumCsqr, sumDsqr, SSA, SSB, SSC, SSD: double; + sumABsqr, sumACsqr, sumBCsqr, sumABCsqr: double; + SSAB, SSAC, SSBC, SSABC, SSwithin, SStotal: double; + MSa, MSb, MSc, MSd, MSAB, MSAC, MSBC, MSABC, MSwithin: double; + data, GrandMean: double; + p, row, col, slice, block: integer; + dfa, dfb, dfc, dfwithin, dftotal, fa, fb, fc: double; + dfd, fd, fab, fac, fbc, fabc, dfab, dfac, dfbc, dfabc: double; + proba, probb, probc, probd: double; + probab, probac, probbc, probabc: double; + lReport: TStrings; begin - NoFactors := 4; - LatinSpecsFrm.PanelD.Visible := true; - LatinSpecsFrm.PanelGrp.Visible := false; - LatinSpecsFrm.AinBtn.Enabled := true; - LatinSpecsFrm.AoutBtn.Enabled := false; - LatinSpecsFrm.BinBtn.Enabled := true; - LatinSpecsFrm.BoutBtn.Enabled := false; - LatinSpecsFrm.CinBtn.Enabled := true; - LatinSpecsFrm.CoutBtn.Enabled := false; -// LatinSpecsFrm.DCodeEdit.Visible := true; - LatinSpecsFrm.ACodeEdit.Text := ''; - LatinSpecsFrm.BCodeEdit.Text := ''; - LatinSpecsFrm.CCodeEdit.Text := ''; - LatinSpecsFrm.DCodeEdit.Text := ''; - LatinSpecsFrm.GrpCodeEdit.Text := ''; - LatinSpecsFrm.DepVarEdit.Text := ''; - LatinSpecsFrm.nPerCellEdit.Text := ''; -// LatinSpecsFrm.GrpCodeEdit.Visible := false; -// LatinSpecsFrm.DCodeLabel.Visible := true; -// LatinSpecsFrm.GrpCodeLabel.Visible := false; -// LatinSpecsFrm.DinBtn.Visible := true; -// LatinSpecsFrm.DoutBtn.Visible := true; - LatinSpecsFrm.DinBtn.Enabled := true; - LatinSpecsFrm.DoutBtn.Enabled := false; -// LatinSpecsFrm.GrpInBtn.Visible := false; -// LatinSpecsFrm.GrpOutBtn.Visible := false; - LatinSpecsFrm.DataInBtn.Enabled := true; - LatinSpecsFrm.DataOutBtn.Enabled := false; - LatinSpecsFrm.ShowModal; - if LatinSpecsFrm.ModalResult = mrCancel then exit; - n := StrToInt(LatinSpecsFrm.nPerCellEdit.Text); - if n <= 0 then - begin - ShowMessage('Please specify the number of cases per cell.'); + LatinSpecsFrm.PrepareForPlan(3); + if LatinSpecsFrm.ShowModal <> mrOK then + exit; + + n := StrToInt(LatinSpecsFrm.nPerCellEdit.Text); + FactorA := LatinSpecsFrm.ACodeEdit.Text; + FactorB := LatinSpecsFrm.BCodeEdit.Text; + FactorC := LatinSpecsFrm.CCodeEdit.Text; + FactorD := LatinSpecsFrm.DCodeEdit.Text; + DataVar := LatinSpecsFrm.DepVarEdit.Text; + + for i := 1 to NoVariables do + begin + cellstring := OS3MainFrm.DataGrid.Cells[i,0]; + if (cellstring = FactorA) then ACol := i; + if (cellstring = FactorB) then BCol := i; + if (cellstring = FactorC) then Ccol := i; + if (cellstring = FactorD) then Dcol := i; + if (cellstring = DataVar) then DataCol := i; + end; + + // determine no. of levels in A, B and C + minA := MaxInt; + minB := MaxInt; + minC := MaxInt; + minD := MaxInt; + maxA := -MaxInt; + maxB := -MaxInt; + maxC := -MaxInt; + maxD := -MaxInt; + + for i := 1 to NoCases do + begin + value := StrToInt(OS3MainFrm.DataGrid.Cells[ACol,i]); + if value < minA then minA := value; + if value > maxA then maxA := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[BCol,i]); + if value < minB then minB := value; + if value > maxB then maxB := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); + if value < minC then minC := value; + if value > maxC then maxC := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol,i]); + if value < minD then minD := value; + if value > maxD then maxD := value; + end; + rangeA := maxA - minA + 1; + rangeB := maxB - minB + 1; + rangeC := maxC - minC + 1; + rangeD := maxD - minD + 1; + + // check for squareness + if (rangeA <> rangeB) or (rangeA <> rangeC) or (rangeB <> rangeC) or (rangeA <> rangeD) then + begin + ErrorMsg('In a Latin square the range of values should all be equal.'); + exit; + end; + p := rangeA; + + // set up an array for cell counts and for cell sums and marginal sums + SetLength(cellcnts, p+1, p+1, p+1); + SetLength(celltotals, p+1, p+1, p+1, p+1); + SetLength(ABmat, p+1, p+1); + SetLength(ACmat, p+1, p+1); + SetLength(BCmat, p+1, p+1); + SetLength(ABCmat, p+1, p+1, p+1); + SetLength(Atotals, p); + SetLength(Btotals, p); + SetLength(Ctotals, p); + SetLength(Dtotals, p); + SetLength(Design,p, p); + + // initialize arrays and values + for i := 0 to p do + for j := 0 to p do + for k := 0 to p do + for m := 0 to p do + celltotals[i,j,k,m] := 0.0; + for i := 0 to p do + for j := 0 to p do + begin + ABmat[i,j] := 0.0; + ACmat[i,j] := 0.0; + BCmat[i,j] := 0.0; + end; + + for i := 0 to p do + for j := 0 to p do + for k := 0 to p do + begin + ABCmat[i,j,k] := 0.0; + cellcnts[i,j,k] := 0; + end; + + for i := 0 to p-1 do + begin + Atotals[i] := 0.0; + Btotals[i] := 0.0; + Ctotals[i] := 0.0; + Dtotals[i] := 0.0; + end; + G := 0.0; + sumxsqr := 0.0; + sumAsqr := 0.0; + sumBsqr := 0.0; + sumCsqr := 0.0; + sumDsqr := 0.0; + sumABsqr := 0.0; + sumACsqr := 0.0; + sumBCsqr := 0.0; + sumABCsqr := 0.0; + term1 := 0.0; + term2 := 0.0; + term3 := 0.0; + term4 := 0.0; + term5 := 0.0; + term6 := 0.0; + term7 := 0.0; + term8 := 0.0; + term9 := 0.0; + term10 := 0.0; + GrandMean := 0.0; + SSwithin := 0.0; + + // Read in the data + for i := 1 to NoCases do + begin + row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); + col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); + slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); + block := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol,i]); + data := StrToFloat(OS3MainFrm.DataGrid.Cells[DataCol,i]); + cellcnts[row-1,col-1,slice-1] := cellcnts[row-1,col-1,slice-1] + 1; + celltotals[row-1,col-1,slice-1,block-1] := celltotals[row-1,col-1,slice-1,block-1] + data; + ABmat[row-1,col-1] := ABmat[row-1,col-1] + data; + ACmat[row-1,slice-1] := ACmat[row-1,slice-1] + data; + BCmat[col-1,slice-1] := BCmat[col-1,slice-1] + data; + ABCmat[row-1,col-1,slice-1] := ABCmat[row-1,col-1,slice-1] + data; + Atotals[row-1] := Atotals[row-1] + data; + Btotals[col-1] := Btotals[col-1] + data; + Ctotals[slice-1] := Ctotals[slice-1] + data; + Dtotals[block-1] := Dtotals[block-1] + data; + sumxsqr := sumxsqr + (data * data); + GrandMean := GrandMean + data; + end; + + // check for equal cell counts in ABCmat + for i := 0 to p-1 do + for j := 0 to p-1 do + for k := 0 to p - 1 do + if cellcnts[i,j,k] <> n then + begin + ErrorMsg('Cell sizes are not equal.'); exit; - end; - FactorA := LatinSpecsFrm.ACodeEdit.Text; - FactorB := LatinSpecsFrm.BCodeEdit.Text; - FactorC := LatinSpecsFrm.CCodeEdit.Text; - FactorD := LatinSpecsFrm.DCodeEdit.Text; - DataVar := LatinSpecsFrm.DepVarEdit.Text; - for i := 1 to NoVariables do - begin - cellstring := OS3MainFrm.DataGrid.Cells[i,0]; - if (cellstring = FactorA) then ACol := i; - if (cellstring = FactorB) then BCol := i; - if (cellstring = FactorC) then Ccol := i; - if (cellstring = FactorD) then Dcol := i; - if (cellstring = DataVar) then DataCol := i; - end; - // determine no. of levels in A, B and C - minA := 1000; - minB := 1000; - minC := 1000; - minD := 1000; - maxA := -1000; - maxB := -1000; - maxC := -1000; - maxD := -1000; - for i := 1 to NoCases do - begin - value := StrToInt(OS3MainFrm.DataGrid.Cells[ACol,i]); - if value < minA then minA := value; - if value > maxA then maxA := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[BCol,i]); - if value < minB then minB := value; - if value > maxB then maxB := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); - if value < minC then minC := value; - if value > maxC then maxC := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol,i]); - if value < minD then minD := value; - if value > maxD then maxD := value; - end; - rangeA := maxA - minA + 1; - rangeB := maxB - minB + 1; - rangeC := maxC - minC + 1; - rangeD := maxD - minD + 1; - - // check for squareness - if ( (rangeA <> rangeB) or (rangeA <> rangeC) or (rangeB <> rangeC) or (rangeA <> rangeD) ) then - begin - ShowMessage('ERROR! In a Latin square the range of values should all be equal!'); - exit; - end; - p := rangeA; - - // set up an array for cell counts and for cell sums and marginal sums - SetLength(cellcnts,p+1,p+1,p+1); - SetLength(celltotals,p+1,p+1,p+1,p+1); - SetLength(ABmat,p+1,p+1); - SetLength(ACmat,p+1,p+1); - SetLength(BCmat,p+1,p+1); - SetLength(ABCmat,p+1,p+1,p+1); - SetLength(Atotals,p); - SetLength(Btotals,p); - SetLength(Ctotals,p); - SetLength(Dtotals,p); - SetLength(Design,p,p); - - // initialize arrays and values - for i := 0 to p do - for j := 0 to p do - for k := 0 to p do - for m := 0 to p do - celltotals[i,j,k,m] := 0.0; - for i := 0 to p do - begin - for j := 0 to p do - begin - ABmat[i,j] := 0.0; - ACmat[i,j] := 0.0; - BCmat[i,j] := 0.0; end; - end; - for i := 0 to p do - begin - for j := 0 to p do + + // calculate values + for i := 0 to p - 1 do // get row, column, slice and block sums + for j := 0 to p-1 do + for k := 0 to p - 1 do + for m := 0 to p - 1 do begin - for k := 0 to p do - begin - ABCmat[i,j,k] := 0.0; - cellcnts[i,j,k] := 0; - end; + celltotals[p,j,k,m] := celltotals[p,j,k,m] + celltotals[i,j,k,m]; + celltotals[i,p,k,m] := celltotals[i,p,k,m] + celltotals[i,j,k,m]; + celltotals[i,j,p,m] := celltotals[i,j,p,m] + celltotals[i,j,k,m]; + celltotals[i,j,k,p] := celltotals[i,j,k,p] + celltotals[i,j,k,m]; end; - end; - for i := 0 to p-1 do - begin - Atotals[i] := 0.0; - Btotals[i] := 0.0; - Ctotals[i] := 0.0; - Dtotals[i] := 0.0; - end; - G := 0.0; - sumxsqr := 0.0; - sumAsqr := 0.0; - sumBsqr := 0.0; - sumCsqr := 0.0; - sumDsqr := 0.0; - sumABsqr := 0.0; - sumACsqr := 0.0; - sumBCsqr := 0.0; - sumABCsqr := 0.0; - term1 := 0.0; - term2 := 0.0; - term3 := 0.0; - term4 := 0.0; - term5 := 0.0; - term6 := 0.0; - term7 := 0.0; - term8 := 0.0; - term9 := 0.0; - term10 := 0.0; - GrandMean := 0.0; - SSwithin := 0.0; - // Read in the data - for i := 1 to NoCases do + for i := 0 to p - 1 do // get row, column and slice sums in ABC matrix + for j := 0 to p-1 do + for k := 0 to p-1 do + begin + ABCmat[p,j,k] := ABCmat[p,j,k] + ABCmat[i,j,k]; + ABCmat[i,p,k] := ABCmat[i,p,k] + ABCmat[i,j,k]; + ABCmat[i,j,p] := ABCmat[i,j,p] + ABCmat[i,j,k]; + end; + + // get 2-way interactions + for i := 0 to p-1 do + for j := 0 to p-1 do begin - row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); - col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); - slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); - block := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol,i]); - data := StrToFloat(OS3MainFrm.DataGrid.Cells[DataCol,i]); - cellcnts[row-1,col-1,slice-1] := cellcnts[row-1,col-1,slice-1] + 1; - celltotals[row-1,col-1,slice-1,block-1] := celltotals[row-1,col-1,slice-1,block-1] + data; - ABmat[row-1,col-1] := ABmat[row-1,col-1] + data; - ACmat[row-1,slice-1] := ACmat[row-1,slice-1] + data; - BCmat[col-1,slice-1] := BCmat[col-1,slice-1] + data; - ABCmat[row-1,col-1,slice-1] := ABCmat[row-1,col-1,slice-1] + data; - Atotals[row-1] := Atotals[row-1] + data; - Btotals[col-1] := Btotals[col-1] + data; - Ctotals[slice-1] := Ctotals[slice-1] + data; - Dtotals[block-1] := Dtotals[block-1] + data; - sumxsqr := sumxsqr + (data * data); - GrandMean := GrandMean + data; + sumABsqr := sumABsqr + (ABmat[i,j] * ABmat[i,j]); + sumACsqr := sumACsqr + (ACmat[i,j] * ACmat[i,j]); + sumBCsqr := SumBCsqr + (BCmat[i,j] * BCmat[i,j]); + ABmat[i,p] := ABmat[i,p] + ABmat[i,j]; + ABmat[p,j] := ABmat[p,j] + ABmat[i,j]; + ACmat[i,p] := ACmat[i,p] + ACmat[i,j]; + ACmat[p,j] := ACmat[p,j] + ACmat[i,j]; + BCmat[i,p] := BCmat[i,p] + BCmat[i,j]; + BCmat[p,j] := BCmat[p,j] + BCmat[i,j]; + for k := 0 to p-1 do + sumABCsqr := sumABCsqr + (ABCmat[i,j,k] * ABCmat[i,j,k]); end; - // check for equal cell counts in ABCmat - for i := 0 to p-1 do - begin - for j := 0 to p-1 do - begin - for k := 0 to p - 1 do - begin - if cellcnts[i,j,k] <> n then - begin - ShowMessage('cell sizes are not equal!'); - goto cleanup; - end; - end; - end; - end; + for i := 0 to p-1 do + begin + sumAsqr := sumAsqr + (Atotals[i] * Atotals[i]); + sumBsqr := sumBsqr + (Btotals[i] * Btotals[i]); + SumCsqr := sumCsqr + (Ctotals[i] * Ctotals[i]); + sumDsqr := sumDsqr + (Dtotals[i] * Dtotals[i]); + end; - // calculate values - for i := 0 to p - 1 do // get row, column, slice and block sums - begin - for j := 0 to p-1 do - begin - for k := 0 to p - 1 do - begin - for m := 0 to p - 1 do - begin - celltotals[p,j,k,m] := celltotals[p,j,k,m] + celltotals[i,j,k,m]; - celltotals[i,p,k,m] := celltotals[i,p,k,m] + celltotals[i,j,k,m]; - celltotals[i,j,p,m] := celltotals[i,j,p,m] + celltotals[i,j,k,m]; - celltotals[i,j,k,p] := celltotals[i,j,k,p] + celltotals[i,j,k,m]; - end; - end; - end; - end; - for i := 0 to p - 1 do // get row, column and slice sums in ABC matrix - begin - for j := 0 to p-1 do - begin - for k := 0 to p-1 do - begin - ABCmat[p,j,k] := ABCmat[p,j,k] + ABCmat[i,j,k]; - ABCmat[i,p,k] := ABCmat[i,p,k] + ABCmat[i,j,k]; - ABCmat[i,j,p] := ABCmat[i,j,p] + ABCmat[i,j,k]; - end; - end; - end; + G := GrandMean; + term1 := (G * G) / (n * p * p * p); + term2 := sumxsqr; + term3 := sumAsqr / (n * p * p); + term4 := sumBsqr / (n * p * p); + term5 := sumCsqr / (n * p * p); + term9 := sumDsqr / (n * p * p); + term6 := sumABsqr / (n * p); + term7 := SumACsqr / (n * p); + term8 := SumBCsqr / (n * p); + term10 := sumABCsqr / n; + SSA := term3 - term1; + SSB := term4 - term1; + SSC := term5 - term1; + SSD := term9 - term1; + SSAB := term6 - term3 - term4 + term1; + SSAC := term7 - term3 - term5 + term1; + SSBC := term8 - term4 - term5 + term1; + SSABC := term10 - term6 - term7 - term8 + term3 + term4 + term5 - term1; + SSABC := SSABC - (term9 - term1); - // get 2-way interactions - for i := 0 to p-1 do - begin - for j := 0 to p-1 do - begin - sumABsqr := sumABsqr + (ABmat[i,j] * ABmat[i,j]); - sumACsqr := sumACsqr + (ACmat[i,j] * ACmat[i,j]); - sumBCsqr := SumBCsqr + (BCmat[i,j] * BCmat[i,j]); - ABmat[i,p] := ABmat[i,p] + ABmat[i,j]; - ABmat[p,j] := ABmat[p,j] + ABmat[i,j]; - ACmat[i,p] := ACmat[i,p] + ACmat[i,j]; - ACmat[p,j] := ACmat[p,j] + ACmat[i,j]; - BCmat[i,p] := BCmat[i,p] + BCmat[i,j]; - BCmat[p,j] := BCmat[p,j] + BCmat[i,j]; - for k := 0 to p-1 do - sumABCsqr := sumABCsqr + (ABCmat[i,j,k] * ABCmat[i,j,k]); - end; - end; - for i := 0 to p-1 do - begin - sumAsqr := sumAsqr + (Atotals[i] * Atotals[i]); - sumBsqr := sumBsqr + (Btotals[i] * Btotals[i]); - SumCsqr := sumCsqr + (Ctotals[i] * Ctotals[i]); - sumDsqr := sumDsqr + (Dtotals[i] * Dtotals[i]); - end; + // get ss within + for i := 0 to p - 1 do + for j := 0 to p - 1 do + for k := 0 to p - 1 do + for m := 0 to p - 1 do + SSwithin := SSwithin + (celltotals[i,j,k,m] * celltotals[i,j,k,m]); + SSwithin := sumXsqr - (SSwithin / n); - G := GrandMean; - term1 := (G * G) / (n * p * p * p); - term2 := sumxsqr; - term3 := sumAsqr / (n * p * p); - term4 := sumBsqr / (n * p * p); - term5 := sumCsqr / (n * p * p); - term9 := sumDsqr / (n * p * p); - term6 := sumABsqr / (n * p); - term7 := SumACsqr / (n * p); - term8 := SumBCsqr / (n * p); - term10 := sumABCsqr / n; - SSA := term3 - term1; - SSB := term4 - term1; - SSC := term5 - term1; - SSD := term9 - term1; - SSAB := term6 - term3 - term4 + term1; - SSAC := term7 - term3 - term5 + term1; - SSBC := term8 - term4 - term5 + term1; - SSABC := term10 - term6 - term7 - term8 + term3 + term4 + term5 - term1; - SSABC := SSABC - (term9 - term1); - - // get ss within - for i := 0 to p - 1 do - for j := 0 to p - 1 do - for k := 0 to p - 1 do - for m := 0 to p - 1 do - SSwithin := SSwithin + (celltotals[i,j,k,m] * celltotals[i,j,k,m]); - SSwithin := sumXsqr - (SSwithin / n); - - // get SS residual - SStotal := sumXsqr - term1; - dfa := p-1; - dfb := p-1; - dfc := p-1; - dfd := p-1; - dfab := (p - 1) * (p - 1); - dfac := dfab; - dfbc := dfab; - dfabc := ( (p-1) * (p-1) * (p-1) ) - (p-1); - dfwithin := p * p * p * (n - 1); - dftotal := n * p * p * p - 1; - MSa := SSA / dfa; - MSb := SSB / dfb; - MSc := SSC / dfc; - MSd := SSD / dfd; - MSab := SSAB / dfab; - MSac := SSAC / dfac; - MSbc := SSBC / dfbc; - MSabc := SSABC / dfabc; + // get SS residual + SStotal := sumXsqr - term1; + dfa := p-1; + dfb := p-1; + dfc := p-1; + dfd := p-1; + dfab := (p - 1) * (p - 1); + dfac := dfab; + dfbc := dfab; + dfabc := (p-1) * (p-1) * (p-1) - (p-1); + dfwithin := p * p * p * (n - 1); + dftotal := n * p * p * p - 1; + MSa := SSA / dfa; + MSb := SSB / dfb; + MSc := SSC / dfc; + MSd := SSD / dfd; + MSab := SSAB / dfab; + MSac := SSAC / dfac; + MSbc := SSBC / dfbc; + MSabc := SSABC / dfabc; // MSres := SSres / dfres; - MSwithin := SSwithin / dfwithin; - fa := MSa / MSwithin; - fb := MSb / MSwithin; - fc := MSc / MSwithin; - fd := MSd / MSwithin; - fab := MSab / MSwithin; - fac := MSac / MSwithin; - fbc := MSbc / MSwithin; - fabc := MSabc / MSwithin; - proba := probf(fa,dfa,dfwithin); - probb := probf(fb,dfb,dfwithin); - probc := probf(fc,dfc,dfwithin); - probd := probf(fd,dfd,dfwithin); - probab := probf(fab,dfab,dfwithin); - probac := probf(fac,dfac,dfwithin); - probbc := probf(fbc,dfbc,dfwithin); - probabc := probf(fabc,dfabc,dfwithin); + MSwithin := SSwithin / dfwithin; + fa := MSa / MSwithin; + fb := MSb / MSwithin; + fc := MSc / MSwithin; + fd := MSd / MSwithin; + fab := MSab / MSwithin; + fac := MSac / MSwithin; + fbc := MSbc / MSwithin; + fabc := MSabc / MSwithin; + proba := ProbF(fa,dfa,dfwithin); + probb := ProbF(fb,dfb,dfwithin); + probc := ProbF(fc,dfc,dfwithin); + probd := ProbF(fd,dfd,dfwithin); + probab := ProbF(fab,dfab,dfwithin); + probac := ProbF(fac,dfac,dfwithin); + probbc := ProbF(fbc,dfbc,dfwithin); + probabc := ProbF(fabc,dfabc,dfwithin); - // show ANOVA table results - OutputFrm.RichEdit.Clear; - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Latin Square Analysis Plan 3 Results'); - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); - OutputFrm.RichEdit.Lines.Add('Source SS DF MS F Prob.>F'); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); - cellstring := 'Factor A '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSA,dfa,MSa,fa,proba]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Factor B '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSB,dfb,MSb,fb,probb]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Factor C '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSC,dfc,MSc,fc,probc]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Factor D '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSD,dfd,MSd,fd,probd]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'A x B '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSAB,dfab,MSab,fab,probab]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'A x C '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSAC,dfac,MSac,fac,probac]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'B x C '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSBC,dfbc,MSbc,fbc,probbc]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'A x B x C '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSABC,dfabc,MSabc,fabc,probabc]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Within '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f',[SSwithin, dfwithin, MSwithin]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Total '; - cellstring := cellstring + format('%9.3f %9.0f',[SStotal, dftotal]); - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); + // show ANOVA table results + lReport := TStringList.Create; + try + lReport.Add('LATIN SQUARE ANALYSIS PLAN 3 RESULTS'); + lReport.Add(''); + lReport.Add('-----------------------------------------------------------'); + lReport.Add('Source SS DF MS F Prob.>F'); + lReport.Add('-----------------------------------------------------------'); + lReport.Add('Factor A %9.3f %9.0f %9.3f %9.3f %9.3f', [SSA, dfa, MSa, fa, proba]); + lReport.Add('Factor B %9.3f %9.0f %9.3f %9.3f %9.3f', [SSB, dfb, MSb, fb, probb]); + lReport.Add('Factor C %9.3f %9.0f %9.3f %9.3f %9.3f', [SSC, dfc, MSc, fc, probc]); + lReport.Add('Factor D %9.3f %9.0f %9.3f %9.3f %9.3f', [SSD, dfd, MSd, fd, probd]); + lReport.Add('A x B %9.3f %9.0f %9.3f %9.3f %9.3f', [SSAB, dfab, MSab, fab, probab]); + lReport.Add('A x C %9.3f %9.0f %9.3f %9.3f %9.3f', [SSAC, dfac, MSac, fac, probac]); + lReport.Add('B x C %9.3f %9.0f %9.3f %9.3f %9.3f', [SSBC, dfbc, MSbc, fbc, probbc]); + lReport.Add('A x B x C %9.3f %9.0f %9.3f %9.3f %9.3f', [SSABC, dfabc, MSabc, fabc, probabc]); + lReport.Add('Within %9.3f %9.0f %9.3f', [SSwithin, dfwithin, MSwithin]); + lReport.Add('Total %9.3f %9.0f', [SStotal, dftotal]); + lReport.Add('-----------------------------------------------------------'); // show design for each block for k := 0 to rangeD - 1 do begin - OutputFrm.RichEdit.Lines.Add(''); - cellstring := 'Experimental Design for block ' + format('%d',[k+1]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorB]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - OutputFrm.RichEdit.Lines.Add(cellstring); - for i := 1 to NoCases do - begin - row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); - col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); - slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); - block := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol,i]); - if block = minD + k then - Design[row-1,col-1] := 'C' + IntToStr(slice); - end; - for i := 0 to p - 1 do - begin - cellstring := format(' %3d ',[i+1]); - for j := 0 to p - 1 do - begin - cellstring := cellstring + format('%5s',[Design[i,j]]); - end; - OutputFrm.RichEdit.Lines.Add(cellstring); - end; - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(''); + lReport.Add('Experimental Design for block %d', [k+1]); + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '-----'; + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorB]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); + lReport.Add(cellstring); + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '-----'; + lReport.Add(cellstring); + + lReport.Add('%10s', [FactorA]); + + for i := 1 to NoCases do + begin + row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); + col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); + slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); + block := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol,i]); + if block = minD + k then + Design[row-1,col-1] := 'C' + IntToStr(slice); + end; + + for i := 0 to p - 1 do + begin + cellstring := format(' %3d ',[i+1]); + for j := 0 to p - 1 do + cellstring := cellstring + format('%5s',[Design[i,j]]); + lReport.Add(cellstring); + end; + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '-----'; + lReport.Add(cellstring); end; // get cell means for i := 0 to p-1 do - for j := 0 to p-1 do - for k := 0 to p - 1 do - for m := 0 to p - 1 do - celltotals[i,j,k,m] := celltotals[i,j,k,m] / n; + for j := 0 to p-1 do + for k := 0 to p - 1 do + for m := 0 to p - 1 do + celltotals[i,j,k,m] := celltotals[i,j,k,m] / n; + for i := 0 to p-1 do begin - for j := 0 to p - 1 do - begin - for k := 0 to p - 1 do - begin - for m := 0 to p - 1 do - begin - celltotals[p,j,k,m] := celltotals[p,j,k,m] / (p * n); - celltotals[i,p,k,m] := celltotals[i,p,k,m] / (p * n); - celltotals[i,j,p,m] := celltotals[i,j,p,m] / (p * n); - celltotals[i,j,k,p] := celltotals[i,j,k,p] / (p * n); - end; - end; - end; + for j := 0 to p - 1 do + begin + for k := 0 to p - 1 do + begin + for m := 0 to p - 1 do + begin + celltotals[p,j,k,m] := celltotals[p,j,k,m] / (p * n); + celltotals[i,p,k,m] := celltotals[i,p,k,m] / (p * n); + celltotals[i,j,p,m] := celltotals[i,j,p,m] / (p * n); + celltotals[i,j,k,p] := celltotals[i,j,k,p] / (p * n); + end; + end; + end; end; + for i := 0 to p-1 do - for j := 0 to p-1 do - for k := 0 to p-1 do - ABCmat[i,j,k] := ABCmat[i,j,k] / n; + for j := 0 to p-1 do + for k := 0 to p-1 do + ABCmat[i,j,k] := ABCmat[i,j,k] / n; for j := 0 to p-1 do - for k := 0 to p-1 do - ABCmat[p,j,k] := ABCmat[p,j,k] / (p * n); + for k := 0 to p-1 do + ABCmat[p,j,k] := ABCmat[p,j,k] / (p * n); for i := 0 to p-1 do - for k := 0 to p-1 do - ABCmat[i,p,k] := ABCmat[i,p,k] / (p * n); + for k := 0 to p-1 do + ABCmat[i,p,k] := ABCmat[i,p,k] / (p * n); for i := 0 to p - 1 do - for j := 0 to p - 1 do - ABCmat[i,j,p] := ABCmat[i,j,p] / (p * n); + for j := 0 to p - 1 do + ABCmat[i,j,p] := ABCmat[i,j,p] / (p * n); GrandMean := GrandMean / (p * p * p * n ); for i := 0 to p-1 do begin - Atotals[i] := Atotals[i] / (p * p * n); - Btotals[i] := Btotals[i] / (p * p * n); - Ctotals[i] := Ctotals[i] / (p * p * n); - Dtotals[i] := Dtotals[i] / (p * p * n); + Atotals[i] := Atotals[i] / (p * p * n); + Btotals[i] := Btotals[i] / (p * p * n); + Ctotals[i] := Ctotals[i] / (p * p * n); + Dtotals[i] := Dtotals[i] / (p * p * n); end; // show table of means for each block for k := 0 to p-1 do begin - OutputFrm.RichEdit.Lines.Add(''); - cellstring := format('BLOCK %d',[k+1]); - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Cell means and totals'); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorB]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); - cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - OutputFrm.RichEdit.Lines.Add(cellstring); - for i := 0 to p-1 do - begin - cellstring := format(' %3d ',[i+1]); - for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[ABCmat[i,j,k]]); - end; - cellstring := cellstring + format(' %8.3f ',[ABCmat[i,p,k]]); - OutputFrm.RichEdit.Lines.Add(cellstring); - end; - cellstring := 'Total '; - for j := 0 to p-1 do - cellstring := cellstring + format(' %8.3f ',[ABCmat[p,j,k]]); - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(''); + lReport.Add('BLOCK %d', [k+1]); + lReport.Add(''); + lReport.Add('Cell means and totals'); + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '----------'; + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorB]); + for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + cellstring := cellstring + ' Total'; + lReport.Add(cellstring); + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '----------'; + lReport.Add(cellstring); + + lReport.Add('%10s', [FactorA]); + for i := 0 to p-1 do + begin + cellstring := Format(' %3d ', [i+1]); + for j := 0 to p - 1 do + cellstring := cellstring + Format(' %8.3f ', [ABCmat[i,j,k]]); + cellstring := cellstring + Format(' %8.3f ', [ABCmat[i,p,k]]); + lReport.Add(cellstring); + end; + + cellstring := 'Total '; + for j := 0 to p-1 do + cellstring := cellstring + Format(' %8.3f ', [ABCmat[p,j,k]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '----------'; + lReport.Add(cellstring); end; // show category means - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Means for each variable'); - OutputFrm.RichEdit.Lines.Add(''); + lReport.Add(''); + lReport.Add('Means for each variable'); + lReport.Add(''); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorA]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Atotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Atotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorB]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + lReport.Add(''); + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '----------'; + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorB]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Btotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Btotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorC]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + lReport.Add(''); + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '----------'; + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorC]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Ctotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Ctotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorD]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + lReport.Add(''); + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '----------'; + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorD]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Dtotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Dtotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); - OutputFrm.ShowModal; + DisplayReport(lReport); + + finally + LReport.Free; -cleanup: Design := nil; Dtotals := nil; Ctotals := nil; @@ -1576,520 +1414,504 @@ cleanup: ABCmat := nil; celltotals := nil; cellcnts := nil; + end; end; -procedure TLatinSqrsFrm.Plan4(Sender: TObject); -label cleanup; +procedure TLatinSqrsFrm.Plan4; var - NoFactors : integer; - n : integer; // no. of subjects per cell - Acol, Bcol, Ccol, Dcol, DataCol : integer; // variable columns in grid - FactorA : string; - FactorB : string; - FactorC : string; - FactorD : string; - DataVar : string; - cellstring : string; - i, j, k, minA, minB, minC, maxA, maxB, maxC : integer; - minD, maxD, rangeA, rangeB, rangeC, rangeD : integer; - value : integer; - cellcnts : IntDyneMat; - ABmat : DblDyneMat; - ABCmat : DblDyneCube; - Atotals : DblDyneVec; - Btotals : DblDyneVec; - Ctotals : DblDyneVec; - Dtotals : DblDyneVec; - design : StrDyneMat; - G, term1, term2, term3, term4, term5, term6, term7 : double; - sumxsqr : double; - sumAsqr, sumBsqr, sumCsqr, sumDsqr, SSA, SSB, SSC, SSD : double; - SSwithin, SSres, SStotal : double; - MSa, MSb, MSc, MSd, MSres, MSwithin : double; - data, GrandMean : double; - p, row, col, slice, block : integer; - dfa, dfb, dfc, dfres, dfwithin, dftotal, fa, fb, fc : double; - dfd, fd, fres : double; - proba, probb, probc, probd, probres : double; + n: integer; // no. of subjects per cell + Acol, Bcol, Ccol, Dcol, DataCol: integer; // variable columns in grid + FactorA: string; + FactorB: string; + FactorC: string; + FactorD: string; + DataVar: string; + cellstring: string; + i, j, k, minA, minB, minC, maxA, maxB, maxC: integer; + minD, maxD, rangeA, rangeB, rangeC, rangeD: integer; + value: integer; + cellcnts: IntDyneMat; + ABmat: DblDyneMat; + ABCmat: DblDyneCube; + Atotals: DblDyneVec; + Btotals: DblDyneVec; + Ctotals: DblDyneVec; + Dtotals: DblDyneVec; + design: StrDyneMat; + G, term1, term2, term3, term4, term5, term6, term7: double; + sumxsqr: double; + sumAsqr, sumBsqr, sumCsqr, sumDsqr, SSA, SSB, SSC, SSD: double; + SSwithin, SSres, SStotal: double; + MSa, MSb, MSc, MSd, MSres, MSwithin: double; + data, GrandMean: double; + p, row, col, slice, block: integer; + dfa, dfb, dfc, dfres, dfwithin, dftotal, fa, fb, fc: double; + dfd, fd, fres: double; + proba, probb, probc, probd, probres: double; + lReport: TStrings; begin - NoFactors := 4; - LatinSpecsFrm.PanelD.Visible := true; - LatinSpecsFrm.PanelGrp.Visible := false; - LatinSpecsFrm.AinBtn.Enabled := true; - LatinSpecsFrm.AoutBtn.Enabled := false; - LatinSpecsFrm.BinBtn.Enabled := true; - LatinSpecsFrm.BoutBtn.Enabled := false; - LatinSpecsFrm.CinBtn.Enabled := true; - LatinSpecsFrm.CoutBtn.Enabled := false; -// LatinSpecsFrm.DCodeEdit.Visible := true; - LatinSpecsFrm.ACodeEdit.Text := ''; - LatinSpecsFrm.BCodeEdit.Text := ''; - LatinSpecsFrm.CCodeEdit.Text := ''; - LatinSpecsFrm.DCodeEdit.Text := ''; - LatinSpecsFrm.GrpCodeEdit.Text := ''; - LatinSpecsFrm.DepVarEdit.Text := ''; - LatinSpecsFrm.nPerCellEdit.Text := ''; -// LatinSpecsFrm.GrpCodeEdit.Visible := false; -// LatinSpecsFrm.DCodeLabel.Visible := true; -// LatinSpecsFrm.GrpCodeLabel.Visible := false; -// LatinSpecsFrm.DinBtn.Visible := true; -// LatinSpecsFrm.DoutBtn.Visible := true; - LatinSpecsFrm.DinBtn.Enabled := true; - LatinSpecsFrm.DoutBtn.Enabled := false; -// LatinSpecsFrm.GrpInBtn.Visible := false; -// LatinSpecsFrm.GrpOutBtn.Visible := false; - LatinSpecsFrm.DataInBtn.Enabled := true; - LatinSpecsFrm.DataOutBtn.Enabled := false; - LatinSpecsFrm.ShowModal; - if LatinSpecsFrm.ModalResult = mrCancel then exit; - n := StrToInt(LatinSpecsFrm.nPerCellEdit.Text); - if n <= 0 then - begin - ShowMessage('Please specify the number of cases per cell.'); - exit; - end; - FactorA := LatinSpecsFrm.ACodeEdit.Text; - FactorB := LatinSpecsFrm.BCodeEdit.Text; - FactorC := LatinSpecsFrm.CCodeEdit.Text; - FactorD := LatinSpecsFrm.DCodeEdit.Text; - DataVar := LatinSpecsFrm.DepVarEdit.Text; - for i := 1 to NoVariables do + LatinSpecsFrm.PrepareForPlan(4); + if LatinSpecsFrm.ShowModal <> mrOK then + exit; + + n := StrToInt(LatinSpecsFrm.nPerCellEdit.Text); + FactorA := LatinSpecsFrm.ACodeEdit.Text; + FactorB := LatinSpecsFrm.BCodeEdit.Text; + FactorC := LatinSpecsFrm.CCodeEdit.Text; + FactorD := LatinSpecsFrm.DCodeEdit.Text; + DataVar := LatinSpecsFrm.DepVarEdit.Text; + + for i := 1 to NoVariables do + begin + cellstring := OS3MainFrm.DataGrid.Cells[i,0]; + if (cellstring = FactorA) then ACol := i; + if (cellstring = FactorB) then BCol := i; + if (cellstring = FactorC) then Ccol := i; + if (cellstring = FactorD) then Dcol := i; + if (cellstring = DataVar) then DataCol := i; + end; + + // determine no. of levels in A, B and C + minA := MaxInt; + minB := MaxInt; + minC := MaxInt; + minD := MaxInt; + maxA := -MaxInt; + maxB := -MaxInt; + maxC := -MaxInt; + maxD := -MaxInt; + + for i := 1 to NoCases do + begin + value := StrToInt(OS3MainFrm.DataGrid.Cells[ACol,i]); + if value < minA then minA := value; + if value > maxA then maxA := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[BCol,i]); + if value < minB then minB := value; + if value > maxB then maxB := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); + if value < minC then minC := value; + if value > maxC then maxC := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol,i]); + if value < minD then minD := value; + if value > maxD then maxD := value; + end; + rangeA := maxA - minA + 1; + rangeB := maxB - minB + 1; + rangeC := maxC - minC + 1; + rangeD := maxD - minD + 1; + + // check for squareness + if (rangeA <> rangeB) or (rangeA <> rangeC) or (rangeB <> rangeC) then + begin + ErrorMsg('In a Latin square the range of values should be equal for A,B and C.'); + exit; + end; + p := rangeA; + + // set up an array for cell counts and for cell sums and marginal sums + SetLength(ABmat, p+1, p+1); + SetLength(ABCmat, p+1, p+1, p+1); + SetLength(cellcnts, p+1, p+1); + SetLength(Atotals, p); + SetLength(Btotals, p); + SetLength(Ctotals, p); + SetLength(Dtotals, p); + SetLength(Design, p, p); + + for i := 0 to p do + for j := 0 to p do + for k := 0 to p do + ABCmat[i,j,k] := 0.0; + + for i := 0 to p-1 do + for j := 0 to p-1 do begin - cellstring := OS3MainFrm.DataGrid.Cells[i,0]; - if (cellstring = FactorA) then ACol := i; - if (cellstring = FactorB) then BCol := i; - if (cellstring = FactorC) then Ccol := i; - if (cellstring = FactorD) then Dcol := i; - if (cellstring = DataVar) then DataCol := i; + cellcnts[i,j] := 0; + ABmat[i,j] := 0.0; end; - // determine no. of levels in A, B and C - minA := 1000; - minB := 1000; - minC := 1000; - minD := 1000; - maxA := -1000; - maxB := -1000; - maxC := -1000; - maxD := -1000; - for i := 1 to NoCases do - begin - value := StrToInt(OS3MainFrm.DataGrid.Cells[ACol,i]); - if value < minA then minA := value; - if value > maxA then maxA := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[BCol,i]); - if value < minB then minB := value; - if value > maxB then maxB := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); - if value < minC then minC := value; - if value > maxC then maxC := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol,i]); - if value < minD then minD := value; - if value > maxD then maxD := value; - end; - rangeA := maxA - minA + 1; - rangeB := maxB - minB + 1; - rangeC := maxC - minC + 1; - rangeD := maxD - minD + 1; + for i := 0 to p-1 do + begin + Atotals[i] := 0.0; + Btotals[i] := 0.0; + Ctotals[i] := 0.0; + Dtotals[i] := 0.0; + end; - // check for squareness - if ( (rangeA <> rangeB) or (rangeA <> rangeC) or (rangeB <> rangeC) ) then - begin - ShowMessage('ERROR! In a Latin square the range of values should be equal for A,B and C!'); - exit; - end; - p := rangeA; + G := 0.0; + sumxsqr := 0.0; + sumAsqr := 0.0; + sumBsqr := 0.0; + sumCsqr := 0.0; + sumDsqr := 0.0; + SSwithin := 0.0; + term1 := 0.0; + term2 := 0.0; + term3 := 0.0; + term4 := 0.0; + term5 := 0.0; + term6 := 0.0; + term7 := 0.0; + GrandMean := 0.0; - // set up an array for cell counts and for cell sums and marginal sums - SetLength(ABmat,p+1,p+1); - SetLength(ABCmat,p+1,p+1,p+1); - SetLength(cellcnts,p+1,p+1); - SetLength(Atotals,p); - SetLength(Btotals,p); - SetLength(Ctotals,p); - SetLength(Dtotals,p); - SetLength(Design,p,p); - - for i := 0 to p do - for j := 0 to p do - for k := 0 to p do - ABCmat[i,j,k] := 0.0; + // Read in the data + for i := 1 to NoCases do + begin + row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); + col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); + slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); + block := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol,i]); + data := StrToFloat(OS3MainFrm.DataGrid.Cells[DataCol,i]); + cellcnts[row-1,col-1] := cellcnts[row-1,col-1] + 1; + ABCmat[row-1,col-1,slice-1] := ABCmat[row-1,col-1,slice-1] + data; + Atotals[row-1] := Atotals[row-1] + data; + Btotals[col-1] := Btotals[col-1] + data; + Ctotals[slice-1] := Ctotals[slice-1] + data; + Dtotals[block-1] := Dtotals[block-1] + data; + sumxsqr := sumxsqr + (data * data); + GrandMean := GrandMean + data; + end; + // collapse c's into a x b + for k := 0 to p-1 do for i := 0 to p-1 do - begin - for j := 0 to p-1 do - begin - cellcnts[i,j] := 0; - ABmat[i,j] := 0.0; - end; - end; + for j := 0 to p-1 do + ABmat[i,j] := ABmat[i,j] + ABCmat[i,j,k]; - for i := 0 to p-1 do - begin - Atotals[i] := 0.0; - Btotals[i] := 0.0; - Ctotals[i] := 0.0; - Dtotals[i] := 0.0; - end; + // get sum of squared cells + for i := 0 to p - 1 do + for j := 0 to p - 1 do + SSwithin := SSwithin + (ABmat[i,j] * ABmat[i,j]); - G := 0.0; - sumxsqr := 0.0; - sumAsqr := 0.0; - sumBsqr := 0.0; - sumCsqr := 0.0; - sumDsqr := 0.0; - SSwithin := 0.0; - term1 := 0.0; - term2 := 0.0; - term3 := 0.0; - term4 := 0.0; - term5 := 0.0; - term6 := 0.0; - term7 := 0.0; - GrandMean := 0.0; + // check for equal cell counts + for i := 0 to p-1 do + for j := 0 to p-1 do + if cellcnts[i,j] <> n then + begin + ErrorMsg('Cell sizes are not equal,'); + Exit; + end; - // Read in the data - for i := 1 to NoCases do - begin - row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); - col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); - slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); - block := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol,i]); - data := StrToFloat(OS3MainFrm.DataGrid.Cells[DataCol,i]); - cellcnts[row-1,col-1] := cellcnts[row-1,col-1] + 1; - ABCmat[row-1,col-1,slice-1] := ABCmat[row-1,col-1,slice-1] + data; - Atotals[row-1] := Atotals[row-1] + data; - Btotals[col-1] := Btotals[col-1] + data; - Ctotals[slice-1] := Ctotals[slice-1] + data; - Dtotals[block-1] := Dtotals[block-1] + data; - sumxsqr := sumxsqr + (data * data); - GrandMean := GrandMean + data; - end; + for i := 0 to p-1 do + begin + sumAsqr := sumAsqr + (Atotals[i] * Atotals[i]); + sumBsqr := sumBsqr + (Btotals[i] * Btotals[i]); + sumCsqr := sumCsqr + (Ctotals[i] * Ctotals[i]); + sumDsqr := sumDsqr + (Dtotals[i] * Dtotals[i]); + end; - // collapse c's into a x b - for k := 0 to p-1 do - for i := 0 to p-1 do - for j := 0 to p-1 do - ABmat[i,j] := ABmat[i,j] + ABCmat[i,j,k]; + G := GrandMean; + term1 := (G * G) / (n * p * p); + term2 := sumxsqr; + term3 := sumAsqr / (n * p); + term4 := sumBsqr / (n * p); + term5 := sumCsqr / (n * p); + term6 := sumDsqr / (n * p); + term7 := SSwithin / n; + SSA := term3 - term1; + SSB := term4 - term1; + SSC := term5 - term1; + SSD := term6 - term1; + SSres := term7 - term3 - term4 - term5 - term6 + 3 * term1; + SSwithin := term2 - term7; + SStotal := term2 - term1; - // get sum of squared cells - for i := 0 to p - 1 do - for j := 0 to p - 1 do - SSwithin := SSwithin + (ABmat[i,j] * ABmat[i,j]); + dfa := p-1; + dfb := p-1; + dfc := p-1; + dfd := p-1; + dfres := (p-1) * (p-3); + dfwithin := p * p * (n - 1); + dftotal := n * p * p - 1; + MSa := SSA / dfa; + MSb := SSB / dfb; + MSc := SSC / dfc; + MSd := SSD / dfd; + if dfres > 0 then MSres := SSres / dfres; + MSwithin := SSwithin / dfwithin; + fa := MSa / MSwithin; + fb := MSb / MSwithin; + fc := MSc / MSwithin; + fd := MSd / MSwithin; + if dfres > 0 then fres := MSres / MSwithin; + proba := probf(fa,dfa,dfwithin); + probb := probf(fb,dfb,dfwithin); + probc := probf(fc,dfc,dfwithin); + probd := probf(fd,dfd,dfwithin); + if dfres > 0 then probres := probf(fres,dfres,dfwithin); - // check for equal cell counts - for i := 0 to p-1 do - begin - for j := 0 to p-1 do - begin - if cellcnts[i,j] <> n then - begin - ShowMessage('cell sizes are not equal!'); - goto cleanup; - end; - end; - end; - - for i := 0 to p-1 do - begin - sumAsqr := sumAsqr + (Atotals[i] * Atotals[i]); - sumBsqr := sumBsqr + (Btotals[i] * Btotals[i]); - sumCsqr := sumCsqr + (Ctotals[i] * Ctotals[i]); - sumDsqr := sumDsqr + (Dtotals[i] * Dtotals[i]); - end; - - G := GrandMean; - term1 := (G * G) / (n * p * p); - term2 := sumxsqr; - term3 := sumAsqr / (n * p); - term4 := sumBsqr / (n * p); - term5 := sumCsqr / (n * p); - term6 := sumDsqr / (n * p); - term7 := SSwithin / n; - SSA := term3 - term1; - SSB := term4 - term1; - SSC := term5 - term1; - SSD := term6 - term1; - SSres := term7 - term3 - term4 - term5 - term6 + (3 * term1); - SSwithin := term2 - term7; - SStotal := term2 - term1; - - dfa := p-1; - dfb := p-1; - dfc := p-1; - dfd := p-1; - dfres := (p-1) * (p-3); - dfwithin := p * p * (n - 1); - dftotal := n * p * p - 1; - MSa := SSA / dfa; - MSb := SSB / dfb; - MSc := SSC / dfc; - MSd := SSD / dfd; - if dfres > 0 then MSres := SSres / dfres; - MSwithin := SSwithin / dfwithin; - fa := MSa / MSwithin; - fb := MSb / MSwithin; - fc := MSc / MSwithin; - fd := MSd / MSwithin; - if dfres > 0 then fres := MSres / MSwithin; - proba := probf(fa,dfa,dfwithin); - probb := probf(fb,dfb,dfwithin); - probc := probf(fc,dfc,dfwithin); - probd := probf(fd,dfd,dfwithin); - if dfres > 0 then probres := probf(fres,dfres,dfwithin); - - // show ANOVA table results - OutputFrm.RichEdit.Clear; - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Greco-Latin Square Analysis (No Interactions)'); - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); - OutputFrm.RichEdit.Lines.Add('Source SS DF MS F Prob.>F'); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); - cellstring := 'Factor A '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSA,dfa,MSa,fa,proba]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Factor B '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSB,dfb,MSb,fb,probb]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Latin Sqr.'; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSC,dfc,MSc,fc,probc]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Greek Sqr.'; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSD,dfd,MSd,fd,probd]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Residual '; + // show ANOVA table results + lReport := TStringList.Create; + try + lReport.Add('GRECO-LATIN SQUARE ANALYSIS (No Interactions)'); + lReport.Add(''); + lReport.Add('-----------------------------------------------------------'); + lReport.Add('Source SS DF MS F Prob.>F'); + lReport.Add('-----------------------------------------------------------'); + lReport.Add('Factor A %9.3f %9.0f %9.3f %9.3f %9.3f', [SSA, dfa, MSa, fa, proba]); + lReport.Add('Factor B %9.3f %9.0f %9.3f %9.3f %9.3f', [SSB, dfb, MSb, fb, probb]); + lReport.Add('Latin Sqr.%9.3f %9.0f %9.3f %9.3f %9.3f', [SSC, dfc, MSc, fc, probc]); + lReport.Add('Greek Sqr.%9.3f %9.0f %9.3f %9.3f %9.3f', [SSD, dfd, MSd, fd, probd]); if dfres > 0 then - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSres,dfres,MSres,fres,probres]) - else cellstring := cellstring + ' - - - - -'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Within '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f',[SSwithin, dfwithin, MSwithin]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Total '; - cellstring := cellstring + format('%9.3f %9.0f',[SStotal, dftotal]); - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); + lReport.Add('Residual %9.3f %9.0f %9.3f %9.3f %9.3f', [SSres, dfres, MSres, fres, probres]) + else + lReport.Add('Residual - - - - -'); + lReport.Add('Within %9.3f %9.0f %9.3f', [SSwithin, dfwithin, MSwithin]); + lReport.Add('Total %9.3f %9.0f', [SStotal, dftotal]); + lReport.Add('-----------------------------------------------------------'); // show design for Latin Square - OutputFrm.RichEdit.Lines.Add(''); - cellstring := 'Experimental Design for Latin Square '; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(''); + lReport.Add('Experimental Design for Latin Square '); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorB]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorB]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + + lReport.Add('%10s', [FactorA]); + for i := 1 to NoCases do begin - row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); - col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); - slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); - Design[row-1,col-1] := 'C' + IntToStr(slice); + row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); + col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); + slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); + Design[row-1,col-1] := 'C' + IntToStr(slice); end; for i := 0 to p - 1 do begin - cellstring := format(' %3d ',[i+1]); - for j := 0 to p - 1 do - cellstring := cellstring + format('%5s',[Design[i,j]]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := Format(' %3d ', [i+1]); + for j := 0 to p - 1 do + cellstring := cellstring + Format('%5s', [Design[i,j]]); + lReport.Add(cellstring); end; + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); // show design for Greek Square - OutputFrm.RichEdit.Lines.Add(''); - cellstring := 'Experimental Design for Greek Square '; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(''); + lReport.Add('Experimental Design for Greek Square '); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorB]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorB]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorA]); + lReport.Add(cellstring); + for i := 1 to NoCases do begin - row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); - col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); - block := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol,i]); - Design[row-1,col-1] := 'C' + IntToStr(block); + row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); + col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); + block := StrToInt(OS3MainFrm.DataGrid.Cells[Dcol,i]); + Design[row-1,col-1] := 'C' + IntToStr(block); end; + for i := 0 to p - 1 do begin - cellstring := format(' %3d ',[i+1]); - for j := 0 to p - 1 do - cellstring := cellstring + format('%5s',[Design[i,j]]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := Format(' %3d ', [i+1]); + for j := 0 to p - 1 do + cellstring := cellstring + Format('%5s', [Design[i,j]]); + lReport.Add(cellstring); end; + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); for i := 0 to p-1 do begin - for j := 0 to p - 1 do - begin - ABmat[i,p] := ABmat[i,p] + ABmat[i,j]; - ABmat[p,j] := ABmat[p,j] + ABmat[i,j]; - end; + for j := 0 to p - 1 do + begin + ABmat[i,p] := ABmat[i,p] + ABmat[i,j]; + ABmat[p,j] := ABmat[p,j] + ABmat[i,j]; + end; end; for i := 0 to p-1 do - for j := 0 to p-1 do - ABmat[i,j] := ABmat[i,j] / n; + for j := 0 to p-1 do + ABmat[i,j] := ABmat[i,j] / n; for i := 0 to p-1 do - ABmat[i,p] := ABmat[i,p] / (n * p); + ABmat[i,p] := ABmat[i,p] / (n * p); for j := 0 to p-1 do - ABmat[p,j] := ABmat[p,j] / (n * p); + ABmat[p,j] := ABmat[p,j] / (n * p); GrandMean := GrandMean / (p * p * n ); for i := 0 to p-1 do begin - Atotals[i] := Atotals[i] / (p * n); - Btotals[i] := Btotals[i] / (p * n); - Ctotals[i] := Ctotals[i] / (p * n); - Dtotals[i] := Dtotals[i] / (p * n); + Atotals[i] := Atotals[i] / (p * n); + Btotals[i] := Btotals[i] / (p * n); + Ctotals[i] := Ctotals[i] / (p * n); + Dtotals[i] := Dtotals[i] / (p * n); end; // show table of means for ABmat - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Cell means and totals'); + lReport.Add(''); + lReport.Add('Cell means and totals'); + lReport.Add(''); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorB]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorB]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorA]); + lReport.Add(cellstring); + for i := 0 to p-1 do begin - cellstring := format(' %3d ',[i+1]); - for j := 0 to p - 1 do - cellstring := cellstring + format(' %8.3f ',[ABmat[i,j]]); - cellstring := cellstring + format(' %8.3f ',[ABmat[i,p]]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := Format(' %3d ', [i+1]); + for j := 0 to p - 1 do + cellstring := cellstring + Format(' %8.3f ', [ABmat[i,j]]); + cellstring := cellstring + Format(' %8.3f ', [ABmat[i,p]]); + lReport.Add(cellstring); end; + cellstring := 'Total '; for j := 0 to p-1 do - cellstring := cellstring + format(' %8.3f ',[ABmat[p,j]]); - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [ABmat[p,j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); // show category means - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Means for each variable'); - OutputFrm.RichEdit.Lines.Add(''); + lReport.Add(''); + lReport.Add('Means for each variable'); + lReport.Add(''); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorA]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Atotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Atotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorB]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + lReport.Add(''); + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '----------'; + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorB]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Btotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Btotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorC]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + lReport.Add(''); + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '----------'; + lReport.Add(cellstring); + cellstring := Format('%10s', [FactorC]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Ctotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Ctotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + + lReport.Add(''); - OutputFrm.RichEdit.Lines.Add(''); cellstring := '----------'; for i := 1 to rangeD + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorD]); - for i := 1 to rangeD do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorD]); + for i := 1 to rangeD do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to rangeD + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to rangeD - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Dtotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Dtotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to rangeD + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); - OutputFrm.ShowModal; + DisplayReport(lReport); + + finally + lReport.Free; -cleanup: Design := nil; Dtotals := nil; Ctotals := nil; @@ -2098,300 +1920,274 @@ cleanup: cellcnts := nil; ABCmat := nil; ABmat := nil; + end; end; -procedure TLatinSqrsFrm.Plan5(Sender: TObject); -label cleanup; +procedure TLatinSqrsFrm.Plan5; var - NoFactors : integer; - n : integer; // no. of subjects per cell - Acol, Bcol, SbjCol, Grpcol, DataCol : integer; // variable columns in grid - FactorA : string; - FactorB : string; - SubjectFactor : string; - GroupFactor : string; - DataVar : string; - cellstring : string; - i, j, k, minA, minB, minGrp, maxA, maxB, maxGrp : integer; - rangeA, rangeB, rangeGrp : integer; - value : integer; - cellcnts : IntDyneMat; - ABmat : DblDyneMat; - ABCmat : DblDyneCube; - GBmat : DblDyneMat; - Atotals : DblDyneVec; - Btotals : DblDyneVec; - Grptotals : DblDyneVec; - Subjtotals : DblDyneMat; - design : StrDyneMat; - G, term1, term2, term3, term4, term5, term6, term7 : double; - sumxsqr : double; - SSbetsubj, SSgroups, SSsubwGrps, SSwithinsubj, SSa, SSb, SSab : double; - SSerrwithin, SStotal, MSgroups, MSsubwGrps, MSa, MSb, MSab : double; - MSerrwithin, DFbetsubj, DFgroups, DFsubwGrps, DFwithinsubj : double; - DFa, DFb, DFab, DFerrwithin, DFtotal : double; - data, GrandMean : double; - p, row, col, subject, group : integer; - proba, probb, probab, probgrps : double; - fa, fb, fab, fgroups : double; - RowLabels, ColLabels : StrDyneVec; - Title : string; + n: integer; // no. of subjects per cell + Acol, Bcol, SbjCol, Grpcol, DataCol: integer; // variable columns in grid + FactorA: string; + FactorB: string; + SubjectFactor: string; + GroupFactor: string; + DataVar: string; + cellstring: string; + i, j, k, minA, minB, minGrp, maxA, maxB, maxGrp: integer; + rangeA, rangeB, rangeGrp: integer; + value: integer; + cellcnts: IntDyneMat; + ABmat: DblDyneMat; + ABCmat: DblDyneCube; + GBmat: DblDyneMat; + Atotals: DblDyneVec; + Btotals: DblDyneVec; + Grptotals: DblDyneVec; + Subjtotals: DblDyneMat; + design: StrDyneMat; + G, term1, term2, term3, term4, term5, term6, term7: double; + sumxsqr: double; + SSbetsubj, SSgroups, SSsubwGrps, SSwithinsubj, SSa, SSb, SSab: double; + SSerrwithin, SStotal, MSgroups, MSsubwGrps, MSa, MSb, MSab: double; + MSerrwithin, DFbetsubj, DFgroups, DFsubwGrps, DFwithinsubj: double; + DFa, DFb, DFab, DFerrwithin, DFtotal: double; + data, GrandMean: double; + p, row, col, subject, group: integer; + proba, probb, probab, probgrps: double; + fa, fb, fab, fgroups: double; + RowLabels, ColLabels: StrDyneVec; + Title: string; + lReport: TStrings; begin - NoFactors := 3; - LatinSpecsFrm.PanelD.Visible := false; - LatinSpecsFrm.PanelGrp.Visible := true; - LatinSpecsFrm.AinBtn.Enabled := true; - LatinSpecsFrm.AoutBtn.Enabled := false; - LatinSpecsFrm.BinBtn.Enabled := true; - LatinSpecsFrm.BoutBtn.Enabled := false; - LatinSpecsFrm.CinBtn.Enabled := true; - LatinSpecsFrm.CoutBtn.Enabled := false; -// LatinSpecsFrm.DCodeEdit.Visible := false; - LatinSpecsFrm.ACodeEdit.Text := ''; - LatinSpecsFrm.BCodeEdit.Text := ''; - LatinSpecsFrm.CCodeEdit.Text := ''; - LatinSpecsFrm.DCodeEdit.Text := ''; - LatinSpecsFrm.GrpCodeEdit.Text := ''; - LatinSpecsFrm.DepVarEdit.Text := ''; - LatinSpecsFrm.nPerCellEdit.Text := ''; -// LatinSpecsFrm.GrpCodeEdit.Visible := true; -// LatinSpecsFrm.DCodeLabel.Visible := false; -// LatinSpecsFrm.GrpCodeLabel.Visible := true; -// LatinSpecsFrm.DinBtn.Visible := false; -// LatinSpecsFrm.DoutBtn.Visible := false; -// LatinSpecsFrm.GrpInBtn.Visible := true; -// LatinSpecsFrm.GrpOutBtn.Visible := true; - LatinSpecsFrm.GrpInBtn.Enabled := true; - LatinSpecsFrm.GrpOutBtn.Enabled := false; - LatinSpecsFrm.DataInBtn.Enabled := true; - LatinSpecsFrm.DataOutBtn.Enabled := false; - LatinSpecsFrm.ShowModal; - if LatinSpecsFrm.ModalResult = mrCancel then exit; - n := StrToInt(LatinSpecsFrm.nPerCellEdit.Text); - if n <= 0 then - begin - ShowMessage('Please specify the number of cases per cell.'); - exit; - end; - FactorA := LatinSpecsFrm.ACodeEdit.Text; - FactorB := LatinSpecsFrm.BCodeEdit.Text; - SubjectFactor := LatinSpecsFrm.CCodeEdit.Text; - GroupFactor := LatinSpecsFrm.GrpCodeEdit.Text; - DataVar := LatinSpecsFrm.DepVarEdit.Text; - for i := 1 to NoVariables do + LatinSpecsFrm.PrepareForPlan(5); + if LatinSpecsFrm.ShowModal <> mrOK then + exit; + + n := StrToInt(LatinSpecsFrm.nPerCellEdit.Text); + FactorA := LatinSpecsFrm.ACodeEdit.Text; + FactorB := LatinSpecsFrm.BCodeEdit.Text; + SubjectFactor := LatinSpecsFrm.CCodeEdit.Text; + GroupFactor := LatinSpecsFrm.GrpCodeEdit.Text; + DataVar := LatinSpecsFrm.DepVarEdit.Text; + + for i := 1 to NoVariables do + begin + cellstring := OS3MainFrm.DataGrid.Cells[i,0]; + if (cellstring = FactorA) then ACol := i; + if (cellstring = FactorB) then BCol := i; + if (cellstring = GroupFactor) then Grpcol := i; + if (cellstring = SubjectFactor) then Sbjcol := i; + if (cellstring = DataVar) then DataCol := i; + end; + + // determine no. of levels in A, B and Group + minA := MaxInt; + minB := MaxInt; + minGrp := MaxInt; + maxA := -MaxInt; + maxB := -MaxInt; + maxGrp := -MaxInt; + + for i := 1 to NoCases do + begin + value := StrToInt(OS3MainFrm.DataGrid.Cells[ACol,i]); + if value < minA then minA := value; + if value > maxA then maxA := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[BCol,i]); + if value < minB then minB := value; + if value > maxB then maxB := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); + if value < minGrp then minGrp := value; + if value > maxGrp then maxGrp := value; + end; + rangeA := maxA - minA + 1; + rangeB := maxB - minB + 1; + rangeGrp := maxGrp - minGrp + 1; + + // check for squareness + if (rangeA <> rangeGrp) then + begin + ErrorMsg('ERROR! In a Latin square the range of values should be equal for A,B and C.'); + exit; + end; + p := rangeA; + + // set up an array for cell counts and for cell sums and marginal sums + SetLength(ABmat, p+1, p+1); + SetLength(ABCmat, p+1, p+1, n+1); + SetLength(cellcnts, p+1, p+1); + SetLength(Atotals, p+1); + SetLength(Btotals, p+1); + SetLength(Grptotals, p+1); + SetLength(Design, p, p); + SetLength(Subjtotals ,p+1, n+1); + SetLength(RowLabels, p+1); + SetLength(ColLabels, n+1); + SetLength(GBmat, p+1, p+1); + + for i := 0 to p-1 do + begin + RowLabels[i] := IntToStr(i+1); + ColLabels[i] := RowLabels[i]; + end; + RowLabels[p] := 'Total'; + ColLabels[p] := 'Total'; + + for i := 0 to p do + for j := 0 to p do + for k := 0 to n do + ABCmat[i,j,k] := 0.0; + + for i := 0 to p do + for j := 0 to p do begin - cellstring := OS3MainFrm.DataGrid.Cells[i,0]; - if (cellstring = FactorA) then ACol := i; - if (cellstring = FactorB) then BCol := i; - if (cellstring = GroupFactor) then Grpcol := i; - if (cellstring = SubjectFactor) then Sbjcol := i; - if (cellstring = DataVar) then DataCol := i; + cellcnts[i,j] := 0; + ABmat[i,j] := 0.0; + GBmat[i,j] := 0.0; end; - // determine no. of levels in A, B and Group - minA := 1000; - minB := 1000; - minGrp := 1000; - maxA := -1000; - maxB := -1000; - maxGrp := -1000; - for i := 1 to NoCases do + for i := 0 to p do + begin + Atotals[i] := 0.0; + Btotals[i] := 0.0; + Grptotals[i] := 0.0; + end; + + for i := 0 to p do + for j := 0 to n do + Subjtotals[i,j] := 0.0; + + G := 0.0; + sumxsqr := 0.0; + term1 := 0.0; + term2 := 0.0; + term3 := 0.0; + term4 := 0.0; + term5 := 0.0; + term6 := 0.0; + term7 := 0.0; + GrandMean := 0.0; + + // Read in the data + for i := 1 to NoCases do + begin + row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); + col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); + group := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); + subject := StrToInt(OS3MainFrm.DataGrid.Cells[Sbjcol,i]); + data := StrToFloat(OS3MainFrm.DataGrid.Cells[DataCol,i]); + cellcnts[group-1,row-1] := cellcnts[group-1,row-1] + 1; + ABCmat[group-1,row-1,subject-1] := ABCmat[group-1,row-1,subject-1] + data; + Subjtotals[group-1,subject-1] := Subjtotals[group-1,subject-1] + data; + GBmat[group-1,col-1] := GBmat[group-1,col-1] + data; + Atotals[col-1] := Atotals[col-1] + data; + Btotals[group-1] := Btotals[group-1] + data; + Grptotals[group-1] := Grptotals[group-1] + data; + sumxsqr := sumxsqr + (data * data); + GrandMean := GrandMean + data; + end; + + // check for equal cell counts + for i := 0 to p-1 do + for j := 0 to p-1 do + if cellcnts[i,j] <> n then + begin + ErrorMsg('Cell sizes are not equal.'); + Exit; + end; + + // collapse subjects's into group x a matrix + for i := 0 to p-1 do // group + for j := 0 to p-1 do // factor a + for k := 0 to n-1 do // subject + ABmat[i,j] := ABmat[i,j] + ABCmat[i,j,k]; + + // get marginal totals for ABmat and GBmat + for i := 0 to p-1 do + for j := 0 to p-1 do begin - value := StrToInt(OS3MainFrm.DataGrid.Cells[ACol,i]); - if value < minA then minA := value; - if value > maxA then maxA := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[BCol,i]); - if value < minB then minB := value; - if value > maxB then maxB := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); - if value < minGrp then minGrp := value; - if value > maxGrp then maxGrp := value; - end; - rangeA := maxA - minA + 1; - rangeB := maxB - minB + 1; - rangeGrp := maxGrp - minGrp + 1; - - // check for squareness - if (rangeA <> rangeGrp) then - begin - ShowMessage('ERROR! In a Latin square the range of values should be equal for A,B and C!'); - exit; - end; - p := rangeA; - - // set up an array for cell counts and for cell sums and marginal sums - SetLength(ABmat,p+1,p+1); - SetLength(ABCmat,p+1,p+1,n+1); - SetLength(cellcnts,p+1,p+1); - SetLength(Atotals,p+1); - SetLength(Btotals,p+1); - SetLength(Grptotals,p+1); - SetLength(Design,p,p); - SetLength(Subjtotals,p+1,n+1); - SetLength(RowLabels,p+1); - SetLength(ColLabels,n+1); - SetLength(GBmat,p+1,p+1); - - for i := 0 to p-1 do - begin - RowLabels[i] := IntToStr(i+1); - ColLabels[i] := RowLabels[i]; - end; - RowLabels[p] := 'Total'; - ColLabels[p] := 'Total'; - - for i := 0 to p do - for j := 0 to p do - for k := 0 to n do - ABCmat[i,j,k] := 0.0; - - for i := 0 to p do - begin - for j := 0 to p do - begin - cellcnts[i,j] := 0; - ABmat[i,j] := 0.0; - GBmat[i,j] := 0.0; - end; + ABmat[p,j] := ABmat[p,j] + ABmat[i,j]; + ABmat[i,p] := ABmat[i,p] + ABmat[i,j]; + GBmat[p,j] := GBmat[p,j] + GBmat[i,j]; + GBmat[i,p] := GBmat[i,p] + GBmat[i,j]; end; - for i := 0 to p do + // get grand total for ABmat and GBmat + for i := 0 to p-1 do + begin + ABmat[p,p] := ABmat[p,p] + ABmat[p,i]; + GBmat[p,p] := GBmat[p,p] + GBmat[p,i]; + end; + + // Get marginal totals for Subjtotals + for i := 0 to p-1 do + for j := 0 to n-1 do begin - Atotals[i] := 0.0; - Btotals[i] := 0.0; - Grptotals[i] := 0.0; + Subjtotals[p,j] := Subjtotals[p,j] + Subjtotals[i,j]; + Subjtotals[i,n] := Subjtotals[i,n] + Subjtotals[i,j]; end; - for i := 0 to p do - for j := 0 to n do - Subjtotals[i,j] := 0.0; + for i := 0 to p-1 do + Subjtotals[p,n] := Subjtotals[p,n] + Subjtotals[i,n]; - G := 0.0; - sumxsqr := 0.0; - term1 := 0.0; - term2 := 0.0; - term3 := 0.0; - term4 := 0.0; - term5 := 0.0; - term6 := 0.0; - term7 := 0.0; - GrandMean := 0.0; + // test block + lReport := TStringList.Create; + try + lReport.Add('Sums for ANOVA Analysis'); + lReport.Add(''); - // Read in the data - for i := 1 to NoCases do - begin - row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); - col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); - group := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); - subject := StrToInt(OS3MainFrm.DataGrid.Cells[Sbjcol,i]); - data := StrToFloat(OS3MainFrm.DataGrid.Cells[DataCol,i]); - cellcnts[group-1,row-1] := cellcnts[group-1,row-1] + 1; - ABCmat[group-1,row-1,subject-1] := ABCmat[group-1,row-1,subject-1] + data; - Subjtotals[group-1,subject-1] := Subjtotals[group-1,subject-1] + data; - GBmat[group-1,col-1] := GBmat[group-1,col-1] + data; - Atotals[col-1] := Atotals[col-1] + data; - Btotals[group-1] := Btotals[group-1] + data; - Grptotals[group-1] := Grptotals[group-1] + data; - sumxsqr := sumxsqr + (data * data); - GrandMean := GrandMean + data; - end; - - // check for equal cell counts - for i := 0 to p-1 do - begin - for j := 0 to p-1 do - begin - if cellcnts[i,j] <> n then - begin - ShowMessage('cell sizes are not equal!'); - goto cleanup; - end; - end; - end; - - // collapse subjects's into group x a matrix - for i := 0 to p-1 do // group - for j := 0 to p-1 do // factor a - for k := 0 to n-1 do // subject - ABmat[i,j] := ABmat[i,j] + ABCmat[i,j,k]; - - // get marginal totals for ABmat and GBmat - for i := 0 to p-1 do - begin - for j := 0 to p-1 do - begin - ABmat[p,j] := ABmat[p,j] + ABmat[i,j]; - ABmat[i,p] := ABmat[i,p] + ABmat[i,j]; - GBmat[p,j] := GBmat[p,j] + GBmat[i,j]; - GBmat[i,p] := GBmat[i,p] + GBmat[i,j]; - end; - end; - - // get grand total for ABmat and GBmat - for i := 0 to p-1 do - begin - ABmat[p,p] := ABmat[p,p] + ABmat[p,i]; - GBmat[p,p] := GBmat[p,p] + GBmat[p,i]; - end; - - // Get marginal totals for Subjtotals - for i := 0 to p-1 do - begin - for j := 0 to n-1 do - begin - Subjtotals[p,j] := Subjtotals[p,j] + Subjtotals[i,j]; - Subjtotals[i,n] := Subjtotals[i,n] + Subjtotals[i,j]; - end; - end; - for i := 0 to p-1 do Subjtotals[p,n] := Subjtotals[p,n] + Subjtotals[i,n]; - // test block - OutputFrm.RichEdit.Lines.Add('Sums for ANOVA Analysis'); - OutputFrm.RichEdit.Lines.Add(''); cellstring := 'Group (rows) times A Factor (columns) sums'; - MAT_PRINT(ABmat,p+1,p+1,cellstring,RowLabels,ColLabels,(n*p*p)); + MatPrint(ABmat, p+1, p+1, cellstring, RowLabels, ColLabels, n*p*p, lReport); + cellstring := 'Group (rows) times B (cells Factor) sums'; - MAT_PRINT(GBmat,p+1,p+1,cellstring,RowLabels,ColLabels,(n*p*p)); + MatPrint(GBmat, p+1, p+1, cellstring, RowLabels, ColLabels, n*p*p, lReport); + Title := 'Groups (rows) times Subjects (columns) matrix'; for i := 0 to n-1 do ColLabels[i] := IntToStr(i+1); ColLabels[n] := 'Total'; - Mat_Print(Subjtotals,p+1,n+1,Title,RowLabels,ColLabels,(n*p*p)); - OutputFrm.ShowModal; + MatPrint(Subjtotals, p+1, n+1, Title, RowLabels, ColLabels, n*p*p, lReport); + + lReport.Add(''); + lReport.Add(DIVIDER); + lReport.Add(''); // get squared sum of subject's totals in each group for i := 0 to p-1 do // group - term7 := term7 + (Subjtotals[i,n] * Subjtotals[i,n]); + term7 := term7 + sqr(Subjtotals[i,n]); term7 := term7 / (n*p); // Sum G^2 sub k // now square each person score in each group and get sum for group for i := 0 to p-1 do - for j := 0 to n-1 do - Subjtotals[i,j] := Subjtotals[i,j] * Subjtotals[i,j]; - for i := 0 to p-1 do Subjtotals[i,n] := 0.0; + for j := 0 to n-1 do + Subjtotals[i,j] := Subjtotals[i,j] * Subjtotals[i,j]; for i := 0 to p-1 do - for j := 0 to n-1 do - Subjtotals[i,n] := Subjtotals[i,n] + Subjtotals[i,j]; + Subjtotals[i,n] := 0.0; + for i := 0 to p-1 do + for j := 0 to n-1 do + Subjtotals[i,n] := Subjtotals[i,n] + Subjtotals[i,j]; for i := 0 to p-1 do term6 := term6 + Subjtotals[i,n]; SSsubwgrps := term6 / p - term7; // get correction term term1 := (GrandMean * GrandMean) / (n * p * p); - term2 := sumxsqr; // get sum of squared a's for term3 for j := 0 to p-1 do - term3 := term3 + (ABmat[p,j] * ABmat[p,j]); + term3 := term3 + (ABmat[p,j] * ABmat[p,j]); term3 := term3 / (n * p); // get sum of squared groups for term4 for i := 0 to p-1 do - term4 := term4 + (ABmat[i,p] * ABmat[i,p]); + term4 := term4 + (ABmat[i,p] * ABmat[i,p]); term4 := term4 / (n * p); // get squared sum of b's (across groups) for term5 for j := 0 to p-1 do - term5 := term5 + (GBmat[p,j] * GBmat[p,j]); + term5 := term5 + (GBmat[p,j] * GBmat[p,j]); term5 := term5 / (n * p); SSgroups := term4 - term1; @@ -2404,8 +2200,8 @@ begin // get sum of squared AB cells for term6 term6 := 0.0; for i := 0 to p-1 do - for j := 0 to p-1 do - term6 := term6 + (ABmat[i,j] * ABmat[i,j]); + for j := 0 to p-1 do + term6 := term6 + (ABmat[i,j] * ABmat[i,j]); term6 := term6 / n; SSab := term6 - term3 - term5 + term1; SSab := SSab - SSgroups; @@ -2438,196 +2234,200 @@ begin probab := probf(fab,dfab,dferrwithin); // show ANOVA table results - OutputFrm.RichEdit.Clear; - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Latin Squares Repeated Analysis Plan 5 (Partial Interactions)'); - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); - OutputFrm.RichEdit.Lines.Add('Source SS DF MS F Prob.>F'); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); - cellstring := 'Betw.Subj.'; - cellstring := cellstring + format('%9.3f %9.0f',[SSbetsubj,dfbetsubj]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Groups '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSgroups,dfgroups,MSgroups,fgroups,probgrps]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Subj.w.g.'; - cellstring := cellstring + format('%9.3f %9.0f %9.3f',[SSsubwgrps,dfsubwgrps,MSsubwgrps]); - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); - cellstring := 'Within Sub'; - cellstring := cellstring + format('%9.3f %9.0f',[SSwithinsubj,dfwithinsubj]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Factor A '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSa,dfa,MSa,fa,proba]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Factor B '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSb,dfb,MSb,fb,probb]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Factor AB'; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSab,dfab,MSab,fab,probab]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Error w. '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f',[SSerrwithin,dferrwithin,MSerrwithin]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Total '; - cellstring := cellstring + format('%9.3f %9.0f',[SStotal, dftotal]); - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); + lReport.Add('LATIN SQUARES REPEATED ANALYSIS Plan 5 (Partial Interactions)'); + lReport.Add(''); + lReport.Add('-----------------------------------------------------------'); + lReport.Add('Source SS DF MS F Prob.>F'); + lReport.Add('-----------------------------------------------------------'); + lReport.Add('Betw.Subj.%9.3f %9.0f', [SSbetsubj, dfbetsubj]); + lReport.Add(' Groups %9.3f %9.0f %9.3f %9.3f %9.3f', [SSgroups, dfgroups, MSgroups, fgroups, probgrps]); + lReport.Add(' Subj.w.g.%9.3f %9.0f %9.3f', [SSsubwgrps, dfsubwgrps, MSsubwgrps]); + lReport.Add(''); + lReport.Add('Within Sub%9.3f %9.0f', [SSwithinsubj, dfwithinsubj]); + lReport.Add(' Factor A %9.3f %9.0f %9.3f %9.3f %9.3f', [SSa, dfa, MSa, fa, proba]); + lReport.Add(' Factor B %9.3f %9.0f %9.3f %9.3f %9.3f', [SSb, dfb, MSb, fb, probb]); + lReport.Add(' Factor AB%9.3f %9.0f %9.3f %9.3f %9.3f', [SSab, dfab, MSab, fab, probab]); + lReport.Add(' Error w. %9.3f %9.0f %9.3f', [SSerrwithin, dferrwithin, MSerrwithin]); + lReport.Add('Total %9.3f %9.0f', [SStotal, dftotal]); + lReport.Add('-----------------------------------------------------------'); // show design for Square - OutputFrm.RichEdit.Lines.Add(''); - cellstring := 'Experimental Design for Latin Square '; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(''); + lReport.Add('Experimental Design for Latin Square '); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorA]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[GroupFactor]); - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + + cellstring := Format('%10s', [GroupFactor]); + lReport.Add(cellstring); + for i := 1 to NoCases do begin - row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); // A (column) effect - col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); // B (cell) effect - group := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); // group (row) - Design[group-1,row-1] := 'B' + IntToStr(col); + row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); // A (column) effect + col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); // B (cell) effect + group := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); // group (row) + Design[group-1,row-1] := 'B' + IntToStr(col); end; + for i := 0 to p - 1 do begin - cellstring := format(' %3d ',[i+1]); - for j := 0 to p - 1 do - cellstring := cellstring + format('%5s',[Design[i,j]]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := Format(' %3d ', [i+1]); + for j := 0 to p - 1 do + cellstring := cellstring + Format('%5s', [Design[i,j]]); + lReport.Add(cellstring); end; + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); for i := 0 to p-1 do - for j := 0 to p-1 do - ABmat[i,j] := ABmat[i,j] / n; + for j := 0 to p-1 do + ABmat[i,j] := ABmat[i,j] / n; for i := 0 to p-1 do - ABmat[i,p] := ABmat[i,p] / (n * p); + ABmat[i,p] := ABmat[i,p] / (n * p); for j := 0 to p-1 do - ABmat[p,j] := ABmat[p,j] / (n * p); + ABmat[p,j] := ABmat[p,j] / (n * p); GrandMean := GrandMean / (p * p * n ); for i := 0 to p-1 do begin - Atotals[i] := Atotals[i] / (p * n); - Btotals[i] := Btotals[i] / (p * n); - Grptotals[i] := Grptotals[i] / (p * n); -// Dtotals[i] := Dtotals[i] / (p * n); + Atotals[i] := Atotals[i] / (p * n); + Btotals[i] := Btotals[i] / (p * n); + Grptotals[i] := Grptotals[i] / (p * n); end; // show table of means for ABmat - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Cell means and totals'); + lReport.Add(''); + lReport.Add('Cell means and totals'); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorA]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[GroupFactor]); - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + + cellstring := Format('%10s', [GroupFactor]); + lReport.Add(cellstring); + for i := 0 to p-1 do begin - cellstring := format(' %3d ',[i+1]); - for j := 0 to p - 1 do - cellstring := cellstring + format(' %8.3f ',[ABmat[i,j]]); - cellstring := cellstring + format(' %8.3f ',[ABmat[i,p]]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := Format(' %3d ', [i+1]); + for j := 0 to p - 1 do + cellstring := cellstring + Format(' %8.3f ', [ABmat[i,j]]); + cellstring := cellstring + Format(' %8.3f ', [ABmat[i,p]]); + lReport.Add(cellstring); end; + cellstring := 'Total '; for j := 0 to p-1 do - cellstring := cellstring + format(' %8.3f ',[ABmat[p,j]]); - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [ABmat[p,j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); // show category means - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Means for each variable'); - OutputFrm.RichEdit.Lines.Add(''); + lReport.Add(''); + lReport.Add('Means for each variable'); + lReport.Add(''); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorA]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Atotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Atotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorB]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + lReport.Add(''); + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '----------'; + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorB]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Btotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Btotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[GroupFactor]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + lReport.Add(''); + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '----------'; + lReport.Add(cellstring); + + cellstring := Format('%10s', [GroupFactor]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Grptotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Grptotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.ShowModal; + lReport.Add(cellstring); + + DisplayReport(lReport); + + finally + lReport.Free; -cleanup: GBmat := nil; ColLabels := nil; RowLabels := nil; @@ -2639,304 +2439,275 @@ cleanup: cellcnts := nil; ABCmat := nil; ABmat := nil; + end; end; -procedure TLatinSqrsFrm.Plan6(Sender: TObject); -label cleanup; +procedure TLatinSqrsFrm.Plan6; var - NoFactors : integer; - n : integer; // no. of subjects per cell - Acol, Bcol, SbjCol, Grpcol, DataCol : integer; // variable columns in grid - FactorA : string; - FactorB : string; - SubjectFactor : string; - GroupFactor : string; - DataVar : string; - cellstring : string; - i, j, k, minA, minB, minGrp, maxA, maxB, maxGrp : integer; - rangeA, rangeB, rangeGrp : integer; - value : integer; - cellcnts : IntDyneMat; - ABmat : DblDyneMat; - ABCmat : DblDyneCube; - GBmat : DblDyneMat; - Atotals : DblDyneVec; - Btotals : DblDyneVec; - Grptotals : DblDyneVec; - Subjtotals : DblDyneMat; - design : StrDyneMat; - G, term1, term2, term3, term4, term5, term6, term7 : double; - sumxsqr : double; - SSbetsubj, SSgroups, SSsubwGrps, SSwithinsubj, SSa, SSb, SSab : double; - SSerrwithin, SStotal, MSgroups, MSsubwGrps, MSa, MSb, MSab : double; - MSerrwithin, DFbetsubj, DFgroups, DFsubwGrps, DFwithinsubj : double; - DFa, DFb, DFab, DFerrwithin, DFtotal : double; - data, GrandMean : double; - p, row, col, subject, group : integer; - proba, probb, probab, probgrps : double; - fa, fb, fab, fgroups : double; - RowLabels, ColLabels : StrDyneVec; - Title : string; + n : integer; // no. of subjects per cell + Acol, Bcol, SbjCol, Grpcol, DataCol: integer; // variable columns in grid + FactorA: string; + FactorB: string; + SubjectFactor: string; + GroupFactor: string; + DataVar: string; + cellstring: string; + i, j, k, minA, minB, minGrp, maxA, maxB, maxGrp: integer; + rangeA, rangeB, rangeGrp: integer; + value: integer; + cellcnts: IntDyneMat; + ABmat: DblDyneMat; + ABCmat: DblDyneCube; + GBmat: DblDyneMat; + Atotals: DblDyneVec; + Btotals: DblDyneVec; + Grptotals: DblDyneVec; + Subjtotals: DblDyneMat; + design: StrDyneMat; + G, term1, term2, term3, term4, term5, term6, term7: double; + sumxsqr: double; + SSbetsubj, SSgroups, SSsubwGrps, SSwithinsubj, SSa, SSb, SSab: double; + SSerrwithin, SStotal, MSgroups, MSsubwGrps, MSa, MSb, MSab: double; + MSerrwithin, DFbetsubj, DFgroups, DFsubwGrps, DFwithinsubj: double; + DFa, DFb, DFab, DFerrwithin, DFtotal: double; + data, GrandMean: double; + p, row, col, subject, group: integer; + proba, probb, probab, probgrps: double; + fa, fb, fab, fgroups: double; + RowLabels, ColLabels: StrDyneVec; + Title: string; + lReport: TStrings; begin - NoFactors := 3; - LatinSpecsFrm.PanelD.Visible := false; - LatinSpecsFrm.PanelGrp.Visible := true; - LatinSpecsFrm.AinBtn.Enabled := true; - LatinSpecsFrm.AoutBtn.Enabled := false; - LatinSpecsFrm.BinBtn.Enabled := true; - LatinSpecsFrm.BoutBtn.Enabled := false; - LatinSpecsFrm.CinBtn.Enabled := true; - LatinSpecsFrm.CoutBtn.Enabled := false; -// LatinSpecsFrm.DCodeEdit.Visible := false; - LatinSpecsFrm.ACodeEdit.Text := ''; - LatinSpecsFrm.BCodeEdit.Text := ''; - LatinSpecsFrm.CCodeEdit.Text := ''; - LatinSpecsFrm.DCodeEdit.Text := ''; - LatinSpecsFrm.GrpCodeEdit.Text := ''; - LatinSpecsFrm.DepVarEdit.Text := ''; - LatinSpecsFrm.nPerCellEdit.Text := ''; -// LatinSpecsFrm.GrpCodeEdit.Visible := true; -// LatinSpecsFrm.DCodeLabel.Visible := false; -// LatinSpecsFrm.GrpCodeLabel.Visible := true; -// LatinSpecsFrm.DinBtn.Visible := false; -// LatinSpecsFrm.DoutBtn.Visible := false; -// LatinSpecsFrm.GrpInBtn.Visible := true; -// LatinSpecsFrm.GrpOutBtn.Visible := true; - LatinSpecsFrm.GrpInBtn.Enabled := true; - LatinSpecsFrm.GrpOutBtn.Enabled := false; - LatinSpecsFrm.DataInBtn.Enabled := true; - LatinSpecsFrm.DataOutBtn.Enabled := false; - LatinSpecsFrm.ShowModal; - if LatinSpecsFrm.ModalResult = mrCancel then exit; - n := StrToInt(LatinSpecsFrm.nPerCellEdit.Text); - if n <= 0 then - begin - ShowMessage('Please specify the number of cases per cell.'); - exit; - end; - FactorA := LatinSpecsFrm.ACodeEdit.Text; - FactorB := LatinSpecsFrm.BCodeEdit.Text; - SubjectFactor := LatinSpecsFrm.CCodeEdit.Text; - GroupFactor := LatinSpecsFrm.GrpCodeEdit.Text; - DataVar := LatinSpecsFrm.DepVarEdit.Text; - for i := 1 to NoVariables do + LatinSpecsFrm.PrepareForPlan(6); + if LatinSpecsFrm.ShowModal <> mrOK then + exit; + + n := StrToInt(LatinSpecsFrm.nPerCellEdit.Text); + FactorA := LatinSpecsFrm.ACodeEdit.Text; + FactorB := LatinSpecsFrm.BCodeEdit.Text; + SubjectFactor := LatinSpecsFrm.CCodeEdit.Text; + GroupFactor := LatinSpecsFrm.GrpCodeEdit.Text; + DataVar := LatinSpecsFrm.DepVarEdit.Text; + + for i := 1 to NoVariables do + begin + cellstring := OS3MainFrm.DataGrid.Cells[i,0]; + if (cellstring = FactorA) then ACol := i; + if (cellstring = FactorB) then BCol := i; + if (cellstring = GroupFactor) then Grpcol := i; + if (cellstring = SubjectFactor) then Sbjcol := i; + if (cellstring = DataVar) then DataCol := i; + end; + + // determine no. of levels in A, B and Group + minA := MaxInt; + minB := MaxInt; + minGrp := MaxInt; + maxA := -MaxInt; + maxB := -MaxInt; + maxGrp := -MaxInt; + + for i := 1 to NoCases do + begin + value := StrToInt(OS3MainFrm.DataGrid.Cells[ACol,i]); + if value < minA then minA := value; + if value > maxA then maxA := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[BCol,i]); + if value < minB then minB := value; + if value > maxB then maxB := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); + if value < minGrp then minGrp := value; + + if value > maxGrp then maxGrp := value; + end; + rangeA := maxA - minA + 1; + rangeB := maxB - minB + 1; + rangeGrp := maxGrp - minGrp + 1; + + // check for squareness + if (rangeA <> rangeGrp) then + begin + ErrorMsg('In a Latin square the range of values should be equal for A,B and C.'); + exit; + end; + p := rangeA; + + // set up an array for cell counts and for cell sums and marginal sums + SetLength(ABmat, p+1, p+1); + SetLength(ABCmat, p+1, p+1, n+1); + SetLength(cellcnts, p+1, p+1); + SetLength(Atotals, p+1); + SetLength(Btotals, p+1); + SetLength(Grptotals, p+1); + SetLength(Design, p, p); + SetLength(Subjtotals, p+1, n+1); + SetLength(RowLabels, p+1); + SetLength(ColLabels, n+1); + SetLength(GBmat, p+1, p+1); + + for i := 0 to p-1 do + begin + RowLabels[i] := IntToStr(i+1); + ColLabels[i] := RowLabels[i]; + end; + RowLabels[p] := 'Total'; + ColLabels[p] := 'Total'; + + for i := 0 to p do + for j := 0 to p do + for k := 0 to n do + ABCmat[i,j,k] := 0.0; + + for i := 0 to p do + for j := 0 to p do begin - cellstring := OS3MainFrm.DataGrid.Cells[i,0]; - if (cellstring = FactorA) then ACol := i; - if (cellstring = FactorB) then BCol := i; - if (cellstring = GroupFactor) then Grpcol := i; - if (cellstring = SubjectFactor) then Sbjcol := i; - if (cellstring = DataVar) then DataCol := i; + cellcnts[i,j] := 0; + ABmat[i,j] := 0.0; + GBmat[i,j] := 0.0; end; - // determine no. of levels in A, B and Group - minA := 1000; - minB := 1000; - minGrp := 1000; - maxA := -1000; - maxB := -1000; - maxGrp := -1000; - for i := 1 to NoCases do + for i := 0 to p do + begin + Atotals[i] := 0.0; + Btotals[i] := 0.0; + Grptotals[i] := 0.0; + end; + + for i := 0 to p do + for j := 0 to n do + Subjtotals[i,j] := 0.0; + + G := 0.0; + sumxsqr := 0.0; + term1 := 0.0; + term2 := 0.0; + term3 := 0.0; + term4 := 0.0; + term5 := 0.0; + term6 := 0.0; + term7 := 0.0; + GrandMean := 0.0; + + // Read in the data + for i := 1 to NoCases do + begin + row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); + col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); + group := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); + subject := StrToInt(OS3MainFrm.DataGrid.Cells[Sbjcol,i]); + data := StrToFloat(OS3MainFrm.DataGrid.Cells[DataCol,i]); + cellcnts[group-1,row-1] := cellcnts[group-1,row-1] + 1; + ABCmat[group-1,row-1,subject-1] := ABCmat[group-1,row-1,subject-1] + data; + Subjtotals[group-1,subject-1] := Subjtotals[group-1,subject-1] + data; + GBmat[group-1,col-1] := GBmat[group-1,col-1] + data; + Atotals[col-1] := Atotals[col-1] + data; + Btotals[group-1] := Btotals[group-1] + data; + Grptotals[group-1] := Grptotals[group-1] + data; + sumxsqr := sumxsqr + (data * data); + GrandMean := GrandMean + data; + end; + + // check for equal cell counts + for i := 0 to p-1 do + for j := 0 to p-1 do + if cellcnts[i,j] <> n then + begin + ErrorMsg('Cell sizes are not equal.'); + exit; + end; + + // collapse subjects's into group x a matrix + for i := 0 to p-1 do // group + for j := 0 to p-1 do // factor a + for k := 0 to n-1 do // subject + ABmat[i,j] := ABmat[i,j] + ABCmat[i,j,k]; + + // get marginal totals for ABmat and GBmat + for i := 0 to p-1 do + for j := 0 to p-1 do begin - value := StrToInt(OS3MainFrm.DataGrid.Cells[ACol,i]); - if value < minA then minA := value; - if value > maxA then maxA := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[BCol,i]); - if value < minB then minB := value; - if value > maxB then maxB := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); - if value < minGrp then minGrp := value; - if value > maxGrp then maxGrp := value; - end; - rangeA := maxA - minA + 1; - rangeB := maxB - minB + 1; - rangeGrp := maxGrp - minGrp + 1; - - // check for squareness - if (rangeA <> rangeGrp) then - begin - ShowMessage('ERROR! In a Latin square the range of values should be equal for A,B and C!'); - exit; - end; - p := rangeA; - - // set up an array for cell counts and for cell sums and marginal sums - SetLength(ABmat,p+1,p+1); - SetLength(ABCmat,p+1,p+1,n+1); - SetLength(cellcnts,p+1,p+1); - SetLength(Atotals,p+1); - SetLength(Btotals,p+1); - SetLength(Grptotals,p+1); - SetLength(Design,p,p); - SetLength(Subjtotals,p+1,n+1); - SetLength(RowLabels,p+1); - SetLength(ColLabels,n+1); - SetLength(GBmat,p+1,p+1); - - for i := 0 to p-1 do - begin - RowLabels[i] := IntToStr(i+1); - ColLabels[i] := RowLabels[i]; - end; - RowLabels[p] := 'Total'; - ColLabels[p] := 'Total'; - - for i := 0 to p do - for j := 0 to p do - for k := 0 to n do - ABCmat[i,j,k] := 0.0; - - for i := 0 to p do - begin - for j := 0 to p do - begin - cellcnts[i,j] := 0; - ABmat[i,j] := 0.0; - GBmat[i,j] := 0.0; - end; + ABmat[p,j] := ABmat[p,j] + ABmat[i,j]; + ABmat[i,p] := ABmat[i,p] + ABmat[i,j]; + GBmat[p,j] := GBmat[p,j] + GBmat[i,j]; + GBmat[i,p] := GBmat[i,p] + GBmat[i,j]; end; - for i := 0 to p do + // get grand total for ABmat and GBmat + for i := 0 to p-1 do + begin + ABmat[p,p] := ABmat[p,p] + ABmat[p,i]; + GBmat[p,p] := GBmat[p,p] + GBmat[p,i]; + end; + + // Get marginal totals for Subjtotals + for i := 0 to p-1 do + for j := 0 to n-1 do begin - Atotals[i] := 0.0; - Btotals[i] := 0.0; - Grptotals[i] := 0.0; + Subjtotals[p,j] := Subjtotals[p,j] + Subjtotals[i,j]; + Subjtotals[i,n] := Subjtotals[i,n] + Subjtotals[i,j]; end; + for i := 0 to p-1 do + Subjtotals[p,n] := Subjtotals[p,n] + Subjtotals[i,n]; - for i := 0 to p do - for j := 0 to n do - Subjtotals[i,j] := 0.0; + // test block + lReport := TStringList.Create; + try + lReport.Add('LATIN SQUARES REPEATED ANALYSIS Plan 6'); + lReport.Add(''); + lReport.Add('Sums for ANOVA Analysis'); + lReport.Add(''); - G := 0.0; - sumxsqr := 0.0; - term1 := 0.0; - term2 := 0.0; - term3 := 0.0; - term4 := 0.0; - term5 := 0.0; - term6 := 0.0; - term7 := 0.0; - GrandMean := 0.0; - - // Read in the data - for i := 1 to NoCases do - begin - row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); - col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); - group := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); - subject := StrToInt(OS3MainFrm.DataGrid.Cells[Sbjcol,i]); - data := StrToFloat(OS3MainFrm.DataGrid.Cells[DataCol,i]); - cellcnts[group-1,row-1] := cellcnts[group-1,row-1] + 1; - ABCmat[group-1,row-1,subject-1] := ABCmat[group-1,row-1,subject-1] + data; - Subjtotals[group-1,subject-1] := Subjtotals[group-1,subject-1] + data; - GBmat[group-1,col-1] := GBmat[group-1,col-1] + data; - Atotals[col-1] := Atotals[col-1] + data; - Btotals[group-1] := Btotals[group-1] + data; - Grptotals[group-1] := Grptotals[group-1] + data; - sumxsqr := sumxsqr + (data * data); - GrandMean := GrandMean + data; - end; - - // check for equal cell counts - for i := 0 to p-1 do - begin - for j := 0 to p-1 do - begin - if cellcnts[i,j] <> n then - begin - ShowMessage('cell sizes are not equal!'); - goto cleanup; - end; - end; - end; - - // collapse subjects's into group x a matrix - for i := 0 to p-1 do // group - for j := 0 to p-1 do // factor a - for k := 0 to n-1 do // subject - ABmat[i,j] := ABmat[i,j] + ABCmat[i,j,k]; - - // get marginal totals for ABmat and GBmat - for i := 0 to p-1 do - begin - for j := 0 to p-1 do - begin - ABmat[p,j] := ABmat[p,j] + ABmat[i,j]; - ABmat[i,p] := ABmat[i,p] + ABmat[i,j]; - GBmat[p,j] := GBmat[p,j] + GBmat[i,j]; - GBmat[i,p] := GBmat[i,p] + GBmat[i,j]; - end; - end; - - // get grand total for ABmat and GBmat - for i := 0 to p-1 do - begin - ABmat[p,p] := ABmat[p,p] + ABmat[p,i]; - GBmat[p,p] := GBmat[p,p] + GBmat[p,i]; - end; - - // Get marginal totals for Subjtotals - for i := 0 to p-1 do - begin - for j := 0 to n-1 do - begin - Subjtotals[p,j] := Subjtotals[p,j] + Subjtotals[i,j]; - Subjtotals[i,n] := Subjtotals[i,n] + Subjtotals[i,j]; - end; - end; - for i := 0 to p-1 do Subjtotals[p,n] := Subjtotals[p,n] + Subjtotals[i,n]; - - // test block - OutputFrm.RichEdit.Clear; - OutputFrm.RichEdit.Lines.Add('Latin Squares Repeated Analysis Plan 6'); - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Sums for ANOVA Analysis'); - OutputFrm.RichEdit.Lines.Add(''); cellstring := 'Group - C (rows) times A Factor (columns) sums'; - MAT_PRINT(ABmat,p+1,p+1,cellstring,RowLabels,ColLabels,(n*p*p)); + MatPrint(ABmat, p+1, p+1, cellstring, RowLabels, ColLabels,n*p*p, lReport); + cellstring := 'Group - C (rows) times B (cells Factor) sums'; - MAT_PRINT(GBmat,p+1,p+1,cellstring,RowLabels,ColLabels,(n*p*p)); + MatPrint(GBmat, p+1, p+1, cellstring, RowLabels, ColLabels, n*p*p, lReport); + Title := 'Group - C (rows) times Subjects (columns) matrix'; for i := 0 to n-1 do ColLabels[i] := IntToStr(i+1); ColLabels[n] := 'Total'; - Mat_Print(Subjtotals,p+1,n+1,Title,RowLabels,ColLabels,(n*p*p)); - OutputFrm.ShowModal; + MatPrint(Subjtotals, p+1, n+1, Title, RowLabels, ColLabels, n*p*p, lReport); + + lReport.Add(''); + lReport.Add(DIVIDER); + lReport.Add(''); // get squared sum of subject's totals in each group for i := 0 to p-1 do // group - term7 := term7 + (Subjtotals[i,n] * Subjtotals[i,n]); + term7 := term7 + (Subjtotals[i,n] * Subjtotals[i,n]); term7 := term7 / (n*p); // Sum G^2 sub k // now square each person score in each group and get sum for group for i := 0 to p-1 do - for j := 0 to n-1 do - Subjtotals[i,j] := Subjtotals[i,j] * Subjtotals[i,j]; + for j := 0 to n-1 do + Subjtotals[i,j] := Subjtotals[i,j] * Subjtotals[i,j]; for i := 0 to p-1 do Subjtotals[i,n] := 0.0; for i := 0 to p-1 do - for j := 0 to n-1 do - Subjtotals[i,n] := Subjtotals[i,n] + Subjtotals[i,j]; + for j := 0 to n-1 do + Subjtotals[i,n] := Subjtotals[i,n] + Subjtotals[i,j]; for i := 0 to p-1 do term6 := term6 + Subjtotals[i,n]; SSsubwgrps := term6 / p - term7; // get correction term - term1 := (GrandMean * GrandMean) / (n * p * p); - + term1 := sqr(GrandMean) / (n * p * p); term2 := sumxsqr; // get sum of squared a's for term3 for j := 0 to p-1 do - term3 := term3 + (ABmat[p,j] * ABmat[p,j]); + term3 := term3 + sqr(ABmat[p,j]); term3 := term3 / (n * p); // get sum of squared groups for term4 for i := 0 to p-1 do - term4 := term4 + (ABmat[i,p] * ABmat[i,p]); + term4 := term4 + sqr(ABmat[i,p]); term4 := term4 / (n * p); // get squared sum of b's (across groups) for term5 for j := 0 to p-1 do - term5 := term5 + (GBmat[p,j] * GBmat[p,j]); + term5 := term5 + sqr(GBmat[p,j]); term5 := term5 / (n * p); SSgroups := term4 - term1; @@ -2949,8 +2720,8 @@ begin // get sum of squared AB cells for term6 term6 := 0.0; for i := 0 to p-1 do - for j := 0 to p-1 do - term6 := term6 + (ABmat[i,j] * ABmat[i,j]); + for j := 0 to p-1 do + term6 := term6 + sqr(ABmat[i,j]); term6 := term6 / n; SSab := term6 - term3 - term5 + term1; SSab := SSab - SSgroups; @@ -2983,195 +2754,198 @@ begin probab := probf(fab,dfab,dferrwithin); // show ANOVA table results - OutputFrm.RichEdit.Clear; - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Latin Squares Repeated Analysis Plan 6'); - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); - OutputFrm.RichEdit.Lines.Add('Source SS DF MS F Prob.>F'); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); - cellstring := 'Betw.Subj.'; - cellstring := cellstring + format('%9.3f %9.0f',[SSbetsubj,dfbetsubj]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Factor C '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSgroups,dfgroups,MSgroups,fgroups,probgrps]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Subj.w.g.'; - cellstring := cellstring + format('%9.3f %9.0f %9.3f',[SSsubwgrps,dfsubwgrps,MSsubwgrps]); - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); - cellstring := 'Within Sub'; - cellstring := cellstring + format('%9.3f %9.0f',[SSwithinsubj,dfwithinsubj]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Factor A '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSa,dfa,MSa,fa,proba]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Factor B '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSb,dfb,MSb,fb,probb]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Residual '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSab,dfab,MSab,fab,probab]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Error w. '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f',[SSerrwithin,dferrwithin,MSerrwithin]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Total '; - cellstring := cellstring + format('%9.3f %9.0f',[SStotal, dftotal]); - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); + lReport.Add('LATIN SQUARES REPEATED ANALYSIS Plan 6'); + lReport.Add(''); + lReport.Add('-----------------------------------------------------------'); + lReport.Add('Source SS DF MS F Prob.>F'); + lReport.Add('-----------------------------------------------------------'); + lReport.Add('Betw.Subj.%9.3f %9.0f', [SSbetsubj, dfbetsubj]); + lReport.Add(' Factor C %9.3f %9.0f %9.3f %9.3f %9.3f', [SSgroups, dfgroups, MSgroups, fgroups, probgrps]); + lReport.Add(' Subj.w.g.%9.3f %9.0f %9.3f', [SSsubwgrps, dfsubwgrps, MSsubwgrps]); + lReport.Add(''); + lReport.Add('Within Sub%9.3f %9.0f',[ SSwithinsubj, dfwithinsubj]); + lReport.Add(' Factor A %9.3f %9.0f %9.3f %9.3f %9.3f', [SSa, dfa, MSa, fa, proba]); + lReport.Add(' Factor B %9.3f %9.0f %9.3f %9.3f %9.3f', [SSb, dfb, MSb, fb, probb]); + lReport.Add(' Residual %9.3f %9.0f %9.3f %9.3f %9.3f', [SSab, dfab, MSab, fab, probab]); + lReport.Add(' Error w. %9.3f %9.0f %9.3f', [SSerrwithin, dferrwithin, MSerrwithin]); + lReport.Add('Total %9.3f %9.0f', [SStotal, dftotal]); + lReport.Add('-----------------------------------------------------------'); // show design for Square - OutputFrm.RichEdit.Lines.Add(''); - cellstring := 'Experimental Design for Latin Square '; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(''); + lReport.Add('Experimental Design for Latin Square '); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorA]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' G C '; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + + lReport.Add(' G C '); + for i := 1 to NoCases do begin - row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); // A (column) effect - col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); // B (cell) effect - group := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); // group (row) - Design[group-1,row-1] := 'B' + IntToStr(col); + row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); // A (column) effect + col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); // B (cell) effect + group := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); // group (row) + Design[group-1,row-1] := 'B' + IntToStr(col); end; + for i := 0 to p - 1 do begin - cellstring := format('%3d %3d ',[i+1,i+1]); - for j := 0 to p - 1 do - cellstring := cellstring + format('%5s',[Design[i,j]]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := Format('%3d %3d ', [i+1,i+1]); + for j := 0 to p - 1 do + cellstring := cellstring + Format('%5s', [Design[i,j]]); + lReport.Add(cellstring); end; + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); for i := 0 to p-1 do - for j := 0 to p-1 do - ABmat[i,j] := ABmat[i,j] / n; + for j := 0 to p-1 do + ABmat[i,j] := ABmat[i,j] / n; for i := 0 to p-1 do - ABmat[i,p] := ABmat[i,p] / (n * p); + ABmat[i,p] := ABmat[i,p] / (n * p); for j := 0 to p-1 do - ABmat[p,j] := ABmat[p,j] / (n * p); + ABmat[p,j] := ABmat[p,j] / (n * p); GrandMean := GrandMean / (p * p * n ); for i := 0 to p-1 do begin - Atotals[i] := Atotals[i] / (p * n); - Btotals[i] := Btotals[i] / (p * n); - Grptotals[i] := Grptotals[i] / (p * n); + Atotals[i] := Atotals[i] / (p * n); + Btotals[i] := Btotals[i] / (p * n); + Grptotals[i] := Grptotals[i] / (p * n); end; // show table of means for ABmat - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Cell means and totals'); + lReport.Add(''); + lReport.Add('Cell means and totals'); + lReport.Add(''); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorA]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[GroupFactor]); - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + + cellstring := Format('%10s', [GroupFactor]); + lReport.Add(cellstring); + for i := 0 to p-1 do begin - cellstring := format(' %3d ',[i+1]); - for j := 0 to p - 1 do - cellstring := cellstring + format(' %8.3f ',[ABmat[i,j]]); - cellstring := cellstring + format(' %8.3f ',[ABmat[i,p]]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := Format(' %3d ', [i+1]); + for j := 0 to p - 1 do + cellstring := cellstring + Format(' %8.3f ', [ABmat[i,j]]); + cellstring := cellstring + Format(' %8.3f ', [ABmat[i,p]]); + lReport.Add(cellstring); end; + cellstring := 'Total '; for j := 0 to p-1 do - cellstring := cellstring + format(' %8.3f ',[ABmat[p,j]]); - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [ABmat[p,j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); // show category means - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Means for each variable'); - OutputFrm.RichEdit.Lines.Add(''); + lReport.Add(''); + lReport.Add('Means for each variable'); + lReport.Add(''); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + cellstring := Format('%10s', [FactorA]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Atotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Atotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorB]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + lReport.Add(''); + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '----------'; + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorB]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Btotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := '----------'; - for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Btotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[GroupFactor]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + lReport.Add(''); + + cellstring := '----------'; + for i := 1 to p + 1 do cellstring := cellstring + '----------'; + lReport.Add(cellstring); + + cellstring := Format('%10s', [GroupFactor]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Grptotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Grptotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.ShowModal; + lReport.Add(cellstring); + + DisplayReport(lReport); + + finally + lReport.Free; -cleanup: GBmat := nil; ColLabels := nil; RowLabels := nil; @@ -3183,340 +2957,313 @@ cleanup: cellcnts := nil; ABCmat := nil; ABmat := nil; + end; end; -procedure TLatinSqrsFrm.Plan7(Sender: TObject); -label cleanup; +procedure TLatinSqrsFrm.Plan7; var - NoFactors : integer; - n : integer; // no. of subjects per cell - Acol, Bcol, Ccol, SbjCol, Grpcol, DataCol : integer; // variable columns in grid - FactorA : string; - FactorB : string; - SubjectFactor : string; - FactorC : string; - GroupFactor : string; - DataVar : string; - cellstring : string; - i, j, k, minA, minB, minC, minGrp, maxA, maxB, maxC, maxGrp : integer; - rangeA, rangeB, rangeC, rangeGrp : integer; - value : integer; - cellcnts : IntDyneMat; - ABmat : DblDyneMat; - ABCmat : DblDyneCube; - GBmat : DblDyneMat; - GCmat : DblDyneMat; - Atotals : DblDyneVec; - Btotals : DblDyneVec; - Ctotals : DblDyneVec; - Grptotals : DblDyneVec; - Subjtotals : DblDyneMat; - design : StrDyneMat; - G, term1, term2, term3, term4, term5, term6, term7, term8, term9 : double; - sumxsqr : double; - SSbetsubj, SSgroups, SSsubwGrps, SSwithinsubj, SSa, SSb, SSc, SSab : double; - SSerrwithin, SStotal, MSgroups, MSsubwGrps, MSa, MSb, MSc, MSab : double; - MSerrwithin, DFbetsubj, DFgroups, DFsubwGrps, DFwithinsubj : double; - DFa, DFb, DFc, DFab, DFerrwithin, DFtotal : double; - data, GrandMean : double; - p, row, col, slice, subject, group : integer; - proba, probb, probc, probab, probgrps : double; - fa, fb, fc, fab, fgroups : double; - RowLabels, ColLabels : StrDyneVec; - Title : string; + n: integer; // no. of subjects per cell + Acol, Bcol, Ccol, SbjCol, Grpcol, DataCol: integer; // variable columns in grid + FactorA: string; + FactorB: string; + SubjectFactor: string; + FactorC: string; + GroupFactor: string; + DataVar: string; + cellstring: string; + i, j, k, minA, minB, minC, minGrp, maxA, maxB, maxC, maxGrp: integer; + rangeA, rangeB, rangeC, rangeGrp: integer; + value: integer; + cellcnts: IntDyneMat; + ABmat: DblDyneMat; + ABCmat: DblDyneCube; + GBmat: DblDyneMat; + GCmat: DblDyneMat; + Atotals: DblDyneVec; + Btotals: DblDyneVec; + Ctotals: DblDyneVec; + Grptotals: DblDyneVec; + Subjtotals: DblDyneMat; + design: StrDyneMat; + G, term1, term2, term3, term4, term5, term6, term7, term8, term9: double; + sumxsqr: double; + SSbetsubj, SSgroups, SSsubwGrps, SSwithinsubj, SSa, SSb, SSc, SSab: double; + SSerrwithin, SStotal, MSgroups, MSsubwGrps, MSa, MSb, MSc, MSab: double; + MSerrwithin, DFbetsubj, DFgroups, DFsubwGrps, DFwithinsubj: double; + DFa, DFb, DFc, DFab, DFerrwithin, DFtotal: double; + data, GrandMean: double; + p, row, col, slice, subject, group: integer; + proba, probb, probc, probab, probgrps: double; + fa, fb, fc, fab, fgroups: double; + RowLabels, ColLabels: StrDyneVec; + Title: string; + lReport: TStrings; begin - NoFactors := 4; - LatinSpecsFrm.PanelD.Visible := true; - LatinSpecsFrm.PanelGrp.Visible := true; - LatinSpecsFrm.AinBtn.Enabled := true; - LatinSpecsFrm.AoutBtn.Enabled := false; - LatinSpecsFrm.BinBtn.Enabled := true; - LatinSpecsFrm.BoutBtn.Enabled := false; - LatinSpecsFrm.CinBtn.Enabled := true; - LatinSpecsFrm.CoutBtn.Enabled := false; -// LatinSpecsFrm.DCodeEdit.Visible := true; - LatinSpecsFrm.ACodeEdit.Text := ''; - LatinSpecsFrm.BCodeEdit.Text := ''; - LatinSpecsFrm.CCodeEdit.Text := ''; - LatinSpecsFrm.DCodeEdit.Text := ''; - LatinSpecsFrm.GrpCodeEdit.Text := ''; - LatinSpecsFrm.DepVarEdit.Text := ''; - LatinSpecsFrm.nPerCellEdit.Text := ''; -// LatinSpecsFrm.GrpCodeEdit.Visible := true; -// LatinSpecsFrm.DCodeLabel.Visible := true; -// LatinSpecsFrm.GrpCodeLabel.Visible := true; -// LatinSpecsFrm.DinBtn.Visible := true; -// LatinSpecsFrm.DoutBtn.Visible := true; - LatinSpecsFrm.DinBtn.Enabled := true; - LatinSpecsFrm.DoutBtn.Enabled := false; -// LatinSpecsFrm.GrpInBtn.Visible := true; -// LatinSpecsFrm.GrpOutBtn.Visible := true; - LatinSpecsFrm.GrpInBtn.Enabled := true; - LatinSpecsFrm.GrpOutBtn.Enabled := false; - LatinSpecsFrm.DataInBtn.Enabled := true; - LatinSpecsFrm.DataOutBtn.Enabled := false; - LatinSpecsFrm.ShowModal; - if LatinSpecsFrm.ModalResult = mrCancel then exit; - n := StrToInt(LatinSpecsFrm.nPerCellEdit.Text); - if n <= 0 then - begin - ShowMessage('Please specify the number of cases per cell.'); - exit; - end; - FactorA := LatinSpecsFrm.ACodeEdit.Text; - FactorB := LatinSpecsFrm.BCodeEdit.Text; - FactorC := LatinSpecsFrm.CCodeEdit.Text; - SubjectFactor := LatinSpecsFrm.DCodeEdit.Text; - GroupFactor := LatinSpecsFrm.GrpCodeEdit.Text; - DataVar := LatinSpecsFrm.DepVarEdit.Text; - for i := 1 to NoVariables do + LatinSpecsFrm.PrepareForPlan(7); + if LatinSpecsFrm.ShowModal <> mrOK then + exit; + + n := StrToInt(LatinSpecsFrm.nPerCellEdit.Text); + FactorA := LatinSpecsFrm.ACodeEdit.Text; + FactorB := LatinSpecsFrm.BCodeEdit.Text; + FactorC := LatinSpecsFrm.CCodeEdit.Text; + SubjectFactor := LatinSpecsFrm.DCodeEdit.Text; + GroupFactor := LatinSpecsFrm.GrpCodeEdit.Text; + DataVar := LatinSpecsFrm.DepVarEdit.Text; + + for i := 1 to NoVariables do + begin + cellstring := OS3MainFrm.DataGrid.Cells[i,0]; + if (cellstring = FactorA) then Acol := i; + if (cellstring = FactorB) then Bcol := i; + if (cellstring = FactorC) then Ccol := i; + if (cellstring = GroupFactor) then Grpcol := i; + if (cellstring = SubjectFactor) then Sbjcol := i; + if (cellstring = DataVar) then DataCol := i; + end; + + // determine no. of levels in A, B, C and Group + minA := MaxInt; + minB := MaxInt; + minGrp := MaxInt; + maxA := -MaxInt; + maxB := -MaxInt; + minC := MaxInt; + maxC := -MaxInt; + maxGrp := -MaxInt; + + for i := 1 to NoCases do + begin + value := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); + if value < minA then minA := value; + if value > maxA then maxA := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); + if value < minB then minB := value; + if value > maxB then maxB := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); + if value < minC then minC := value; + if value > maxC then maxC := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); + if value < minGrp then minGrp := value; + if value > maxGrp then maxGrp := value; + end; + rangeA := maxA - minA + 1; + rangeB := maxB - minB + 1; + rangeC := maxC - minC + 1; + rangeGrp := maxGrp - minGrp + 1; + + // check for squareness + if (rangeA <> rangeB) or (rangeA <> rangeC) or (rangeA <> rangeGrp) then + begin + ErrorMsg('In a Latin square the range of values should be equal for A,B and C.'); + exit; + end; + p := rangeA; + + // set up an array for cell counts and for cell sums and marginal sums + SetLength(ABmat, p+1, p+1); + SetLength(ABCmat, p+1, p+1, n+1); + SetLength(cellcnts, p+1, p+1); + SetLength(Atotals, p+1); + SetLength(Btotals, p+1); + SetLength(Ctotals, p+1); + SetLength(Grptotals, p+1); + SetLength(Design, p, p); + SetLength(Subjtotals, p+1, n+1); + SetLength(RowLabels, p+1); + SetLength(ColLabels, n+1); + SetLength(GBmat, p+1, p+1); + SetLength(GCmat, p+1, p+1); + + for i := 0 to p-1 do + begin + RowLabels[i] := IntToStr(i+1); + ColLabels[i] := RowLabels[i]; + end; + RowLabels[p] := 'Total'; + ColLabels[p] := 'Total'; + + for i := 0 to p do + for j := 0 to p do + for k := 0 to n do + ABCmat[i,j,k] := 0.0; + + for i := 0 to p do + for j := 0 to p do begin - cellstring := OS3MainFrm.DataGrid.Cells[i,0]; - if (cellstring = FactorA) then Acol := i; - if (cellstring = FactorB) then Bcol := i; - if (cellstring = FactorC) then Ccol := i; - if (cellstring = GroupFactor) then Grpcol := i; - if (cellstring = SubjectFactor) then Sbjcol := i; - if (cellstring = DataVar) then DataCol := i; + cellcnts[i,j] := 0; + ABmat[i,j] := 0.0; + GBmat[i,j] := 0.0; + GCmat[i,j] := 0.0; end; - // determine no. of levels in A, B, C and Group - minA := 1000; - minB := 1000; - minGrp := 1000; - maxA := -1000; - maxB := -1000; - minC := 1000; - maxC := -1000; - maxGrp := -1000; - for i := 1 to NoCases do + for i := 0 to p do + begin + Atotals[i] := 0.0; + Btotals[i] := 0.0; + Ctotals[i] := 0.0; + Grptotals[i] := 0.0; + end; + + for i := 0 to p do + for j := 0 to n do + Subjtotals[i,j] := 0.0; + + G := 0.0; + sumxsqr := 0.0; + term1 := 0.0; + term2 := 0.0; + term3 := 0.0; + term4 := 0.0; + term5 := 0.0; + term6 := 0.0; + term7 := 0.0; + term8 := 0.0; + term9 := 0.0; + GrandMean := 0.0; + + // Read in the data + for i := 1 to NoCases do + begin + row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); + col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); + slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); + group := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); + subject := StrToInt(OS3MainFrm.DataGrid.Cells[Sbjcol,i]); + data := StrToFloat(OS3MainFrm.DataGrid.Cells[DataCol,i]); + cellcnts[group-1,row-1] := cellcnts[group-1,row-1] + 1; + ABCmat[group-1,row-1,slice-1] := ABCmat[group-1,row-1,slice-1] + data; + Subjtotals[group-1,subject-1] := Subjtotals[group-1,subject-1] + data; + GBmat[group-1,col-1] := GBmat[group-1,col-1] + data; + GCmat[group-1,slice-1] := GCmat[group-1,slice-1] + data; + Atotals[row-1] := Atotals[row-1] + data; + Btotals[col-1] := Btotals[col-1] + data; + Ctotals[slice-1] := Ctotals[slice-1] + data; + Grptotals[group-1] := Grptotals[group-1] + data; + sumxsqr := sumxsqr + (data * data); + GrandMean := GrandMean + data; + end; + + // check for equal cell counts + for i := 0 to p-1 do + for j := 0 to p-1 do + if cellcnts[i,j] <> n then + begin + ErrorMsg('Cell sizes are not equal.'); + exit; + end; + + // collapse slices into group x a matrix + // result is the group times A matrix with BC cells containing n cases each + for i := 0 to p-1 do // group + for j := 0 to p-1 do // factor a + for k := 0 to n-1 do // factor c + ABmat[i,j] := ABmat[i,j] + ABCmat[i,j,k]; + + // get marginal totals for ABmat, GBmat and GCmat + for i := 0 to p-1 do + for j := 0 to p-1 do begin - value := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); - if value < minA then minA := value; - if value > maxA then maxA := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); - if value < minB then minB := value; - if value > maxB then maxB := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); - if value < minC then minC := value; - if value > maxC then maxC := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); - if value < minGrp then minGrp := value; - if value > maxGrp then maxGrp := value; - end; - rangeA := maxA - minA + 1; - rangeB := maxB - minB + 1; - rangeC := maxC - minC + 1; - rangeGrp := maxGrp - minGrp + 1; - - // check for squareness - if ((rangeA <> rangeB) or (rangeA <> rangeC) or (rangeA <> rangeGrp)) then - begin - ShowMessage('ERROR! In a Latin square the range of values should be equal for A,B and C!'); - exit; - end; - p := rangeA; - - // set up an array for cell counts and for cell sums and marginal sums - SetLength(ABmat,p+1,p+1); - SetLength(ABCmat,p+1,p+1,n+1); - SetLength(cellcnts,p+1,p+1); - SetLength(Atotals,p+1); - SetLength(Btotals,p+1); - SetLength(Ctotals,p+1); - SetLength(Grptotals,p+1); - SetLength(Design,p,p); - SetLength(Subjtotals,p+1,n+1); - SetLength(RowLabels,p+1); - SetLength(ColLabels,n+1); - SetLength(GBmat,p+1,p+1); - SetLength(GCmat,p+1,p+1); - - for i := 0 to p-1 do - begin - RowLabels[i] := IntToStr(i+1); - ColLabels[i] := RowLabels[i]; - end; - RowLabels[p] := 'Total'; - ColLabels[p] := 'Total'; - - for i := 0 to p do - for j := 0 to p do - for k := 0 to n do - ABCmat[i,j,k] := 0.0; - - for i := 0 to p do - begin - for j := 0 to p do - begin - cellcnts[i,j] := 0; - ABmat[i,j] := 0.0; - GBmat[i,j] := 0.0; - GCmat[i,j] := 0.0; - end; + ABmat[p,j] := ABmat[p,j] + ABmat[i,j]; + ABmat[i,p] := ABmat[i,p] + ABmat[i,j]; + GBmat[p,j] := GBmat[p,j] + GBmat[i,j]; + GBmat[i,p] := GBmat[i,p] + GBmat[i,j]; + GCmat[p,j] := GCmat[p,j] + GCmat[i,j]; + GCmat[i,p] := GCmat[i,p] + GCmat[i,j]; end; - for i := 0 to p do + // get grand total for ABmat, GBmat and GCmat + for i := 0 to p-1 do + begin + ABmat[p,p] := ABmat[p,p] + ABmat[p,i]; + GBmat[p,p] := GBmat[p,p] + GBmat[p,i]; + GCmat[p,p] := GCmat[p,p] + GCmat[p,i]; + end; + + // Get marginal totals for Subjtotals + for i := 0 to p-1 do // groups 1-p + for j := 0 to n-1 do // subjects 1-n begin - Atotals[i] := 0.0; - Btotals[i] := 0.0; - Ctotals[i] := 0.0; - Grptotals[i] := 0.0; + Subjtotals[p,j] := Subjtotals[p,j] + Subjtotals[i,j]; + Subjtotals[i,n] := Subjtotals[i,n] + Subjtotals[i,j]; end; - for i := 0 to p do - for j := 0 to n do - Subjtotals[i,j] := 0.0; - - G := 0.0; - sumxsqr := 0.0; - term1 := 0.0; - term2 := 0.0; - term3 := 0.0; - term4 := 0.0; - term5 := 0.0; - term6 := 0.0; - term7 := 0.0; - term8 := 0.0; - term9 := 0.0; - GrandMean := 0.0; - - // Read in the data - for i := 1 to NoCases do - begin - row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); - col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); - slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); - group := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); - subject := StrToInt(OS3MainFrm.DataGrid.Cells[Sbjcol,i]); - data := StrToFloat(OS3MainFrm.DataGrid.Cells[DataCol,i]); - cellcnts[group-1,row-1] := cellcnts[group-1,row-1] + 1; - ABCmat[group-1,row-1,slice-1] := ABCmat[group-1,row-1,slice-1] + data; - Subjtotals[group-1,subject-1] := Subjtotals[group-1,subject-1] + data; - GBmat[group-1,col-1] := GBmat[group-1,col-1] + data; - GCmat[group-1,slice-1] := GCmat[group-1,slice-1] + data; - Atotals[row-1] := Atotals[row-1] + data; - Btotals[col-1] := Btotals[col-1] + data; - Ctotals[slice-1] := Ctotals[slice-1] + data; - Grptotals[group-1] := Grptotals[group-1] + data; - sumxsqr := sumxsqr + (data * data); - GrandMean := GrandMean + data; - end; - - // check for equal cell counts - for i := 0 to p-1 do - begin - for j := 0 to p-1 do - begin - if cellcnts[i,j] <> n then - begin - ShowMessage('cell sizes are not equal!'); - goto cleanup; - end; - end; - end; - - // collapse slices into group x a matrix - // result is the group times A matrix with BC cells containing n cases each - for i := 0 to p-1 do // group - for j := 0 to p-1 do // factor a - for k := 0 to n-1 do // factor c - ABmat[i,j] := ABmat[i,j] + ABCmat[i,j,k]; - - // get marginal totals for ABmat, GBmat and GCmat - for i := 0 to p-1 do - begin - for j := 0 to p-1 do - begin - ABmat[p,j] := ABmat[p,j] + ABmat[i,j]; - ABmat[i,p] := ABmat[i,p] + ABmat[i,j]; - GBmat[p,j] := GBmat[p,j] + GBmat[i,j]; - GBmat[i,p] := GBmat[i,p] + GBmat[i,j]; - GCmat[p,j] := GCmat[p,j] + GCmat[i,j]; - GCmat[i,p] := GCmat[i,p] + GCmat[i,j]; - end; - end; - - // get grand total for ABmat, GBmat and GCmat - for i := 0 to p-1 do - begin - ABmat[p,p] := ABmat[p,p] + ABmat[p,i]; - GBmat[p,p] := GBmat[p,p] + GBmat[p,i]; - GCmat[p,p] := GCmat[p,p] + GCmat[p,i]; - end; - - // Get marginal totals for Subjtotals - for i := 0 to p-1 do // groups 1-p - begin - for j := 0 to n-1 do // subjects 1-n - begin - Subjtotals[p,j] := Subjtotals[p,j] + Subjtotals[i,j]; - Subjtotals[i,n] := Subjtotals[i,n] + Subjtotals[i,j]; - end; - end; - for i := 0 to p-1 do Subjtotals[p,n] := Subjtotals[p,n] + Subjtotals[i,n]; + for i := 0 to p-1 do + Subjtotals[p,n] := Subjtotals[p,n] + Subjtotals[i,n]; + lReport := TStringList.Create; + try // test block - OutputFrm.RichEdit.Clear; - OutputFrm.RichEdit.Lines.Add('Latin Squares Repeated Analysis Plan 7 (superimposed squares)'); - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Sums for ANOVA Analysis'); - OutputFrm.RichEdit.Lines.Add(''); + lReport.Add('LATIN SQUARES REPEATED ANALYSIS PLAN 7 (superimposed squares)'); + lReport.Add(''); + lReport.Add('Sums for ANOVA Analysis'); + lReport.Add(''); + cellstring := 'Group (rows) times A Factor (columns) sums'; - MAT_PRINT(ABmat,p+1,p+1,cellstring,RowLabels,ColLabels,(n*p*p)); + MatPrint(ABmat, p+1, p+1, cellstring, RowLabels, ColLabels, n*p*p, lReport); + cellstring := 'Group (rows) times B (cells Factor) sums'; - MAT_PRINT(GBmat,p+1,p+1,cellstring,RowLabels,ColLabels,(n*p*p)); + MatPrint(GBmat, p+1, p+1, cellstring, RowLabels, ColLabels, n*p*p, lReport); + cellstring := 'Group (rows) times C (cells Factor) sums'; - MAT_PRINT(GCmat,p+1,p+1,cellstring,RowLabels,ColLabels,(n*p*p)); + MatPrint(GCmat, p+1, p+1, cellstring, RowLabels, ColLabels, n*p*p, lReport); + for i := 0 to n-1 do ColLabels[i] := IntToStr(i+1); ColLabels[n] := 'Total'; + Title := 'Group (rows) times Subjects (columns) sums'; - Mat_Print(Subjtotals,p+1,n+1,Title,RowLabels,ColLabels,(n*p*p)); - OutputFrm.ShowModal; + MatPrint(Subjtotals, p+1, n+1, Title, RowLabels, ColLabels, n*p*p, lReport); + + lReport.Add(''); + lReport.Add(DIVIDER); + lReport.Add(''); // get squared sum of subject's totals in each group for i := 0 to p-1 do // group - term7 := term7 + (Subjtotals[i,n] * Subjtotals[i,n]); + term7 := term7 + (Subjtotals[i,n] * Subjtotals[i,n]); term7 := term7 / (n*p); // Sum G^2 sub k // now square each person score in each group and get sum for group for i := 0 to p-1 do // groups - for j := 0 to n-1 do // subjects - Subjtotals[i,j] := Subjtotals[i,j] * Subjtotals[i,j]; + for j := 0 to n-1 do // subjects + Subjtotals[i,j] := Subjtotals[i,j] * Subjtotals[i,j]; for i := 0 to p-1 do Subjtotals[i,n] := 0.0; // clear group totals // get sum of squared person scores in each group for i := 0 to p-1 do // groups - for j := 0 to n-1 do // subjects - Subjtotals[i,n] := Subjtotals[i,n] + Subjtotals[i,j]; + for j := 0 to n-1 do // subjects + Subjtotals[i,n] := Subjtotals[i,n] + Subjtotals[i,j]; // get sum of squares for subjects within groups for i := 0 to p-1 do term6 := term6 + Subjtotals[i,n]; SSsubwgrps := (term6 / p) - term7; // get correction term and term for total sum of squares - term1 := (GrandMean * GrandMean) / (n * p * p); + term1 := sqr(GrandMean) / (n * p * p); term2 := sumxsqr; // get sum of squared groups for term4 of sum of squares for groups for i := 0 to p-1 do - term4 := term4 + (Grptotals[i] * Grptotals[i]); + term4 := term4 + sqr(Grptotals[i]); term4 := term4 / (n * p); // get sum of squared a's for term3 for j := 0 to p-1 do // levels of a - term3 := term3 + (Atotals[j] * Atotals[j]); + term3 := term3 + sqr(Atotals[j]); term3 := term3 / (n * p); // get squared sum of b's (across groups) for term5 of sum of squares b for j := 0 to p-1 do - term5 := term5 + (Btotals[j] * Btotals[j]); + term5 := term5 + sqr(Btotals[j]); term5 := term5 / (n * p); // get squared sum of c's (across groups) for term8 of SS for c for j := 0 to p-1 do - term8 := term8 + (Ctotals[j] * Ctotals[j]); + term8 := term8 + sqr(Ctotals[j]); term8 := term8 / (n * p); SSgroups := term4 - term1; @@ -3530,8 +3277,8 @@ begin // get sum of squared AB cells for term6 term6 := 0.0; for i := 0 to p-1 do - for j := 0 to p-1 do - term6 := term6 + (ABmat[i,j] * ABmat[i,j]); + for j := 0 to p-1 do + term6 := term6 + sqr(ABmat[i,j]); term9 := term6 / n - term1; term6 := sumxsqr - (term6 / n); // SS within cells from sum squared x's SSerrwithin := term6 - SSsubwgrps; @@ -3561,239 +3308,242 @@ begin fb := MSb / MSerrwithin; fc := MSc / MSerrwithin; if dfab > 0 then fab := MSab / MSerrwithin; - probgrps := probf(fgroups,dfgroups,dfsubwgrps); - proba := probf(fa,dfa,dferrwithin); - probb := probf(fb,dfb,dferrwithin); - probc := probf(fc,dfc,dferrwithin); - probab := probf(fab,dfab,dferrwithin); + probgrps := probf(fgroups, dfgroups, dfsubwgrps); + proba := probf(fa, dfa, dferrwithin); + probb := probf(fb, dfb, dferrwithin); + probc := probf(fc, dfc, dferrwithin); + probab := probf(fab, dfab, dferrwithin); // show ANOVA table results - OutputFrm.RichEdit.Clear; - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Latin Squares Repeated Analysis Plan 7 (superimposed squares)'); - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); - OutputFrm.RichEdit.Lines.Add('Source SS DF MS F Prob.>F'); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); - cellstring := 'Betw.Subj.'; - cellstring := cellstring + format('%9.3f %9.0f',[SSbetsubj,dfbetsubj]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Groups '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSgroups,dfgroups,MSgroups,fgroups,probgrps]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Subj.w.g.'; - cellstring := cellstring + format('%9.3f %9.0f %9.3f',[SSsubwgrps,dfsubwgrps,MSsubwgrps]); - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); - cellstring := 'Within Sub'; - cellstring := cellstring + format('%9.3f %9.0f',[SSwithinsubj,dfwithinsubj]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Factor A '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSa,dfa,MSa,fa,proba]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Factor B '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSb,dfb,MSb,fb,probb]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Factor C '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSc,dfc,MSc,fc,probc]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' residual '; + lReport.Add('LATIN SQUARES REPEATED ANALYSIS PLAN 7 (superimposed squares)'); + lReport.Add(''); + lReport.Add('-----------------------------------------------------------'); + lReport.Add('Source SS DF MS F Prob.>F'); + lReport.Add('-----------------------------------------------------------'); + lReport.Add('Betw.Subj.%9.3f %9.0f', [SSbetsubj, dfbetsubj]); + lReport.Add(' Groups %9.3f %9.0f %9.3f %9.3f %9.3f', [SSgroups, dfgroups, MSgroups, fgroups, probgrps]); + lReport.Add(' Subj.w.g.%9.3f %9.0f %9.3f', [SSsubwgrps, dfsubwgrps, MSsubwgrps]); + lReport.Add(''); + lReport.Add('Within Sub%9.3f %9.0f', [SSwithinsubj, dfwithinsubj]); + lReport.Add(' Factor A %9.3f %9.0f %9.3f %9.3f %9.3f', [SSa, dfa, MSa, fa, proba]); + lReport.Add(' Factor B %9.3f %9.0f %9.3f %9.3f %9.3f', [SSb, dfb, MSb, fb, probb]); + lReport.Add(' Factor C %9.3f %9.0f %9.3f %9.3f %9.3f', [SSc, dfc, MSc, fc, probc]); if dfab > 0 then - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSab,dfab,MSab,fab,probab]) + lReport.Add(' residual %9.3f %9.0f %9.3f %9.3f %9.3f', [SSab, dfab, MSab, fab, probab]) else - cellstring := cellstring + format(' - %9.0f -',[dfab]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Error w. '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f',[SSerrwithin,dferrwithin,MSerrwithin]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Total '; - cellstring := cellstring + format('%9.3f %9.0f',[SStotal, dftotal]); - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); + lReport.Add(' residual - %9.0f -', [dfab]); + lReport.Add(' Error w. %9.3f %9.0f %9.3f', [SSerrwithin, dferrwithin, MSerrwithin]); + lReport.Add('Total %9.3f %9.0f', [SStotal, dftotal]); + lReport.Add('-----------------------------------------------------------'); // show design for Square - OutputFrm.RichEdit.Lines.Add(''); - cellstring := 'Experimental Design for Latin Square '; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(''); + lReport.Add('Experimental Design for Latin Square '); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorA]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[GroupFactor]); - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + + cellstring := Format('%10s', [GroupFactor]); + lReport.Add(cellstring); + for i := 1 to NoCases do begin - row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); // A (column) effect - col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); // B (cell) effect - slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); // C (cell) effect - group := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); // group (row) - Design[group-1,row-1] := 'BC' + IntToStr(col) + IntToStr(slice); + row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); // A (column) effect + col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); // B (cell) effect + slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); // C (cell) effect + group := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); // group (row) + Design[group-1,row-1] := 'BC' + IntToStr(col) + IntToStr(slice); end; + for i := 0 to p - 1 do begin - cellstring := format(' %3d ',[i+1]); - for j := 0 to p - 1 do - cellstring := cellstring + format('%5s',[Design[i,j]]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := Format(' %3d ', [i+1]); + for j := 0 to p - 1 do + cellstring := cellstring + Format('%5s', [Design[i,j]]); + lReport.Add(cellstring); end; + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); // get means for i := 0 to p-1 do - for j := 0 to p-1 do - ABmat[i,j] := ABmat[i,j] / n; + for j := 0 to p-1 do + ABmat[i,j] := ABmat[i,j] / n; for i := 0 to p-1 do - ABmat[i,p] := ABmat[i,p] / (n * p); + ABmat[i,p] := ABmat[i,p] / (n * p); for j := 0 to p-1 do - ABmat[p,j] := ABmat[p,j] / (n * p); + ABmat[p,j] := ABmat[p,j] / (n * p); GrandMean := GrandMean / (p * p * n ); for i := 0 to p-1 do begin - Atotals[i] := Atotals[i] / (p * n); - Btotals[i] := Btotals[i] / (p * n); - Ctotals[i] := Ctotals[i] / (p * n); - Grptotals[i] := Grptotals[i] / (p * n); + Atotals[i] := Atotals[i] / (p * n); + Btotals[i] := Btotals[i] / (p * n); + Ctotals[i] := Ctotals[i] / (p * n); + Grptotals[i] := Grptotals[i] / (p * n); end; // show table of means for ABmat // means for Groups by A matrix - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Cell means and totals'); + lReport.Add(''); + lReport.Add('Cell means and totals'); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorA]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[GroupFactor]); - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + + cellstring := Format('%10s', [GroupFactor]); + lReport.Add(cellstring); + for i := 0 to p-1 do begin - cellstring := format(' %3d ',[i+1]); - for j := 0 to p - 1 do - cellstring := cellstring + format(' %8.3f ',[ABmat[i,j]]); - cellstring := cellstring + format(' %8.3f ',[ABmat[i,p]]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := Format(' %3d ', [i+1]); + for j := 0 to p - 1 do + cellstring := cellstring + Format(' %8.3f ', [ABmat[i,j]]); + cellstring := cellstring + Format(' %8.3f ', [ABmat[i,p]]); + lReport.Add(cellstring); end; + cellstring := 'Total '; for j := 0 to p-1 do - cellstring := cellstring + format(' %8.3f ',[ABmat[p,j]]); - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [ABmat[p,j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); // show category means - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Means for each variable'); - OutputFrm.RichEdit.Lines.Add(''); + lReport.Add(''); + lReport.Add('Means for each variable'); + lReport.Add(''); // factor A means cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorA]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorA]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); + cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Atotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Atotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); // means for B - OutputFrm.RichEdit.Lines.Add(''); + lReport.Add(''); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorB]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorB]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Btotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Btotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); // C means - OutputFrm.RichEdit.Lines.Add(''); + lReport.Add(''); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[FactorC]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + + cellstring := Format('%10s', [FactorC]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Ctotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Ctotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); // Group means - OutputFrm.RichEdit.Lines.Add(''); + lReport.Add(''); cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[GroupFactor]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); + lReport.Add(cellstring); + cellstring := Format('%10s', [GroupFactor]); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); cellstring := cellstring + ' Total'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := ' '; for j := 0 to p - 1 do - begin - cellstring := cellstring + format(' %8.3f ',[Grptotals[j]]); - end; - cellstring := cellstring + format(' %8.3f ',[GrandMean]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := cellstring + Format(' %8.3f ', [Grptotals[j]]); + cellstring := cellstring + Format(' %8.3f ', [GrandMean]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '----------'; - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.ShowModal; + lReport.Add(cellstring); + + DisplayReport(lReport); + + finally + lReport.Free; -cleanup: GCmat := nil; GBmat := nil; ColLabels := nil; @@ -3807,393 +3557,360 @@ cleanup: cellcnts := nil; ABCmat := nil; ABmat := nil; + end; end; -procedure TLatinSqrsFrm.Plan9(Sender: TObject); -label cleanup; +procedure TLatinSqrsFrm.Plan9; var - NoFactors, row, col, slice, group, index : integer; - Acol, Bcol, Ccol, SbjCol, Grpcol, DataCol : integer; // variable columns in grid - FactorA : string; - FactorB : string; - FactorC : string; - SubjectFactor : string; - GroupFactor : string; - DataVar : string; - cellstring : string; - i, j, k, m, minA, minB, minC, minGrp, maxA, maxB, maxC, maxGrp : integer; - n, subject, nosubjects, rangeA, rangeB, rangeC, rangeGrp : integer; - p, q, rows, value : integer; - ABC, AGC : DblDyneCube; - AB, AC, BC, RC : DblDyneMat; - A, B, C, Persons, Gm, R : DblDyneVec; - cellcnts : IntDyneVec; - Design : StrDyneMat; - RowLabels : StrDyneVec; - ColLabels : StrDyneVec; - G, sumxsqr, sumAsqr, sumBsqr, sumABsqr, sumACsqr : double; - sumBCsqr, sumABCsqr, sumPsqr, sumGmsqr, sumRsqr : double; - SSbetsubj, SSc, SSrows, SScxrow, SSsubwgrps, SSa : double; - SSwithinsubj, SSerrwithin : double; - SSb, SSac, SSbc, SSabprime, SSABCprime, SStotal : double; - term1, term2, term3, term4, term5, term6, term7, term8, term9, term10 : double; - term11, term12 : double; - dfc, dfrows, dfcxrow, dfsubwgrps, dfwithinsubj, dfa, dfb,dfac : double; - dfbc, dfabprime, dfabcprime,dferrwithin, dftotal, dfbetsubj : double; - MSc, MSrows, MScxrow, MSsubwgrps, MSa : double; - MSb, MSac, MSbc, MSabprime, MSabcprime, MSerrwithin: double; - fc, frows, fcxrow, fsubwgrps, fa, fb, fac, fbc, fabprime, fabcprime : double; - probc, probrows, probcxrow, probsubwgrps, proba, probb : double; - probac, probbc, probabprime, probabcprime : double; - data : double; + row, col, slice, group, index: integer; + Acol, Bcol, Ccol, SbjCol, Grpcol, DataCol: integer; // variable columns in grid + FactorA: string; + FactorB: string; + FactorC: string; + SubjectFactor: string; + GroupFactor: string; + DataVar: string; + cellstring: string; + i, j, k, m, minA, minB, minC, minGrp, maxA, maxB, maxC, maxGrp: integer; + n, subject, nosubjects, rangeA, rangeB, rangeC, rangeGrp: integer; + p, q, rows, value: integer; + ABC, AGC: DblDyneCube; + AB, AC, BC, RC: DblDyneMat; + A, B, C, Persons, Gm, R: DblDyneVec; + cellcnts: IntDyneVec; + Design: StrDyneMat; + RowLabels: StrDyneVec; + ColLabels: StrDyneVec; + G, sumxsqr, sumAsqr, sumBsqr, sumABsqr, sumACsqr: double; + sumBCsqr, sumABCsqr, sumPsqr, sumGmsqr, sumRsqr: double; + SSbetsubj, SSc, SSrows, SScxrow, SSsubwgrps, SSa: double; + SSwithinsubj, SSerrwithin: double; + SSb, SSac, SSbc, SSabprime, SSABCprime, SStotal: double; + term1, term2, term3, term4, term5, term6, term7, term8, term9, term10: double; + term11, term12: double; + dfc, dfrows, dfcxrow, dfsubwgrps, dfwithinsubj, dfa, dfb,dfac: double; + dfbc, dfabprime, dfabcprime,dferrwithin, dftotal, dfbetsubj: double; + MSc, MSrows, MScxrow, MSsubwgrps, MSa: double; + MSb, MSac, MSbc, MSabprime, MSabcprime, MSerrwithin: double; + fc, frows, fcxrow, fsubwgrps, fa, fb, fac, fbc, fabprime, fabcprime: double; + probc, probrows, probcxrow, probsubwgrps, proba, probb: double; + probac, probbc, probabprime, probabcprime: double; + data : double; + lReport: TStrings; begin - NoFactors := 4; - cellstring := LatinSpecsFrm.DCodeLabel.Caption; // get current label - LatinSpecsFrm.DCodeLabel.Caption := 'Subject No.'; // set new label - LatinSpecsFrm.PanelD.Visible := true; - LatinSpecsFrm.PanelGrp.Visible := true; - LatinSpecsFrm.AinBtn.Enabled := true; - LatinSpecsFrm.AoutBtn.Enabled := false; - LatinSpecsFrm.BinBtn.Enabled := true; - LatinSpecsFrm.BoutBtn.Enabled := false; - LatinSpecsFrm.CinBtn.Enabled := true; - LatinSpecsFrm.CoutBtn.Enabled := false; -// LatinSpecsFrm.DCodeEdit.Visible := true; - LatinSpecsFrm.ACodeEdit.Text := ''; - LatinSpecsFrm.BCodeEdit.Text := ''; - LatinSpecsFrm.CCodeEdit.Text := ''; - LatinSpecsFrm.DCodeEdit.Text := ''; - LatinSpecsFrm.GrpCodeEdit.Text := ''; - LatinSpecsFrm.DepVarEdit.Text := ''; - LatinSpecsFrm.nPerCellEdit.Text := ''; -// LatinSpecsFrm.GrpCodeEdit.Visible := true; -// LatinSpecsFrm.DCodeLabel.Visible := true; -// LatinSpecsFrm.GrpCodeLabel.Visible := true; -// LatinSpecsFrm.DinBtn.Visible := true; -// LatinSpecsFrm.DoutBtn.Visible := true; - LatinSpecsFrm.DinBtn.Enabled := true; - LatinSpecsFrm.DoutBtn.Enabled := false; -// LatinSpecsFrm.GrpInBtn.Visible := true; -// LatinSpecsFrm.GrpOutBtn.Visible := true; - LatinSpecsFrm.GrpInBtn.Enabled := true; - LatinSpecsFrm.GrpOutBtn.Enabled := false; - LatinSpecsFrm.DataInBtn.Enabled := true; - LatinSpecsFrm.DataOutBtn.Enabled := false; - LatinSpecsFrm.ShowModal; - if LatinSpecsFrm.ModalResult = mrCancel then exit; - LatinSpecsFrm.DCodeLabel.Caption := cellstring; // restore label - n := StrToInt(LatinSpecsFrm.nPerCellEdit.Text); // no. persons per cell - if n <= 0 then - begin - ShowMessage('Please specify the number of subjects per group.'); - exit; - end; - FactorA := LatinSpecsFrm.ACodeEdit.Text; - FactorB := LatinSpecsFrm.BCodeEdit.Text; - FactorC := LatinSpecsFrm.CCodeEdit.Text; - SubjectFactor := LatinSpecsFrm.DCodeEdit.Text; - GroupFactor := LatinSpecsFrm.GrpCodeEdit.Text; - DataVar := LatinSpecsFrm.DepVarEdit.Text; - for i := 1 to NoVariables do + cellstring := LatinSpecsFrm.DCodeLabel.Caption; // get current label + LatinSpecsFrm.DCodeLabel.Caption := 'Subject No.'; // set new label + LatinSpecsFrm.PrepareForPlan(9); + if LatinSpecsFrm.ShowModal <> mrOK then + exit; + + LatinSpecsFrm.DCodeLabel.Caption := cellstring; // restore label + + n := StrToInt(LatinSpecsFrm.nPerCellEdit.Text); // no. persons per cell + FactorA := LatinSpecsFrm.ACodeEdit.Text; + FactorB := LatinSpecsFrm.BCodeEdit.Text; + FactorC := LatinSpecsFrm.CCodeEdit.Text; + SubjectFactor := LatinSpecsFrm.DCodeEdit.Text; + GroupFactor := LatinSpecsFrm.GrpCodeEdit.Text; + DataVar := LatinSpecsFrm.DepVarEdit.Text; + + for i := 1 to NoVariables do + begin + cellstring := OS3MainFrm.DataGrid.Cells[i,0]; + if (cellstring = FactorA) then Acol := i; + if (cellstring = FactorB) then Bcol := i; + if (cellstring = FactorC) then Ccol := i; + if (cellstring = GroupFactor) then Grpcol := i; + if (cellstring = SubjectFactor) then Sbjcol := i; + if (cellstring = DataVar) then DataCol := i; + end; + + // determine no. of levels in A, B, C and Group + minA := MaxInt; + minB := MaxInt; + minGrp := MaxInt; + maxA := -MaxInt; + maxB := -MaxInt; + minC := MaxInt; + maxC := -MaxInt; + maxGrp := -MaxInt; + nosubjects := 0; + for i := 1 to NoCases do + begin + value := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); + if value < minA then minA := value; + if value > maxA then maxA := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); + if value < minB then minB := value; + if value > maxB then maxB := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); + if value < minC then minC := value; + if value > maxC then maxC := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[sbjcol,i]); + if value > nosubjects then nosubjects := value; + + value := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); + if value < minGrp then minGrp := value; + if value > maxGrp then maxGrp := value; + end; + rangeA := maxA - minA + 1; + rangeB := maxB - minB + 1; + rangeC := maxC - minC + 1; + rangeGrp := maxGrp - minGrp + 1; + + // check for squareness + if (rangeA <> rangeB) then + begin + ErrorMsg('In a Latin square the range of values should be equal for A,B and C.'); + exit; + end; + p := rangeA; + q := rangeC; + + // set up an array for cell counts and for cell sums and marginal sums + SetLength(ABC, p+1, p+1, q+1); + SetLength(AGC, p+1, rangegrp+1, q+1); + SetLength(AB, p+1, p+1); + SetLength(AC, p+1, q+1); + SetLength(BC, p+1, q+1); + SetLength(RC, (rangegrp div q)+1, q+1); + SetLength(A, p+1); + SetLength(B, p+1); + SetLength(C, q+1); + SetLength(Persons, nosubjects+1); + SetLength(Gm, rangegrp+1); + SetLength(R, p+1); + SetLength(cellcnts, p+1); + SetLength(Design, rangegrp, p); + SetLength(RowLabels, 100); // TODO: create RowLabels and ColLabels with proper size + SetLength(ColLabels, 100); + + // initialize arrays + for i := 0 to p-1 do + begin + RowLabels[i] := IntToStr(i+1); + ColLabels[i] := RowLabels[i]; + end; + RowLabels[p] := 'Total'; + ColLabels[p] := 'Total'; + + for i := 0 to p do + for j := 0 to p do + for k := 0 to q do + ABC[i,j,k] := 0.0; + + for i := 0 to p do + for j := 0 to rangegrp do + for k := 0 to q do + AGC[i,j,k] := 0.0; + + for i := 0 to p do + for j := 0 to p do + AB[i,j] := 0.0; + + for i := 0 to p do + for j := 0 to q do + AC[i,j] := 0.0; + + for i := 0 to p do + for j := 0 to q do + BC[i,j] := 0.0; + + for i := 0 to p do + for j := 0 to q do + RC[i,j] := 0.0; + + for i := 0 to p do A[i] := 0.0; + for i := 0 to p do B[i] := 0.0; + for i := 0 to q do C[i] := 0.0; + for i := 0 to nosubjects do Persons[i] := 0.0; + for i := 0 to rangegrp do Gm[i] := 0.0; + for i := 0 to p do R[i] := 0.0; + for i := 0 to p do cellcnts[i] := 0; + + // initialize single values + G := 0.0; + sumxsqr := 0.0; + sumAsqr := 0.0; + sumBsqr := 0.0; + sumABsqr := 0.0; + sumACsqr := 0.0; + sumBCsqr := 0.0; + sumABCsqr := 0.0; + sumRsqr := 0.0; + sumGmsqr := 0.0; + sumRsqr := 0.0; + sumPsqr := 0.0; + term2 := 0.0; + term3 := 0.0; + term4 := 0.0; + term5 := 0.0; + term6 := 0.0; + term7 := 0.0; + term8 := 0.0; + term9 := 0.0; + term10 := 0.0; + term11 := 0.0; + term12 := 0.0; + + // Read in the data + for index := 1 to NoCases do + begin + i := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,index]); + j := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,index]); + k := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,index]); + m := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,index]); + subject := StrToInt(OS3MainFrm.DataGrid.Cells[Sbjcol,index]); + data := StrToFloat(OS3MainFrm.DataGrid.Cells[DataCol,index]); + cellcnts[j-1] := cellcnts[j-1] + 1; + ABC[i-1,j-1,k-1] := ABC[i-1,j-1,k-1] + data; + AGC[i-1,m-1,k-1] := AGC[i-1,m-1,k-1] + data; + AB[i-1,j-1] := AB[i-1,j-1] + data; + AC[i-1,k-1] := AC[i-1,k-1] + data; + BC[j-1,k-1] := BC[j-1,k-1] + data; + A[i-1] := A[i-1] + data; + B[j-1] := B[j-1] + data; + C[k-1] := C[k-1] + data; + Gm[m-1] := Gm[m-1] + data; + Persons[subject-1] := Persons[subject-1] + data; + sumxsqr := sumxsqr + (data * data); + G := G + data; + end; + + // check for equal cell counts in b treatments + for i := 1 to p-1 do + if cellcnts[i-1] <> cellcnts[i] then begin - cellstring := OS3MainFrm.DataGrid.Cells[i,0]; - if (cellstring = FactorA) then Acol := i; - if (cellstring = FactorB) then Bcol := i; - if (cellstring = FactorC) then Ccol := i; - if (cellstring = GroupFactor) then Grpcol := i; - if (cellstring = SubjectFactor) then Sbjcol := i; - if (cellstring = DataVar) then DataCol := i; + ErrorMsg('Cell sizes are not equal.'); + exit; end; - // determine no. of levels in A, B, C and Group - minA := 1000; - minB := 1000; - minGrp := 1000; - maxA := -1000; - maxB := -1000; - minC := 1000; - maxC := -1000; - maxGrp := -1000; - nosubjects := 0; - for i := 1 to NoCases do + // get sums in the RC matrix + rows := rangegrp div q; + for i := 0 to rows - 1 do + for j := 0 to q-1 do begin - value := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); - if value < minA then minA := value; - if value > maxA then maxA := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); - if value < minB then minB := value; - if value > maxB then maxB := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); - if value < minC then minC := value; - if value > maxC then maxC := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[sbjcol,i]); - if value > nosubjects then nosubjects := value; - value := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); - if value < minGrp then minGrp := value; - if value > maxGrp then maxGrp := value; - end; - rangeA := maxA - minA + 1; - rangeB := maxB - minB + 1; - rangeC := maxC - minC + 1; - rangeGrp := maxGrp - minGrp + 1; - - // check for squareness - if (rangeA <> rangeB) then - begin - ShowMessage('ERROR! In a Latin square the range of values should be equal for A,B and C!'); - exit; - end; - p := rangeA; - q := rangeC; - - // set up an array for cell counts and for cell sums and marginal sums - SetLength(ABC,p+1,p+1,q+1); - SetLength(AGC,p+1,rangegrp+1,q+1); - SetLength(AB,p+1,p+1); - SetLength(AC,p+1,q+1); - SetLength(BC,p+1,q+1); - SetLength(RC,(rangegrp div q)+1,q+1); - SetLength(A,p+1); - SetLength(B,p+1); - SetLength(C,q+1); - SetLength(Persons,nosubjects+1); - SetLength(Gm,rangegrp+1); - SetLength(R,p+1); - SetLength(cellcnts,p+1); - SetLength(Design,rangegrp,p); - SetLength(RowLabels,100); - SetLength(ColLabels,100); - - // initialize arrays - for i := 0 to p-1 do - begin - RowLabels[i] := IntToStr(i+1); - ColLabels[i] := RowLabels[i]; - end; - RowLabels[p] := 'Total'; - ColLabels[p] := 'Total'; - - for i := 0 to p do - for j := 0 to p do - for k := 0 to q do - ABC[i,j,k] := 0.0; - - for i := 0 to p do - for j := 0 to rangegrp do - for k := 0 to q do - AGC[i,j,k] := 0.0; - - for i := 0 to p do - for j := 0 to p do - AB[i,j] := 0.0; - - for i := 0 to p do - for j := 0 to q do - AC[i,j] := 0.0; - - for i := 0 to p do - for j := 0 to q do - BC[i,j] := 0.0; - - for i := 0 to p do - for j := 0 to q do - RC[i,j] := 0.0; - - for i := 0 to p do A[i] := 0.0; - for i := 0 to p do B[i] := 0.0; - for i := 0 to q do C[i] := 0.0; - for i := 0 to nosubjects do Persons[i] := 0.0; - for i := 0 to rangegrp do Gm[i] := 0.0; - for i := 0 to p do R[i] := 0.0; - for i := 0 to p do cellcnts[i] := 0; - - // initialize single values - G := 0.0; - sumxsqr := 0.0; - sumAsqr := 0.0; - sumBsqr := 0.0; - sumABsqr := 0.0; - sumACsqr := 0.0; - sumBCsqr := 0.0; - sumABCsqr := 0.0; - sumRsqr := 0.0; - sumGmsqr := 0.0; - sumRsqr := 0.0; - sumPsqr := 0.0; - term2 := 0.0; - term3 := 0.0; - term4 := 0.0; - term5 := 0.0; - term6 := 0.0; - term7 := 0.0; - term8 := 0.0; - term9 := 0.0; - term10 := 0.0; - term11 := 0.0; - term12 := 0.0; - - // Read in the data - for index := 1 to NoCases do - begin - i := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,index]); - j := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,index]); - k := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,index]); - m := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,index]); - subject := StrToInt(OS3MainFrm.DataGrid.Cells[Sbjcol,index]); - data := StrToFloat(OS3MainFrm.DataGrid.Cells[DataCol,index]); - cellcnts[j-1] := cellcnts[j-1] + 1; - ABC[i-1,j-1,k-1] := ABC[i-1,j-1,k-1] + data; - AGC[i-1,m-1,k-1] := AGC[i-1,m-1,k-1] + data; - AB[i-1,j-1] := AB[i-1,j-1] + data; - AC[i-1,k-1] := AC[i-1,k-1] + data; - BC[j-1,k-1] := BC[j-1,k-1] + data; - A[i-1] := A[i-1] + data; - B[j-1] := B[j-1] + data; - C[k-1] := C[k-1] + data; - Gm[m-1] := Gm[m-1] + data; - Persons[subject-1] := Persons[subject-1] + data; - sumxsqr := sumxsqr + (data * data); - G := G + data; - end; - - // check for equal cell counts in b treatments - for i := 1 to p-1 do - begin - if cellcnts[i-1] <> cellcnts[i] then - begin - ShowMessage('cell sizes are not equal!'); - goto cleanup; - end; - end; - - // get sums in the RC matrix - rows := rangegrp div q; - for i := 0 to rows - 1 do - begin - for j := 0 to q-1 do - begin // k := (i * q) + j; - k := i + q * j; - RC[i,j] := Gm[k]; - end; + k := i + q * j; + RC[i,j] := Gm[k]; end; - // get marginal totals for RC array - for i := 0 to rows -1 do + // get marginal totals for RC array + for i := 0 to rows -1 do + for j := 0 to q-1 do begin - for j := 0 to q-1 do - begin - RC[i,q] := RC[i,q] + RC[i,j]; - RC[rows,j] := RC[rows,j] + RC[i,j]; - end; + RC[i,q] := RC[i,q] + RC[i,j]; + RC[rows,j] := RC[rows,j] + RC[i,j]; end; - // get marginal totals for arrays ABC and AGC - for i := 0 to p-1 do + // get marginal totals for arrays ABC and AGC + for i := 0 to p-1 do + for j := 0 to p-1 do begin - for j := 0 to p-1 do - begin - for k := 0 to q-1 do - begin - ABC[i,j,q] := ABC[i,j,q] + ABC[i,j,k]; - ABC[i,p,k] := ABC[i,p,k] + ABC[i,j,k]; - ABC[p,j,k] := ABC[p,j,k] + ABC[i,j,k]; - end; - end; + for k := 0 to q-1 do + begin + ABC[i,j,q] := ABC[i,j,q] + ABC[i,j,k]; + ABC[i,p,k] := ABC[i,p,k] + ABC[i,j,k]; + ABC[p,j,k] := ABC[p,j,k] + ABC[i,j,k]; + end; end; - for i := 0 to p-1 do + for i := 0 to p-1 do + for j := 0 to rangegrp - 1 do + for k := 0 to q-1 do + begin + AGC[i,j,q] := AGC[i,j,q] + AGC[i,j,k]; + AGC[i,rangegrp,k] := AGC[i,rangegrp,k] + AGC[i,j,k]; + AGC[p,j,k] := AGC[p,j,k] + AGC[i,j,k]; + end; + + for i := 0 to p-1 do + for j := 0 to q-1 do begin - for j := 0 to rangegrp - 1 do - begin - for k := 0 to q-1 do - begin - AGC[i,j,q] := AGC[i,j,q] + AGC[i,j,k]; - AGC[i,rangegrp,k] := AGC[i,rangegrp,k] + AGC[i,j,k]; - AGC[p,j,k] := AGC[p,j,k] + AGC[i,j,k]; - end; - end; + AC[p,j] := AC[p,j] + AC[i,j]; + AC[i,q] := AC[i,q] + AC[i,j]; + BC[p,j] := BC[p,j] + BC[i,j]; + BC[i,q] := BC[i,q] + BC[i,j]; end; - for i := 0 to p-1 do + // get grand total for AC, BC and RC + for i := 0 to q-1 do + begin + AC[p,q] := AC[p,q] + AC[p,i]; + BC[p,q] := BC[p,q] + BC[p,i]; + RC[p,q] := RC[p,q] + RC[p,i]; + end; + + // get margins and totals in AB matrix + for i := 0 to p-1 do + for j := 0 to p-1 do begin - for j := 0 to q-1 do - begin - AC[p,j] := AC[p,j] + AC[i,j]; - AC[i,q] := AC[i,q] + AC[i,j]; - BC[p,j] := BC[p,j] + BC[i,j]; - BC[i,q] := BC[i,q] + BC[i,j]; - end; + AB[p,j] := AB[p,j] + AB[i,j]; + AB[i,p] := AB[i,p] + AB[i,j]; end; + for i := 0 to p-1 do + AB[p,p] := AB[p,p] + AB[i,p]; - // get grand total for AC, BC and RC - for i := 0 to q-1 do - begin - AC[p,q] := AC[p,q] + AC[p,i]; - BC[p,q] := BC[p,q] + BC[p,i]; - RC[p,q] := RC[p,q] + RC[p,i]; - end; + // get total for groups + for m := 0 to rangegrp - 1 do + Gm[rangegrp] := Gm[rangegrp] + Gm[m]; - // get margins and totals in AB matrix - for i := 0 to p-1 do - begin - for j := 0 to p-1 do - begin - AB[p,j] := AB[p,j] + AB[i,j]; - AB[i,p] := AB[i,p] + AB[i,j]; - end; - end; - for i := 0 to p-1 do AB[p,p] := AB[p,p] + AB[i,p]; - - // get total for groups - for m := 0 to rangegrp - 1 do Gm[rangegrp] := Gm[rangegrp] + Gm[m]; - - // test block - OutputFrm.RichEdit.Clear; - OutputFrm.RichEdit.Lines.Add('Latin Squares Repeated Analysis Plan 9'); - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Sums for ANOVA Analysis'); - OutputFrm.RichEdit.Lines.Add(''); - cellstring := 'ABC matrix'; - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); + // test block + lReport := TStringList.Create; + try + lReport.Add('LATIN SQUARES REPEATED ANALYSIS PLAN 9'); + lReport.Add(''); + lReport.Add('Sums for ANOVA Analysis'); + lReport.Add(''); + lReport.Add('ABC matrix'); + lReport.Add(''); for k := 0 to q-1 do begin - cellstring := format('C level %d',[k+1]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' '; - for j := 0 to p-1 do cellstring := cellstring + format(' %3d ',[j+1]); - OutputFrm.RichEdit.Lines.Add(cellstring); - for i := 0 to p-1 do // row - begin - cellstring := format(' %3d ',[i+1]); - for j := 0 to p-1 do - begin - cellstring := cellstring + format('%9.3f ',[ABC[i,j,k]]); - end; - OutputFrm.RichEdit.Lines.Add(cellstring); - end; - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add(''); + lReport.Add('C level %d', [k+1]); + cellstring := ' '; + for j := 0 to p-1 do cellstring := cellstring + Format(' %3d ', [j+1]); + lReport.Add(cellstring); + + // row + for i := 0 to p-1 do + begin + cellstring := Format(' %3d ', [i+1]); + for j := 0 to p-1 do + cellstring := cellstring + Format('%9.3f ', [ABC[i,j,k]]); + lReport.Add(cellstring); + end; + lReport.Add(''); + lReport.Add(''); end; + cellstring := 'AB sums'; - MAT_PRINT(AB,p+1,p+1,cellstring,RowLabels,ColLabels,(n*p*q)); + MatPrint(AB, p+1, p+1, cellstring, RowLabels, ColLabels, n*p*q, lReport); + cellstring := 'AC sums'; - MAT_PRINT(AC,p+1,q+1,cellstring,RowLabels,ColLabels,(n*p*q)); + MatPrint(AC, p+1, q+1, cellstring, RowLabels, ColLabels, n*p*q, lReport); + cellstring := 'BC sums'; - MAT_PRINT(BC,p+1,q+1,cellstring,RowLabels,ColLabels,(n*p*q)); + MatPrint(BC, p+1, q+1, cellstring, RowLabels, ColLabels, n*p*q, lReport); + cellstring := 'RC sums'; - MAT_PRINT(RC,rows+1,q+1,cellstring,RowLabels,ColLabels,(n*p*q)); + MatPrint(RC, rows+1, q+1, cellstring, RowLabels, ColLabels, n*p*q, lReport); + cellstring := 'Group totals'; for i := 0 to rangegrp-1 do ColLabels[i] := IntToStr(i+1); ColLabels[rangegrp] := 'Total'; - DynVectorPrint(Gm,rangegrp+1,cellstring,ColLabels,(n*p*q)); + DynVectorPrint(Gm, rangegrp+1, cellstring, ColLabels, n*p*q, lReport); for i := 0 to nosubjects-1 do ColLabels[i] := IntToStr(i+1); ColLabels[nosubjects] := 'Total'; cellstring := 'Subjects sums'; - DynVectorPrint(Persons,nosubjects+1,cellstring,ColLabels,(n*p*q)); - OutputFrm.ShowModal; + DynVectorPrint(Persons, nosubjects+1, cellstring, ColLabels, n*p*q, lReport); + + lReport.Add(''); + lReport.Add(DIVIDER); + lReport.Add(''); term1 := (G * G) / (n * p * p * q); term2 := sumXsqr; @@ -4204,21 +3921,21 @@ begin for i := 0 to q-1 do term5 := term5 + (C[i] * C[i]); term5 := term5 / (n * p * p); for i := 0 to p-1 do - for j := 0 to p-1 do - term6 := term6 + (AB[i,j] * AB[i,j]); + for j := 0 to p-1 do + term6 := term6 + (AB[i,j] * AB[i,j]); term6 := term6 / (n * q); for i := 0 to p-1 do - for j := 0 to q-1 do - term7 := term7 + (AC[i,j] * AC[i,j]); + for j := 0 to q-1 do + term7 := term7 + (AC[i,j] * AC[i,j]); term7 := term7 / (n * p); for i := 0 to p-1 do - for j := 0 to q-1 do - term8 := term8 + (BC[i,j] * BC[i,j]); + for j := 0 to q-1 do + term8 := term8 + (BC[i,j] * BC[i,j]); term8 := term8 / (n * p); for i := 0 to p-1 do - for j := 0 to p-1 do - for k := 0 to q-1 do - term9 := term9 + (ABC[i,j,k] * ABC[i,j,k]); + for j := 0 to p-1 do + for k := 0 to q-1 do + term9 := term9 + (ABC[i,j,k] * ABC[i,j,k]); term9 := term9 / n; for i := 0 to nosubjects-1 do term10 := term10 + (persons[i] * persons[i]); term10 := term10 / p; @@ -4228,36 +3945,23 @@ begin term12 := term12 / (n * p * q); // term check - OutputFrm.RichEdit.Clear; - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Computation Terms'); - cellstring := format('Term1 = %9.3f',[term1]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('term2 = %9.3f',[term2]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('term3 = %9.3f',[term3]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('term4 = %9.3f',[term4]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('term5 = %9.3f',[term5]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('term6 = %9.3f',[term6]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('term7 = %9.3f',[term7]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('term8 = %9.3f',[term8]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('term9 = %9.3f',[term9]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('term10 = %9.3f',[term10]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('term11 = %9.3f',[term11]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('term12 = %9.3f',[term12]); - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.ShowModal; - OutputFrm.RichEdit.Clear; + lReport.Add('COMPUTATION TERMS'); + lReport.Add('Term1: %9.3f', [term1]); + lReport.Add('Term2: %9.3f', [term2]); + lReport.Add('Term3: %9.3f', [term3]); + lReport.Add('Term4: %9.3f', [term4]); + lReport.Add('Term5: %9.3f', [term5]); + lReport.Add('Term6: %9.3f', [term6]); + lReport.Add('Term7: %9.3f', [term7]); + lReport.Add('Term8: %9.3f', [term8]); + lReport.Add('Term9: %9.3f', [term9]); + lReport.Add('Term10: %9.3f', [term10]); + lReport.Add('Term11: %9.3f', [term11]); + lReport.Add('Term12: %9.3f', [term12]); + + lReport.Add(''); + lReport.Add(DIVIDER); + lReport.Add(''); // now get sums of squares SSbetsubj := term10 - term1; @@ -4327,137 +4031,114 @@ begin probabcprime := probf(fabcprime,dfabcprime,dferrwithin); // show ANOVA table results - OutputFrm.RichEdit.Clear; - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Latin Squares Repeated Analysis Plan 9'); - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); - OutputFrm.RichEdit.Lines.Add('Source SS DF MS F Prob.>F'); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); - cellstring := 'Betw.Subj.'; - cellstring := cellstring + format('%9.3f %9.0f',[SSbetsubj,dfbetsubj]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Factor C '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSc,dfc,MSc,fc,probc]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Rows '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSrows,dfrows,MSrows,frows,probrows]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' C x row '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SScxrow,dfcxrow,MScxrow,fcxrow,probcxrow]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Subj.w.g.'; - cellstring := cellstring + format('%9.3f %9.0f %9.3f',[SSsubwgrps,dfsubwgrps,MSsubwgrps]); - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); - cellstring := 'Within Sub'; - cellstring := cellstring + format('%9.3f %9.0f',[SSwithinsubj,dfwithinsubj]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Factor A '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSa,dfa,MSa,fa,proba]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Factor B '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSb,dfb,MSb,fb,probb]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Factor AC'; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSac,dfac,MSac,fac,probac]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Factor BC'; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSbc,dfbc,MSbc,fbc,probbc]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' AB prime '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSabprime,dfabprime,MSabprime,fabprime,probabprime]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' ABC prime'; - cellstring := cellstring + format('%9.3f %9.0f %9.3f %9.3f %9.3f',[SSabcprime,dfabcprime,MSabcprime,fabcprime,probabcprime]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' Error w. '; - cellstring := cellstring + format('%9.3f %9.0f %9.3f',[SSerrwithin,dferrwithin,MSerrwithin]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := 'Total '; - OutputFrm.RichEdit.Lines.Add(''); - cellstring := cellstring + format('%9.3f %9.0f',[SStotal, dftotal]); - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add('-----------------------------------------------------------'); - OutputFrm.ShowModal; - OutputFrm.RichEdit.Clear; + lReport.Add('LATIN SQUARES REPEATED ANALYSUS PLAN 9'); + lReport.Add(''); + lReport.Add('-----------------------------------------------------------'); + lReport.Add('Source SS DF MS F Prob.>F'); + lReport.Add('-----------------------------------------------------------'); + lReport.Add('Betw.Subj.%9.3f %9.0f', [SSbetsubj, dfbetsubj]); + lReport.Add(' Factor C %9.3f %9.0f %9.3f %9.3f %9.3f', [SSc, dfc, MSc, fc, probc]); + lReport.Add(' Rows %9.3f %9.0f %9.3f %9.3f %9.3f', [SSrows, dfrows, MSrows, frows, probrows]); + lReport.Add(' C x row %9.3f %9.0f %9.3f %9.3f %9.3f', [SScxrow, dfcxrow, MScxrow, fcxrow, probcxrow]); + lReport.Add(' Subj.w.g.%9.3f %9.0f %9.3f', [SSsubwgrps, dfsubwgrps, MSsubwgrps]); + lReport.Add(''); + lReport.Add('Within Sub%9.3f %9.0f', [SSwithinsubj, dfwithinsubj]); + lReport.Add(' Factor A %9.3f %9.0f %9.3f %9.3f %9.3f', [SSa, dfa, MSa, fa, proba]); + lReport.Add(' Factor B %9.3f %9.0f %9.3f %9.3f %9.3f', [SSb, dfb, MSb, fb, probb]); + lReport.Add(' Factor AC%9.3f %9.0f %9.3f %9.3f %9.3f', [SSac, dfac, MSac, fac, probac]); + lReport.Add(' Factor BC%9.3f %9.0f %9.3f %9.3f %9.3f', [SSbc, dfbc, MSbc, fbc, probbc]); + lReport.Add(' AB prime %9.3f %9.0f %9.3f %9.3f %9.3f', [SSabprime, dfabprime, MSabprime, fabprime, probabprime]); + lReport.Add(' ABC prime%9.3f %9.0f %9.3f %9.3f %9.3f', [SSabcprime, dfabcprime, MSabcprime, fabcprime, probabcprime]); + lReport.Add(' Error w. %9.3f %9.0f %9.3f', [SSerrwithin, dferrwithin, MSerrwithin]); + lReport.Add(''); + lReport.Add('Total %9.3f %9.0f', [SStotal, dftotal]); + lReport.Add('-----------------------------------------------------------'); + + lReport.Add(''); + lReport.Add(DIVIDER); + lReport.Add(''); // show design for Squares c1, c2, etc. - OutputFrm.RichEdit.Lines.Add(''); - cellstring := 'Experimental Design for Latin Square '; - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); + lReport.Add('Experimental Design for Latin Square '); + lReport.Add(''); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + cellstring := format('%10s',[FactorA]); - for i := 1 to p do cellstring := cellstring + format(' %3d ',[i]); - OutputFrm.RichEdit.Lines.Add(cellstring); + for i := 1 to p do cellstring := cellstring + Format(' %3d ', [i]); + lReport.Add(cellstring); + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := format('%10s',[GroupFactor]); - OutputFrm.RichEdit.Lines.Add(cellstring); + lReport.Add(cellstring); + + lReport.Add('%10s', [GroupFactor]); for i := 1 to NoCases do begin - row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); // A (column) effect - col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); // B (cell) effect - slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); // C (cell) effect - group := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); // group (row) - Design[group-1,row-1] := 'B' + IntToStr(col); + row := StrToInt(OS3MainFrm.DataGrid.Cells[Acol,i]); // A (column) effect + col := StrToInt(OS3MainFrm.DataGrid.Cells[Bcol,i]); // B (cell) effect + slice := StrToInt(OS3MainFrm.DataGrid.Cells[Ccol,i]); // C (cell) effect + group := StrToInt(OS3MainFrm.DataGrid.Cells[Grpcol,i]); // group (row) + Design[group-1, row-1] := 'B' + IntToStr(col); end; + for i := 0 to rangegrp - 1 do begin - cellstring := format(' %3d ',[i+1]); - for j := 0 to p - 1 do - cellstring := cellstring + format('%5s',[Design[i,j]]); - OutputFrm.RichEdit.Lines.Add(cellstring); + cellstring := format(' %3d ',[i+1]); + for j := 0 to p - 1 do + cellstring := cellstring + format('%5s', [Design[i,j]]); + lReport.Add(cellstring); end; + cellstring := '----------'; for i := 1 to p + 1 do cellstring := cellstring + '-----'; - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.ShowModal; - OutputFrm.RichEdit.Clear; + lReport.Add(cellstring); + + lReport.Add(''); + lReport.Add(DIVIDER); + lReport.Add(''); // get means G := G / (p * p * q * n ); for i := 0 to p-1 do - for j := 0 to p-1 do - for k := 0 to q-1 do - ABC[i,j,k] := ABC[i,j,k] / n; + for j := 0 to p-1 do + for k := 0 to q-1 do + ABC[i,j,k] := ABC[i,j,k] / n; for i := 0 to p-1 do - for j := 0 to p-1 do - AB[i,j] := AB[i,j] / (n * p); + for j := 0 to p-1 do + AB[i,j] := AB[i,j] / (n * p); for i := 0 to p-1 do AB[i,p] := AB[i,p] / (n * p * p); for j := 0 to p-1 do AB[p,j] := AB[p,j] / (n * p * p); AB[p,p] := G; for i := 0 to p-1 do - for j := 0 to q-1 do - AC[i,j] := AC[i,j] / (n * p); + for j := 0 to q-1 do + AC[i,j] := AC[i,j] / (n * p); for i := 0 to p-1 do AC[i,q] := AC[i,q] / (n * p * p); for j := 0 to q-1 do AC[p,j] := AC[p,j] / (n * p * p); AC[p,q] := G; for i := 0 to p-1 do - for j := 0 to q-1 do - BC[i,j] := BC[i,j] / (n * p); + for j := 0 to q-1 do + BC[i,j] := BC[i,j] / (n * p); for i := 0 to p-1 do BC[i,q] := BC[i,q] / (n * p * p); for j := 0 to q-1 do BC[p,j] := BC[p,j] / (n * p * p); BC[p,q] := G; for i := 0 to rows-1 do - for j := 0 to q-1 do - RC[i,j] := RC[i,j] / (p * n); + for j := 0 to q-1 do + RC[i,j] := RC[i,j] / (p * n); for i := 0 to rows-1 do RC[i,q] := RC[i,q] / (p * q * n); for j := 0 to q-1 do RC[p,j] := RC[p,j] / (q * p * n); RC[p,q] := G; for i := 0 to p-1 do begin - A[i] := A[i] / (p * n * q); - B[i] := B[i] / (p * n * q); + A[i] := A[i] / (p * n * q); + B[i] := B[i] / (p * n * q); end; A[p] := G; B[p] := G; @@ -4471,52 +4152,57 @@ begin for i := 0 to nosubjects-1 do Persons[i] := Persons[i] / n; Persons[nosubjects] := G; - OutputFrm.RichEdit.Clear; - OutputFrm.RichEdit.Lines.Add('Latin Squares Repeated Analysis Plan 9'); - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add('Means for ANOVA Analysis'); - OutputFrm.RichEdit.Lines.Add(''); - cellstring := 'ABC matrix'; - OutputFrm.RichEdit.Lines.Add(cellstring); - OutputFrm.RichEdit.Lines.Add(''); + lReport.Add('LATIN SQUARES REPEATED ANALYSIS PLAN 9'); + lReport.Add(''); + lReport.Add('Means for ANOVA Analysis'); + lReport.Add(''); + lReport.Add('ABC matrix'); + lReport.Add(''); for k := 0 to q-1 do begin - cellstring := format('C level %d',[k+1]); - OutputFrm.RichEdit.Lines.Add(cellstring); - cellstring := ' '; - for j := 0 to p-1 do cellstring := cellstring + format(' %3d ',[j+1]); - OutputFrm.RichEdit.Lines.Add(cellstring); - for i := 0 to p-1 do // row - begin - cellstring := format(' %3d ',[i+1]); - for j := 0 to p-1 do - begin - cellstring := cellstring + format('%9.3f ',[ABC[i,j,k]]); - end; - OutputFrm.RichEdit.Lines.Add(cellstring); - end; - OutputFrm.RichEdit.Lines.Add(''); - OutputFrm.RichEdit.Lines.Add(''); + lReport.Add('C level %d', [k+1]); + + cellstring := ' '; + for j := 0 to p-1 do cellstring := cellstring + Format(' %3d ', [j+1]); + lReport.Add(cellstring); + + for i := 0 to p-1 do // row + begin + cellstring := Format(' %3d ', [i+1]); + for j := 0 to p-1 do + cellstring := cellstring + Format('%9.3f ', [ABC[i,j,k]]); + lReport.Add(cellstring); + end; + lReport.Add(''); + lReport.Add(''); end; + cellstring := 'AB Means'; - MAT_PRINT(AB,p+1,p+1,cellstring,RowLabels,ColLabels,(n*p*p*q)); + MatPrint(AB, p+1, p+1, cellstring, RowLabels, ColLabels, n*p*p*q, lReport); + cellstring := 'AC Means'; - MAT_PRINT(AC,p+1,q+1,cellstring,RowLabels,ColLabels,(n*p*p*q)); + MatPrint(AC, p+1, q+1, cellstring, RowLabels, ColLabels, n*p*p*q, lReport); + cellstring := 'BC Means'; - MAT_PRINT(BC,p+1,q+1,cellstring,RowLabels,ColLabels,(n*p*p*q)); + MatPrint(BC, p+1, q+1, cellstring, RowLabels, ColLabels, n*p*p*q, lReport); + cellstring := 'RC Means'; - MAT_PRINT(RC,rows+1,q+1,cellstring,RowLabels,ColLabels,(n*p*p*q)); + MatPrint(RC, rows+1, q+1, cellstring, RowLabels, ColLabels, n*p*p*q, lReport); + cellstring := 'Group Means'; for i := 0 to rangegrp-1 do ColLabels[i] := IntToStr(i+1); ColLabels[rangegrp] := 'Total'; - DynVectorPrint(Gm,rangegrp+1,cellstring,ColLabels,(n*p*p*q)); + DynVectorPrint(Gm, rangegrp+1, cellstring, ColLabels, n*p*p*q, lReport); for i := 0 to nosubjects-1 do ColLabels[i] := IntToStr(i+1); ColLabels[nosubjects] := 'Total'; cellstring := 'Subjects Means'; - DynVectorPrint(Persons,nosubjects+1,cellstring,ColLabels,(n*p*p*q)); - OutputFrm.ShowModal; + DynVectorPrint(Persons, nosubjects+1, cellstring, ColLabels, n*p*p*q, lReport); + + DisplayReport(lReport); + + finally + lReport.Free; -cleanup: ColLabels := nil; RowLabels := nil; Design := nil; @@ -4533,6 +4219,7 @@ cleanup: AB := nil; AGC := nil; ABC := nil; + end; end; initialization diff --git a/applications/lazstats/source/forms/analysis/descriptive/comparedistunit.pas b/applications/lazstats/source/forms/analysis/descriptive/comparedistunit.pas index ed3717fa2..db9474a1f 100644 --- a/applications/lazstats/source/forms/analysis/descriptive/comparedistunit.pas +++ b/applications/lazstats/source/forms/analysis/descriptive/comparedistunit.pas @@ -67,7 +67,7 @@ var implementation uses - Math; + Math, Utils; { TCompareDistFrm } @@ -159,7 +159,7 @@ begin end; if msg <> '' then begin - MessageDlg(msg, mtError, [mbOK], 0); + ErrorMsg(msg); exit; end; @@ -360,7 +360,7 @@ begin max2 := max1; if max2 > 13 then begin - MessageDlg('Value > 13 found. Factorial too large - exiting.', mtError, [mbOK], 0); + ErrorMsg('Value > 13 found. Factorial too large - exiting.'); exit; end; for i := 1 to Ncases do diff --git a/applications/lazstats/source/forms/analysis/measurement_programs/relchangeunit.pas b/applications/lazstats/source/forms/analysis/measurement_programs/relchangeunit.pas index 97b1b32ed..441c7df17 100644 --- a/applications/lazstats/source/forms/analysis/measurement_programs/relchangeunit.pas +++ b/applications/lazstats/source/forms/analysis/measurement_programs/relchangeunit.pas @@ -47,7 +47,7 @@ var implementation uses - Math; + Math, Utils; { TRelChangeFrm } @@ -97,19 +97,19 @@ begin if (OldRelEdit.Text = '') or not TryStrToFloat(OldRelEdit.Text, oldRel) then begin OldRelEdit.SetFocus; - MessageDlg('Valid number required.', mtError, [mbOK], 0); + ErrorMsg('Valid number required.'); exit; end; if (OldVarEdit.Text = '') or not TryStrToFloat(OldVarEdit.Text, oldVar) then begin OldVarEdit.SetFocus; - MessageDlg('Valid number required.', mtError, [mbOK], 0); + ErrorMsg('Valid number required.'); exit; end; if (NewVarEdit.Text = '') or not TryStrToFloat(NewVarEdit.Text, newVar) then begin NewVarEdit.SetFocus; - MessageDlg('Valid number required.', mtError, [mbOK], 0); + ErrorMsg('Valid number required.'); exit; end; newRel := 1.0 - (oldVar / newVar) * (1.0 - oldRel); diff --git a/applications/lazstats/source/forms/analysis/measurement_programs/succintunit.pas b/applications/lazstats/source/forms/analysis/measurement_programs/succintunit.pas index d34f4c93f..c26ed6bd8 100644 --- a/applications/lazstats/source/forms/analysis/measurement_programs/succintunit.pas +++ b/applications/lazstats/source/forms/analysis/measurement_programs/succintunit.pas @@ -52,7 +52,7 @@ var implementation uses - Math; + Math, Utils; { TSuccIntFrm } @@ -127,7 +127,7 @@ var begin if ItemList.Items.Count = 0 then begin - MessageDlg('No variables selected.', mtError, [mbOK], 0); + ErrorMsg('No variables selected.'); exit; end; diff --git a/applications/lazstats/source/forms/mainunit.lfm b/applications/lazstats/source/forms/mainunit.lfm index a255894fd..288679aa0 100644 --- a/applications/lazstats/source/forms/mainunit.lfm +++ b/applications/lazstats/source/forms/mainunit.lfm @@ -992,33 +992,33 @@ object OS3MainFrm: TOS3MainFrm OnClick = ProbltzClick end object probzbetween: TMenuItem - Caption = 'Prob between 2 z values' + Caption = 'Probability between two z Values' OnClick = probzbetweenClick end object MenuItem45: TMenuItem Caption = '-' end object inversez: TMenuItem - Caption = 'z for a given cum. Probability' + Caption = 'z for a given Cumulative Probability' OnClick = inversezClick end object MenuItem44: TMenuItem Caption = '-' end object Chiprob: TMenuItem - Caption = 'Chisquare Probability' + Caption = 'Chi-Square Probability' OnClick = ChiprobClick end object tprob: TMenuItem - Caption = 'Student t probability' + Caption = 'Student t Probability' OnClick = tprobClick end object Fprob: TMenuItem - Caption = 'F probability' + Caption = 'F Probability' OnClick = FprobClick end object HypergeoProb: TMenuItem - Caption = 'Hypergeometric probability' + Caption = 'Hypergeometric Probability' OnClick = HypergeoProbClick end end diff --git a/applications/lazstats/source/forms/mainunit.pas b/applications/lazstats/source/forms/mainunit.pas index 35881e315..ad1f8eeb4 100644 --- a/applications/lazstats/source/forms/mainunit.pas +++ b/applications/lazstats/source/forms/mainunit.pas @@ -453,6 +453,7 @@ implementation { TOS3MainFrm } uses + Utils, OptionsUnit, OutputUnit, LicenseUnit, TransFrmUnit, DescriptiveUnit, FreqUnit, CrossTabUnit, BreakDownUnit, BoxPlotUnit, NormalityUnit, Rot3DUnit, PlotXYUnit, BubblePlotUnit, StemLeafUnit, MultXvsYUnit, OneSampUnit, @@ -1163,17 +1164,16 @@ end; // Menu "Variables" > "Transform Variables" procedure TOS3MainFrm.TransformClick(Sender: TObject); var - MyErrorString : string; + err: string; begin - try - if TransFrm = nil then - Application.CreateForm(TTransFrm, TransFrm); - TransFrm.ShowModal; - except -// MyErrorString := 'ErrorCode: ' + IntToStr(Error) + #13#10; - MyErrorString := 'Error in showing transformations'; - MessageDlg(MyErrorString , mtError, [mbOk], 0); - end; + try + if TransFrm = nil then + Application.CreateForm(TTransFrm, TransFrm); + TransFrm.ShowModal; + except + err := 'Error in showing transformations'; + ErrorMsg(err); + end; end; // Menu "Analysis" > "Comparisons" > "t-tests" @@ -1722,7 +1722,7 @@ begin if TryStrToInt(response, GroupCol) and (GroupCol > 0) then break else - MessageDlg('Illegal value entered for index of group column.', mtError, [mbOk], 0); + ErrorMsg('Illegal value entered for index of group column.'); until false; response := '2'; @@ -1732,7 +1732,7 @@ begin if TryStrToInt(response, VarCol) then break else - MessageDlg('Illegal value entered for index of variable column.', mtError, [mbOK], 0); + ErrorMsg('Illegal value entered for index of variable column.'); until false; NoCases := StrToInt(NoCasesEdit.text); diff --git a/applications/lazstats/source/units/utils.pas b/applications/lazstats/source/units/utils.pas index a105f1827..fb9b3db29 100644 --- a/applications/lazstats/source/units/utils.pas +++ b/applications/lazstats/source/units/utils.pas @@ -5,10 +5,12 @@ unit Utils; interface uses - Classes, SysUtils, StdCtrls; + Classes, SysUtils, StdCtrls, Dialogs; function AnySelected(AListbox: TListBox): Boolean; +procedure ErrorMsg(const AMsg: String); + procedure Exchange(var a, b: Double); overload; procedure Exchange(var a, b: Integer); overload; procedure Exchange(var a, b: String); overload; @@ -28,6 +30,11 @@ begin end; end; +procedure ErrorMsg(const AMsg: String); +begin + MessageDlg(AMsg, mtError, [mbOK], 0); +end; + procedure Exchange(var a, b: Double); var tmp: Double;