LazStats: Inherit form of WithinANOVAUnit from TBasicStatsReportAndChartForm. Minor refactoring.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7793 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-10-22 22:14:06 +00:00
parent f495e6fb12
commit f76d424ce3
3 changed files with 413 additions and 396 deletions

View File

@ -1,244 +1,198 @@
object WithinANOVAFrm: TWithinANOVAFrm inherited WithinANOVAFrm: TWithinANOVAFrm
Left = 544 Left = 544
Height = 362 Height = 329
Top = 330 Top = 330
Width = 458 Width = 722
HelpType = htKeyword HelpType = htKeyword
HelpKeyword = 'html/WithinSubjectsAnalysisofVariance.htm' HelpKeyword = 'html/WithinSubjectsAnalysisofVariance.htm'
AutoSize = True
Caption = 'Within Subjects ANOVA and Hoyt Reliability Estimates' Caption = 'Within Subjects ANOVA and Hoyt Reliability Estimates'
ClientHeight = 362 ClientHeight = 329
ClientWidth = 458 ClientWidth = 722
OnActivate = FormActivate inherited ParamsPanel: TPanel
OnCreate = FormCreate Height = 313
OnShow = FormShow Width = 288
Position = poMainFormCenter ClientHeight = 313
LCLVersion = '2.1.0.0' ClientWidth = 288
object Label1: TLabel inherited CloseBtn: TButton
AnchorSideLeft.Control = Owner Left = 233
AnchorSideTop.Control = Owner Top = 288
Left = 8 TabOrder = 8
Height = 15 end
Top = 8 inherited ComputeBtn: TButton
Width = 97 Left = 149
BorderSpacing.Left = 8 Top = 288
BorderSpacing.Top = 8 TabOrder = 7
Caption = 'Available Variables' end
ParentColor = False inherited ResetBtn: TButton
end Left = 87
object Label2: TLabel Top = 288
AnchorSideLeft.Control = SelList TabOrder = 6
AnchorSideTop.Control = Owner end
Left = 251 inherited HelpBtn: TButton
Height = 15 Left = 28
Top = 8 Top = 288
Width = 96 TabOrder = 5
BorderSpacing.Top = 8 end
Caption = 'Selected Variables:' inherited ButtonBevel: TBevel
ParentColor = False Top = 272
end Width = 288
object VarList: TListBox end
AnchorSideLeft.Control = Owner object Label1: TLabel[5]
AnchorSideTop.Control = Label1 AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Side = asrBottom AnchorSideTop.Control = ParamsPanel
AnchorSideRight.Control = InBtn Left = 0
AnchorSideBottom.Control = GroupBox1 Height = 15
Left = 8 Top = 0
Height = 229 Width = 97
Top = 25 BorderSpacing.Right = 6
Width = 199 Caption = 'Available Variables'
Anchors = [akTop, akLeft, akRight, akBottom] ParentColor = False
BorderSpacing.Left = 8 end
BorderSpacing.Top = 2 object Label2: TLabel[6]
BorderSpacing.Right = 8 AnchorSideLeft.Control = SelList
BorderSpacing.Bottom = 8 AnchorSideTop.Control = ParamsPanel
Constraints.MinHeight = 220 Left = 163
ItemHeight = 0 Height = 15
MultiSelect = True Top = 0
OnSelectionChange = VarListSelectionChange Width = 96
TabOrder = 0 Caption = 'Selected Variables:'
end ParentColor = False
object InBtn: TBitBtn end
AnchorSideLeft.Control = Owner object VarList: TListBox[7]
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = VarList AnchorSideTop.Control = Label1
Left = 215 AnchorSideTop.Side = asrBottom
Height = 28 AnchorSideRight.Control = InBtn
Top = 25 AnchorSideBottom.Control = GroupBox1
Width = 28 Left = 0
Images = MainDataModule.ImageList Height = 177
ImageIndex = 1 Top = 17
OnClick = InBtnClick Width = 125
Spacing = 0 Anchors = [akTop, akLeft, akRight, akBottom]
TabOrder = 1 BorderSpacing.Top = 2
end BorderSpacing.Right = 6
object OutBtn: TBitBtn BorderSpacing.Bottom = 8
AnchorSideLeft.Control = Owner ItemHeight = 0
AnchorSideLeft.Side = asrCenter MultiSelect = True
AnchorSideTop.Control = InBtn OnDblClick = VarListDblClick
AnchorSideTop.Side = asrBottom OnSelectionChange = VarListSelectionChange
Left = 215
Height = 28
Top = 57
Width = 28
BorderSpacing.Top = 4
Images = MainDataModule.ImageList
ImageIndex = 0
OnClick = OutBtnClick
Spacing = 0
TabOrder = 2
end
object SelList: TListBox
AnchorSideLeft.Control = InBtn
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Label2
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = GroupBox1
Left = 251
Height = 229
Top = 25
Width = 199
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Top = 2
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
ItemHeight = 0
MultiSelect = True
OnSelectionChange = VarListSelectionChange
TabOrder = 3
end
object GroupBox1: TGroupBox
AnchorSideLeft.Control = Owner
AnchorSideBottom.Control = Bevel1
Left = 8
Height = 51
Top = 262
Width = 384
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Right = 8
Caption = 'Options:'
ChildSizing.LeftRightSpacing = 12
ChildSizing.TopBottomSpacing = 6
ChildSizing.HorizontalSpacing = 20
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 3
ClientHeight = 31
ClientWidth = 380
TabOrder = 4
object RelChk: TCheckBox
Left = 12
Height = 19
Top = 6
Width = 124
Caption = 'Reliability Estimates'
TabOrder = 0 TabOrder = 0
end end
object AssumpChk: TCheckBox object InBtn: TBitBtn[8]
Left = 156 AnchorSideLeft.Control = ParamsPanel
Height = 19 AnchorSideLeft.Side = asrCenter
Top = 6 AnchorSideTop.Control = VarList
Width = 113 Left = 131
Caption = 'Test Assumptions' Height = 26
Top = 17
Width = 26
Images = MainDataModule.ImageList
ImageIndex = 1
OnClick = InBtnClick
Spacing = 0
TabOrder = 1 TabOrder = 1
end end
object PlotChk: TCheckBox object OutBtn: TBitBtn[9]
Left = 289 AnchorSideLeft.Control = ParamsPanel
Height = 19 AnchorSideLeft.Side = asrCenter
Top = 6 AnchorSideTop.Control = InBtn
Width = 79 AnchorSideTop.Side = asrBottom
Caption = 'Plot Means' Left = 131
Height = 26
Top = 47
Width = 26
BorderSpacing.Top = 4
Images = MainDataModule.ImageList
ImageIndex = 0
OnClick = OutBtnClick
Spacing = 0
TabOrder = 2 TabOrder = 2
end end
object GroupBox1: TGroupBox[10]
AnchorSideLeft.Control = ParamsPanel
AnchorSideBottom.Control = ButtonBevel
Left = 0
Height = 70
Top = 202
Width = 251
Anchors = [akLeft, akBottom]
AutoSize = True
BorderSpacing.Right = 8
Caption = 'Options:'
ChildSizing.LeftRightSpacing = 12
ChildSizing.TopBottomSpacing = 6
ChildSizing.HorizontalSpacing = 20
ChildSizing.Layout = cclTopToBottomThenLeftToRight
ChildSizing.ControlsPerLine = 2
ClientHeight = 50
ClientWidth = 247
TabOrder = 4
object RelChk: TCheckBox
Left = 12
Height = 19
Top = 6
Width = 124
Caption = 'Reliability Estimates'
TabOrder = 0
end
object AssumpChk: TCheckBox
Left = 12
Height = 19
Top = 25
Width = 124
Caption = 'Test Assumptions'
TabOrder = 1
end
object PlotChk: TCheckBox
Left = 156
Height = 19
Top = 6
Width = 79
Caption = 'Plot Means'
TabOrder = 2
end
end
object SelList: TListBox[11]
AnchorSideLeft.Control = InBtn
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Label2
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = GroupBox1
Left = 163
Height = 177
Top = 17
Width = 125
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 6
BorderSpacing.Top = 2
BorderSpacing.Bottom = 8
ItemHeight = 0
MultiSelect = True
OnDblClick = SelListDblClick
OnSelectionChange = VarListSelectionChange
TabOrder = 3
end
end end
object ResetBtn: TButton inherited ParamsSplitter: TSplitter
AnchorSideRight.Control = ComputeBtn Left = 300
AnchorSideBottom.Control = Owner Height = 329
AnchorSideBottom.Side = asrBottom
Left = 245
Height = 25
Top = 329
Width = 54
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 6
end end
object ComputeBtn: TButton inherited PageControl: TPageControl
AnchorSideRight.Control = CloseBtn Left = 309
AnchorSideBottom.Control = Owner Height = 313
AnchorSideBottom.Side = asrBottom Width = 405
Left = 307 inherited ReportPage: TTabSheet
Height = 25 Caption = 'ANOVA Results'
Top = 329 end
Width = 76 object ReliabilityPage: TTabSheet[1]
Anchors = [akRight, akBottom] Caption = 'Reliability Estimates'
AutoSize = True end
BorderSpacing.Left = 8 object TestAssumptionsPage: TTabSheet[2]
BorderSpacing.Top = 8 Caption = 'Test Assumptions'
BorderSpacing.Right = 8 end
BorderSpacing.Bottom = 8 inherited ChartPage: TTabSheet[3]
Caption = 'Compute' end
OnClick = ComputeBtnClick
TabOrder = 7
end
object CloseBtn: TButton
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 391
Height = 25
Top = 329
Width = 55
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 12
BorderSpacing.Bottom = 8
Caption = 'Close'
ModalResult = 11
TabOrder = 8
end
object HelpBtn: TButton
Tag = 157
AnchorSideRight.Control = ResetBtn
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 186
Height = 25
Top = 329
Width = 51
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 12
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Help'
OnClick = HelpBtnClick
TabOrder = 5
end
object Bevel1: TBevel
AnchorSideLeft.Control = Owner
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = CloseBtn
Left = 0
Height = 8
Top = 313
Width = 458
Anchors = [akLeft, akRight, akBottom]
Shape = bsBottomLine
end end
end end

