From 94677510b70f1cc2eeaf9fe1b3027a3c088d26f3 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sat, 5 Dec 2020 12:40:55 +0000 Subject: [PATCH] LazStats: Some refactoring in LatinSqrsUnit git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7923 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../analysis/comparisons/latinsqrsunit.lfm | 24 ++-- .../analysis/comparisons/latinsqrsunit.pas | 119 ++++++++---------- 2 files changed, 57 insertions(+), 86 deletions(-) diff --git a/applications/lazstats/source/forms/analysis/comparisons/latinsqrsunit.lfm b/applications/lazstats/source/forms/analysis/comparisons/latinsqrsunit.lfm index 719c1a274..03e1ce10e 100644 --- a/applications/lazstats/source/forms/analysis/comparisons/latinsqrsunit.lfm +++ b/applications/lazstats/source/forms/analysis/comparisons/latinsqrsunit.lfm @@ -60,14 +60,14 @@ inherited LatinSqrsForm: TLatinSqrsForm DropDownCount = 16 ItemHeight = 15 Items.Strings = ( - 'Plan 1. Three Factors (A,B,C) with no interactions.' - 'Plan 2. Four Factors (A,B,C,D) with partial interactions.' - 'Plan 3. Like Plan 2 but different assumptions (Partial confounding of interaction ABC.)' - 'Plan 4. The Greco-Latin with no interactions assumed.' - 'Plan 5. Repeated measures Latin Square (random assignment of groups to rows.)' - 'Plan 6. Fractional replication of a three factor factorial experiment in incomplete blocks.' - 'Plan 7. Plan 5 with superimposing of an orthogonal Latin square.' - 'Plan 9. AxBxC (same square used for all levels of Factor C.)' + 'Plan 1. Three Factors (A,B,C) with no interactions' + 'Plan 2. Four Factors (A,B,C,D) with partial interactions' + 'Plan 3. Like Plan 2 but different assumptions (partial confounding of interaction ABC)' + 'Plan 4. The Greco-Latin with no interactions assumed' + 'Plan 5. Repeated measures Latin Square (random assignment of groups to rows)' + 'Plan 6. Fractional replication of a three factor factorial experiment in incomplete blocks' + 'Plan 7. Plan 5 with superimposing of an orthogonal Latin square' + 'Plan 9. AxBxC (same square used for all levels of factor C)' ) OnChange = PlanComboChange Style = csDropDownList @@ -527,12 +527,4 @@ inherited LatinSqrsForm: TLatinSqrsForm Left = 367 Height = 573 end - inherited PageControl: TPageControl - Left = 376 - Height = 557 - Width = 530 - ActivePage = ReportPage - TabIndex = 0 - TabOrder = 1 - end end diff --git a/applications/lazstats/source/forms/analysis/comparisons/latinsqrsunit.pas b/applications/lazstats/source/forms/analysis/comparisons/latinsqrsunit.pas index 19d35e6fe..e65078fa9 100644 --- a/applications/lazstats/source/forms/analysis/comparisons/latinsqrsunit.pas +++ b/applications/lazstats/source/forms/analysis/comparisons/latinsqrsunit.pas @@ -6,14 +6,14 @@ interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, - ComCtrls, Buttons, MainUnit, Globals, GraphLib, - MatrixLib, BasicStatsReportAndChartFormUnit; + ComCtrls, Buttons, MainUnit, Globals, + MatrixLib, BasicStatsReportFormUnit; type { TLatinSqrsForm } - TLatinSqrsForm = class(TBasicStatsReportAndChartForm) + TLatinSqrsForm = class(TBasicStatsReportForm) ACodeEdit: TEdit; ACodeLabel: TLabel; AInBtn: TBitBtn; @@ -368,14 +368,10 @@ begin FactorC := CCodeEdit.Text; DataVar := 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 = DataVar) then DataCol := i; - end; + ACol := GetVariableIndex(OS3MainFrm.DataGrid, FactorA); + BCol := GetVariableIndex(OS3MainFrm.DataGrid, FactorB); + CCol := GetVariableIndex(OS3MainFrm.DataGrid, FactorC); + DataCol := GetVariableIndex(OS3MainFrm.DataGrid, DataVar); // determine no. of levels in A, B and C if not GetRange(ACol, rangeA, mn, mx) then exit; @@ -424,10 +420,10 @@ begin // Read in the data for i := 1 to NoCases do begin - row := Round(StrToFloat(OS3MainFrm.DataGrid.Cells[Acol,i])); - col := Round(StrTofloat(OS3MainFrm.DataGrid.Cells[Bcol,i])); - slice := Round(StrToFloat(OS3MainFrm.DataGrid.Cells[Ccol,i])); - data := StrToFloat(OS3MainFrm.DataGrid.Cells[DataCol,i]); + row := Round(StrToFloat(OS3MainFrm.DataGrid.Cells[Acol, i])); + col := Round(StrTofloat(OS3MainFrm.DataGrid.Cells[Bcol, i])); + slice := Round(StrToFloat(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; @@ -667,15 +663,11 @@ begin FactorD := DCodeEdit.Text; DataVar := 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; + ACol := GetVariableIndex(OS3MainFrm.DataGrid, FactorA); + BCol := GetVariableIndex(OS3MainFrm.DataGrid, FactorB); + CCol := GetVariableIndex(OS3MainFrm.DataGrid, FactorC); + DCol := GetVariableIndex(OS3MainFrm.DataGrid, FactorD); + DataCol := GetVariableIndex(OS3MainFrm.DataGrid, DataVar); // determine no. of levels in A, B and C if not GetRange(ACol, rangeA, mn, mx) then exit; @@ -1080,15 +1072,11 @@ begin FactorD := DCodeEdit.Text; DataVar := 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; + ACol := GetVariableIndex(OS3MainFrm.DataGrid, FactorA); + BCol := GetVariableIndex(OS3MainFrm.DataGrid, FactorB); + CCol := GetVariableIndex(OS3MainFrm.DataGrid, FactorC); + DCol := GetVariableIndex(OS3MainFrm.DataGrid, FactorD); + DataCol := GetVariableIndex(OS3MainFrm.DataGrid, DataVar); // determine no. of levels in A, B and C if not GetRange(ACol, rangeA, mn, mx) then exit; @@ -1615,15 +1603,11 @@ begin FactorD := DCodeEdit.Text; DataVar := 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; + ACol := GetVariableIndex(OS3MainFrm.DataGrid, FactorA); + BCol := GetVariableIndex(OS3MainFrm.DataGrid, FactorB); + CCol := GetVariableIndex(OS3MainFrm.DataGrid, FactorC); + DCol := GetVariableIndex(OS3MainFrm.DataGrid, FactorD); + DataCol := GetVariableIndex(OS3MainFrm.DataGrid, DataVar); // determine no. of levels in A, B and C if not GetRange(ACol, rangeA, mn, mx) then exit; @@ -2086,15 +2070,11 @@ begin GroupFactor := GrpCodeEdit.Text; DataVar := 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; + ACol := GetVariableIndex(OS3MainFrm.DataGrid, FactorA); + BCol := GetVariableIndex(OS3MainFrm.DataGrid, FactorB); + GrpCol := GetVariableIndex(OS3MainFrm.DataGrid, GroupFactor); + SbjCol := GetVariableIndex(OS3MainFrm.DataGrid, SubjectFactor); + DataCol := GetVariableIndex(OS3MainFrm.DataGrid, DataVar); // determine no. of levels in A, B and Group if not GetRange(ACol, rangeA, mn, mx) then exit; @@ -2567,15 +2547,11 @@ begin GroupFactor := GrpCodeEdit.Text; DataVar := 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; + ACol := GetVariableIndex(OS3MainFrm.DataGrid, FactorA); + BCol := GetVariableIndex(OS3MainFrm.DataGrid, FactorB); + GrpCol := GetVariableIndex(OS3MainFrm.DataGrid, GroupFactor); + SbjCol := GetVariableIndex(OS3MainFrm.DataGrid, SubjectFactor); + DataCol := GetVariableIndex(OS3MainFrm.DataGrid, DataVar); // determine no. of levels in A, B and Group if not GetRange(ACol, rangeA, mn, mx) then exit; @@ -3051,16 +3027,12 @@ begin GroupFactor := GrpCodeEdit.Text; DataVar := 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; + ACol := GetVariableIndex(OS3MainFrm.DataGrid, FactorA); + BCol := GetVariableIndex(OS3MainFrm.DataGrid, FactorB); + CCol := GetVariableIndex(OS3MainFrm.DataGrid, FactorC); + GrpCol := GetVariableIndex(OS3MainFrm.DataGrid, GroupFactor); + SbjCol := GetVariableIndex(OS3MainFrm.DataGrid, SubjectFactor); + DataCol := GetVariableIndex(OS3MainFrm.DataGrid, DataVar); // determine no. of levels in A, B, C and Group if not GetRange(ACol, rangeA, mn, mx) then exit; @@ -3623,6 +3595,13 @@ begin GroupFactor := GrpCodeEdit.Text; DataVar := DepVarEdit.Text; + ACol := GetVariableIndex(OS3MainFrm.DataGrid, FactorA); + BCol := GetVariableIndex(OS3MainFrm.DataGrid, FactorB); + CCol := GetVariableIndex(OS3MainFrm.DataGrid, FactorC); + GrpCol := GetVariableIndex(OS3MainFrm.DataGrid, GroupFactor); + SbjCol := GetVariableIndex(OS3MainFrm.DataGrid, SubjectFactor); + DataCol := GetVariableIndex(OS3MainFrm.DataGrid, DataVar); + for i := 1 to NoVariables do begin cellstring := OS3MainFrm.DataGrid.Cells[i,0];