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,86 +1,106 @@
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
end
inherited ComputeBtn: TButton
Left = 149
Top = 288
TabOrder = 7
end
inherited ResetBtn: TButton
Left = 87
Top = 288
TabOrder = 6
end
inherited HelpBtn: TButton
Left = 28
Top = 288
TabOrder = 5
end
inherited ButtonBevel: TBevel
Top = 272
Width = 288
end
object Label1: TLabel[5]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = ParamsPanel
Left = 0
Height = 15 Height = 15
Top = 8 Top = 0
Width = 97 Width = 97
BorderSpacing.Left = 8 BorderSpacing.Right = 6
BorderSpacing.Top = 8
Caption = 'Available Variables' Caption = 'Available Variables'
ParentColor = False ParentColor = False
end end
object Label2: TLabel object Label2: TLabel[6]
AnchorSideLeft.Control = SelList AnchorSideLeft.Control = SelList
AnchorSideTop.Control = Owner AnchorSideTop.Control = ParamsPanel
Left = 251 Left = 163
Height = 15 Height = 15
Top = 8 Top = 0
Width = 96 Width = 96
BorderSpacing.Top = 8
Caption = 'Selected Variables:' Caption = 'Selected Variables:'
ParentColor = False ParentColor = False
end end
object VarList: TListBox object VarList: TListBox[7]
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = Label1 AnchorSideTop.Control = Label1
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = InBtn AnchorSideRight.Control = InBtn
AnchorSideBottom.Control = GroupBox1 AnchorSideBottom.Control = GroupBox1
Left = 8 Left = 0
Height = 229 Height = 177
Top = 25 Top = 17
Width = 199 Width = 125
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Top = 2 BorderSpacing.Top = 2
BorderSpacing.Right = 8 BorderSpacing.Right = 6
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Constraints.MinHeight = 220
ItemHeight = 0 ItemHeight = 0
MultiSelect = True MultiSelect = True
OnDblClick = VarListDblClick
OnSelectionChange = VarListSelectionChange OnSelectionChange = VarListSelectionChange
TabOrder = 0 TabOrder = 0
end end
object InBtn: TBitBtn object InBtn: TBitBtn[8]
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = VarList AnchorSideTop.Control = VarList
Left = 215 Left = 131
Height = 28 Height = 26
Top = 25 Top = 17
Width = 28 Width = 26
Images = MainDataModule.ImageList Images = MainDataModule.ImageList
ImageIndex = 1 ImageIndex = 1
OnClick = InBtnClick OnClick = InBtnClick
Spacing = 0 Spacing = 0
TabOrder = 1 TabOrder = 1
end end
object OutBtn: TBitBtn object OutBtn: TBitBtn[9]
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = InBtn AnchorSideTop.Control = InBtn
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 215 Left = 131
Height = 28 Height = 26
Top = 57 Top = 47
Width = 28 Width = 26
BorderSpacing.Top = 4 BorderSpacing.Top = 4
Images = MainDataModule.ImageList Images = MainDataModule.ImageList
ImageIndex = 0 ImageIndex = 0
@ -88,47 +108,24 @@ object WithinANOVAFrm: TWithinANOVAFrm
Spacing = 0 Spacing = 0
TabOrder = 2 TabOrder = 2
end end
object SelList: TListBox object GroupBox1: TGroupBox[10]
AnchorSideLeft.Control = InBtn AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrBottom AnchorSideBottom.Control = ButtonBevel
AnchorSideTop.Control = Label2 Left = 0
AnchorSideTop.Side = asrBottom Height = 70
AnchorSideRight.Control = Owner Top = 202
AnchorSideRight.Side = asrBottom Width = 251
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] Anchors = [akLeft, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Right = 8 BorderSpacing.Right = 8
Caption = 'Options:' Caption = 'Options:'
ChildSizing.LeftRightSpacing = 12 ChildSizing.LeftRightSpacing = 12
ChildSizing.TopBottomSpacing = 6 ChildSizing.TopBottomSpacing = 6
ChildSizing.HorizontalSpacing = 20 ChildSizing.HorizontalSpacing = 20
ChildSizing.Layout = cclLeftToRightThenTopToBottom ChildSizing.Layout = cclTopToBottomThenLeftToRight
ChildSizing.ControlsPerLine = 3 ChildSizing.ControlsPerLine = 2
ClientHeight = 31 ClientHeight = 50
ClientWidth = 380 ClientWidth = 247
TabOrder = 4 TabOrder = 4
object RelChk: TCheckBox object RelChk: TCheckBox
Left = 12 Left = 12
@ -139,15 +136,15 @@ object WithinANOVAFrm: TWithinANOVAFrm
TabOrder = 0 TabOrder = 0
end end
object AssumpChk: TCheckBox object AssumpChk: TCheckBox
Left = 156 Left = 12
Height = 19 Height = 19
Top = 6 Top = 25
Width = 113 Width = 124
Caption = 'Test Assumptions' Caption = 'Test Assumptions'
TabOrder = 1 TabOrder = 1
end end
object PlotChk: TCheckBox object PlotChk: TCheckBox
Left = 289 Left = 156
Height = 19 Height = 19
Top = 6 Top = 6
Width = 79 Width = 79
@ -155,90 +152,47 @@ object WithinANOVAFrm: TWithinANOVAFrm
TabOrder = 2 TabOrder = 2
end end
end end
object ResetBtn: TButton object SelList: TListBox[11]
AnchorSideRight.Control = ComputeBtn AnchorSideLeft.Control = InBtn
AnchorSideBottom.Control = Owner AnchorSideLeft.Side = asrBottom
AnchorSideBottom.Side = asrBottom AnchorSideTop.Control = Label2
Left = 245 AnchorSideTop.Side = asrBottom
Height = 25 AnchorSideRight.Control = ParamsPanel
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
object ComputeBtn: TButton
AnchorSideRight.Control = CloseBtn
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 307
Height = 25
Top = 329
Width = 76
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 7
end
object CloseBtn: TButton
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner AnchorSideBottom.Control = GroupBox1
AnchorSideBottom.Side = asrBottom Left = 163
Left = 391 Height = 177
Height = 25 Top = 17
Top = 329 Width = 125
Width = 55 Anchors = [akTop, akLeft, akRight, akBottom]
Anchors = [akRight, akBottom] BorderSpacing.Left = 6
AutoSize = True BorderSpacing.Top = 2
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 12
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
Caption = 'Close' ItemHeight = 0
ModalResult = 11 MultiSelect = True
TabOrder = 8 OnDblClick = SelListDblClick
end OnSelectionChange = VarListSelectionChange
object HelpBtn: TButton TabOrder = 3
Tag = 157 end
AnchorSideRight.Control = ResetBtn end
AnchorSideBottom.Control = Owner inherited ParamsSplitter: TSplitter
AnchorSideBottom.Side = asrBottom Left = 300
Left = 186 Height = 329
Height = 25 end
Top = 329 inherited PageControl: TPageControl
Width = 51 Left = 309
Anchors = [akRight, akBottom] Height = 313
AutoSize = True Width = 405
BorderSpacing.Left = 12 inherited ReportPage: TTabSheet
BorderSpacing.Top = 8 Caption = 'ANOVA Results'
BorderSpacing.Right = 8 end
BorderSpacing.Bottom = 8 object ReliabilityPage: TTabSheet[1]
Caption = 'Help' Caption = 'Reliability Estimates'
OnClick = HelpBtnClick end
TabOrder = 5 object TestAssumptionsPage: TTabSheet[2]
end Caption = 'Test Assumptions'
object Bevel1: TBevel end
AnchorSideLeft.Control = Owner inherited ChartPage: TTabSheet[3]
AnchorSideRight.Control = Owner end
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,119 +26,115 @@ 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);
@ -154,14 +145,8 @@ begin
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('-----------------------------------------------------------');
@ -277,26 +265,30 @@ begin
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('');
lReport.Add('Mean of all scores = %.3f with standard deviation = %.3f', [GrandMean, sqrt(MStot)]); lReport.Add('Mean of all scores: %8.3f', [GrandMean]);
lReport.Add(''); lReport.Add(' with standard deviation: %8.3f', [sqrt(MStot)]);
lReport.Add('');
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,68 +377,36 @@ 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]);
end; lReport.Add('Probability of larger chisquare: %10.3f', [1.0-prob]);
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; end;
// Clean-up
RowVar := nil;
RowMeans := nil;
ColVar := nil;
ColMeans := nil;
ColLabels := nil;
GraphFrm.Xpoints := nil;
GraphFrm.Ypoints := nil;
Selected := nil;
end;
procedure TWithinANOVAFrm.InBtnClick(Sender: TObject); procedure TWithinANOVAFrm.InBtnClick(Sender: TObject);
var var
@ -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;