You've already forked lazarus-ccr
LazStats: Massive refactoring of LSMRegUnit re-using general regression routines.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7782 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -6,7 +6,7 @@ interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Dialogs,
|
||||
Globals, DictionaryUnit, FunctionsLib, DataProcs, MainUnit;
|
||||
Globals, DictionaryUnit, FunctionsLib, GridProcs, DataProcs, MainUnit;
|
||||
|
||||
//type
|
||||
// TRegItem = (riMeanVarStdDev, riXTX);
|
||||
@ -142,6 +142,9 @@ procedure DynIntMatPrint(Mat: IntDyneMat; Rows, Cols: integer; YTitle: string;
|
||||
procedure SymMatRoots(A : DblDyneMat; M : integer; VAR E : DblDyneVec; VAR V : DblDyneMat);
|
||||
procedure matinv(a, vtimesw, v, w: DblDyneMat; n: integer);
|
||||
|
||||
procedure AddVariable(AVarName: String; AData: DblDyneVec;
|
||||
ANumFormat: String; const ABadRows: IntDyneVec);
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
@ -1113,10 +1116,12 @@ begin
|
||||
DictionaryFrm.NewVar(col);
|
||||
DictionaryFrm.DictGrid.Cells[1,col] := 'Pred.z';
|
||||
OS3MainFrm.DataGrid.Cells[col,0] := 'Pred.z';
|
||||
|
||||
col := NoVariables + 1;
|
||||
DictionaryFrm.NewVar(col);
|
||||
DictionaryFrm.DictGrid.Cells[1,col] := 'z Resid.';
|
||||
OS3MainFrm.DataGrid.Cells[col,0] := 'z Resid.';
|
||||
|
||||
for i := 1 to NoCases do
|
||||
begin
|
||||
zpredicted := 0.0;
|
||||
@ -1134,10 +1139,12 @@ begin
|
||||
z2 := (z2 - Means[NoVars-1]) / StdDevs[NoVars-1];
|
||||
OS3MainFrm.DataGrid.Cells[col,i] := format('%8.4f',[(z2 - zpredicted)]);
|
||||
end;
|
||||
|
||||
col := NoVariables + 1;
|
||||
DictionaryFrm.NewVar(col);
|
||||
DictionaryFrm.DictGrid.Cells[1,col] := 'Pred.Raw';
|
||||
OS3MainFrm.DataGrid.Cells[col,0] := 'Pred.Raw';
|
||||
|
||||
{ calculate raw predicted scores and store in grid at col }
|
||||
for i := 1 to NoCases do
|
||||
begin
|
||||
@ -1145,11 +1152,13 @@ begin
|
||||
StdDevs[NoVars-1] + Means[NoVars-1];
|
||||
OS3MainFrm.DataGrid.Cells[col,i] := format('%8.3f',[predicted]);
|
||||
end;
|
||||
|
||||
{ Calculate residuals of predicted raw scores }
|
||||
col := NoVariables +1;
|
||||
DictionaryFrm.NewVar(col);
|
||||
DictionaryFrm.DictGrid.Cells[1,col] := 'Raw Resid.';
|
||||
OS3MainFrm.DataGrid.Cells[col,0] := 'Raw Resid.';
|
||||
|
||||
for i := 1 to NoCases do
|
||||
begin
|
||||
Index := ColNoSelected[NoVars-1];
|
||||
@ -1157,19 +1166,23 @@ begin
|
||||
StrToFloat(Trim(OS3MainFrm.DataGrid.Cells[Index,i]));
|
||||
OS3MainFrm.DataGrid.Cells[col,i] := Format('%8.3f',[resid]);
|
||||
end;
|
||||
|
||||
{ Calculate Confidence Interval for raw predicted score }
|
||||
col := NoVariables + 1;
|
||||
DictionaryFrm.NewVar(col);
|
||||
DictionaryFrm.DictGrid.Cells[1,col] := 'StdErrPred';
|
||||
OS3MainFrm.DataGrid.Cells[col,0] := 'StdErrPred';
|
||||
|
||||
col := NoVariables + 1;
|
||||
DictionaryFrm.NewVar(col);
|
||||
DictionaryFrm.DictGrid.Cells[1,col] := 'Low 95%';
|
||||
OS3MainFrm.DataGrid.Cells[col,0] := 'Low 95%';
|
||||
|
||||
col := NoVariables + 1;
|
||||
DictionaryFrm.NewVar(col);
|
||||
DictionaryFrm.DictGrid.Cells[1,col] := 'Top 95%';
|
||||
OS3MainFrm.DataGrid.Cells[col,0] := 'Top 95%';
|
||||
|
||||
for i := 1 to NoCases do
|
||||
begin
|
||||
{ get term1 of the std. err. prediction }
|
||||
@ -2348,5 +2361,50 @@ begin
|
||||
rv1 := nil;
|
||||
end;
|
||||
|
||||
{ Adds a new variable named AColTitle after the last grid column
|
||||
and writes the specified data to it in the specified number format.
|
||||
Rows mentioned in ABadRows must be omitted because they are not contained in
|
||||
AData. }
|
||||
procedure AddVariable(AVarName: String; AData: DblDyneVec;
|
||||
ANumFormat: String; const ABadRows: IntDyneVec);
|
||||
|
||||
function IsBadRow(ARow: Integer): Boolean;
|
||||
var
|
||||
j: Integer;
|
||||
begin
|
||||
for j := 0 to High(ABadRows) do
|
||||
if ARow = ABadRows[j] then
|
||||
begin
|
||||
Result := true;
|
||||
exit;
|
||||
end;
|
||||
Result := false;
|
||||
end;
|
||||
|
||||
var
|
||||
i, j, colIndex, row: Integer;
|
||||
begin
|
||||
colIndex := GetVariableIndex(OS3MainFrm.DataGrid, AVarname);
|
||||
if colIndex = -1 then
|
||||
begin
|
||||
colIndex := NoVariables + 1;
|
||||
DictionaryFrm.NewVar(colIndex);
|
||||
DictionaryFrm.DictGrid.Cells[1, colIndex] := AVarName;
|
||||
DictionaryFrm.DictGrid.Cells[7, colIndex] := 'R';
|
||||
OS3MainFrm.DataGrid.Cells[colIndex, 0] := AVarName;
|
||||
OS3MainFrm.NoVarsEdit.Text := IntToStr(NoVariables);
|
||||
end;
|
||||
row := 1;
|
||||
for i := 0 to High(AData) do
|
||||
begin
|
||||
while IsBadRow(row) do inc(row);
|
||||
if row >= OS3MainFrm.DataGrid.RowCount then
|
||||
raise Exception.Create('Bad row error.');
|
||||
OS3MainFrm.DataGrid.Cells[colIndex, row] := Format(ANumFormat, [AData[i]]);
|
||||
inc(row);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
|
||||
|
Reference in New Issue
Block a user