View File

@ -7,22 +7,17 @@ unit WithinANOVAUnit;
interface interface
uses uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, Buttons, ExtCtrls, Math, StdCtrls, Buttons, ExtCtrls, ComCtrls, Math,
MainUnit, FunctionsLib, OutputUnit, MatrixLib, Globals, DataProcs, MainUnit, FunctionsLib, MatrixLib, Globals,
GraphLib, ContextHelpUnit; ReportFrameUnit, BasicStatsReportAndChartFormUnit;
type type
{ TWithinANOVAFrm } { TWithinANOVAFrm }
TWithinANOVAFrm = class(TForm) TWithinANOVAFrm = class(TBasicStatsReportAndChartForm)
AssumpChk: TCheckBox; AssumpChk: TCheckBox;
Bevel1: TBevel;
HelpBtn: TButton;
ResetBtn: TButton;
ComputeBtn: TButton;
CloseBtn: TButton;
PlotChk: TCheckBox; PlotChk: TCheckBox;
RelChk: TCheckBox; RelChk: TCheckBox;
GroupBox1: TGroupBox; GroupBox1: TGroupBox;
@ -31,137 +26,127 @@ type
SelList: TListBox; SelList: TListBox;
OutBtn: TBitBtn; OutBtn: TBitBtn;
Label1: TLabel; Label1: TLabel;
ReliabilityPage: TTabSheet;
TestAssumptionsPage: TTabSheet;
VarList: TListBox; VarList: TListBox;
procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure HelpBtnClick(Sender: TObject);
procedure InBtnClick(Sender: TObject); procedure InBtnClick(Sender: TObject);
procedure OutBtnClick(Sender: TObject); procedure OutBtnClick(Sender: TObject);
procedure ResetBtnClick(Sender: TObject); procedure SelListDblClick(Sender: TObject);
procedure VarListSelectionChange(Sender: TObject; User: boolean); procedure VarListDblClick(Sender: TObject);
procedure VarListSelectionChange(Sender: TObject; {%H-}User: boolean);
private private
{ private declarations } FReliabilityReportFrame: TReportFrame;
FAutoSized: Boolean; FTestAssumptionsReportFrame: TReportFrame;
procedure UpdateBtnStates; procedure Plot(ColMeans: DblDyneVec; ColLabels: StrDyneVec);
protected
procedure AdjustConstraints; override;
procedure Compute; override;
procedure UpdateBtnStates; override;
function Validate(out AMsg: String; out AControl: TWinControl): Boolean; override;
public public
{ public declarations } constructor Create(AOwner: TComponent); override;
procedure Reset; override;
end; end;
var var
WithinANOVAFrm: TWithinANOVAFrm; WithinANOVAFrm: TWithinANOVAFrm;
implementation implementation
{$R *.lfm}
uses uses
MathUnit; TAChartUtils, TACustomSeries,
GridProcs,
Utils, MathUnit, ChartFrameUnit;
{ TWithinANOVAFrm } { TWithinANOVAFrm }
procedure TWithinANOVAFrm.ResetBtnClick(Sender: TObject); constructor TWithinANOVAFrm.Create(AOwner: TComponent);
VAR
i: integer;
begin begin
VarList.Clear; inherited;
SelList.Clear;
PlotChk.Checked := false; FReliabilityReportFrame := TReportFrame.Create(self);
RelChk.Checked := false; FReliabilityReportFrame.Name := '';
AssumpChk.Checked := false; FReliabilityReportFrame.Parent := ReliabilityPage;
for i := 1 to NoVariables do FReliabilityReportFrame.Align := alClient;
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]); FReliabilityReportFrame.BorderSpacing.Left := 0;
UpdateBtnStates; FReliabilityReportFrame.BorderSpacing.Top := 0;
FReliabilityReportFrame.BorderSpacing.Bottom := 0;
FReliabilityReportFrame.BorderSpacing.Right := 0;
FTestAssumptionsReportFrame := TReportFrame.Create(self);
FTestAssumptionsReportFrame.Name := '';
FTestAssumptionsReportFrame.Parent := TestAssumptionsPage;
FTestAssumptionsReportFrame.Align := alClient;
FTestAssumptionsReportFrame.BorderSpacing.Left := 0;
FTestAssumptionsReportFrame.BorderSpacing.Top := 0;
FTestAssumptionsReportFrame.BorderSpacing.Bottom := 0;
FTestAssumptionsReportFrame.BorderSpacing.Right := 0;
FChartFrame.Chart.Margins.Bottom := 0;
PageControl.ActivePageIndex := 0;
end; end;
procedure TWithinANOVAFrm.FormActivate(Sender: TObject);
var procedure TWithinANOVAFrm.AdjustConstraints;
w: Integer;
begin begin
if FAutoSized then inherited;
exit;
w := MaxValue([HelpBtn.Width, ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]); ParamsPanel.Constraints.MinWidth := Max(
HelpBtn.Constraints.MinWidth := w; 4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left,
ResetBtn.Constraints.MinWidth := w; GroupBox1.Width
ComputeBtn.Constraints.MinWidth := w; );
CloseBtn.Constraints.MinWidth := w; ParamsPanel.Constraints.MinHeight := OutBtn.Top + 6*OutBtn.Height +
VarList.BorderSpacing.Bottom + GroupBox1.Height + ButtonBevel.Height +
Constraints.MinWidth := Width; CloseBtn.BorderSpacing.Top + CloseBtn.Height;
Constraints.MinHeight := Height;
FAutoSized := True;
end; end;
procedure TWithinANOVAFrm.FormCreate(Sender: TObject);
begin
Assert(OS3MainFrm <> nil);
if GraphFrm = nil then
Application.CreateForm(TGraphFrm, GraphFrm);
end;
procedure TWithinANOVAFrm.FormShow(Sender: TObject); procedure TWithinANOVAFrm.Compute;
begin
ResetBtnClick(self);
end;
procedure TWithinANOVAFrm.HelpBtnClick(Sender: TObject);
begin
if ContextHelpForm = nil then
Application.CreateForm(TContextHelpForm, ContextHelpForm);
ContextHelpForm.HelpMessage((Sender as TButton).tag);
end;
procedure TWithinANOVAFrm.ComputeBtnClick(Sender: TObject);
var var
i, j, k, f3: integer; i, j, k, f3: integer;
LabelStr: string;
NoSelected, count, row: integer; NoSelected, count, row: integer;
SSrows, SScols, SSwrows, SSerr, SStot: double; SSrows, SScols, SSwrows, SSerr, SStot: double;
MSrows, MScols, MSwrows, MSerr, MStot: double; MSrows, MScols, MSwrows, MSerr, MStot: double;
dfrows, dfcols, dfwrows, dferr, dftot: double; dfrows, dfcols, dfwrows, dferr, dftot: double;
f1, probf1, GrandMean, Term1, Term2, Term3, Term4: double; f1, probf1, GrandMean, Term1, Term2, Term3, Term4: double;
r1, r2, r3, r4, X, avgvar, avgcov: double; r1, r2, r3, r4, X, XSq, avgvar, avgcov: double;
determ1, determ2, M2, C2, chi2, prob: double; determ1, determ2, M2, C2, chi2, prob: double;
errorfound: boolean; errorfound: boolean;
Selected: IntDyneVec; Selected: IntDyneVec = nil;
ColLabels: StrDyneVec; ColLabels: StrDyneVec = nil;
ColMeans, ColVar, RowMeans, RowVar, ColStdDev: DblDyneVec; ColMeans: DblDyneVec = nil;
varcovmat, vcmat, workmat: DblDyneMat; ColVar: DblDyneVec = nil;
RowMeans: DblDyneVec = nil;
RowVar: DblDyneVec = nil;
ColStdDev: DblDyneVec = nil;
varcovmat: DblDyneMat = nil;
vcmat: dblDyneMat = nil;
workmat: DblDyneMat = nil;
title: string; title: string;
lReport: TStrings; lReport: TStrings;
begin begin
if SelList.Items.Count = 0 then
begin
MessageDlg('No variables selected.', mtError, [mbOK], 0);
exit;
end;
if SelList.Items.Count = 1 then
begin
MessageDlg('At least two variables must be selected.', mtError, [mbOK], 0);
exit;
end;
errorfound := false; errorfound := false;
NoSelected := SelList.Items.Count; NoSelected := SelList.Items.Count;
Caption := IntToStr(NoSelected);
SetLength(Selected,NoSelected); SetLength(Selected, NoSelected);
SetLength(ColLabels,NoSelected); SetLength(ColLabels, NoSelected);
SetLength(ColMeans,NoSelected); SetLength(ColMeans, NoSelected);
SetLength(ColVar,NoSelected); SetLength(ColVar, NoSelected);
SetLength(RowMeans,NoCases); SetLength(RowMeans, NoCases);
SetLength(RowVar,NoCases); SetLength(RowVar, NoCases);
for i := 0 to NoSelected - 1 do for i := 0 to NoSelected - 1 do
begin begin
LabelStr := SelList.Items[i]; Selected[i] := GetVariableIndex(OS3MainFrm.DataGrid, SelList.Items[i]);
for j := 1 to NoVariables do ColLabels[i] := SelList.Items[i];
if LabelStr = OS3MainFrm.DataGrid.Cells[j, 0] then
begin
Selected[i] := j;
ColLabels[i] := labelStr;
break;
end;
end; end;
// Initialize values // Initialize values
@ -188,28 +173,31 @@ begin
row := 0; row := 0;
for i := 1 to NoCases do for i := 1 to NoCases do
begin begin
if not GoodRecord(i,NoSelected,Selected) then continue; if not GoodRecord(OS3MainFrm.DataGrid, i, Selected) then continue;
count := count + 1; count := count + 1;
for j := 1 to NoSelected do for j := 1 to NoSelected do
begin begin
k := Selected[j-1]; k := Selected[j-1];
X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[k,i])); X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[k,i]));
Xsq := X*X;
RowMeans[row] := RowMeans[row] + X; RowMeans[row] := RowMeans[row] + X;
RowVar[row] := RowVar[row] + (X * X); RowVar[row] := RowVar[row] + Xsq;
ColMeans[j-1] := ColMeans[j-1] + X; ColMeans[j-1] := ColMeans[j-1] + X;
ColVar[j-1] := ColVar[j-1] + (X * X); ColVar[j-1] := ColVar[j-1] + Xsq;
GrandMean := GrandMean + X; GrandMean := GrandMean + X;
SStot := SStot + (X * X); SStot := SStot + XSq;
end; end;
row := row + 1; row := row + 1;
end; end;
// Calculate ANOVA results // Calculate ANOVA results
Term1 := (GrandMean * GrandMean) / (count * NoSelected); Term1 := sqr(GrandMean) / (count * NoSelected);
Term2 := SStot; Term2 := SStot;
for i := 1 to count do SSrows := SSrows + (RowMeans[i-1] * RowMeans[i-1]); for i := 0 to count-1 do
SSrows := SSrows + sqr(RowMeans[i]);
Term4 := SSrows / NoSelected; Term4 := SSrows / NoSelected;
for i := 1 to NoSelected do SScols := SScols + (ColMeans[i-1] * ColMeans[i-1]); for i := 0 to NoSelected-1 do
SScols := SScols + sqr(ColMeans[i]);
Term3 := SScols / count; Term3 := SScols / count;
SSrows := Term4 - Term1; SSrows := Term4 - Term1;
SScols := Term3 - Term1; SScols := Term3 - Term1;
@ -258,9 +246,9 @@ begin
lReport := TStringList.Create; lReport := TStringList.Create;
try try
// print results // print results
lReport.Add('Treatments by Subjects (AxS) ANOVA Results.'); lReport.Add('TREATMENTS BY SUBJECTS (AxS) ANOVA RESULTS');
lReport.Add(''); lReport.Add('');
lReport.Add('Data File = ' + OS3MainFrm.FileNameEdit.Text); lReport.Add('Data File: ' + OS3MainFrm.FileNameEdit.Text);
lReport.Add(''); lReport.Add('');
lReport.Add(''); lReport.Add('');
lReport.Add('-----------------------------------------------------------'); lReport.Add('-----------------------------------------------------------');
@ -276,27 +264,31 @@ begin
lReport.Add(''); lReport.Add('');
lReport.Add(''); lReport.Add('');
lReport.Add('TREATMENT (COLUMN) MEANS AND STANDARD DEVIATIONS'); lReport.Add('TREATMENT (COLUMN) MEANS AND STANDARD DEVIATIONS');
lReport.Add('VARIABLE MEAN STD.DEV.'); lReport.Add('VARIABLE MEAN STD.DEV. ');
lReport.Add('-------- ---------- ----------');
for i := 1 to NoSelected do for i := 1 to NoSelected do
lReport.Add('%-8s%10.3f%10.3f', [ColLabels[i-1], ColMeans[i-1], sqrt(ColVar[i-1])]); lReport.Add('%-8s %10.3f %10.3f', [ColLabels[i-1], ColMeans[i-1], sqrt(ColVar[i-1])]);
lReport.Add('');
lReport.Add('Mean of all scores = %.3f with standard deviation = %.3f', [GrandMean, sqrt(MStot)]);
lReport.Add('');
lReport.Add(''); lReport.Add('');
lReport.Add('Mean of all scores: %8.3f', [GrandMean]);
lReport.Add(' with standard deviation: %8.3f', [sqrt(MStot)]);
FReportFrame.DisplayReport(lReport);
// Do reliability estimates if requested // Do reliability estimates if requested
if RelChk.Checked then if RelChk.Checked then
begin begin
lReport.Clear;
lReport.Add('RELIABILITY ESTIMATES'); lReport.Add('RELIABILITY ESTIMATES');
lReport.Add(''); lReport.Add('');
lReport.Add('TYPE OF ESTIMATE VALUE'); lReport.Add('TYPE OF ESTIMATE VALUE ');
lReport.Add('---------------------------- -------');
lReport.Add('Unadjusted total reliability %7.3f', [r1]); lReport.Add('Unadjusted total reliability %7.3f', [r1]);
lReport.Add('Unadjusted item reliability %7.3f', [r2]); lReport.Add('Unadjusted item reliability %7.3f', [r2]);
lReport.Add('Adjusted total (Cronbach) %7.3f', [r3]); lReport.Add('Adjusted total (Cronbach) %7.3f', [r3]);
lReport.Add('Adjusted item reliability %7.3f', [r4]); lReport.Add('Adjusted item reliability %7.3f', [r4]);
lReport.Add(''); FReliabilityReportFrame.DisplayReport(lReport);
lReport.Add('');
end; end;
ReliabilityPage.TabVisible := RelChk.Checked;
// Test assumptions of variance - covariance homogeneity if requested // Test assumptions of variance - covariance homogeneity if requested
if AssumpChk.Checked then if AssumpChk.Checked then
@ -307,13 +299,14 @@ begin
SetLength(ColStdDev,NoSelected); SetLength(ColStdDev,NoSelected);
errorfound := false; errorfound := false;
count := NoCases; count := NoCases;
lReport.Clear;
lReport.Add('BOX TEST FOR HOMOGENEITY OF VARIANCE-COVARIANCE MATRIX'); lReport.Add('BOX TEST FOR HOMOGENEITY OF VARIANCE-COVARIANCE MATRIX');
lReport.Add(''); lReport.Add('');
GridCovar(NoSelected, Selected, varcovmat, ColMeans, ColVar, ColStdDev, errorfound, count); GridCovar(NoSelected, Selected, varcovmat, ColMeans, ColVar, ColStdDev, errorfound, count);
title := 'SAMPLE COVARIANCE MATRIX'; title := 'SAMPLE COVARIANCE MATRIX';
MatPrint(varcovmat, NoSelected, NoSelected, title, ColLabels, ColLabels, NoCases, lReport); MatPrint(varcovmat, NoSelected, NoSelected, title, ColLabels, ColLabels, NoCases, lReport);
if errorfound then if errorfound then
MessageDlg('Zero variance found for a variable.', mtError, [mbOK], 0); ErrorMsg('Zero variance found for a variable.');
// get average of variances into workmat diagonal and average of // get average of variances into workmat diagonal and average of
// covariances into workmat off-diagonals (See Winer, pg 371) // covariances into workmat off-diagonals (See Winer, pg 371)
@ -368,7 +361,7 @@ begin
begin begin
M2 := 0.0; M2 := 0.0;
errorfound := true; errorfound := true;
MessageDlg('A determinant <= zero was found.', mtError, [mbOK], 0); ErrorMsg('A determinant <= zero was found.');
end; end;
if not errorfound then if not errorfound then
begin begin
@ -384,69 +377,37 @@ begin
if chi2 >= 1000.0 then prob := 0.0; if chi2 >= 1000.0 then prob := 0.0;
end; end;
end; end;
title := 'ASSUMED POP. COVARIANCE MATRIX'; title := 'ASSUMED POP. COVARIANCE MATRIX';
for i := 0 to NoSelected-1 do for i := 0 to NoSelected-1 do
for j := 0 to NoSelected-1 do for j := 0 to NoSelected-1 do
varcovmat[i,j] := workmat[i,j]; varcovmat[i,j] := workmat[i,j];
MatPrint(varcovmat, NoSelected, NoSelected, title, ColLabels, ColLabels, NoCases, lReport); MatPrint(varcovmat, NoSelected, NoSelected, title, ColLabels, ColLabels, NoCases, lReport);
lReport.Add('Determinant of variance-covariance matrix = %10.3g', [determ1]); lReport.Add('Determinant of variance-covariance matrix: %10.3g', [determ1]);
lReport.Add('Determinant of homogeneity matrix = %10.3g', [determ2]); lReport.Add('Determinant of homogeneity matrix: %10.3g', [determ2]);
if not errorfound then if not errorfound then
begin begin
lReport.Add('ChiSquare = %10.3f with %3d degrees of freedom', [chi2,f3]); lReport.Add('ChiSquare: %10.3f', [chi2]);
lReport.Add('Probability of larger chisquare = %6.3g', [1.0-prob]); lReport.Add(' with %d degrees of freedom', [f3]);
lReport.Add('Probability of larger chisquare: %10.3f', [1.0-prob]);
end; end;
end;
DisplayReport(lReport); FTestAssumptionsReportFrame.DisplayReport(lReport);
end;
TestAssumptionsPage.TabVisible := AssumpChk.Checked;
finally finally
lReport.Free; lReport.Free;
ColStdDev := nil;
workmat := nil;
vcmat := nil;
varcovmat := nil;
end; end;
{ Now, plot values if indicated in options list } { Finally, plot values if indicated in options list }
if PlotChk.Checked then if PlotChk.Checked then
begin Plot(ColMeans, ColLabels);
SetLength(GraphFrm.Xpoints,1,NoSelected); ChartPage.TabVisible := PlotChk.Checked;
SetLength(GraphFrm.Ypoints,1,NoSelected); ChartPage.PageIndex := PageControl.PageCount-1;
// use rowvar to hold variable no.
for i := 1 to NoSelected do
begin
rowvar[i-1] := Selected[i-1];
GraphFrm.Xpoints[0,i-1] := Selected[i-1];
GraphFrm.Ypoints[0,i-1] := ColMeans[i-1];
end;
GraphFrm.nosets := 1;
GraphFrm.nbars := NoSelected;
GraphFrm.Heading := 'WITHIN SUBJECTS ANOVA';
GraphFrm.XTitle := 'Repeated Measure Var. No.';
GraphFrm.YTitle := 'Mean';
GraphFrm.barwideprop := 0.5;
GraphFrm.AutoScaled := true;
GraphFrm.GraphType := 2; // 3d Vertical Bar Chart
GraphFrm.BackColor := clYellow;
GraphFrm.WallColor := clBlack;
GraphFrm.FloorColor := clLtGray;
GraphFrm.ShowBackWall := true;
GraphFrm.ShowModal;
end;
// Clean-up
RowVar := nil;
RowMeans := nil;
ColVar := nil;
ColMeans := nil;
ColLabels := nil;
GraphFrm.Xpoints := nil;
GraphFrm.Ypoints := nil;
Selected := nil;
end; end;
procedure TWithinANOVAFrm.InBtnClick(Sender: TObject); procedure TWithinANOVAFrm.InBtnClick(Sender: TObject);
var var
i: integer; i: integer;
@ -465,6 +426,7 @@ begin
UpdateBtnStates; UpdateBtnStates;
end; end;
procedure TWithinANOVAFrm.OutBtnClick(Sender: TObject); procedure TWithinANOVAFrm.OutBtnClick(Sender: TObject);
var var
i: integer; i: integer;
@ -485,11 +447,77 @@ begin
UpdateBtnStates; UpdateBtnStates;
end; end;
procedure TWithinANOVAFrm.Plot(ColMeans: DblDyneVec; ColLabels: StrDyneVec);
var
ser: TChartSeries;
begin
FChartFrame.Clear;
FChartFrame.SetTitle('WITHIN SUBJECTS ANOVA');
FChartFrame.SetXTitle('Repeated Measure Variables');
FChartFrame.SetYTitle('Mean');
ser := FChartFrame.PlotXY(ptBars, nil, ColMeans, ColLabels, nil, '', DATA_COLORS[0]);
FChartFrame.Chart.BottomAxis.Marks.Source := ser.Source;
FChartFrame.Chart.BottomAxis.Marks.Style := smsLabel;
FChartFrame.Chart.Legend.Visible := false;
end;
procedure TWithinANOVAFrm.Reset;
var
i: integer;
begin
inherited;
if FReliabilityReportFrame <> nil then
FReliabilityReportFrame.Clear;
if FTestAssumptionsReportFrame <> nil then
FTestAssumptionsReportFrame.Clear;
VarList.Clear;
SelList.Clear;
PlotChk.Checked := false;
RelChk.Checked := false;
AssumpChk.Checked := false;
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
ReliabilityPage.TabVisible := false;
TestAssumptionsPage.TabVisible := false;
ChartPage.TabVisible := false;
UpdateBtnStates;
end;
procedure TWithinANOVAFrm.SelListDblClick(Sender: TObject);
var
index: Integer;
begin
index := SelList.ItemIndex;
if index > -1 then
begin
VarList.Items.Add(SelList.Items[index]);
SelList.Items.Delete(index);
UpdateBtnStates;
end;
end;
procedure TWithinANOVAFrm.UpdateBtnStates; procedure TWithinANOVAFrm.UpdateBtnStates;
var var
i: Integer; i: Integer;
lEnabled: Boolean; lEnabled: Boolean;
begin begin
inherited;
if FReliabilityReportFrame <> nil then
FReliabilityReportFrame.UpdateBtnStates;
if FTestAssumptionsReportFrame <> nil then
FTestAssumptionsReportFrame.UpdateBtnStates;
lEnabled := false; lEnabled := false;
for i:=0 to VarList.Items.Count-1 do for i:=0 to VarList.Items.Count-1 do
if VarList.Selected[i] then if VarList.Selected[i] then
@ -509,6 +537,42 @@ begin
OutBtn.Enabled := lEnabled; OutBtn.Enabled := lEnabled;
end; end;
function TWithinANOVAFrm.Validate(out AMsg: String; out AControl: TWinControl): Boolean;
begin
Result := false;
if SelList.Items.Count = 0 then
begin
AControl := VarList;
AMsg := 'No variables selected.';
exit;
end;
if SelList.Items.Count = 1 then
begin
AControl := VarList;
AMsg := 'At least two variables must be selected.';
exit;
end;
Result := true;
end;
procedure TWithinANOVAFrm.VarListDblClick(Sender: TObject);
var
index: Integer;
begin
index := VarList.ItemIndex;
if index > -1 then
begin
SelList.Items.Add(VarList.Items[index]);
VarList.Items.Delete(index);
UpdateBtnStates;
end;
end;
procedure TWithinANOVAFrm.VarListSelectionChange(Sender: TObject; procedure TWithinANOVAFrm.VarListSelectionChange(Sender: TObject;
User: boolean); User: boolean);
begin begin
@ -516,8 +580,5 @@ begin
end; end;
initialization
{$I withinanovaunit.lrs}
end. end.

View File

@ -42,10 +42,12 @@ begin
inherited; inherited;
FReportFrame := TReportFrame.Create(self); FReportFrame := TReportFrame.Create(self);
FReportFrame.Name := '';
FReportFrame.Parent := ReportPage; FReportFrame.Parent := ReportPage;
FReportFrame.Align := alClient; FReportFrame.Align := alClient;
FChartFrame := TChartFrame.Create(self); FChartFrame := TChartFrame.Create(self);
FChartFrame.Name := '';
FChartFrame.Parent := ChartPage; FChartFrame.Parent := ChartPage;
FChartFrame.Align := alClient; FChartFrame.Align := alClient;
FChartFrame.Chart.BottomAxis.Intervals.MaxLength := 80; FChartFrame.Chart.BottomAxis.Intervals.MaxLength := 80;