You've already forked lazarus-ccr
LazStats: Add pagecontrol tabs to ChiSqrUnits for partial reports.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7804 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -61,7 +61,7 @@ inherited ChiSqrFrm: TChiSqrFrm
|
|||||||
ClientHeight = 69
|
ClientHeight = 69
|
||||||
ClientWidth = 420
|
ClientWidth = 420
|
||||||
Items.Strings = (
|
Items.Strings = (
|
||||||
'Count vases classified by row and column vectors in the data grid'
|
'Count cases classified by row and column vectors in the data grid'
|
||||||
'Use frequencies recorded in the data grid for row and column variables'
|
'Use frequencies recorded in the data grid for row and column variables'
|
||||||
'Use proportions recorded in the data grid for row and column variables'
|
'Use proportions recorded in the data grid for row and column variables'
|
||||||
)
|
)
|
||||||
@ -391,4 +391,30 @@ inherited ChiSqrFrm: TChiSqrFrm
|
|||||||
Left = 436
|
Left = 436
|
||||||
Height = 503
|
Height = 503
|
||||||
end
|
end
|
||||||
|
object PageControl: TPageControl[2]
|
||||||
|
Left = 445
|
||||||
|
Height = 487
|
||||||
|
Top = 8
|
||||||
|
Width = 561
|
||||||
|
ActivePage = ResultsPage
|
||||||
|
Align = alClient
|
||||||
|
BorderSpacing.Left = 4
|
||||||
|
BorderSpacing.Top = 8
|
||||||
|
BorderSpacing.Right = 8
|
||||||
|
BorderSpacing.Bottom = 8
|
||||||
|
TabIndex = 0
|
||||||
|
TabOrder = 2
|
||||||
|
object ResultsPage: TTabSheet
|
||||||
|
Caption = 'Results'
|
||||||
|
end
|
||||||
|
object FrequenciesPage: TTabSheet
|
||||||
|
Caption = 'Frequencies'
|
||||||
|
end
|
||||||
|
object RowColPage: TTabSheet
|
||||||
|
Caption = 'Row/Column Proportions'
|
||||||
|
end
|
||||||
|
object CellChiSqrPage: TTabSheet
|
||||||
|
Caption = 'Cell ChiSqr'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,9 +6,9 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
|
||||||
ExtCtrls, StdCtrls, Buttons,
|
ExtCtrls, StdCtrls, Buttons, ComCtrls,
|
||||||
MainUnit, FunctionsLib, GraphLib, Globals, MatrixLib, DataProcs,
|
MainUnit, FunctionsLib, GraphLib, Globals, MatrixLib, DataProcs,
|
||||||
DictionaryUnit, BasicStatsReportFormUnit;
|
DictionaryUnit, ReportFrameUnit, BasicStatsReportFormUnit;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -17,10 +17,15 @@ type
|
|||||||
TChiSqrFrm = class(TBasicStatsReportForm)
|
TChiSqrFrm = class(TBasicStatsReportForm)
|
||||||
ObsChk: TCheckBox;
|
ObsChk: TCheckBox;
|
||||||
ExpChk: TCheckBox;
|
ExpChk: TCheckBox;
|
||||||
|
PageControl: TPageControl;
|
||||||
PropsChk: TCheckBox;
|
PropsChk: TCheckBox;
|
||||||
CellChiChk: TCheckBox;
|
CellChiChk: TCheckBox;
|
||||||
SaveFChk: TCheckBox;
|
SaveFChk: TCheckBox;
|
||||||
OptionsGroup: TGroupBox;
|
OptionsGroup: TGroupBox;
|
||||||
|
ResultsPage: TTabSheet;
|
||||||
|
FrequenciesPage: TTabSheet;
|
||||||
|
RowColPage: TTabSheet;
|
||||||
|
CellChiSqrPage: TTabSheet;
|
||||||
YatesChk: TCheckBox;
|
YatesChk: TCheckBox;
|
||||||
RowIn: TBitBtn;
|
RowIn: TBitBtn;
|
||||||
RowOut: TBitBtn;
|
RowOut: TBitBtn;
|
||||||
@ -48,7 +53,11 @@ type
|
|||||||
procedure RowOutClick(Sender: TObject);
|
procedure RowOutClick(Sender: TObject);
|
||||||
procedure VarListDblClick(Sender: TObject);
|
procedure VarListDblClick(Sender: TObject);
|
||||||
procedure VarListSelectionChange(Sender: TObject; User: boolean);
|
procedure VarListSelectionChange(Sender: TObject; User: boolean);
|
||||||
|
|
||||||
private
|
private
|
||||||
|
FFrequenciesReportFrame: TReportFrame;
|
||||||
|
FRowColPropsReportFrame: TReportFrame;
|
||||||
|
FCellChiSqrReportFrame: TReportFrame;
|
||||||
|
|
||||||
protected
|
protected
|
||||||
procedure AdjustConstraints; override;
|
procedure AdjustConstraints; override;
|
||||||
@ -69,7 +78,8 @@ implementation
|
|||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Math;
|
Math,
|
||||||
|
Utils, GridProcs;
|
||||||
|
|
||||||
{ TChiSqrFrm }
|
{ TChiSqrFrm }
|
||||||
|
|
||||||
@ -78,8 +88,48 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
if DictionaryFrm = nil then
|
if DictionaryFrm = nil then
|
||||||
Application.CreateForm(TDictionaryFrm, DictionaryFrm);
|
Application.CreateForm(TDictionaryFrm, DictionaryFrm);
|
||||||
|
|
||||||
|
FReportFrame.Parent := ResultsPage;
|
||||||
|
FReportFrame.BorderSpacing.Left := 0;
|
||||||
|
FReportFrame.BorderSpacing.Top := 0;
|
||||||
|
FReportFrame.BorderSpacing.Bottom := 0;
|
||||||
|
FReportFrame.BorderSpacing.Right := 0;
|
||||||
|
InitToolbar(FReportFrame.ReportToolbar, tpRight);
|
||||||
|
|
||||||
|
FFrequenciesReportFrame := TReportFrame.Create(self);
|
||||||
|
FFrequenciesReportFrame.Name := '';
|
||||||
|
FFrequenciesReportFrame.Parent := FrequenciesPage;
|
||||||
|
FFrequenciesReportFrame.Align := alClient;
|
||||||
|
FFrequenciesReportFrame.BorderSpacing.Left := 0;
|
||||||
|
FFrequenciesReportFrame.BorderSpacing.Top := 0;
|
||||||
|
FFrequenciesReportFrame.BorderSpacing.Bottom := 0;
|
||||||
|
FFrequenciesReportFrame.BorderSpacing.Right := 0;
|
||||||
|
InitToolbar(FFrequenciesReportFrame.ReportToolbar, tpRight);
|
||||||
|
|
||||||
|
FRowColPropsReportFrame := TReportFrame.Create(self);
|
||||||
|
FRowColPropsReportFrame.Name := '';
|
||||||
|
FRowColPropsReportFrame.Parent := RowColPage;
|
||||||
|
FRowColPropsReportFrame.Align := alClient;
|
||||||
|
FRowColPropsReportFrame.BorderSpacing.Left := 0;
|
||||||
|
FRowColPropsReportFrame.BorderSpacing.Top := 0;
|
||||||
|
FRowColPropsReportFrame.BorderSpacing.Bottom := 0;
|
||||||
|
FRowColPropsReportFrame.BorderSpacing.Right := 0;
|
||||||
|
InitToolbar(FRowColPropsReportFrame.ReportToolbar, tpRight);
|
||||||
|
|
||||||
|
FCellChiSqrReportFrame := TReportFrame.Create(self);
|
||||||
|
FCellChiSqrReportFrame.Name := '';
|
||||||
|
FCellChiSqrReportFrame.Parent := CellChiSqrPage;
|
||||||
|
FCellChiSqrReportFrame.Align := alClient;
|
||||||
|
FCellChiSqrReportFrame.BorderSpacing.Left := 0;
|
||||||
|
FCellChiSqrReportFrame.BorderSpacing.Top := 0;
|
||||||
|
FCellChiSqrReportFrame.BorderSpacing.Bottom := 0;
|
||||||
|
FCellChiSqrReportFrame.BorderSpacing.Right := 0;
|
||||||
|
InitToolbar(FCellChiSqrReportFrame.ReportToolbar, tpRight);
|
||||||
|
|
||||||
|
PageControl.ActivePageIndex := 0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TChiSqrFrm.AdjustConstraints;
|
procedure TChiSqrFrm.AdjustConstraints;
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
@ -127,30 +177,24 @@ var
|
|||||||
Prop: DblDyneMat = nil;
|
Prop: DblDyneMat = nil;
|
||||||
Expected: DblDyneMat = nil;
|
Expected: DblDyneMat = nil;
|
||||||
CellChi: DblDyneMat = nil;
|
CellChi: DblDyneMat = nil;
|
||||||
|
RowLabels: StrDyneVec = nil;
|
||||||
|
ColLabels: StrDyneVec = nil;
|
||||||
|
yates : boolean = false;
|
||||||
|
|
||||||
|
NoSelected, NCases, NRows, NCols: Integer;
|
||||||
i, j, RowNo, ColNo, DepNo, MinRow, MaxRow, MinCol, MaxCol: integer;
|
i, j, RowNo, ColNo, DepNo, MinRow, MaxRow, MinCol, MaxCol: integer;
|
||||||
Row, Col, NoSelected, Ncases, Nrows, Ncols, FObs, df : integer;
|
Row, Col, FObs, df: integer;
|
||||||
RowLabels, ColLabels : StrDyneVec;
|
PObs, ChiSquare, ProbChi, phi, SumX, SumY, VarX, VarY, likelihood: double;
|
||||||
cellstring: string;
|
|
||||||
PObs, ChiSquare, ProbChi, phi, SumX, SumY, VarX, VarY, liklihood : double;
|
|
||||||
yates : boolean;
|
|
||||||
title : string;
|
title : string;
|
||||||
Adjchisqr, probliklihood, G, pearsonr, MantelHaenszel, MHprob : double;
|
AdjChiSqr, AdjProbChi, probLikelihood, G, pearsonr, MantelHaenszel, MHprob: double;
|
||||||
Adjprobchi, CoefCont, CramerV : double;
|
CoefCont, CramerV: double;
|
||||||
lReport: TStrings;
|
lReport: TStrings;
|
||||||
begin
|
begin
|
||||||
|
RowNo := GetVariableIndex(OS3MainFrm.DataGrid, RowEdit.Text);
|
||||||
|
ColNo := GetVariableIndex(OS3MainFrm.DataGrid, ColEdit.Text);
|
||||||
|
DepNo := GetVariableIndex(OS3MainFrm.DataGrid, DepEdit.Text);
|
||||||
|
|
||||||
SetLength(ColNoSelected, NoVariables);
|
SetLength(ColNoSelected, NoVariables);
|
||||||
yates := false;
|
|
||||||
RowNo := 0;
|
|
||||||
ColNo := 0;
|
|
||||||
DepNo := 0;
|
|
||||||
for i := 1 to NoVariables do
|
|
||||||
begin
|
|
||||||
cellstring := OS3MainFrm.DataGrid.Cells[i,0];
|
|
||||||
if cellstring = RowEdit.Text then RowNo := i;
|
|
||||||
if cellstring = ColEdit.Text then ColNo := i;
|
|
||||||
if cellstring = DepEdit.Text then DepNo := i;
|
|
||||||
end;
|
|
||||||
ColNoSelected[0] := RowNo;
|
ColNoSelected[0] := RowNo;
|
||||||
ColNoSelected[1] := ColNo;
|
ColNoSelected[1] := ColNo;
|
||||||
NoSelected := 2;
|
NoSelected := 2;
|
||||||
@ -159,14 +203,16 @@ begin
|
|||||||
NoSelected := 3;
|
NoSelected := 3;
|
||||||
ColNoSelected[2] := DepNo;
|
ColNoSelected[2] := DepNo;
|
||||||
end;
|
end;
|
||||||
// get min and max of row and col numbers
|
SetLength(ColNoSelected, NoSelected);
|
||||||
MinRow := 1000;
|
|
||||||
MaxRow := 0;
|
// Get min and max of row and col numbers
|
||||||
MinCol := 1000;
|
MinRow := MaxInt;
|
||||||
MaxCol := 0;
|
MaxRow := -MinRow;
|
||||||
|
MinCol := MaxInt;
|
||||||
|
MaxCol := -MinCol;
|
||||||
for i := 1 to NoCases do
|
for i := 1 to NoCases do
|
||||||
begin
|
begin
|
||||||
if not GoodRecord(i,NoSelected,ColNoSelected) then continue;
|
if not GoodRecord(OS3MainFrm.DataGrid, i, ColNoSelected) then continue;
|
||||||
Row := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[RowNo, i])));
|
Row := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[RowNo, i])));
|
||||||
Col := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNo, i])));
|
Col := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNo, i])));
|
||||||
if Row > MaxRow then MaxRow := Row;
|
if Row > MaxRow then MaxRow := Row;
|
||||||
@ -174,18 +220,19 @@ begin
|
|||||||
if Col > MaxCol then MaxCol := Col;
|
if Col > MaxCol then MaxCol := Col;
|
||||||
if Col < MinCol then MinCol := Col;
|
if Col < MinCol then MinCol := Col;
|
||||||
end;
|
end;
|
||||||
Nrows := MaxRow - MinRow + 1;
|
NRows := MaxRow - MinRow + 1;
|
||||||
Ncols := MaxCol - MinCol + 1;
|
NCols := MaxCol - MinCol + 1;
|
||||||
|
|
||||||
// allocate and initialize
|
// allocate and initialize
|
||||||
SetLength(Freq,Nrows+1,Ncols+1);
|
SetLength(Freq, NRows+1, NCols+1);
|
||||||
SetLength(Prop,Nrows+1,Ncols+1);
|
SetLength(Prop, NRows+1, NCols+1);
|
||||||
SetLength(Expected,Nrows,Ncols);
|
SetLength(Expected, NRows, NCols);
|
||||||
SetLength(CellChi,Nrows,Ncols);
|
SetLength(CellChi, NRows, NCols);
|
||||||
SetLength(RowLabels,Nrows+1);
|
SetLength(RowLabels, NRows+1);
|
||||||
SetLength(ColLabels,Ncols+1);
|
SetLength(ColLabels, NCols+1);
|
||||||
for i := 1 to Nrows + 1 do
|
|
||||||
for j := 1 to Ncols + 1 do Freq[i-1,j-1] := 0;
|
for i := 1 to NRows + 1 do
|
||||||
|
for j := 1 to NCols + 1 do Freq[i-1, j-1] := 0;
|
||||||
|
|
||||||
// get cell data
|
// get cell data
|
||||||
NCases := 0;
|
NCases := 0;
|
||||||
@ -193,7 +240,7 @@ begin
|
|||||||
0 : begin // count number of cases in each row and column combination
|
0 : begin // count number of cases in each row and column combination
|
||||||
for i := 1 to NoCases do
|
for i := 1 to NoCases do
|
||||||
begin
|
begin
|
||||||
if not GoodRecord(i,NoSelected,ColNoSelected) then continue;
|
if not GoodRecord(OS3MainFrm.DataGrid, i, ColNoSelected) then continue;
|
||||||
NCases := NCases + 1;
|
NCases := NCases + 1;
|
||||||
Row := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[RowNo, i])));
|
Row := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[RowNo, i])));
|
||||||
Col := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNo, i])));
|
Col := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNo, i])));
|
||||||
@ -205,7 +252,7 @@ begin
|
|||||||
1 : begin // read frequencies data from grid
|
1 : begin // read frequencies data from grid
|
||||||
for i := 1 to NoCases do
|
for i := 1 to NoCases do
|
||||||
begin
|
begin
|
||||||
if not GoodRecord(i,NoSelected,ColNoSelected) then continue;
|
if not GoodRecord(OS3MainFrm.DataGrid, i, ColNoSelected) then continue;
|
||||||
Row := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[RowNo, i])));
|
Row := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[RowNo, i])));
|
||||||
Col := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNo, i])));
|
Col := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNo, i])));
|
||||||
Row := Row - MinRow + 1;
|
Row := Row - MinRow + 1;
|
||||||
@ -219,7 +266,7 @@ begin
|
|||||||
NCases := StrToInt(NCasesEdit.Text);
|
NCases := StrToInt(NCasesEdit.Text);
|
||||||
for i := 1 to NoCases do
|
for i := 1 to NoCases do
|
||||||
begin
|
begin
|
||||||
if not GoodRecord(i,NoSelected,ColNoSelected) then continue;
|
if not GoodRecord(OS3MainFrm.Datagrid, i, ColNoSelected) then continue;
|
||||||
Row := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[RowNo, i])));
|
Row := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[RowNo, i])));
|
||||||
Col := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNo, i])));
|
Col := round(StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[ColNo, i])));
|
||||||
Row := Row - MinRow + 1;
|
Row := Row - MinRow + 1;
|
||||||
@ -231,87 +278,106 @@ begin
|
|||||||
end; // end case
|
end; // end case
|
||||||
Freq[Nrows, Ncols] := NCases;
|
Freq[Nrows, Ncols] := NCases;
|
||||||
|
|
||||||
// Now, calculate expected values
|
// Calculate expected values
|
||||||
// Get row totals first
|
// Get row totals first
|
||||||
for i := 1 to Nrows do
|
for i := 1 to NRows do
|
||||||
for j := 1 to Ncols do
|
for j := 1 to Ncols do
|
||||||
Freq[i-1,Ncols] := Freq[i-1,Ncols] + Freq[i-1,j-1];
|
Freq[i-1, NCols] := Freq[i-1, NCols] + Freq[i-1, j-1];
|
||||||
|
|
||||||
// Get col totals next
|
// Get col totals next
|
||||||
for j := 1 to Ncols do
|
for j := 1 to NCols do
|
||||||
for i := 1 to Nrows do
|
for i := 1 to NRows do
|
||||||
Freq[Nrows,j-1] := Freq[Nrows,j-1] + Freq[i-1,j-1];
|
Freq[NRows, j-1] := Freq[NRows, j-1] + Freq[i-1, j-1];
|
||||||
|
|
||||||
// Then get expected values and cell chi-squares
|
// Then get expected values and cell chi-squares
|
||||||
ChiSquare := 0.0;
|
ChiSquare := 0.0;
|
||||||
AdjChisqr := 0.0;
|
AdjChisqr := 0.0;
|
||||||
if (YatesChk.Checked) and (Nrows = 2) and (Ncols = 2) then yates := true;
|
|
||||||
for i := 1 to Nrows do
|
if (YatesChk.Checked) and (NRows = 2) and (NCols = 2) then
|
||||||
|
yates := true;
|
||||||
|
|
||||||
|
for i := 1 to NRows do
|
||||||
begin
|
begin
|
||||||
for j := 1 to Ncols do
|
for j := 1 to Ncols do
|
||||||
begin
|
begin
|
||||||
Expected[i-1,j-1] := Freq[Nrows,j-1] * Freq[i-1,Ncols] / NCases;
|
Expected[i-1, j-1] := Freq[NRows, j-1] * Freq[i-1, NCols] / NCases;
|
||||||
if Expected[i-1, j-1] > 0.0 then
|
if Expected[i-1, j-1] > 0.0 then
|
||||||
CellChi[i-1, j-1] := sqr(Freq[i-1, j-1] - Expected[i-1, j-1]) / Expected[i-1, j-1]
|
CellChi[i-1, j-1] := sqr(Freq[i-1, j-1] - Expected[i-1, j-1]) / Expected[i-1, j-1]
|
||||||
else begin
|
else begin
|
||||||
MessageDlg('Zero expected value found.', mtError, [mbOK], 0);
|
ErrorMsg('Zero expected value found.');
|
||||||
CellChi[i-1,j-1] := 0.0;
|
CellChi[i-1,j-1] := 0.0;
|
||||||
end;
|
end;
|
||||||
ChiSquare := ChiSquare + CellChi[i-1, j-1];
|
ChiSquare := ChiSquare + CellChi[i-1, j-1];
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
df := (Nrows - 1) * (Ncols - 1);
|
df := (Nrows - 1) * (Ncols - 1);
|
||||||
if yates = true then // 2 x 2 corrected chi-square
|
if yates then // 2 x 2 corrected chi-square
|
||||||
begin
|
begin
|
||||||
Adjchisqr := abs((Freq[0,0] * Freq[1,1]) - (Freq[0,1] * Freq[1,0]));
|
AdjChiSqr := abs((Freq[0,0] * Freq[1,1]) - (Freq[0,1] * Freq[1,0]));
|
||||||
Adjchisqr := sqr(Adjchisqr - NCases / 2.0) * NCases; // numerator
|
AdjChiSqr := sqr(AdjChiSqr - NCases / 2.0) * NCases; // numerator
|
||||||
Adjchisqr := Adjchisqr / (Freq[0,2] * Freq[1,2] * Freq[2,0] * Freq[2,1]);
|
AdjChiSqr := AdjChiSqr / (Freq[0,2] * Freq[1,2] * Freq[2,0] * Freq[2,1]);
|
||||||
Adjprobchi := 1.0 - chisquaredprob(Adjchisqr,df);
|
AdjProbChi := 1.0 - ChiSquaredProb(AdjChiSqr, df);
|
||||||
end;
|
end;
|
||||||
ProbChi := 1.0 - chisquaredprob(ChiSquare,df); // prob. larger chi
|
ProbChi := 1.0 - ChiSquaredProb(ChiSquare, df); // prob. larger chi
|
||||||
|
|
||||||
//Print results to output form
|
for i := 1 to NRows do RowLabels[i-1] := Format('Row %d', [i]);
|
||||||
|
RowLabels[NRows] := 'Total';
|
||||||
|
|
||||||
|
for j := 1 to NCols do ColLabels[j-1] := Format('Col.%d', [j]);
|
||||||
|
ColLabels[NCols] := 'Total';
|
||||||
|
|
||||||
|
// Print results to output frames
|
||||||
lReport := TStringList.Create;
|
lReport := TStringList.Create;
|
||||||
try
|
try
|
||||||
lReport.Add('CHI-SQUARE ANALYSIS RESULTS');
|
// print frequencies tables requested by user
|
||||||
|
if ObsChk.Checked or ExpChk.Checked then
|
||||||
|
begin
|
||||||
|
FrequenciesPage.TabVisible := true;
|
||||||
|
|
||||||
// print tables requested by use
|
lReport.Add('CHI-SQUARE ANALYSIS RESULTS');
|
||||||
for i := 1 to Nrows do RowLabels[i-1] := Format('Row %d', [i]);
|
|
||||||
RowLabels[Nrows] := 'Total';
|
|
||||||
for j := 1 to Ncols do ColLabels[j-1] := Format('COL.%d', [j]);
|
|
||||||
ColLabels[Ncols] := 'Total';
|
|
||||||
|
|
||||||
if ObsChk.Checked then
|
if ObsChk.Checked then
|
||||||
begin
|
begin
|
||||||
IntArrayPrint(Freq, Nrows+1, Ncols+1,'Rows',
|
IntArrayPrint(Freq, NRows+1, NCols+1, 'Rows', RowLabels, ColLabels, 'OBSERVED FREQUENCIES', lReport);
|
||||||
RowLabels, ColLabels,'OBSERVED FREQUENCIES', lReport);
|
lReport.Add(DIVIDER_SMALL_AUTO);
|
||||||
lReport.Add('------------------------------------------------------------------------------');
|
|
||||||
lReport.Add('');
|
lReport.Add('');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if ExpChk.Checked then
|
if ExpChk.Checked then
|
||||||
begin
|
begin
|
||||||
title := 'EXPECTED FREQUENCIES';
|
title := 'EXPECTED FREQUENCIES';
|
||||||
MatPrint(Expected,Nrows,Ncols,title,RowLabels,ColLabels,NCases, lReport);
|
MatPrint(Expected, NRows, NCols, title, RowLabels, ColLabels, NCases, lReport);
|
||||||
lReport.Add('------------------------------------------------------------------------------');
|
|
||||||
lReport.Add('');
|
|
||||||
end;
|
end;
|
||||||
|
FFrequenciesReportFrame.DisplayReport(lReport);
|
||||||
|
lReport.Clear;
|
||||||
|
end else
|
||||||
|
FrequenciesPage.TabVisible := false;
|
||||||
|
|
||||||
if PropsChk.Checked then
|
if PropsChk.Checked then
|
||||||
begin
|
begin
|
||||||
|
RowColPage.TabVisible := true;
|
||||||
title := 'ROW PROPORTIONS';
|
title := 'ROW PROPORTIONS';
|
||||||
for i := 1 to Nrows + 1 do
|
for i := 1 to NRows + 1 do
|
||||||
begin
|
begin
|
||||||
for j := 1 to Ncols do
|
for j := 1 to NCols do
|
||||||
begin
|
begin
|
||||||
if Freq[i-1,Ncols] > 0.0 then
|
if Freq[i-1, NCols] > 0.0 then
|
||||||
Prop[i-1,j-1] := Freq[i-1,j-1] / Freq[i-1,Ncols]
|
Prop[i-1, j-1] := Freq[i-1, j-1] / Freq[i-1, NCols]
|
||||||
else Prop[i-1,j-1] := 0.0;
|
else
|
||||||
|
Prop[i-1, j-1] := 0.0;
|
||||||
end;
|
end;
|
||||||
if Freq[i-1,Ncols] > 0.0 then Prop[i-1,Ncols] := 1.0
|
if Freq[i-1, NCols] > 0.0 then
|
||||||
else Prop[i-1,Ncols] := 0.0;
|
Prop[i-1, NCols] := 1.0
|
||||||
|
else
|
||||||
|
Prop[i-1, NCols] := 0.0;
|
||||||
end;
|
end;
|
||||||
MatPrint(Prop,Nrows+1,Ncols+1,title,RowLabels,ColLabels,NCases, lReport);
|
lReport.Add('CHI-SQUARE ANALYSIS RESULTS');
|
||||||
lReport.Add('------------------------------------------------------------------------------');
|
|
||||||
lReport.Add('');
|
lReport.Add('');
|
||||||
|
MatPrint(Prop, NRows+1, NCols+1, title, RowLabels, ColLabels, NCases, lReport);
|
||||||
|
|
||||||
|
lReport.Add(DIVIDER_SMALL_AUTO);
|
||||||
|
lReport.Add('');
|
||||||
|
|
||||||
title := 'COLUMN PROPORTIONS';
|
title := 'COLUMN PROPORTIONS';
|
||||||
for j := 1 to Ncols + 1 do
|
for j := 1 to Ncols + 1 do
|
||||||
begin
|
begin
|
||||||
@ -319,57 +385,84 @@ begin
|
|||||||
begin
|
begin
|
||||||
if Freq[Nrows,j-1] > 0.0 then
|
if Freq[Nrows,j-1] > 0.0 then
|
||||||
Prop[i-1,j-1] := Freq[i-1,j-1] / Freq[Nrows,j-1]
|
Prop[i-1,j-1] := Freq[i-1,j-1] / Freq[Nrows,j-1]
|
||||||
else Prop[i-1,j-1] := 0.0;
|
else
|
||||||
|
Prop[i-1,j-1] := 0.0;
|
||||||
end;
|
end;
|
||||||
if Freq[Nrows,j-1] > 0.0 then Prop[NRows,j-1] := 1.0
|
if Freq[Nrows,j-1] > 0.0 then
|
||||||
else Prop[NRows,j-1] := 0.0;
|
Prop[NRows,j-1] := 1.0
|
||||||
|
else
|
||||||
|
Prop[NRows,j-1] := 0.0;
|
||||||
end;
|
end;
|
||||||
MatPrint(Prop,Nrows+1,Ncols+1,title,RowLabels,ColLabels,NCases, lReport);
|
MatPrint(Prop, NRows+1, NCols+1, title, RowLabels, ColLabels, NCases, lReport);
|
||||||
lReport.Add('------------------------------------------------------------------------------');
|
|
||||||
|
lReport.Add(DIVIDER_SMALL_AUTO);
|
||||||
lReport.Add('');
|
lReport.Add('');
|
||||||
|
|
||||||
Title := 'PROPORTIONS OF TOTAL N';
|
Title := 'PROPORTIONS OF TOTAL N';
|
||||||
for i := 1 to Nrows + 1 do
|
for i := 1 to NRows + 1 do
|
||||||
for j := 1 to Ncols + 1 do Prop[i-1,j-1] := Freq[i-1,j-1] / NCases;
|
for j := 1 to NCols + 1 do
|
||||||
|
Prop[i-1,j-1] := Freq[i-1,j-1] / NCases;
|
||||||
Prop[Nrows, Ncols] := 1.0;
|
Prop[Nrows, Ncols] := 1.0;
|
||||||
MatPrint(Prop,Nrows+1,Ncols+1,title,RowLabels,ColLabels,NCases, lReport);
|
MatPrint(Prop, NRows+1, NCols+1, title, RowLabels, ColLabels, NCases, lReport);
|
||||||
lReport.Add('------------------------------------------------------------------------------');
|
|
||||||
|
lReport.Add(DIVIDER_SMALL_AUTO);
|
||||||
lReport.Add('');
|
lReport.Add('');
|
||||||
end;
|
|
||||||
|
FRowColPropsReportFrame.DisplayReport(lReport);
|
||||||
|
lReport.Clear;
|
||||||
|
end else
|
||||||
|
RowColPage.TabVisible := false;
|
||||||
|
|
||||||
if CellChiChk.Checked then
|
if CellChiChk.Checked then
|
||||||
begin
|
begin
|
||||||
|
CellChiSqrPage.TabVisible := true;
|
||||||
|
lReport.Add('CHI-SQUARE ANALYSIS RESULTS');
|
||||||
|
lReport.Add('');
|
||||||
title := 'CHI-SQUARED VALUE FOR CELLS';
|
title := 'CHI-SQUARED VALUE FOR CELLS';
|
||||||
MatPrint(CellChi,Nrows,Ncols,title,RowLabels,ColLabels,NCases, lReport);
|
MatPrint(CellChi, NRows, NCols, title, RowLabels, ColLabels, NCases, lReport);
|
||||||
lReport.Add('------------------------------------------------------------------------------');
|
FCellChiSqrReportFrame.DisplayReport(lReport);
|
||||||
|
lReport.Clear;
|
||||||
|
end else
|
||||||
|
CellChiSqrPage.TabVisible := false;
|
||||||
|
|
||||||
|
lReport.Add('CHI-SQUARE ANALYSIS RESULTS');
|
||||||
|
lReport.Add('');
|
||||||
|
lReport.Add('Chi-square: %.3f', [ChiSquare]);
|
||||||
|
lReport.Add(' with %d degrees of freedom', [DF]);
|
||||||
|
lReport.Add(' Probability > value is %.4f', [ProbChi]);
|
||||||
|
lReport.Add('');
|
||||||
|
if yates then
|
||||||
|
begin
|
||||||
|
lReport.Add('Chi-square using Yates correction: %.3f', [AdjChiSqr]);
|
||||||
|
lReport.Add(' Probability > value is %.4f', [AdjProbChi]);
|
||||||
lReport.Add('');
|
lReport.Add('');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
lReport.Add('Chi-square: %.3f with D.F. = %d. Prob. > value %.3f', [ChiSquare, df, ProbChi]);
|
likelihood := 0.0;
|
||||||
lReport.Add('');
|
for i := 0 to NRows-1 do
|
||||||
if yates then
|
for j := 0 to NCols-1 do
|
||||||
lReport.Add('Chi-square using Yates correction: %.3f and Prob > value: %.3f', [Adjchisqr, Adjprobchi]);
|
|
||||||
|
|
||||||
liklihood := 0.0;
|
|
||||||
for i := 0 to Nrows-1 do
|
|
||||||
for j := 0 to Ncols-1 do
|
|
||||||
if (Freq[i, j] > 0.0) then
|
if (Freq[i, j] > 0.0) then
|
||||||
liklihood := Liklihood + (Freq[i,j] * (ln(Expected[i,j] / Freq[i,j])));
|
likelihood := Likelihood + (Freq[i, j] * (ln(Expected[i, j] / Freq[i,j ])));
|
||||||
liklihood := -2.0 * liklihood;
|
likelihood := -2.0 * likelihood;
|
||||||
probliklihood := 1.0 - chisquaredprob(liklihood,df);
|
probLikelihood := 1.0 - ChiSquaredProb(likelihood, df);
|
||||||
lReport.Add('Likelihood Ratio: %.3f with prob. > value %.4f', [liklihood, probliklihood]);
|
lReport.Add('Likelihood Ratio: %.3f', [likelihood]);
|
||||||
|
lReport.Add(' Probability > value is %.4f', [probLikelihood]);
|
||||||
|
lReport.Add('');
|
||||||
|
|
||||||
G := 0.0;
|
G := 0.0;
|
||||||
for i := 0 to Nrows-1 do
|
for i := 0 to NRows-1 do
|
||||||
for j := 0 to Ncols-1 do
|
for j := 0 to NCols-1 do
|
||||||
if (Expected[i, j] > 0) then
|
if (Expected[i, j] > 0) then
|
||||||
G := G + Freq[i, j] * (ln(Freq[i, j] / Expected[i, j]));
|
G := G + Freq[i, j] * (ln(Freq[i, j] / Expected[i, j]));
|
||||||
G := 2.0 * G;
|
G := 2.0 * G;
|
||||||
probliklihood := 1.0 - chisquaredprob(G,df);
|
probLikelihood := 1.0 - ChiSquaredProb(G, df);
|
||||||
lReport.Add('G statistic: %.3f with prob. > value %.4f', [G, probliklihood]);
|
lReport.Add('G statistic: %.3f ', [G]);
|
||||||
|
lReport.Add(' Probability > value is %.4f', [G, probLikelihood]);
|
||||||
|
lReport.Add('');
|
||||||
|
|
||||||
if ((Nrows > 1) and (Ncols > 1)) then
|
if ((NRows > 1) and (NCols > 1)) then
|
||||||
begin
|
begin
|
||||||
phi := sqrt(ChiSquare / Ncases);
|
phi := sqrt(ChiSquare / NCases);
|
||||||
lReport.Add('phi correlation: %.4f', [phi]);
|
lReport.Add('phi correlation: %.4f', [phi]);
|
||||||
lReport.Add('');
|
lReport.Add('');
|
||||||
|
|
||||||
@ -378,34 +471,35 @@ begin
|
|||||||
SumY := 0.0;
|
SumY := 0.0;
|
||||||
VarX := 0.0;
|
VarX := 0.0;
|
||||||
VarY := 0.0;
|
VarY := 0.0;
|
||||||
for i := 0 to Nrows-1 do SumX := SumX + ( (i+1) * Freq[i,Ncols] );
|
for i := 0 to NRows-1 do SumX := SumX + ( (i+1) * Freq[i, NCols] );
|
||||||
for j := 0 to Ncols-1 do SumY := SumY + ( (j+1) * Freq[Nrows,j] );
|
for j := 0 to NCols-1 do SumY := SumY + ( (j+1) * Freq[NRows, j] );
|
||||||
for i := 0 to Nrows-1 do VarX := VarX + ( ((i+1)*(i+1)) * Freq[i,Ncols] );
|
for i := 0 to NRows-1 do VarX := VarX + ( sqr(i+1) * Freq[i, NCols] );
|
||||||
for j := 0 to Ncols-1 do VarY := VarY + ( ((j+1)*(j+1)) * Freq[Nrows,j] );
|
for j := 0 to NCols-1 do VarY := VarY + ( sqr(j+1) * Freq[NRows, j] );
|
||||||
VarX := VarX - ((SumX * SumX) / Ncases);
|
VarX := VarX - sqr(SumX) / NCases;
|
||||||
VarY := VarY - ((SumY * SumY) / Ncases);
|
VarY := VarY - sqr(SumY) / NCases;
|
||||||
for i := 0 to Nrows-1 do
|
for i := 0 to NRows-1 do
|
||||||
for j := 0 to Ncols-1 do
|
for j := 0 to NCols-1 do
|
||||||
pearsonr := pearsonr + ((i+1)*(j+1) * Freq[i,j]);
|
pearsonR := pearsonR + ((i+1)*(j+1) * Freq[i, j]);
|
||||||
pearsonr := pearsonr - (SumX * SumY / Ncases);
|
pearsonR := pearsonR - (SumX * SumY / Ncases);
|
||||||
pearsonr := pearsonr / sqrt(VarX * VarY);
|
pearsonR := pearsonR / sqrt(VarX * VarY);
|
||||||
lReport.Add('Pearson Correlation r: %.4f', [pearsonr]);
|
lReport.Add('Pearson Correlation r: %.4f', [pearsonR]);
|
||||||
lReport.Add('');
|
lReport.Add('');
|
||||||
|
|
||||||
MantelHaenszel := (Ncases-1) * (pearsonr * pearsonr);
|
MantelHaenszel := (NCases-1) * sqr(pearsonR);
|
||||||
MHprob := 1.0 - chisquaredprob(MantelHaenszel,1);
|
MHprob := 1.0 - ChiSquaredProb(MantelHaenszel, 1);
|
||||||
lReport.Add('Mantel-Haenszel Test of Linear Association: %.3f with probability > value %.4f', [MantelHaenszel, MHprob]);
|
lReport.Add('Mantel-Haenszel Test of Linear Association: %.3f', [MantelHaenszel]);
|
||||||
|
lReport.Add(' Probability > value is %.4f', [MantelHaenszel, MHprob]);
|
||||||
lReport.Add('');
|
lReport.Add('');
|
||||||
|
|
||||||
CoefCont := sqrt(ChiSquare / (ChiSquare + Ncases));
|
CoefCont := sqrt(ChiSquare / (ChiSquare + NCases));
|
||||||
lReport.Add('The coefficient of contingency: %.3f', [CoefCont]);
|
lReport.Add('The coefficient of contingency is %.3f', [CoefCont]);
|
||||||
lReport.Add('');
|
lReport.Add('');
|
||||||
|
|
||||||
if (Nrows < Ncols) then
|
if (Nrows < Ncols) then
|
||||||
CramerV := sqrt(ChiSquare / (Ncases * ((Nrows-1))))
|
CramerV := sqrt(ChiSquare / (NCases * ((NRows-1))))
|
||||||
else
|
else
|
||||||
CramerV := sqrt(ChiSquare / (Ncases * ((Ncols-1))));
|
CramerV := sqrt(ChiSquare / (NCases * ((NCols-1))));
|
||||||
lReport.Add('Cramers V: %.3f', [CramerV]);
|
lReport.Add('Cramers V is %.3f', [CramerV]);
|
||||||
lReport.Add('');
|
lReport.Add('');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -548,6 +642,10 @@ begin
|
|||||||
CellChiChk.Checked := false;
|
CellChiChk.Checked := false;
|
||||||
SaveFChk.Checked := false;
|
SaveFChk.Checked := false;
|
||||||
|
|
||||||
|
FrequenciesPage.TabVisible := false;
|
||||||
|
RowColPage.TabVisible := false;
|
||||||
|
CellChiSqrPage.TabVisible := false;
|
||||||
|
|
||||||
UpdateBtnStates;
|
UpdateBtnStates;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
|
|
||||||
FReportFrame := TReportFrame.Create(self);
|
FReportFrame := TReportFrame.Create(self);
|
||||||
|
FReportFrame.Name := '';
|
||||||
FReportFrame.Parent := Self;
|
FReportFrame.Parent := Self;
|
||||||
FReportFrame.Align := alClient;
|
FReportFrame.Align := alClient;
|
||||||
FReportFrame.BorderSpacing.Left := 4;
|
FReportFrame.BorderSpacing.Left := 4;
|
||||||
|
@ -57,8 +57,8 @@ const
|
|||||||
|
|
||||||
constructor TReportFrame.Create(AOwner: TComponent);
|
constructor TReportFrame.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
Name := '';
|
|
||||||
inherited;
|
inherited;
|
||||||
|
Name := '';
|
||||||
ReportPanel.Color := ReportMemo.Color;
|
ReportPanel.Color := ReportMemo.Color;
|
||||||
UpdateBtnStates;
|
UpdateBtnStates;
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user