LazStats: Integrate charts of WLSUnit into tabs on the WLSFrm

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7772 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-10-12 13:43:51 +00:00
parent b4cef759cb
commit fb92b9fb1d
5 changed files with 281 additions and 118 deletions

View File

@ -161,6 +161,7 @@ var
tmpX: DblDyneVec = nil; tmpX: DblDyneVec = nil;
tmpY: DblDyneVec = nil; tmpY: DblDyneVec = nil;
conf: DblDyneVec = nil; conf: DblDyneVec = nil;
ext: TDoubleRect;
xmin, xmax, ymin, ymax: Double; xmin, xmax, ymin, ymax: Double;
rightLabels: TListChartSource; rightLabels: TListChartSource;
topLabels: TListChartSource; topLabels: TListChartSource;
@ -204,11 +205,11 @@ begin
ser := FChartFrame.PlotXY(ptLines, XPoints, conf, nil, nil, 'Lower confidence band', clRed); ser := FChartFrame.PlotXY(ptLines, XPoints, conf, nil, nil, 'Lower confidence band', clRed);
rightLabels.Add(ser.yValue[ser.Count-1], ser.YValue[ser.Count-1], 'LCL'); rightLabels.Add(ser.yValue[ser.Count-1], ser.YValue[ser.Count-1], 'LCL');
end; end;
{
FChartFrame.Chart.Prepare; FChartFrame.Chart.Prepare;
FChartFrame.GetXRange(xmin, xmax, false); FChartFrame.GetXRange(xmin, xmax, false);
FChartFrame.GetYRange(ymin, ymax, false); FChartFrame.GetYRange(ymin, ymax, false);
}
// Draw means // Draw means
if MeansChk.Checked then if MeansChk.Checked then
with ARegressionResults do with ARegressionResults do
@ -222,10 +223,11 @@ begin
// Draw regression line // Draw regression line
if LineChk.Checked then if LineChk.Checked then
begin begin
ext := FChartFrame.Chart.GetFullExtent;
SetLength(tmpX, 2); SetLength(tmpX, 2);
SetLength(tmpY, 2); SetLength(tmpY, 2);
tmpX[0] := xmin; tmpX[0] := ext.a.x;
tmpX[1] := xmax; tmpX[1] := ext.b.x;
with ARegressionResults do with ARegressionResults do
begin begin
tmpY[1] := tmpX[1] * Slope + Intercept; tmpY[1] := tmpX[1] * Slope + Intercept;

View File

@ -390,19 +390,35 @@ inherited WLSFrm: TWLSFrm
Height = 412 Height = 412
Top = 8 Top = 8
Width = 500 Width = 500
ActivePage = OLSPage ActivePage = ResidualsRegPage
Align = alClient Align = alClient
BorderSpacing.Left = 4 BorderSpacing.Left = 4
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Right = 8 BorderSpacing.Right = 8
BorderSpacing.Bottom = 8 BorderSpacing.Bottom = 8
TabIndex = 0 TabIndex = 1
TabOrder = 2 TabOrder = 2
object OLSPage: TTabSheet object OLSPage: TTabSheet
Caption = 'OLS Regression' Caption = 'OLS Regression'
end end
object ResidualsRegPage: TTabSheet object ResidualsRegPage: TTabSheet
Caption = 'Squared Residuals Regression' Caption = 'Squared Residuals Regression'
ClientHeight = 384
ClientWidth = 492
object ResRegPageControl: TPageControl
Left = 8
Height = 368
Top = 8
Width = 476
ActivePage = ResRegReportPage
Align = alClient
BorderSpacing.Around = 8
TabIndex = 0
TabOrder = 0
object ResRegReportPage: TTabSheet
Caption = 'Report'
end
end
end end
object WLSPage: TTabSheet object WLSPage: TTabSheet
Caption = 'WLS Regression' Caption = 'WLS Regression'

View File

