2020-03-30 18:01:44 +00:00
|
|
|
// Use file "itemdata2.laz" for testing
|
|
|
|
|
|
|
|
unit WithinANOVAUnit;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2020-10-22 22:14:06 +00:00
|
|
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
|
|
|
|
StdCtrls, Buttons, ExtCtrls, ComCtrls, Math,
|
|
|
|
MainUnit, FunctionsLib, MatrixLib, Globals,
|
|
|
|
ReportFrameUnit, BasicStatsReportAndChartFormUnit;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TWithinANOVAFrm }
|
|
|
|
|
2020-10-22 22:14:06 +00:00
|
|
|
TWithinANOVAFrm = class(TBasicStatsReportAndChartForm)
|
2020-03-30 18:01:44 +00:00
|
|
|
AssumpChk: TCheckBox;
|
|
|
|
PlotChk: TCheckBox;
|
|
|
|
RelChk: TCheckBox;
|
|
|
|
GroupBox1: TGroupBox;
|
|
|
|
InBtn: TBitBtn;
|
|
|
|
Label2: TLabel;
|
|
|
|
SelList: TListBox;
|
|
|
|
OutBtn: TBitBtn;
|
|
|
|
Label1: TLabel;
|
2020-10-22 22:14:06 +00:00
|
|
|
ReliabilityPage: TTabSheet;
|
|
|
|
TestAssumptionsPage: TTabSheet;
|
2020-03-30 18:01:44 +00:00
|
|
|
VarList: TListBox;
|
|
|
|
procedure InBtnClick(Sender: TObject);
|
|
|
|
procedure OutBtnClick(Sender: TObject);
|
2020-10-22 22:14:06 +00:00
|
|
|
procedure SelListDblClick(Sender: TObject);
|
|
|
|
procedure VarListDblClick(Sender: TObject);
|
|
|
|
procedure VarListSelectionChange(Sender: TObject; {%H-}User: boolean);
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
private
|
2020-10-22 22:14:06 +00:00
|
|
|
FReliabilityReportFrame: TReportFrame;
|
|
|
|
FTestAssumptionsReportFrame: TReportFrame;
|
|
|
|
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;
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
public
|
2020-10-22 22:14:06 +00:00
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
procedure Reset; override;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
WithinANOVAFrm: TWithinANOVAFrm;
|
|
|
|
|
2020-10-22 22:14:06 +00:00
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
implementation
|
|
|
|
|
2020-10-22 22:14:06 +00:00
|
|
|
{$R *.lfm}
|
|
|
|
|
2020-09-28 14:05:34 +00:00
|
|
|
uses
|
2020-10-22 22:14:06 +00:00
|
|
|
TAChartUtils, TACustomSeries,
|
|
|
|
GridProcs,
|
|
|
|
Utils, MathUnit, ChartFrameUnit;
|
2020-09-28 14:05:34 +00:00
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-10-22 22:14:06 +00:00
|
|
|
{ TWithinANOVAFrm }
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-10-22 22:14:06 +00:00
|
|
|
constructor TWithinANOVAFrm.Create(AOwner: TComponent);
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-10-22 22:14:06 +00:00
|
|
|
inherited;
|
|
|
|
|
|
|
|
FReliabilityReportFrame := TReportFrame.Create(self);
|
|
|
|
FReliabilityReportFrame.Name := '';
|
|
|
|
FReliabilityReportFrame.Parent := ReliabilityPage;
|
|
|
|
FReliabilityReportFrame.Align := alClient;
|
|
|
|
FReliabilityReportFrame.BorderSpacing.Left := 0;
|
|
|
|
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;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-10-22 22:14:06 +00:00
|
|
|
procedure TWithinANOVAFrm.AdjustConstraints;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-10-22 22:14:06 +00:00
|
|
|
inherited;
|
|
|
|
|
|
|
|
ParamsPanel.Constraints.MinWidth := Max(
|
|
|
|
4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left,
|
|
|
|
GroupBox1.Width
|
|
|
|
);
|
|
|
|
ParamsPanel.Constraints.MinHeight := OutBtn.Top + 6*OutBtn.Height +
|
|
|
|
VarList.BorderSpacing.Bottom + GroupBox1.Height + ButtonBevel.Height +
|
|
|
|
CloseBtn.BorderSpacing.Top + CloseBtn.Height;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-10-22 22:14:06 +00:00
|
|
|
procedure TWithinANOVAFrm.Compute;
|
2020-03-30 18:01:44 +00:00
|
|
|
var
|
|
|
|
i, j, k, f3: integer;
|
|
|
|
NoSelected, count, row: integer;
|
|
|
|
SSrows, SScols, SSwrows, SSerr, SStot: double;
|
|
|
|
MSrows, MScols, MSwrows, MSerr, MStot: double;
|
|
|
|
dfrows, dfcols, dfwrows, dferr, dftot: double;
|
2020-04-21 20:45:15 +00:00
|
|
|
f1, probf1, GrandMean, Term1, Term2, Term3, Term4: double;
|
2020-10-22 22:14:06 +00:00
|
|
|
r1, r2, r3, r4, X, XSq, avgvar, avgcov: double;
|
2020-03-30 18:01:44 +00:00
|
|
|
determ1, determ2, M2, C2, chi2, prob: double;
|
|
|
|
errorfound: boolean;
|
2020-10-22 22:14:06 +00:00
|
|
|
Selected: IntDyneVec = nil;
|
|
|
|
ColLabels: StrDyneVec = nil;
|
|
|
|
ColMeans: DblDyneVec = nil;
|
|
|
|
ColVar: DblDyneVec = nil;
|
|
|
|
RowMeans: DblDyneVec = nil;
|
|
|
|
RowVar: DblDyneVec = nil;
|
|
|
|
ColStdDev: DblDyneVec = nil;
|
|
|
|
varcovmat: DblDyneMat = nil;
|
|
|
|
vcmat: dblDyneMat = nil;
|
|
|
|
workmat: DblDyneMat = nil;
|
2020-03-30 18:01:44 +00:00
|
|
|
title: string;
|
|
|
|
lReport: TStrings;
|
|
|
|
begin
|
|
|
|
errorfound := false;
|
|
|
|
NoSelected := SelList.Items.Count;
|
|
|
|
|
2020-10-22 22:14:06 +00:00
|
|
|
SetLength(Selected, NoSelected);
|
|
|
|
SetLength(ColLabels, NoSelected);
|
|
|
|
SetLength(ColMeans, NoSelected);
|
|
|
|
SetLength(ColVar, NoSelected);
|
|
|
|
SetLength(RowMeans, NoCases);
|
|
|
|
SetLength(RowVar, NoCases);
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
for i := 0 to NoSelected - 1 do
|
|
|
|
begin
|
2020-10-22 22:14:06 +00:00
|
|
|
Selected[i] := GetVariableIndex(OS3MainFrm.DataGrid, SelList.Items[i]);
|
|
|
|
ColLabels[i] := SelList.Items[i];
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
// Initialize values
|
|
|
|
SScols := 0.0;
|
|
|
|
SSrows := 0.0;
|
|
|
|
SStot := 0.0;
|
|
|
|
dfwrows := 0.0;
|
|
|
|
dftot := 0.0;
|
|
|
|
GrandMean := 0.0;
|
|
|
|
count := 0;
|
|
|
|
|
|
|
|
for i := 0 to NoSelected-1 do
|
|
|
|
begin
|
|
|
|
ColMeans[i] := 0.0;
|
|
|
|
ColVar[i] := 0.0;
|
|
|
|
end;
|
|
|
|
for j := 0 to NoCases-1 do
|
|
|
|
begin
|
|
|
|
RowMeans[j] := 0.0;
|
|
|
|
RowVar[j] := 0.0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
// Read data and compute sums while reading
|
|
|
|
row := 0;
|
|
|
|
for i := 1 to NoCases do
|
|
|
|
begin
|
2020-10-22 22:14:06 +00:00
|
|
|
if not GoodRecord(OS3MainFrm.DataGrid, i, Selected) then continue;
|
2020-03-30 18:01:44 +00:00
|
|
|
count := count + 1;
|
|
|
|
for j := 1 to NoSelected do
|
|
|
|
begin
|
|
|
|
k := Selected[j-1];
|
|
|
|
X := StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[k,i]));
|
2020-10-22 22:14:06 +00:00
|
|
|
Xsq := X*X;
|
2020-03-30 18:01:44 +00:00
|
|
|
RowMeans[row] := RowMeans[row] + X;
|
2020-10-22 22:14:06 +00:00
|
|
|
RowVar[row] := RowVar[row] + Xsq;
|
2020-03-30 18:01:44 +00:00
|
|
|
ColMeans[j-1] := ColMeans[j-1] + X;
|
2020-10-22 22:14:06 +00:00
|
|
|
ColVar[j-1] := ColVar[j-1] + Xsq;
|
2020-03-30 18:01:44 +00:00
|
|
|
GrandMean := GrandMean + X;
|
2020-10-22 22:14:06 +00:00
|
|
|
SStot := SStot + XSq;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
row := row + 1;
|
|
|
|
end;
|
|
|
|
|
|
|
|
// Calculate ANOVA results
|
2020-10-22 22:14:06 +00:00
|
|
|
Term1 := sqr(GrandMean) / (count * NoSelected);
|
2020-03-30 18:01:44 +00:00
|
|
|
Term2 := SStot;
|
2020-10-22 22:14:06 +00:00
|
|
|
for i := 0 to count-1 do
|
|
|
|
SSrows := SSrows + sqr(RowMeans[i]);
|
2020-03-30 18:01:44 +00:00
|
|
|
Term4 := SSrows / NoSelected;
|
2020-10-22 22:14:06 +00:00
|
|
|
for i := 0 to NoSelected-1 do
|
|
|
|
SScols := SScols + sqr(ColMeans[i]);
|
2020-03-30 18:01:44 +00:00
|
|
|
Term3 := SScols / count;
|
|
|
|
SSrows := Term4 - Term1;
|
|
|
|
SScols := Term3 - Term1;
|
|
|
|
SSwrows := Term2 - Term4;
|
|
|
|
SSerr := Term2 - Term3 - Term4 + Term1;
|
|
|
|
SStot := Term2 - Term1;
|
|
|
|
dfrows := count - 1;
|
|
|
|
dfcols := NoSelected - 1;
|
|
|
|
dfwrows := count * (NoSelected - 1);
|
|
|
|
dferr := (count - 1) * (NoSelected - 1);
|
|
|
|
dftot := (count * NoSelected) - 1;
|
|
|
|
MSrows := SSrows / dfrows;
|
|
|
|
MScols := SScols / dfcols;
|
|
|
|
MSwrows := SSwrows / dfwrows;
|
|
|
|
MSerr := SSerr / dferr;
|
|
|
|
MStot := SStot / dftot; // variance of all scores
|
|
|
|
GrandMean := GrandMean / (count * NoSelected);
|
|
|
|
for i := 0 to count-1 do
|
|
|
|
begin
|
|
|
|
RowVar[i] := RowVar[i] - (RowMeans[i] * RowMeans[i] / NoSelected);
|
|
|
|
RowVar[i] := RowVar[i] / (NoSelected - 1);
|
|
|
|
RowMeans[i] := RowMeans[i] / NoSelected;
|
|
|
|
end;
|
|
|
|
for i := 0 to NoSelected-1 do
|
|
|
|
begin
|
|
|
|
ColVar[i] := ColVar[i] - (ColMeans[i] * ColMeans[i] / count);
|
|
|
|
ColVar[i] := ColVar[i] / (count - 1);
|
|
|
|
ColMeans[i] := ColMeans[i] / count;
|
|
|
|
end;
|
|
|
|
f1 := MScols / MSerr; // treatment F statistic
|
2020-09-28 14:05:34 +00:00
|
|
|
probf1 := ProbF(f1, dfcols, dferr);
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
// Do reliability terms if requested
|
|
|
|
if RelChk.Checked then
|
|
|
|
begin
|
|
|
|
r1 := 1.0 - (MSwrows / MSrows); // unadjusted reliability of test
|
|
|
|
r2 := (MSrows - MSwrows) / (MSrows + (NoSelected - 1) * MSwrows);
|
|
|
|
// r2 is unadjusted reliability of a single item
|
|
|
|
r3 := (MSrows - MSerr) / MSrows; // Cronbach alpha for test
|
|
|
|
r4 := (MSrows - MSerr) / (MSrows + (NoSelected - 1) * MSerr);
|
|
|
|
// r4 is adjusted reliability of a single item
|
|
|
|
end;
|
|
|
|
|
|
|
|
// do homogeneity of variance and covariance checks if requested
|
|
|
|
|
|
|
|
lReport := TStringList.Create;
|
|
|
|
try
|
|
|
|
// print results
|
2020-10-22 22:14:06 +00:00
|
|
|
lReport.Add('TREATMENTS BY SUBJECTS (AxS) ANOVA RESULTS');
|
2020-03-30 18:01:44 +00:00
|
|
|
lReport.Add('');
|
2020-10-22 22:14:06 +00:00
|
|
|
lReport.Add('Data File: ' + OS3MainFrm.FileNameEdit.Text);
|
2020-03-30 18:01:44 +00:00
|
|
|
lReport.Add('');
|
|
|
|
lReport.Add('');
|
|
|
|
lReport.Add('-----------------------------------------------------------');
|
|
|
|
lReport.Add('SOURCE DF SS MS F Prob. > F');
|
|
|
|
lReport.Add('-----------------------------------------------------------');
|
|
|
|
lReport.Add('SUBJECTS %4.0f%10.3f%10.3f', [dfrows, SSrows, MSrows]);
|
|
|
|
lReport.Add('WITHIN SUBJECTS%4.0f%10.3f%10.3f', [dfwrows, SSwrows, MSwrows]);
|
|
|
|
lReport.Add(' TREATMENTS %4.0f%10.3f%10.3f%10.3f%10.3f', [dfcols, SScols, MScols, f1, probf1]);
|
|
|
|
lReport.Add(' RESIDUAL %4.0f%10.3f%10.3f', [dferr, SSerr, MSerr]);
|
|
|
|
lReport.Add('-----------------------------------------------------------');
|
|
|
|
lReport.Add('TOTAL %4.0f%10.3f%10.3f', [dftot, SStot, MStot]);
|
|
|
|
lReport.Add('-----------------------------------------------------------');
|
|
|
|
lReport.Add('');
|
|
|
|
lReport.Add('');
|
|
|
|
lReport.Add('TREATMENT (COLUMN) MEANS AND STANDARD DEVIATIONS');
|
2020-10-22 22:14:06 +00:00
|
|
|
lReport.Add('VARIABLE MEAN STD.DEV. ');
|
|
|
|
lReport.Add('-------- ---------- ----------');
|
2020-03-30 18:01:44 +00:00
|
|
|
for i := 1 to NoSelected do
|
2020-10-22 22:14:06 +00:00
|
|
|
lReport.Add('%-8s %10.3f %10.3f', [ColLabels[i-1], ColMeans[i-1], sqrt(ColVar[i-1])]);
|
2020-03-30 18:01:44 +00:00
|
|
|
lReport.Add('');
|
2020-10-22 22:14:06 +00:00
|
|
|
lReport.Add('Mean of all scores: %8.3f', [GrandMean]);
|
|
|
|
lReport.Add(' with standard deviation: %8.3f', [sqrt(MStot)]);
|
|
|
|
|
|
|
|
FReportFrame.DisplayReport(lReport);
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
// Do reliability estimates if requested
|
|
|
|
if RelChk.Checked then
|
|
|
|
begin
|
2020-10-22 22:14:06 +00:00
|
|
|
lReport.Clear;
|
2020-03-30 18:01:44 +00:00
|
|
|
lReport.Add('RELIABILITY ESTIMATES');
|
|
|
|
lReport.Add('');
|
2020-10-22 22:14:06 +00:00
|
|
|
lReport.Add('TYPE OF ESTIMATE VALUE ');
|
|
|
|
lReport.Add('---------------------------- -------');
|
2020-03-30 18:01:44 +00:00
|
|
|
lReport.Add('Unadjusted total reliability %7.3f', [r1]);
|
|
|
|
lReport.Add('Unadjusted item reliability %7.3f', [r2]);
|
|
|
|
lReport.Add('Adjusted total (Cronbach) %7.3f', [r3]);
|
|
|
|
lReport.Add('Adjusted item reliability %7.3f', [r4]);
|
2020-10-22 22:14:06 +00:00
|
|
|
FReliabilityReportFrame.DisplayReport(lReport);
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
2020-10-22 22:14:06 +00:00
|
|
|
ReliabilityPage.TabVisible := RelChk.Checked;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
// Test assumptions of variance - covariance homogeneity if requested
|
|
|
|
if AssumpChk.Checked then
|
|
|
|
begin
|
|
|
|
SetLength(varcovmat,NoSelected+1,NoSelected+1);
|
|
|
|
SetLength(vcmat,NoSelected+1,NoSelected+1);
|
|
|
|
SetLength(workmat,NoSelected+1,NoSelected+1);
|
|
|
|
SetLength(ColStdDev,NoSelected);
|
|
|
|
errorfound := false;
|
|
|
|
count := NoCases;
|
2020-10-22 22:14:06 +00:00
|
|
|
lReport.Clear;
|
2020-03-30 18:01:44 +00:00
|
|
|
lReport.Add('BOX TEST FOR HOMOGENEITY OF VARIANCE-COVARIANCE MATRIX');
|
|
|
|
lReport.Add('');
|
|
|
|
GridCovar(NoSelected, Selected, varcovmat, ColMeans, ColVar, ColStdDev, errorfound, count);
|
|
|
|
title := 'SAMPLE COVARIANCE MATRIX';
|
|
|
|
MatPrint(varcovmat, NoSelected, NoSelected, title, ColLabels, ColLabels, NoCases, lReport);
|
|
|
|
if errorfound then
|
2020-10-22 22:14:06 +00:00
|
|
|
ErrorMsg('Zero variance found for a variable.');
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
// get average of variances into workmat diagonal and average of
|
|
|
|
// covariances into workmat off-diagonals (See Winer, pg 371)
|
|
|
|
avgvar := 0.0;
|
|
|
|
avgcov := 0.0;
|
|
|
|
for i := 0 to NoSelected-1 do
|
|
|
|
vcmat[i,i] := varcovmat[i,i];
|
|
|
|
for i := 0 to NoSelected-2 do
|
|
|
|
begin
|
|
|
|
for j := i+1 to NoSelected-1 do
|
|
|
|
begin
|
|
|
|
vcmat[i,j] := varcovmat[i,j];
|
|
|
|
vcmat[j,i] := vcmat[i,j];
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
for i := 0 to NoSelected-1 do
|
|
|
|
avgvar := avgvar + varcovmat[i,i];
|
|
|
|
for i := 0 to NoSelected-2 do
|
|
|
|
for j := i+1 to NoSelected-1 do
|
|
|
|
avgcov := avgcov + varcovmat[i,j];
|
|
|
|
avgvar := avgvar / NoSelected;
|
|
|
|
avgcov := avgcov / (NoSelected * NoSelected - 1) / 2.0;
|
|
|
|
for i := 0 to NoSelected-1 do
|
|
|
|
workmat[i,i] := avgvar;
|
|
|
|
for i := 0 to NoSelected-2 do
|
|
|
|
begin
|
|
|
|
for j := i+1 to NoSelected-1 do
|
|
|
|
begin
|
|
|
|
workmat[i,j] := avgcov;
|
|
|
|
workmat[j,i] := workmat[i,j];
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
// get determinants of varcov and workmat
|
|
|
|
determ1 := 0.0;
|
|
|
|
determ2 := 0.0;
|
|
|
|
M2 := 0.0;
|
|
|
|
C2 := 0.0;
|
|
|
|
chi2 := 0.0;
|
|
|
|
prob := 0.0;
|
|
|
|
Determ(vcmat,NoSelected,NoSelected,determ1,errorfound);
|
|
|
|
if determ1 < 0.0 then determ1 := 0.0;
|
|
|
|
Determ(workmat,NoSelected,NoSelected,determ2,errorfound);
|
|
|
|
if determ2 < 0.0 then determ2 := 0.0;
|
|
|
|
count := NoCases;
|
|
|
|
GridCovar(NoSelected,Selected,varcovmat,ColMeans,ColVar,ColStdDev,errorfound,count);
|
|
|
|
errorfound := false;
|
|
|
|
if ((determ1 > 0.0) and (determ2 > 0.0)) then
|
|
|
|
M2 := -(NoCases*NoSelected - 1) * ln(determ1 / determ2)
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
M2 := 0.0;
|
|
|
|
errorfound := true;
|
2020-10-22 22:14:06 +00:00
|
|
|
ErrorMsg('A determinant <= zero was found.');
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
if not errorfound then
|
|
|
|
begin
|
|
|
|
C2 := NoSelected * (NoSelected+1) * (NoSelected + 1) * (2 * NoSelected - 3);
|
|
|
|
C2 := C2 / (6 * (count - 1)*(NoSelected - 1) * (NoSelected * NoSelected + NoSelected - 4));
|
|
|
|
chi2 := (1.0 - C2) * M2;
|
|
|
|
f3 := (NoSelected * NoSelected + NoSelected - 4) div 2;
|
|
|
|
if ((chi2 > 0.01) and (chi2 < 1000.0)) then
|
|
|
|
prob := chisquaredprob(chi2,f3)
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
if chi2 <= 0.0 then prob := 1.0;
|
|
|
|
if chi2 >= 1000.0 then prob := 0.0;
|
|
|
|
end;
|
|
|
|
end;
|
2020-10-22 22:14:06 +00:00
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
title := 'ASSUMED POP. COVARIANCE MATRIX';
|
|
|
|
for i := 0 to NoSelected-1 do
|
|
|
|
for j := 0 to NoSelected-1 do
|
|
|
|
varcovmat[i,j] := workmat[i,j];
|
|
|
|
MatPrint(varcovmat, NoSelected, NoSelected, title, ColLabels, ColLabels, NoCases, lReport);
|
2020-10-22 22:14:06 +00:00
|
|
|
lReport.Add('Determinant of variance-covariance matrix: %10.3g', [determ1]);
|
|
|
|
lReport.Add('Determinant of homogeneity matrix: %10.3g', [determ2]);
|
2020-03-30 18:01:44 +00:00
|
|
|
if not errorfound then
|
|
|
|
begin
|
2020-10-22 22:14:06 +00:00
|
|
|
lReport.Add('ChiSquare: %10.3f', [chi2]);
|
|
|
|
lReport.Add(' with %d degrees of freedom', [f3]);
|
|
|
|
lReport.Add('Probability of larger chisquare: %10.3f', [1.0-prob]);
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-10-22 22:14:06 +00:00
|
|
|
FTestAssumptionsReportFrame.DisplayReport(lReport);
|
|
|
|
end;
|
|
|
|
TestAssumptionsPage.TabVisible := AssumpChk.Checked;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
finally
|
|
|
|
lReport.Free;
|
|
|
|
end;
|
|
|
|
|
2020-10-22 22:14:06 +00:00
|
|
|
{ Finally, plot values if indicated in options list }
|
2020-03-30 18:01:44 +00:00
|
|
|
if PlotChk.Checked then
|
2020-10-22 22:14:06 +00:00
|
|
|
Plot(ColMeans, ColLabels);
|
|
|
|
ChartPage.TabVisible := PlotChk.Checked;
|
|
|
|
ChartPage.PageIndex := PageControl.PageCount-1;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-10-22 22:14:06 +00:00
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
procedure TWithinANOVAFrm.InBtnClick(Sender: TObject);
|
|
|
|
var
|
|
|
|
i: integer;
|
|
|
|
begin
|
|
|
|
i := 0;
|
|
|
|
while i < VarList.Items.Count do
|
|
|
|
begin
|
|
|
|
if VarList.Selected[i] then
|
|
|
|
begin
|
|
|
|
SelList.Items.Add(VarList.Items[i]);
|
|
|
|
VarList.Items.Delete(i);
|
|
|
|
i := 0;
|
|
|
|
end else
|
|
|
|
inc(i);
|
|
|
|
end;
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
|
|
|
|
2020-10-22 22:14:06 +00:00
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
procedure TWithinANOVAFrm.OutBtnClick(Sender: TObject);
|
|
|
|
var
|
|
|
|
i: integer;
|
|
|
|
begin
|
|
|
|
i := 0;
|
|
|
|
while i < SelList.Items.Count do
|
|
|
|
begin
|
|
|
|
if SelList.Selected[i] then
|
|
|
|
begin
|
|
|
|
VarList.Items.Add(SelList.Items[i]);
|
|
|
|
SelList.Items.Delete(i);
|
|
|
|
i := 0;
|
|
|
|
end else
|
|
|
|
inc(i);
|
|
|
|
end;
|
|
|
|
VarList.ItemIndex := -1;
|
|
|
|
SelList.ItemIndex := -1;
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
|
|
|
|
2020-10-22 22:14:06 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
procedure TWithinANOVAFrm.UpdateBtnStates;
|
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
lEnabled: Boolean;
|
|
|
|
begin
|
2020-10-22 22:14:06 +00:00
|
|
|
inherited;
|
|
|
|
|
|
|
|
if FReliabilityReportFrame <> nil then
|
|
|
|
FReliabilityReportFrame.UpdateBtnStates;
|
|
|
|
if FTestAssumptionsReportFrame <> nil then
|
|
|
|
FTestAssumptionsReportFrame.UpdateBtnStates;
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
lEnabled := false;
|
|
|
|
for i:=0 to VarList.Items.Count-1 do
|
|
|
|
if VarList.Selected[i] then
|
|
|
|
begin
|
|
|
|
lEnabled := true;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
InBtn.Enabled := lEnabled;
|
|
|
|
|
|
|
|
lEnabled := false;
|
|
|
|
for i:=0 to SelList.Items.Count-1 do
|
|
|
|
if SelList.Selected[i] then
|
|
|
|
begin
|
|
|
|
lEnabled := true;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
OutBtn.Enabled := lEnabled;
|
|
|
|
end;
|
|
|
|
|
2020-10-22 22:14:06 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
procedure TWithinANOVAFrm.VarListSelectionChange(Sender: TObject;
|
|
|
|
User: boolean);
|
|
|
|
begin
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
end.
|
|
|
|
|