2020-03-30 18:01:44 +00:00
|
|
|
// Use file "anova2.laz" for testing
|
|
|
|
|
|
|
|
unit BoxPlotUnit;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2020-08-23 17:51:36 +00:00
|
|
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
|
2020-09-21 21:39:40 +00:00
|
|
|
StdCtrls, ExtCtrls, Printers, ComCtrls, Buttons,
|
2020-09-27 17:59:39 +00:00
|
|
|
MainUnit, Globals, DataProcs, ContextHelpUnit,
|
2020-09-27 18:07:50 +00:00
|
|
|
BasicStatsFormUnit, ReportFrameUnit, ChartFrameUnit;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TBoxPlotFrm }
|
|
|
|
|
2020-09-27 17:59:39 +00:00
|
|
|
TBoxPlotFrm = class(TBasicStatsForm)
|
2020-03-30 18:01:44 +00:00
|
|
|
Bevel2: TBevel;
|
|
|
|
HelpBtn: TButton;
|
2020-09-21 21:39:40 +00:00
|
|
|
PageControl1: TPageControl;
|
|
|
|
ParamsPanel: TPanel;
|
2020-03-30 18:01:44 +00:00
|
|
|
ResetBtn: TButton;
|
|
|
|
ComputeBtn: TButton;
|
|
|
|
CloseBtn: TButton;
|
|
|
|
MeasEdit: TEdit;
|
|
|
|
GroupEdit: TEdit;
|
|
|
|
Label1: TLabel;
|
|
|
|
Label2: TLabel;
|
|
|
|
Label3: TLabel;
|
2020-09-21 21:39:40 +00:00
|
|
|
ParamsSplitter: TSplitter;
|
|
|
|
ReportPage: TTabSheet;
|
|
|
|
ChartPage: TTabSheet;
|
2020-03-30 18:01:44 +00:00
|
|
|
VarList: TListBox;
|
2020-09-21 21:39:40 +00:00
|
|
|
GrpInBtn: TBitBtn;
|
|
|
|
GrpOutBtn: TBitBtn;
|
|
|
|
MeasInBtn: TBitBtn;
|
|
|
|
MeasOutBtn: TBitBtn;
|
2020-09-20 20:37:17 +00:00
|
|
|
procedure CloseBtnClick(Sender: TObject);
|
2020-03-30 18:01:44 +00:00
|
|
|
procedure ComputeBtnClick(Sender: TObject);
|
|
|
|
procedure FormActivate(Sender: TObject);
|
|
|
|
procedure FormCreate(Sender: TObject);
|
2020-09-21 21:39:40 +00:00
|
|
|
procedure GrpOutBtnClick(Sender: TObject);
|
|
|
|
procedure GrpInBtnClick(Sender: TObject);
|
2020-03-30 18:01:44 +00:00
|
|
|
procedure HelpBtnClick(Sender: TObject);
|
2020-09-21 21:39:40 +00:00
|
|
|
procedure MeasInBtnClick(Sender: TObject);
|
|
|
|
procedure MeasOutBtnClick(Sender: TObject);
|
2020-03-30 18:01:44 +00:00
|
|
|
procedure ResetBtnClick(Sender: TObject);
|
2020-09-21 21:39:40 +00:00
|
|
|
procedure VarListDblClick(Sender: TObject);
|
|
|
|
procedure VarListSelectionChange(Sender: TObject; User: boolean);
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
private
|
|
|
|
{ private declarations }
|
|
|
|
FAutoSized: Boolean;
|
2020-09-21 21:39:40 +00:00
|
|
|
FReportFrame: TReportFrame;
|
|
|
|
FChartFrame: TChartFrame;
|
2020-08-23 17:51:36 +00:00
|
|
|
procedure BoxPlot(const LowQrtl, HiQrtl, TenPcnt, NinetyPcnt, Medians: DblDyneVec);
|
2020-09-21 21:39:40 +00:00
|
|
|
function Percentile(nScoreGrps: integer; APercentile: Double;
|
|
|
|
const Freq, CumFreq, Scores: DblDyneVec): double;
|
|
|
|
procedure UpdateBtnStates;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
public
|
|
|
|
{ public declarations }
|
2020-09-27 17:59:39 +00:00
|
|
|
procedure Reset; override;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
BoxPlotFrm: TBoxPlotFrm;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2020-08-23 17:51:36 +00:00
|
|
|
{$R *.lfm}
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
uses
|
2020-09-21 21:39:40 +00:00
|
|
|
TAChartUtils, TALegend, TAMultiSeries,
|
2020-08-23 17:51:36 +00:00
|
|
|
Math, Utils;
|
|
|
|
|
|
|
|
const
|
|
|
|
BOX_COLORS: Array[0..3] of TColor = (clBlue, clGreen, clFuchsia, clLime);
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
{ TBoxPlotFrm }
|
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
procedure TBoxPlotFrm.BoxPlot(const LowQrtl, HiQrtl, TenPcnt, NinetyPcnt, Medians: DblDyneVec);
|
2020-03-30 18:01:44 +00:00
|
|
|
var
|
2020-09-21 21:39:40 +00:00
|
|
|
i: Integer;
|
|
|
|
ser: TBoxAndWhiskerSeries;
|
|
|
|
clr: TColor;
|
|
|
|
nBars: Integer;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-09-21 21:39:40 +00:00
|
|
|
nBars := Length(LowQrtl);
|
|
|
|
if (nBars <> Length(HiQrtl)) or (nBars <> Length(TenPcnt)) or
|
|
|
|
(nBars <> Length(NinetyPcnt)) or (nBars <> Length(Medians)) then
|
|
|
|
begin
|
|
|
|
ErrorMsg('Box-Plot: all data arrays must have the same lengths.');
|
|
|
|
exit;
|
|
|
|
end;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
FChartFrame.Clear;
|
2020-08-23 17:51:36 +00:00
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
// Titles
|
|
|
|
FChartFrame.SetTitle('Box-and-Whisker Plot for ' + OS3MainFrm.FileNameEdit.Text);
|
|
|
|
FChartFrame.SetFooter('BLACK: median, BOX: 25th to 75th percentile, WHISKERS: 10th and 90th percentile');
|
|
|
|
FChartFrame.SetXTitle(GroupEdit.Text);
|
|
|
|
FChartFrame.SetYTitle(MeasEdit.Text);
|
2020-09-20 14:15:41 +00:00
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
ser := TBoxAndWhiskerSeries.create(FChartFrame);
|
|
|
|
for i := 0 to nBars-1 do
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-09-21 21:39:40 +00:00
|
|
|
clr := BOX_COLORS[i mod Length(BOX_COLORS)];
|
|
|
|
ser.AddXY(i+1, TenPcnt[i], LowQrtl[i], Medians[i], HiQrtl[i], NinetyPcnt[i], '', clr);
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
2020-09-21 21:39:40 +00:00
|
|
|
FChartFrame.Chart.BottomAxis.Marks.Source := ser.ListSource;
|
|
|
|
FChartFrame.Chart.BottomAxis.Marks.Style := smsXValue;
|
|
|
|
FChartFrame.Chart.AddSeries(ser);
|
|
|
|
|
|
|
|
FChartFrame.UpdateBtnStates;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-08-23 17:51:36 +00:00
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
procedure TBoxPlotFrm.CloseBtnClick(Sender: TObject);
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-09-21 21:39:40 +00:00
|
|
|
Close;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-08-23 17:51:36 +00:00
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
procedure TBoxPlotFrm.ComputeBtnClick(Sender: TObject);
|
|
|
|
var
|
|
|
|
lReport: TStrings;
|
2020-08-23 17:51:36 +00:00
|
|
|
i, j, k, GrpVar, MeasVar, mingrp, maxgrp, G, NoGrps, cnt: integer;
|
2020-09-21 21:39:40 +00:00
|
|
|
nScoreGrps, numValues: integer;
|
|
|
|
X: Double;
|
2020-08-23 17:51:36 +00:00
|
|
|
MinScore, MaxScore, IntervalSize, lastX: double;
|
|
|
|
cellstring: string;
|
|
|
|
done: boolean;
|
|
|
|
Freq: DblDyneVec = nil;
|
|
|
|
Scores: DblDyneVec = nil;
|
|
|
|
CumFreq: DblDyneVec = nil;
|
|
|
|
pRank: DblDyneVec = nil;
|
|
|
|
GrpSize: IntDyneVec = nil;
|
|
|
|
Means: DblDyneVec = nil;
|
|
|
|
LowQrtl: DblDyneVec = nil;
|
|
|
|
HiQrtl: DbldyneVec = nil;
|
|
|
|
TenPcntile: DblDyneVec = nil;
|
|
|
|
NinetyPcntile: DblDyneVec = nil;
|
|
|
|
Median: DblDyneVec = nil;
|
2020-09-21 21:39:40 +00:00
|
|
|
ColNoSelected: IntDyneVec;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
|
|
|
lReport := TStringList.Create;
|
|
|
|
try
|
|
|
|
lReport.Add('BOX PLOTS OF GROUPS');
|
|
|
|
lReport.Add('');
|
|
|
|
|
|
|
|
GrpVar := 0;
|
|
|
|
MeasVar := 0;
|
|
|
|
for i := 1 to NoVariables do
|
|
|
|
begin
|
|
|
|
cellstring := OS3MainFrm.DataGrid.Cells[i,0];
|
|
|
|
if cellstring = GroupEdit.Text then GrpVar := i;
|
|
|
|
if cellstring = MeasEdit.Text then MeasVar := i;
|
|
|
|
end;
|
|
|
|
if GrpVar = 0 then
|
|
|
|
begin
|
2020-08-23 17:51:36 +00:00
|
|
|
ErrorMsg('Group variable not selected.');
|
2020-03-30 18:01:44 +00:00
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
if MeasVar = 0 then
|
|
|
|
begin
|
2020-08-23 17:51:36 +00:00
|
|
|
ErrorMsg('Measurement variable not selected.');
|
2020-03-30 18:01:44 +00:00
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
SetLength(ColNoSelected, 2);
|
2020-03-30 18:01:44 +00:00
|
|
|
ColNoSelected[0] := GrpVar;
|
|
|
|
ColNoSelected[1] := MeasVar;
|
|
|
|
|
|
|
|
// get minimum and maximum group values
|
2020-08-23 17:51:36 +00:00
|
|
|
minGrp := MaxInt;
|
|
|
|
maxGrp := -MaxInt;
|
2020-03-30 18:01:44 +00:00
|
|
|
for i := 1 to NoCases do
|
|
|
|
begin
|
2020-09-21 21:39:40 +00:00
|
|
|
if not GoodRecord(i, Length(ColNoSelected), ColNoSelected) then continue;
|
2020-08-23 17:51:36 +00:00
|
|
|
G := round(StrToFloat(OS3MainFrm.DataGrid.Cells[GrpVar, i]));
|
|
|
|
minGrp := Min(G, minGrp);
|
|
|
|
maxGrp := Max(G, maxGrp);
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
2020-08-23 17:51:36 +00:00
|
|
|
NoGrps := maxGrp - minGrp + 1;
|
2020-03-30 18:01:44 +00:00
|
|
|
if NoGrps > 30 then
|
|
|
|
begin
|
2020-08-23 17:51:36 +00:00
|
|
|
ErrorMsg('Too many groups for a meaningful plot (max: 20)');
|
2020-03-30 18:01:44 +00:00
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
// get minimum and maximum scores and score interval
|
2020-08-23 17:51:36 +00:00
|
|
|
IntervalSize := Infinity;
|
2020-03-30 18:01:44 +00:00
|
|
|
lastX := 0.0;
|
2020-08-23 17:51:36 +00:00
|
|
|
X := StrToFloat(OS3MainFrm.DataGrid.Cells[MeasVar, 1]);
|
|
|
|
MinScore := X;
|
|
|
|
MaxScore := X;
|
2020-09-21 21:39:40 +00:00
|
|
|
numValues := 0;
|
2020-03-30 18:01:44 +00:00
|
|
|
for i := 1 to NoCases do
|
|
|
|
begin
|
2020-09-21 21:39:40 +00:00
|
|
|
if not GoodRecord(i, Length(ColNoSelected), ColNoSelected) then continue;
|
|
|
|
inc(numValues);
|
2020-08-23 17:51:36 +00:00
|
|
|
X := StrToFloat(OS3MainFrm.DataGrid.Cells[MeasVar, i]);
|
|
|
|
MaxScore := Max(MaxScore, X);
|
|
|
|
MinScore := Min(MinScore, X);
|
2020-03-30 18:01:44 +00:00
|
|
|
if i > 1 then // get interval size as minimum difference between 2 scores
|
|
|
|
begin
|
2020-08-23 17:51:36 +00:00
|
|
|
if (X <> lastX) and (abs(X - lastX) < IntervalSize) then
|
|
|
|
IntervalSize := abs(X - lastX);
|
2020-03-30 18:01:44 +00:00
|
|
|
lastX := X;
|
|
|
|
end else
|
|
|
|
lastX := X;
|
|
|
|
end;
|
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
SetLength(Scores, 2*numValues + 1); // over-dimensioned, will be trimmed later.
|
2020-08-23 17:51:36 +00:00
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
// check for excess no. of intervals and reset if needed
|
2020-08-23 17:51:36 +00:00
|
|
|
nScoreGrps := round((MaxScore - MinScore) / IntervalSize);
|
2020-09-21 21:39:40 +00:00
|
|
|
if nScoreGrps > 2 * numValues then
|
|
|
|
Intervalsize := (MaxScore - MinScore) / numValues;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
// setup score groups
|
|
|
|
done := false;
|
2020-08-23 17:51:36 +00:00
|
|
|
Scores[0] := MinScore - IntervalSize / 2.0;
|
|
|
|
nScoreGrps := 0;
|
|
|
|
lastX := MaxScore + IntervalSize + IntervalSize / 2.0;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
while not done do
|
|
|
|
begin
|
2020-08-23 17:51:36 +00:00
|
|
|
inc(nScoreGrps);
|
|
|
|
Scores[nScoreGrps] := MinScore + (nScoreGrps * IntervalSize) - IntervalSize / 2.0;
|
|
|
|
if Scores[nScoreGrps] > lastX then done := true;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
2020-08-23 17:51:36 +00:00
|
|
|
Scores[nScoreGrps + 1] := Scores[nScoreGrps] + IntervalSize;
|
|
|
|
if Scores[0] < MinScore then MinScore := Scores[0];
|
|
|
|
if Scores[nScoreGrps] > MaxScore then MaxScore := Scores[nScoreGrps];
|
|
|
|
|
|
|
|
SetLength(Scores, nScoreGrps+1); // trim to used length
|
|
|
|
SetLength(Freq, nScoreGrps);
|
|
|
|
SetLength(CumFreq, nScoreGrps);
|
|
|
|
SetLength(pRank, nScoreGrps);
|
|
|
|
|
|
|
|
SetLength(GrpSize, NoGrps);
|
|
|
|
SetLength(Means, NoGrps);
|
|
|
|
SetLength(LowQrtl, NoGrps);
|
|
|
|
SetLength(HiQrtl, NoGrps);
|
|
|
|
SetLength(TenPcntile, NoGrps);
|
|
|
|
SetLength(NinetyPcntile, NoGrps);
|
|
|
|
SetLength(Median, NoGrps);
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
// do analysis for each group
|
2020-08-23 17:51:36 +00:00
|
|
|
for j := 0 to NoGrps-1 do // group
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-08-23 17:51:36 +00:00
|
|
|
Means[j] := 0.0;
|
|
|
|
GrpSize[j] := 0;
|
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
// get score groups for this group j
|
2020-08-23 17:51:36 +00:00
|
|
|
for i := 0 to nScoreGrps-1 do
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-08-23 17:51:36 +00:00
|
|
|
CumFreq[i] := 0.0;
|
|
|
|
Freq[i] := 0.0;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
cnt := 0;
|
|
|
|
for i := 1 to NoCases do
|
|
|
|
begin // get scores for this group j
|
2020-09-21 21:39:40 +00:00
|
|
|
if not GoodRecord(i, Length(ColNoSelected), ColNoSelected) then continue;
|
2020-08-23 17:51:36 +00:00
|
|
|
G := round(StrToFloat(OS3MainFrm.DataGrid.Cells[GrpVar, i]));
|
|
|
|
G := G - minGrp + 1;
|
|
|
|
if G = j+1 then // subject in this group
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-08-23 17:51:36 +00:00
|
|
|
inc(cnt);
|
|
|
|
X := StrToFloat(OS3MainFrm.DataGrid.Cells[MeasVar, i]);
|
|
|
|
Means[j] := Means[j] + X;
|
2020-03-30 18:01:44 +00:00
|
|
|
// find score interval and add to the frequency
|
2020-08-23 17:51:36 +00:00
|
|
|
for k := 0 to nScoreGrps do
|
2020-03-30 18:01:44 +00:00
|
|
|
if (X >= Scores[k]) and (X < Scores[k+1]) then
|
2020-08-23 17:51:36 +00:00
|
|
|
Freq[k] := Freq[k] + 1.0;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
end;
|
2020-09-21 21:39:40 +00:00
|
|
|
|
2020-08-23 17:51:36 +00:00
|
|
|
GrpSize[j] := cnt;
|
2020-09-21 21:39:40 +00:00
|
|
|
if GrpSize[j] = 0 then
|
|
|
|
begin
|
|
|
|
Means[j] := NaN;
|
|
|
|
Median[j] := NaN;
|
|
|
|
Continue;
|
|
|
|
end;
|
|
|
|
|
|
|
|
Means[j] := Means[j] / GrpSize[j];
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
// accumulate frequencies
|
2020-08-23 17:51:36 +00:00
|
|
|
CumFreq[0] := Freq[0];
|
|
|
|
for i := 1 to nScoreGrps-1 do
|
|
|
|
CumFreq[i] := CumFreq[i-1] + Freq[i];
|
|
|
|
CumFreq[nScoreGrps] := CumFreq[nScoreGrps-1];
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
// get percentile ranks
|
2020-08-23 17:51:36 +00:00
|
|
|
pRank[0] := ((CumFreq[0] / 2.0) / GrpSize[j]) * 100.0;
|
|
|
|
for i := 1 to nScoreGrps-1 do
|
|
|
|
pRank[i] := ((CumFreq[i-1] + (Freq[i] / 2.0)) / GrpSize[j]) * 100.0;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
// get centiles required.
|
2020-08-23 17:51:36 +00:00
|
|
|
TenPcntile[j] := Percentile(nScoreGrps, 0.10 * GrpSize[j], Freq, CumFreq, Scores);
|
|
|
|
NinetyPcntile[j] := Percentile(nScoreGrps, 0.90 * GrpSize[j], Freq, CumFreq, Scores);
|
|
|
|
LowQrtl[j] := Percentile(nScoreGrps, 0.25 * GrpSize[j], Freq, CumFreq, Scores);
|
|
|
|
Median[j] := Percentile(nScoreGrps, 0.50 * GrpSize[j], Freq, CumFreq, Scores);
|
|
|
|
HiQrtl[j] := Percentile(nScoreGrps, 0.75 * GrpSize[j], Freq, CumFreq, Scores);
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
if j > 0 then lReport.Add('');
|
|
|
|
lReport.Add('RESULTS FOR GROUP %d, MEAN %.3f', [j+1, Means[j]]);
|
|
|
|
lReport.Add('');
|
|
|
|
lReport.Add('Centile Value');
|
|
|
|
lReport.Add('------------ -------');
|
|
|
|
lReport.Add('Ten %6.3f', [TenPcntile[j]]);
|
|
|
|
lReport.Add('Twenty five %6.3f', [LowQrtl[j]]);
|
|
|
|
lReport.Add('Median %6.3f', [Median[j]]);
|
|
|
|
lReport.Add('Seventy five %6.3f', [HiQrtl[j]]);
|
|
|
|
lReport.Add('Ninety %6.3f', [NinetyPcntile[j]]);
|
|
|
|
lReport.Add('');
|
|
|
|
lReport.Add('Score Range Frequency Cum.Freq. Percentile Rank');
|
|
|
|
lReport.Add('--------------- --------- --------- ---------------');
|
|
|
|
for i := 0 to nScoreGrps-1 do
|
|
|
|
lReport.Add('%6.2f - %6.2f %6.2f %6.2f %6.2f', [
|
|
|
|
Scores[i], Scores[i+1], Freq[i], CumFreq[i], pRank[i]
|
|
|
|
]);
|
|
|
|
lReport.Add('');
|
2020-03-30 18:01:44 +00:00
|
|
|
end; // get values for next group
|
|
|
|
|
2020-08-23 17:51:36 +00:00
|
|
|
// Show the report with the frequencies
|
2020-09-21 21:39:40 +00:00
|
|
|
FReportFrame.DisplayReport(lReport);
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-08-23 17:51:36 +00:00
|
|
|
// Plot the boxes
|
|
|
|
BoxPlot(LowQrtl, HiQrtl, TenPcntile, NinetyPcntile, Median);
|
2020-03-30 18:01:44 +00:00
|
|
|
finally
|
|
|
|
lReport.Free;
|
|
|
|
|
|
|
|
// Clean up
|
2020-08-23 17:51:36 +00:00
|
|
|
Median := nil;
|
|
|
|
NinetyPcntile := nil;
|
|
|
|
TenPcntile := nil;
|
|
|
|
HiQrtl := nil;
|
|
|
|
LowQrtl := nil;
|
|
|
|
Means := nil;
|
|
|
|
GrpSize := nil;
|
|
|
|
CumFreq := nil;
|
|
|
|
Scores := nil;
|
|
|
|
Freq := nil;
|
2020-03-30 18:01:44 +00:00
|
|
|
ColNoSelected := nil;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2020-08-23 17:51:36 +00:00
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
procedure TBoxPlotFrm.FormActivate(Sender: TObject);
|
|
|
|
var
|
|
|
|
w: Integer;
|
|
|
|
begin
|
|
|
|
if FAutoSized then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
w := MaxValue([HelpBtn.Width, ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]);
|
|
|
|
HelpBtn.Constraints.MinWidth := w;
|
|
|
|
ResetBtn.Constraints.MinWidth := w;
|
|
|
|
ComputeBtn.Constraints.MinWidth := w;
|
|
|
|
CloseBtn.Constraints.MinWidth := w;
|
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
ParamsPanel.Constraints.MinWidth := Max(
|
|
|
|
4*w + 3*HelpBtn.BorderSpacing.Right,
|
|
|
|
Max(Label1.Width, Label3.Width) * 2 + MeasInBtn.Width + 2 * MeasInBtn.BorderSpacing.Left
|
|
|
|
);
|
|
|
|
ParamsPanel.Constraints.MinHeight := VarList.Top + VarList.Constraints.MinHeight +
|
|
|
|
Bevel2.Height + CloseBtn.Height + CloseBtn.BorderSpacing.Top;
|
|
|
|
|
|
|
|
Constraints.MinHeight := ParamsPanel.Constraints.MinHeight + ParamsPanel.BorderSpacing.Around*2;
|
|
|
|
Constraints.MinWidth := ParamsPanel.Constraints.MinWidth + 200;
|
2020-09-22 09:40:36 +00:00
|
|
|
if Height < Constraints.MinHeight then Height := 1; // enforce auto-sizing
|
|
|
|
if Width < Constraints.MiNWidth then Width := 1;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-09-20 20:37:17 +00:00
|
|
|
Position := poDesigned;
|
2020-03-30 18:01:44 +00:00
|
|
|
FAutoSized := true;
|
|
|
|
end;
|
|
|
|
|
2020-08-23 17:51:36 +00:00
|
|
|
|
2020-03-30 18:01:44 +00:00
|
|
|
procedure TBoxPlotFrm.FormCreate(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Assert(OS3MainFrm <> nil);
|
2020-09-21 21:39:40 +00:00
|
|
|
|
2020-09-23 11:19:08 +00:00
|
|
|
InitForm(self);
|
2020-09-22 13:20:08 +00:00
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
FReportFrame := TReportFrame.Create(self);
|
|
|
|
FReportFrame.Parent := ReportPage;
|
|
|
|
FReportFrame.Align := alClient;
|
|
|
|
|
|
|
|
FChartFrame := TChartFrame.Create(self);
|
|
|
|
FChartFrame.Parent := ChartPage;
|
|
|
|
FChartFrame.Align := alClient;
|
|
|
|
FChartFrame.Chart.Legend.Alignment := laBottomCenter;
|
|
|
|
FChartFrame.Chart.Legend.ColumnCount := 3;
|
|
|
|
FChartFrame.Chart.Legend.TextFormat := tfHTML;
|
|
|
|
FChartFrame.Chart.BottomAxis.Intervals.MaxLength := 80;
|
|
|
|
FChartFrame.Chart.BottomAxis.Intervals.MinLength := 30;
|
|
|
|
|
2020-09-20 14:15:41 +00:00
|
|
|
Reset;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-08-23 17:51:36 +00:00
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
procedure TBoxPlotFrm.GrpInBtnClick(Sender: TObject);
|
|
|
|
var
|
|
|
|
index: integer;
|
|
|
|
begin
|
|
|
|
index := VarList.ItemIndex;
|
|
|
|
if (index > -1) and (GroupEdit.Text = '') then
|
|
|
|
begin
|
|
|
|
GroupEdit.Text := VarList.Items[index];
|
|
|
|
VarList.Items.Delete(index);
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TBoxPlotFrm.GrpOutBtnClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if GroupEdit.Text <> '' then
|
|
|
|
begin
|
|
|
|
VarList.Items.Add(GroupEdit.Text);
|
|
|
|
GroupEdit.Text := '';
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TBoxPlotFrm.HelpBtnClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if ContextHelpForm = nil then
|
|
|
|
Application.CreateForm(TContextHelpForm, ContextHelpForm);
|
2020-09-22 10:42:22 +00:00
|
|
|
ContextHelpForm.HelpMessage((Sender as TButton).Tag);
|
2020-09-21 21:39:40 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TBoxPlotFrm.MeasInBtnClick(Sender: TObject);
|
|
|
|
var
|
|
|
|
index: integer;
|
|
|
|
begin
|
|
|
|
index := VarList.ItemIndex;
|
|
|
|
if (index > -1) and (MeasEdit.Text = '') then
|
|
|
|
begin
|
|
|
|
MeasEdit.Text := VarList.Items[index];
|
|
|
|
VarList.Items.Delete(index);
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBoxPlotFrm.MeasOutBtnClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if MeasEdit.Text <> '' then
|
|
|
|
begin
|
|
|
|
VarList.Items.Add(MeasEdit.Text);
|
|
|
|
MeasEdit.Text := '';
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2020-08-23 17:51:36 +00:00
|
|
|
function TBoxPlotFrm.Percentile(nScoreGrps: integer;
|
2020-09-21 21:39:40 +00:00
|
|
|
APercentile: double; const Freq, CumFreq, Scores: DblDyneVec): double;
|
2020-03-30 18:01:44 +00:00
|
|
|
var
|
|
|
|
i, interval: integer;
|
2020-08-23 17:51:36 +00:00
|
|
|
LLimit, ULimit, cumLower, intervalFreq: double;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
|
|
|
interval := 0;
|
2020-08-23 17:51:36 +00:00
|
|
|
for i := 0 to nScoreGrps-1 do
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-08-23 17:51:36 +00:00
|
|
|
if CumFreq[i] > APercentile then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
|
|
|
interval := i;
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if interval > 0 then
|
|
|
|
begin
|
2020-08-23 17:51:36 +00:00
|
|
|
LLimit := Scores[interval];
|
|
|
|
ULimit := Scores[interval+1];
|
|
|
|
cumLower := CumFreq[interval-1];
|
|
|
|
intervalFreq := Freq[interval];
|
2020-09-21 21:39:40 +00:00
|
|
|
end else
|
2020-03-30 18:01:44 +00:00
|
|
|
begin // Percentile in first interval
|
2020-08-23 17:51:36 +00:00
|
|
|
LLimit := Scores[0];
|
|
|
|
ULimit := Scores[1];
|
|
|
|
cumLower := 0.0;
|
|
|
|
intervalFreq := Freq[0];
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-08-23 17:51:36 +00:00
|
|
|
if intervalFreq > 0 then
|
|
|
|
Result := LLimit + ((APercentile - cumLower) / intervalFreq) * (ULimit- LLimit)
|
2020-03-30 18:01:44 +00:00
|
|
|
else
|
2020-08-23 17:51:36 +00:00
|
|
|
Result := LLimit;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
2020-08-23 17:51:36 +00:00
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
procedure TBoxPlotFrm.Reset;
|
2020-08-23 17:51:36 +00:00
|
|
|
var
|
2020-09-21 21:39:40 +00:00
|
|
|
i: integer;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-09-21 21:39:40 +00:00
|
|
|
VarList.Clear;
|
|
|
|
GroupEdit.Text := '';
|
|
|
|
MeasEdit.Text := '';
|
|
|
|
for i := 1 to NoVariables do
|
|
|
|
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
|
|
|
|
UpdateBtnStates;
|
|
|
|
end;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
2020-08-23 17:51:36 +00:00
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
procedure TBoxPlotFrm.ResetBtnClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Reset;
|
|
|
|
end;
|
2020-08-23 17:51:36 +00:00
|
|
|
|
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
procedure TBoxPlotFrm.UpdateBtnStates;
|
|
|
|
begin
|
|
|
|
MeasinBtn.Enabled := (VarList.ItemIndex > -1) and (MeasEdit.Text = '');
|
|
|
|
MeasoutBtn.Enabled := (MeasEdit.Text <> '');
|
|
|
|
|
|
|
|
GrpinBtn.Enabled := (VarList.ItemIndex > -1) and (GroupEdit.Text = '');
|
|
|
|
grpoutBtn.Enabled := (GroupEdit.Text <> '');
|
|
|
|
|
|
|
|
FReportFrame.UpdateBtnStates;
|
|
|
|
FChartFrame.UpdateBtnStates;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
2020-09-21 21:39:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
procedure TBoxPlotFrm.VarListDblClick(Sender: TObject);
|
2020-03-30 18:01:44 +00:00
|
|
|
var
|
2020-09-21 21:39:40 +00:00
|
|
|
index: integer;
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-09-21 21:39:40 +00:00
|
|
|
index := VarList.ItemIndex;
|
|
|
|
if index > -1 then
|
2020-03-30 18:01:44 +00:00
|
|
|
begin
|
2020-09-21 21:39:40 +00:00
|
|
|
if MeasEdit.Text = '' then
|
|
|
|
MeasEdit.Text := VarList.Items[index]
|
|
|
|
else
|
|
|
|
GroupEdit.Text := VarList.Items[index];
|
2020-09-22 09:40:36 +00:00
|
|
|
VarList.Items.Delete(index);
|
|
|
|
UpdateBtnStates;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
2020-09-21 21:39:40 +00:00
|
|
|
end;
|
2020-03-30 18:01:44 +00:00
|
|
|
|
|
|
|
|
2020-09-21 21:39:40 +00:00
|
|
|
procedure TBoxPlotFrm.VarListSelectionChange(Sender: TObject; User: boolean);
|
|
|
|
begin
|
|
|
|
UpdateBtnStates;
|
2020-03-30 18:01:44 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
end.
|
|
|
|
|