@ -8,7 +8,7 @@ uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, Buttons, ExtCtrls, ComCtrls, StdCtrls, Buttons, ExtCtrls, ComCtrls,
Globals, MainUnit, DictionaryUnit, Matrixlib, Globals, MainUnit, DictionaryUnit, Matrixlib,
DataProcs, BlankFrmUnit, ReportFrameUnit, BasicStatsParamsFormUnit; //BasicStatsReportAndChartFormUnit; DataProcs, BlankFrmUnit, ReportFrameUnit, ChartFrameUnit, BasicStatsParamsFormUnit; //BasicStatsReportAndChartFormUnit;
type type
@ -21,7 +21,9 @@ type
IndOutBtn: TBitBtn; IndOutBtn: TBitBtn;
PageControl: TPageControl; PageControl: TPageControl;
OLSPage: TTabSheet; OLSPage: TTabSheet;
ResRegPageControl: TPageControl;
ResidualsRegPage: TTabSheet; ResidualsRegPage: TTabSheet;
ResRegReportPage: TTabSheet;
WLSPage: TTabSheet; WLSPage: TTabSheet;
WghtInBtn: TBitBtn; WghtInBtn: TBitBtn;
WghtOutBtn: TBitBtn; WghtOutBtn: TBitBtn;
@ -56,10 +58,19 @@ type
OLSReportFrame: TReportFrame; OLSReportFrame: TReportFrame;
ResidualsRegReportFrame: TReportFrame; ResidualsRegReportFrame: TReportFrame;
WLSReportFrame: TReportFrame; WLSReportFrame: TReportFrame;
procedure CreateOrGetChartFrame(AColIndex: Integer; AVarName: String;
out AMemo: TMemo; out AChartFrame: TChartFrame);
function GetPageCaption(AVarName: String): String;
procedure PredictIt(ColNoSelected: IntDyneVec; NoVars: integer; procedure PredictIt(ColNoSelected: IntDyneVec; NoVars: integer;
Means, StdDevs, BetaWeights: DblDyneVec; Means, StdDevs, BetaWeights: DblDyneVec;
StdErrEst: double; NoIndepVars: integer); StdErrEst: double; NoIndepVars: integer);
procedure PlotXY(AChartFrame: TChartFrame; const XPoints, YPoints, UpConf, LowConf: DblDyneVec;
ConfBand, XMean, YMean, R, Slope, Intercept: Double; XLabel, YLabel: String);
procedure PlotXY(Xpoints, Ypoints, UpConf, LowConf: DblDyneVec; procedure PlotXY(Xpoints, Ypoints, UpConf, LowConf: DblDyneVec;
ConfBand, Xmean, Ymean, R, Slope, Intercept: double; ConfBand, Xmean, Ymean, R, Slope, Intercept: double;
Xmax, Xmin, Ymax, Ymin: double; Xmax, Xmin, Ymax, Ymin: double;
@ -86,6 +97,7 @@ implementation
{$R *.lfm} {$R *.lfm}
uses uses
TAChartUtils, TALegend,
Utils, GridProcs, MathUnit; Utils, GridProcs, MathUnit;
{ TWLSFrm } { TWLSFrm }
@ -108,7 +120,7 @@ begin
ResidualsRegReportFrame := TReportFrame.Create(self); ResidualsRegReportFrame := TReportFrame.Create(self);
ResidualsRegReportFrame.Name := ''; ResidualsRegReportFrame.Name := '';
ResidualsRegReportFrame.Parent := ResidualsRegPage; ResidualsRegReportFrame.Parent := ResRegReportPage;
ResidualsRegReportFrame.Align := alClient; ResidualsRegReportFrame.Align := alClient;
ResidualsRegReportFrame.BorderSpacing.Left := 0; ResidualsRegReportFrame.BorderSpacing.Left := 0;
ResidualsRegReportFrame.BorderSpacing.Top := 0; ResidualsRegReportFrame.BorderSpacing.Top := 0;
@ -167,6 +179,8 @@ var
errorcode: Boolean = false; errorcode: Boolean = false;
C: TWinControl; C: TWinControl;
msg: String; msg: String;
chartFrame: TChartFrame;
memo: TMemo;
begin begin
if not Validate(msg, C) then if not Validate(msg, C) then
begin begin
@ -187,10 +201,10 @@ begin
SetLength(tprobs, NoVariables + 2); SetLength(tprobs, NoVariables + 2);
SetLength(RowLabels, NoVariables + 2); SetLength(RowLabels, NoVariables + 2);
SetLength(IndepCols, NoVariables + 2); SetLength(IndepCols, NoVariables + 2);
SetLength(Xpoints, NoCases + 1); // SetLength(Xpoints, NoCases + 1);
SetLength(Ypoints, NoCases + 1); // SetLength(Ypoints, NoCases + 1);
SetLength(UpConf, NoCases + 1); // SetLength(UpConf, NoCases + 1);
SetLength(lowConf, NoCases + 1); // SetLength(lowConf, NoCases + 1);
SetLength(ColNoSelected, 2); SetLength(ColNoSelected, 2);
lReport := TStringList.Create; lReport := TStringList.Create;
@ -198,7 +212,7 @@ begin
NCases := NoCases; NCases := NoCases;
NoIndep := IndVarList.Items.Count; NoIndep := IndVarList.Items.Count;
// wp: Next SetLength crashes... // wp: This SetLength crashes...
// SetLength(IndepCols, NoIndep+1); // +1 because the dep col will be stuffed in there, too // SetLength(IndepCols, NoIndep+1); // +1 because the dep col will be stuffed in there, too
// SetLength(RowLabels, NoIndep); // SetLength(RowLabels, NoIndep);
@ -334,7 +348,7 @@ begin
if (DataProcs.ValidValue(i, col-2)) then // do we have a valid squared OLS residual? if (DataProcs.ValidValue(i, col-2)) then // do we have a valid squared OLS residual?
begin begin
predicted := 0.0; predicted := 0.0;
for j := 0 to Noindep - 1 do for j := 0 to NoIndep - 1 do
begin begin
pos := IndepCols[j]; pos := IndepCols[j];
X := StrToFloat(OS3MainFrm.DataGrid.Cells[pos,i]); X := StrToFloat(OS3MainFrm.DataGrid.Cells[pos,i]);
@ -342,22 +356,24 @@ begin
end; end;
predicted := predicted + BWeights[Noindep]; predicted := predicted + BWeights[Noindep];
predicted := abs(predicted); predicted := abs(predicted);
OS3MainFrm.DataGrid.Cells[col-1,i] := Format('%8.3f', [predicted]); OS3MainFrm.DataGrid.Cells[col-1,i] := Format('%.3f', [predicted]);
if (predicted > 0.0) then if (predicted > 0.0) then
predicted := 1.0 / sqrt(predicted) predicted := 1.0 / sqrt(predicted)
else else
predicted := 0.0; predicted := 0.0;
OS3MainFrm.DataGrid.Cells[col,i] := Format('%8.3f', [predicted]); OS3MainFrm.DataGrid.Cells[col,i] := Format('%.3f', [predicted]);
end; // if valid case end; // if valid case
end; // next i end; // next i
end; // if regresChk end; // if regresChk
// Now, plot squared residuals against each independent variable // Now, plot squared residuals against each independent variable
if PlotChk.Checked and RegResChk.Checked then if RegResChk.Checked then
begin begin
xCol := DepCol; xCol := DepCol;
for ii := 0 to NoIndep - 1 do for ii := 0 to NoIndep - 1 do
begin begin
SetLength(xPoints, NoCases);
SetLength(yPoints, NoCases);
yCol := IndepCols[ii]; yCol := IndepCols[ii];
N := 0; N := 0;
ColNoSelected[0] := xCol; ColNoSelected[0] := xCol;
@ -377,7 +393,6 @@ begin
for i := 1 to NoCases do for i := 1 to NoCases do
begin begin
if (not DataProcs.GoodRecord(i,NoSelected,ColNoSelected)) then continue; if (not DataProcs.GoodRecord(i,NoSelected,ColNoSelected)) then continue;
N := N + 1;
X := StrToFloat(OS3MainFrm.DataGrid.Cells[Xcol,i]); X := StrToFloat(OS3MainFrm.DataGrid.Cells[Xcol,i]);
Y := StrToFloat(OS3MainFrm.DataGrid.Cells[Ycol,i]); Y := StrToFloat(OS3MainFrm.DataGrid.Cells[Ycol,i]);
Xpoints[N] := X; Xpoints[N] := X;
@ -391,7 +406,10 @@ begin
Xvariance := Xvariance + X * X; Xvariance := Xvariance + X * X;
Yvariance := Yvariance + Y * Y; Yvariance := Yvariance + Y * Y;
R := R + X * Y; R := R + X * Y;
N := N + 1;
end; end;
SetLength(xPoints, N);
SetLength(yPoints, N);
// sort on X // sort on X
SortOnX(xPoints, yPoints); SortOnX(xPoints, yPoints);
@ -418,8 +436,7 @@ begin
Intercept := Ymean - Slope * Xmean; Intercept := Ymean - Slope * Xmean;
// Now, print the descriptive statistics if requested // Now, print the descriptive statistics if requested
lReport.Add('X versus Y Plot'); lReport.Clear;
lReport.Add('');
lReport.Add('Data file: %s', [OS3MainFrm.FileNameEdit.Text]); lReport.Add('Data file: %s', [OS3MainFrm.FileNameEdit.Text]);
lReport.Add(''); lReport.Add('');
lReport.Add('Variables:'); lReport.Add('Variables:');
@ -437,17 +454,13 @@ begin
lReport.Add('Standard Error of Estimate: %8.2f', [SEPred]); lReport.Add('Standard Error of Estimate: %8.2f', [SEPred]);
lReport.Add('Number of good cases: %8d', [N]); lReport.Add('Number of good cases: %8d', [N]);
// FReportFrame.DisplayReport(lReport); // Get upper and lower confidence points for each X value
// lReport.Clear; SetLength(UpConf, N);
lReport.Add(''); SetLength(LowConf, N);
lReport.Add(DIVIDER);
lReport.Add('');
// get upper and lower confidence points for each X value
ConfBand := 0.95; ConfBand := 0.95;
DF := N - 2; DF := N - 2;
t := inverset(ConfBand,DF); t := inverset(ConfBand,DF);
for i := 1 to N do for i := 0 to N-1 do
begin begin
X := Xpoints[i]; X := Xpoints[i];
predicted := Slope * X + Intercept; predicted := Slope * X + Intercept;
@ -458,11 +471,27 @@ begin
if (lowConf[i] < Ymin) then Ymin := lowConf[i]; if (lowConf[i] < Ymin) then Ymin := lowConf[i];
end; end;
// plot the values (and optional line and confidence band if elected) // Plot the values, line and confidence band
CreateOrGetChartFrame(yCol, yLabel, memo, chartFrame);
chartFrame.Clear;
PlotXY(chartFrame, XPoints, YPoints, upConf, lowConf, confBand, xMean, yMean, R, slope, intercept, xLabel, yLabel);
memo.Lines.Assign(lReport);
lReport.Clear;
{
if NormPltChk.Checked then
PlotNormalDist(chartFrame, normDistValue);
PlotFreq(chartFrame, col, cellVal, xLabels, freq);
}
if PlotChk.Checked then
begin
PlotXY(Xpoints, Ypoints, UpConf, lowConf, ConfBand, Xmean, Ymean, R, PlotXY(Xpoints, Ypoints, UpConf, lowConf, ConfBand, Xmean, Ymean, R,
Slope, Intercept, Xmax, Xmin, Ymax, Ymin, N, XLabel, YLabel); Slope, Intercept, Xmax, Xmin, Ymax, Ymin, N, XLabel, YLabel);
BlankFrm.ShowModal; BlankFrm.ShowModal;
end; end;
end;
// FReportFrame.DisplayReport(lReport); // FReportFrame.DisplayReport(lReport);
end; end;
@ -586,6 +615,59 @@ begin
end; end;
procedure TWLSFrm.CreateOrGetChartFrame(AColIndex: Integer; AVarName: String;
out AMemo: TMemo; out AChartFrame: TChartFrame);
var
sheetTitle: String;
tabSheet: TTabSheet;
i: Integer;
begin
sheetTitle := GetPageCaption(AVarName);
// Find existing sheet first.
for i := 1 to ResRegPageControl.PageCount-1 do
if ResRegPageControl.Pages[i].Caption = sheetTitle then begin
tabSheet := ResRegPageControl.Pages[i];
AChartFrame := tabSheet.Controls[0] as TChartFrame;
AMemo := tabSheet.Controls[1] as TMemo;
exit;
end;
// Not found: create new sheet ...
tabSheet := ResRegPageControl.AddTabSheet;
tabSheet.Caption := sheetTitle;
tabSheet.Tag := AColIndex;
// ... and add ChartFrame
AChartFrame := TChartFrame.Create(tabSheet);
AChartFrame.Parent := tabSheet;
AChartFrame.Align := alClient;
AChartFrame.Chart.Legend.Alignment := laBottomCenter;
AChartFrame.Chart.Legend.ColumnCount := 3;
AChartFrame.Chart.Legend.TextFormat := tfHTML;
AChartFrame.Chart.BottomAxis.Intervals.MaxLength := 80;
AChartFrame.Chart.BottomAxis.Intervals.MinLength := 30;
// ... and add memo
AMemo := TMemo.Create(tabSheet);
AMemo.Parent := tabSheet;
AMemo.Align := alBottom;
AMemo.BorderStyle := bsNone;
AMemo.Font.Name := 'Courier New';
AMemo.Font.Size := 8;
AMemo.ReadOnly := true;
AMemo.Scrollbars := ssAutoBoth;
AMemo.WordWrap := false;
// ... and splitter
with TSplitter.Create(tabSheet) do
begin
Parent := tabSheet;
Align := alBottom;
end;
end;
procedure TWLSFrm.DepInBtnClick(Sender: TObject); procedure TWLSFrm.DepInBtnClick(Sender: TObject);
var var
index: integer; index: integer;
@ -611,6 +693,12 @@ begin
end; end;
function TWLSFrm.GetPageCaption(AVarName: String): String;
begin
Result := 'Plot of ' + AVarName;
end;
procedure TWLSFrm.IndInBtnClick(Sender: TObject); procedure TWLSFrm.IndInBtnClick(Sender: TObject);
var var
i: integer; i: integer;
@ -661,16 +749,15 @@ begin
end; end;
end; end;
// routine obtains predicted raw and standardized scores and their { Routine obtains predicted raw and standardized scores and their
// residuals. It is assumed that the dependent variable is last in the residuals. It is assumed that the dependent variable is last in the
// list of variable column pointers stored in the ColNoSelected vector. list of variable column pointers stored in the ColNoSelected vector.
// Get the z predicted score and its residual Get the z predicted score and its residual }
procedure TWLSFrm.PredictIt(ColNoSelected: IntDyneVec; NoVars: integer; procedure TWLSFrm.PredictIt(ColNoSelected: IntDyneVec; NoVars: integer;
Means, StdDevs, BetaWeights: DblDyneVec; Means, StdDevs, BetaWeights: DblDyneVec; StdErrEst: double; NoIndepVars: integer);
StdErrEst: double; NoIndepVars: integer);
var var
col, i, j, k, Index: integer; col, i, j, k, Index: integer;
predicted, zpredicted, z1, z2, resid, residsqr : double; predicted, zpredicted, z1, z2, resid, residsqr: double;
begin begin
col := NoVariables + 1; col := NoVariables + 1;
// NoVariables := col; // NoVariables := col;
@ -696,14 +783,14 @@ begin
z1 := (StrToFloat(OS3MainFrm.DataGrid.Cells[k,i]) - Means[j]) / StdDevs[j]; z1 := (StrToFloat(OS3MainFrm.DataGrid.Cells[k,i]) - Means[j]) / StdDevs[j];
zpredicted := zpredicted + (z1 * BetaWeights[j]); zpredicted := zpredicted + (z1 * BetaWeights[j]);
end; end;
OS3MainFrm.DataGrid.Cells[col-1,i] := Format('%8.4f',[zpredicted]); OS3MainFrm.DataGrid.Cells[col-1,i] := Format('%.4f',[zpredicted]);
if StdDevs[NoVars-1] <> 0.0 then if StdDevs[NoVars-1] <> 0.0 then
begin begin
Index := ColNoSelected[NoVars-1]; Index := ColNoSelected[NoVars-1];
z2 := StrToFloat(OS3MainFrm.DataGrid.Cells[Index,i]); z2 := StrToFloat(OS3MainFrm.DataGrid.Cells[Index,i]);
z2 := (z2 - Means[NoVars-1]) / StdDevs[NoVars-1]; // z score z2 := (z2 - Means[NoVars-1]) / StdDevs[NoVars-1]; // z score
OS3MainFrm.DataGrid.Cells[col,i] := Format('%8.4f',[z2 - zpredicted]); // z residual OS3MainFrm.DataGrid.Cells[col,i] := Format('%.4f',[z2 - zpredicted]); // z residual
end; end;
end; end;
@ -713,11 +800,12 @@ begin
DictionaryFrm.NewVar(col); DictionaryFrm.NewVar(col);
DictionaryFrm.DictGrid.Cells[1,col] := 'Pred.Raw'; DictionaryFrm.DictGrid.Cells[1,col] := 'Pred.Raw';
OS3MainFrm.DataGrid.Cells[col,0] := 'Pred.Raw'; OS3MainFrm.DataGrid.Cells[col,0] := 'Pred.Raw';
// calculate raw predicted scores and store in DataGrid at col // calculate raw predicted scores and store in DataGrid at col
for i := 1 to NoCases do for i := 1 to NoCases do
begin // predicted raw obtained from previously predicted z score begin // predicted raw obtained from previously predicted z score
predicted := StrToFloat(OS3MainFrm.DataGrid.Cells[col-2,i]) * StdDevs[NoVars-1] + Means[NoVars-1]; predicted := StrToFloat(OS3MainFrm.DataGrid.Cells[col-2,i]) * StdDevs[NoVars-1] + Means[NoVars-1];
OS3MainFrm.DataGrid.Cells[col,i] := Format('%8.3f',[predicted]); OS3MainFrm.DataGrid.Cells[col,i] := Format('%.3f',[predicted]);
end; end;
// Calculate residuals of predicted raw scores end; // Calculate residuals of predicted raw scores end;
@ -731,7 +819,7 @@ begin
begin begin
Index := ColNoSelected[NoVars-1]; Index := ColNoSelected[NoVars-1];
resid := StrToFloat(OS3MainFrm.DataGrid.Cells[col-1,i]) - StrToFloat(OS3MainFrm.DataGrid.Cells[Index,i]); resid := StrToFloat(OS3MainFrm.DataGrid.Cells[col-1,i]) - StrToFloat(OS3MainFrm.DataGrid.Cells[Index,i]);
OS3MainFrm.DataGrid.Cells[col,i] := Format('%8.3f',[resid]); OS3MainFrm.DataGrid.Cells[col,i] := Format('%.3f',[resid]);
end; end;
// get square of raw residuals // get square of raw residuals
@ -748,6 +836,47 @@ begin
end; end;
end; end;
procedure TWLSFrm.PlotXY(AChartFrame: TChartFrame;
const XPoints, YPoints, UpConf, LowConf: DblDyneVec;
ConfBand, XMean, YMean, R, Slope, Intercept: Double; XLabel, YLabel: String);
var
xpts: DblDyneVec = nil;
ypts: DblDyneVec = nil;
ext: TDoubleRect;
begin
AChartFrame.SetFooter(Format('R(X,Y) = %.3f, Slope = %.3f, Intercept = %.3f', [
R, Slope, Intercept
]));
// Data points
AChartFrame.SetXTitle(XLabel);
AChartFrame.SetYTitle(YLabel);
AChartFrame.PlotXY(ptSymbols, XPoints, YPoints, nil, nil, 'Data', DATA_COLORS[0]);
// Regression line
SetLength(xpts, 2);
SetLengtH(ypts, 2);
ext := AChartFrame.Chart.GetFullExtent;
xpts[0] := ext.a.x;
xpts[0] := ext.b.x;
ypts[0] := Intercept + Slope * xpts[0];
ypts[1] := Intercept + Slope * xpts[1];
AChartFrame.PlotXY(ptLines, xpts, ypts, nil, nil, 'Predicted', clBlack);
// Upper and lower confidence limit curves
AChartFrame.PlotXY(ptLines, XPoints, UpConf, nil, nil, 'UCL', clRed);
AChartFrame.PlotXY(ptLines, XPoints, LowConf, nil, nil, 'LCL', clRed);
// Mean lines
AChartFrame.VertLine(XMean, clGreen, psDashDot, 'Mean ' + XLabel);
// topLabels.Add(XMean, XMean, 'Mean ' + XLabel);
AChartFrame.HorLine(YMean, clGreen, psDash, 'Mean ' + YLabel);
// rightLabels.Add(YMean, YMean, 'Mean ' + YLabel);
end;
procedure TWLSFrm.PlotXY(Xpoints, Ypoints, UpConf, LowConf : DblDyneVec; procedure TWLSFrm.PlotXY(Xpoints, Ypoints, UpConf, LowConf : DblDyneVec;
ConfBand, Xmean, Ymean, R, Slope, Intercept : double; ConfBand, Xmean, Ymean, R, Slope, Intercept : double;
Xmax, Xmin, Ymax, Ymin : double; Xmax, Xmin, Ymax, Ymin : double;
@ -887,7 +1016,7 @@ begin
end; end;
// draw points for x and y pairs // draw points for x and y pairs
for i := 1 to N do for i := 0 to N-1 do
begin begin
ypos := round(vhi * ( (Ymax - Ypoints[i]) / (Ymax - Ymin))); ypos := round(vhi * ( (Ymax - Ypoints[i]) / (Ymax - Ymin)));
ypos := ypos + vtop; ypos := ypos + vtop;
@ -903,12 +1032,12 @@ begin
if not (ConfBand = 0.0) then if not (ConfBand = 0.0) then
begin begin
BlankFrm.Image1.Canvas.Pen.Color := clRed; BlankFrm.Image1.Canvas.Pen.Color := clRed;
ypos := round(vhi * ((Ymax - UpConf[1]) / (Ymax - Ymin))); ypos := round(vhi * ((Ymax - UpConf[0]) / (Ymax - Ymin)));
ypos := ypos + vtop; ypos := ypos + vtop;
xpos := round(hwide * ( (Xpoints[1] - Xmin) / (Xmax - Xmin))); xpos := round(hwide * ( (Xpoints[0] - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft; xpos := xpos + hleft;
BlankFrm.Image1.Canvas.MoveTo(xpos,ypos); BlankFrm.Image1.Canvas.MoveTo(xpos,ypos);
for i := 2 to N do for i := 1 to N-1 do
begin begin
ypos := round(vhi * ((Ymax - UpConf[i]) / (Ymax - Ymin))); ypos := round(vhi * ((Ymax - UpConf[i]) / (Ymax - Ymin)));
ypos := ypos + vtop; ypos := ypos + vtop;
@ -916,12 +1045,12 @@ begin
xpos := xpos + hleft; xpos := xpos + hleft;
BlankFrm.Image1.Canvas.LineTo(xpos,ypos); BlankFrm.Image1.Canvas.LineTo(xpos,ypos);
end; end;
ypos := round(vhi * ((Ymax - LowConf[1]) / (Ymax - Ymin))); ypos := round(vhi * ((Ymax - LowConf[0]) / (Ymax - Ymin)));
ypos := ypos + vtop; ypos := ypos + vtop;
xpos := round(hwide * ( (Xpoints[1] - Xmin) / (Xmax - Xmin))); xpos := round(hwide * ( (Xpoints[0] - Xmin) / (Xmax - Xmin)));
xpos := xpos + hleft; xpos := xpos + hleft;
BlankFrm.Image1.Canvas.MoveTo(xpos,ypos); BlankFrm.Image1.Canvas.MoveTo(xpos,ypos);
for i := 2 to N do for i := 1 to N-1 do
begin begin
ypos := round(vhi * ((Ymax - LowConf[i]) / (Ymax - Ymin))); ypos := round(vhi * ((Ymax - LowConf[i]) / (Ymax - Ymin)));
ypos := ypos + vtop; ypos := ypos + vtop;

View File

@ -2114,7 +2114,7 @@ procedure TOS3MainFrm.mnuAnalysisMultReg_WeightedClick(Sender: TObject);
begin begin
if WLSFrm = nil then if WLSFrm = nil then
Application.CreateForm(TWLSFrm, WLSFrm); Application.CreateForm(TWLSFrm, WLSFrm);
WLSFrm.ShowModal; WLSFrm.Show;
end; end;

View File

@ -53,7 +53,7 @@ procedure EffectCode(GridCol, min, max : integer;
procedure MReg(NoIndep: integer; const IndepCols: IntDyneVec; DepCol: integer; procedure MReg(NoIndep: integer; const IndepCols: IntDyneVec; DepCol: integer;
const RowLabels: StrDyneVec; const RowLabels: StrDyneVec;
const Means, Variances, StdDevs, BWeights, BetaWeights, BStdErrs, Bttests, tProbs: DblDyneVec; const Means, Variances, StdDevs, BWeights, BetaWeights, BStdErrs, Bttests, tProbs: DblDyneVec;
out R2, StdErrEst: double; NCases: integer; out ErrorCode: boolean; out R2, StdErrEst: double; out NCases: integer; out ErrorCode: boolean;
PrintAll: boolean; AReport: TStrings); PrintAll: boolean; AReport: TStrings);
procedure Dynnonsymroots(var a : DblDyneMat; nv : integer; procedure Dynnonsymroots(var a : DblDyneMat; nv : integer;
@ -622,10 +622,26 @@ begin
coef := nil; coef := nil;
end; end;
{ Calculates a multiple regression on data in the mainform's grid
NoIndep ..... Count of independent variables
IndepCols ... Grid column indices of the independent variables
DepCol ...... Grid column index of the dependent variable
RowLabels ... Names of the independent variables (they will be displayed in the
printout of matrices as rowlabels.
Means ....... Mean value for each independent variable
Variances ... Variance of each independent variable
StdDevs ..... Standard deviations of each independent variable
NCases ...... Count of valid cases found in the grid
ErrorCode ... if true, an error has occured during the calculations
PrintAll .... if true, intermediate matrices and vectors are written to the report
AReport ..... a string list to which the report is written.
}
procedure MReg(NoIndep: integer; const IndepCols: IntDyneVec; DepCol: integer; procedure MReg(NoIndep: integer; const IndepCols: IntDyneVec; DepCol: integer;
const RowLabels: StrDyneVec; const RowLabels: StrDyneVec;
const Means, Variances, StdDevs, BWeights, BetaWeights, BStdErrs, Bttests, tProbs: DblDyneVec; const Means, Variances, StdDevs, BWeights, BetaWeights, BStdErrs, Bttests, tProbs: DblDyneVec;
out R2, StdErrEst: double; NCases: integer; out ErrorCode: boolean; out R2, StdErrEst: double; out NCases: integer; out ErrorCode: boolean;
PrintAll: boolean; AReport: TStrings); PrintAll: boolean; AReport: TStrings);
var var
i, j, N: integer; i, j, N: integer;
@ -718,8 +734,8 @@ begin
AReport.Add(DIVIDER_SMALL); AReport.Add(DIVIDER_SMALL);
// augment the matrix // augment the matrix
for i := 1 to NCases do for i := 0 to NCases-1 do
X[i-1, NoIndep] := 1.0; X[i, NoIndep] := 1.0;
Y[NCases] := 1.0; Y[NCases] := 1.0;
// get transpose of augmented X matrix // get transpose of augmented X matrix