diff --git a/applications/lazstats/source/forms/analysis/correlation/autocorunit.pas b/applications/lazstats/source/forms/analysis/correlation/autocorunit.pas index e5353da65..a5ed68349 100644 --- a/applications/lazstats/source/forms/analysis/correlation/autocorunit.pas +++ b/applications/lazstats/source/forms/analysis/correlation/autocorunit.pas @@ -1017,7 +1017,7 @@ end; procedure TAutoCorrFrm.realft(var data: DblDyneVec; n: longword; isign: integer); var - i,i1,i2,i3,i4,np3 : longword; + i,i1,i2,i3,i4,np3 : integer; // was: longword; c1,c2,h1r,h1i,h2r,h2i : double; wr,wi,wpr,wpi,wtemp,theta : double; diff --git a/applications/lazstats/source/forms/analysis/correlation/canonunit.pas b/applications/lazstats/source/forms/analysis/correlation/canonunit.pas index af2b1deec..adc2c1e76 100644 --- a/applications/lazstats/source/forms/analysis/correlation/canonunit.pas +++ b/applications/lazstats/source/forms/analysis/correlation/canonunit.pas @@ -153,15 +153,13 @@ begin end; procedure TCannonFrm.ComputeBtnClick(Sender: TObject); -const - SEPARATOR = '==========================================================================='; var - i, j, k, count, a_size, b_size, no_factors, novars, IER: integer; + i, j, k, count, a_size, b_size, no_factors, novars: integer; cellstring, gridstring: string; s, m, n, df1, df2, q, w, pcnt_extracted, trace : double; minroot, critical_prob, Lambda, Pillia : double; chisqr, HLTrace, chiprob, ftestprob, Roys, f, Hroot : double; - raa, rbb, rab, rba, bigmat, prod, first_prod, second_prod : DblDyneMat; + raa, rbb, rab, rba, bigmat, first_prod, second_prod : DblDyneMat; char_equation, raainv, rbbinv, eigenvectors, norm_a, norm_b : DblDyneMat; raw_a, raw_b, a_cors, b_cors, eigentrans, theta, tempmat : DblDyneMat; mean, variance, stddev, roots, root_chi, chi_prob, pv_a, pv_b : DblDyneVec; @@ -209,7 +207,6 @@ begin SetLength(rab,a_size,b_size); SetLength(rba,b_size,a_size); SetLength(bigmat,novars+1,novars+1); - SetLength(prod,novars,novars); SetLength(first_prod,novars,novars); SetLength(second_prod,novars,novars); SetLength(char_equation,novars,novars); @@ -296,7 +293,7 @@ begin // Get means, standard deviations, etc. for total matrix Correlations(novars,selected,bigmat,mean,variance,stddev,errorcode,Ncases); count := Ncases; - if (IER = 1)then + if errorcode then // wp: was "if (IER = 1) then", but IER is not initialized... begin MessageDlg('Zero variance found for a variable-terminating', mtError, [mbOK], 0); exit; @@ -327,7 +324,7 @@ begin title := 'Left-Right Correlation Matrix'; MatPrint(rab, a_size, b_size, title, RowLabels, ColLabels, NCases, lReport); lReport.Add(''); - lReport.Add(SEPARATOR); + lReport.Add(DIVIDER); lReport.Add(''); end; @@ -367,7 +364,7 @@ begin MatPrint(char_equation, b_size, b_size, title, CanLabels, CanLabels, NCases, lReport); lReport.Add(''); - lReport.Add(SEPARATOR); + lReport.Add(DIVIDER); lReport.Add(''); // now get roots and vectors of the characteristic equation using @@ -503,7 +500,7 @@ begin lReport.Add('Roys Largest Root F-Test %10.4f %2.0f %2.0f %12.4f', [Roys, df1, df2, ftestprob]); lReport.Add(''); - lReport.Add(SEPARATOR); + lReport.Add(DIVIDER); lReport.Add(''); if EigenChk.Checked then @@ -511,7 +508,7 @@ begin title := 'Eigenvectors'; MatPrint(eigenvectors, b_size, b_size, title, CanLabels, CanLabels, NCases, lReport); lReport.Add(''); - lReport.Add(SEPARATOR); + lReport.Add(DIVIDER); lReport.Add(''); end; @@ -522,7 +519,7 @@ begin MatPrint(norm_b, b_size, b_size, title, ColLabels, CanLabels, NCases, lReport); lReport.Add(''); - lReport.Add(SEPARATOR); + lReport.Add(DIVIDER); lReport.Add(''); title := 'Raw Right Side Weights'; @@ -532,7 +529,7 @@ begin MatPrint(raw_b, b_size, b_size, title, ColLabels, CanLabels, NCases, lReport); lReport.Add(''); - lReport.Add(SEPARATOR); + lReport.Add(DIVIDER); lReport.Add(''); title := 'Right Side Correlations with Function'; @@ -542,7 +539,7 @@ begin MatPrint(b_cors, b_size, b_size, title, ColLabels, CanLabels, NCases, lReport); lReport.Add(''); - lReport.Add(SEPARATOR); + lReport.Add(DIVIDER); lReport.Add(''); if RedundChk.Checked then @@ -563,7 +560,7 @@ begin lReport.Add('%8d %15.5f %12.5f', [i, pv_b[i-1], rd_b[i-1]]); lReport.Add(''); - lReport.Add(SEPARATOR); + lReport.Add(DIVIDER); lReport.Add(''); end; @@ -604,7 +601,6 @@ begin char_equation := nil; second_prod := nil; first_prod := nil; - prod := nil; rba := nil; rab := nil; rbb := nil; diff --git a/applications/lazstats/source/forms/analysis/descriptive/comparedistunit.pas b/applications/lazstats/source/forms/analysis/descriptive/comparedistunit.pas index 6f73c66e9..941b26871 100644 --- a/applications/lazstats/source/forms/analysis/descriptive/comparedistunit.pas +++ b/applications/lazstats/source/forms/analysis/descriptive/comparedistunit.pas @@ -122,7 +122,7 @@ var Cumfreq2 : DblDyneVec; i, j, k, col1, col2, Ncases, noints : integer; min1, max1, min2, max2, range1, range2, value : double; - incrsize1, incrsize2, prob1,prob2, KS, mean, DegFree : double; + incrsize1, incrsize2, prob1,prob2, {%H-}KS, mean, DegFree : double; cellval, name1, name2 : string; df1, df2 : integer; xtitle : string; diff --git a/applications/lazstats/source/forms/analysis/descriptive/normalityunit.pas b/applications/lazstats/source/forms/analysis/descriptive/normalityunit.pas index d0986969f..72c946a3c 100644 --- a/applications/lazstats/source/forms/analysis/descriptive/normalityunit.pas +++ b/applications/lazstats/source/forms/analysis/descriptive/normalityunit.pas @@ -140,16 +140,16 @@ end; procedure TNormalityFrm.ApplyBtnClick(Sender: TObject); var w: Double = 0.0; - temp, pw : double; + pw: Double = 0.0; + temp: double; skew, kurtosis : double; mean, variance, stddev, deviation, devsqr, M2, M3, M4 : double; i, j, n, n1, n2, ier : integer; - varlabel : string; selcol : integer; data, a, z, x : DblDyneVec; freq : IntDyneVec; fval, jval, DP : DblDyneVec; - F1, DPP, D, D1, A0, C1, D15, D10, D05, D025, t2 : double; + F1, DPP, D, A0, C1, D15, D10, D05, D025, t2 : double; init : boolean; msg : string; @@ -181,7 +181,6 @@ begin init := false; n := 0; - varlabel := TestVarEdit.Text; // place values into the data array SetLength(data, NoCases+1); // arrays start at 1 @@ -225,8 +224,8 @@ begin Cleanup; exit; end; - WEdit.Text := Format('%8.4f', [w]); - ProbEdit.Text := Format('%8.4f', [pw]); + WEdit.Text := Format('%.4f', [w]); + ProbEdit.Text := Format('%.4f', [pw]); // Now do Lilliefors // Get unique scores and their frequencies @@ -280,8 +279,8 @@ begin skew := (n * M3) / ((n - 1) * (n - 2) * stddev * variance); kurtosis := (n * (n + 1) * M4) - (3 * M2 * M2 * (n - 1)); kurtosis := kurtosis /( (n - 1) * (n - 2) * (n - 3) * (variance * variance) ); - SkewEdit.Text := Format('%8.3f', [skew]); - KurtosisEdit.Text := Format('%8.3f', [kurtosis]); + SkewEdit.Text := Format('%.3f', [skew]); + KurtosisEdit.Text := Format('%.3f', [kurtosis]); // obtain the test statistic for i := 1 to n1 do @@ -313,8 +312,7 @@ begin end; DPP := DP[n1]; D := DPP; - D1 := D; - StatEdit.Text := Format('%8.3f', [D]); + StatEdit.Text := Format('%.3f', [D]); A0 := sqrt(n); C1 := A0 - 0.01 + (0.85 / A0); D15 := 0.775 / C1; diff --git a/applications/lazstats/source/forms/analysis/descriptive/resistancelineunit.pas b/applications/lazstats/source/forms/analysis/descriptive/resistancelineunit.pas index 2a218985e..4737fcbb6 100644 --- a/applications/lazstats/source/forms/analysis/descriptive/resistancelineunit.pas +++ b/applications/lazstats/source/forms/analysis/descriptive/resistancelineunit.pas @@ -103,7 +103,6 @@ end; procedure TResistanceLineForm.ComputeBtnClick(Sender: TObject); var XYPoints : DblDyneMat; - XYMedians : DblDyneMat; XMedians : DblDyneVec; YMedians : DblDyneVec; XVector, YVector : DblDyneVec; @@ -122,7 +121,6 @@ var lReport: TStrings; begin SetLength(XYPoints, NoCases, NoCases); - SetLength(XYMedians, 3, 3); SetLength(XMedians, 3); SetLength(YMedians, 3); SetLength(XVector, NoCases); @@ -383,7 +381,6 @@ begin XVector := nil; YMedians := nil; XMedians := nil; - XYMedians := nil; XYPoints := nil; end; end; diff --git a/applications/lazstats/source/forms/analysis/multiple_regression/coxregunit.pas b/applications/lazstats/source/forms/analysis/multiple_regression/coxregunit.pas index eabd04795..ab61549e9 100644 --- a/applications/lazstats/source/forms/analysis/multiple_regression/coxregunit.pas +++ b/applications/lazstats/source/forms/analysis/multiple_regression/coxregunit.pas @@ -188,7 +188,6 @@ var prob : double; // probability of chi square SurvT : DblDyneVec; Stat : DblDyneVec; - Dupl : DblDyneVec; Alpha : DblDyneVec; a : DblDyneVec; b : DblDyneVec; @@ -277,7 +276,6 @@ begin SetLength(SurvT,nC + 1); SetLength(Stat,nC + 1); - SetLength(Dupl,nC + 1); SetLength(Alpha,nC + 1); SetLength(x,(nC + 1) * (nR + 1)); SetLength(b,nC + 1); @@ -533,7 +531,6 @@ begin SurvT := nil; Stat := nil; - Dupl := nil; Alpha := nil; x := nil; b := nil; diff --git a/applications/lazstats/source/forms/analysis/multivariate/discrimunit.pas b/applications/lazstats/source/forms/analysis/multivariate/discrimunit.pas index 86711ca55..788801708 100644 --- a/applications/lazstats/source/forms/analysis/multivariate/discrimunit.pas +++ b/applications/lazstats/source/forms/analysis/multivariate/discrimunit.pas @@ -165,7 +165,7 @@ procedure TDiscrimFrm.ComputeBtnClick(Sender: TObject); var i, j, k, grp, grpvalue, matrow, matcol, noroots, dfchi, n2, k2 : integer; NoSelected : integer; - outline, GroupLabel, ColHead : string; + outline, ColHead: string; Title : string; GrpVar, NoGrps, nowithin, TotalCases, value, grpno : integer; ColNoSelected : IntDyneVec; @@ -229,7 +229,6 @@ begin if GroupVar.Text = OS3MainFrm.DataGrid.Cells[j,0] then begin GrpVar := j; - GroupLabel := OS3MainFrm.DataGrid.Cells[j,0]; ColNoSelected[NoSelected-1] := j; end; end; // next j variable diff --git a/applications/lazstats/source/forms/analysis/multivariate/medianpolishunit.pas b/applications/lazstats/source/forms/analysis/multivariate/medianpolishunit.pas index 9c3eadfeb..66d2d93b4 100644 --- a/applications/lazstats/source/forms/analysis/multivariate/medianpolishunit.pas +++ b/applications/lazstats/source/forms/analysis/multivariate/medianpolishunit.pas @@ -104,7 +104,7 @@ end; procedure TMedianPolishForm.ComputeBtnClick(Sender: TObject); var - NoSelected, DepVarCol, F1Col, F2Col, i, j, k : integer; + DepVarCol, F1Col, F2Col, i, j, k : integer; minrow, maxrow, mincol, maxcol : integer; intvalue, xrange, yrange, row, col, N, count, iteration : integer; X, M, sumrowmedians, sumcolmedians, GrandMedian, scale, TotResid : double; @@ -167,8 +167,7 @@ begin if cellstring = Factor1.Text then F1Col := i; if cellstring = Factor2.Text then F2Col := i; end; - NoSelected := 3; - SetLength(ColNoSelected,3); + SetLength(ColNoSelected, 3); ColNoSelected[0] := DepVarCol; ColNoSelected[1] := F1Col; ColNoSelected[2] := F2Col; diff --git a/applications/lazstats/source/units/functionslib.pas b/applications/lazstats/source/units/functionslib.pas index ce252a7e4..9acb8e5bb 100644 --- a/applications/lazstats/source/units/functionslib.pas +++ b/applications/lazstats/source/units/functionslib.pas @@ -23,8 +23,8 @@ function probf(f,df1,df2 : extended) : extended; FUNCTION alnorm(x : double; upper : boolean): double; procedure ppnd7 (p : double; VAR normal_dev : double; VAR ifault : integer); FUNCTION poly(c : Array of double; nord : integer; x : double): double; // RESULT(fn_val) -procedure swilk (var init : boolean; var x : DblDyneVec; n : integer; n1 : integer; - n2 : integer; var a : DblDyneVec; var w : double; var pw : double; var ifault : integer); +procedure swilk (var init : boolean; const x: DblDyneVec; n, n1, n2: integer; + const a: DblDyneVec; var w, pw: double; out ifault: integer); procedure SVDinverse(VAR a : DblDyneMat; N : integer); function probt(t,df1 : double) : double; function inverset(Probt, DF : double) : double; @@ -824,8 +824,8 @@ begin END; // FUNCTION poly //----------------------------------------------------------------------- -procedure swilk (var init : boolean; var x : DblDyneVec; n : integer; n1 : integer; - n2 : integer; var a : DblDyneVec; var w : double; var pw : double; var ifault : integer); +procedure swilk (var init: boolean; const x: DblDyneVec; n, n1, n2: integer; + const a: DblDyneVec; var w, pw: double; out ifault: integer); // ALGORITHM AS R94 APPL. STATIST. (1995) VOL.44, NO.4 // Calculates the Shapiro-Wilk W test and its significance level diff --git a/applications/lazstats/source/units/matrixlib.pas b/applications/lazstats/source/units/matrixlib.pas index 46456c2d7..a900590bc 100644 --- a/applications/lazstats/source/units/matrixlib.pas +++ b/applications/lazstats/source/units/matrixlib.pas @@ -75,24 +75,11 @@ procedure MReg(NoIndep : integer; VAR errorcode : boolean; PrintAll : boolean); -procedure MReg(NoIndep : integer; - {VAR} IndepCols : IntDyneVec; - DepCol : integer; - {VAR} RowLabels : StrDyneVec; - {VAR} Means : DblDyneVec; - {VAR} Variances : DblDyneVec; - {VAR} StdDevs : DblDyneVec; - {VAR} BWeights : DblDyneVec; - {VAR} BetaWeights : DblDyneVec; - {VAR} BStdErrs : DblDyneVec; - {VAR} Bttests : DblDyneVec; - {VAR} tProbs : DblDyneVec; - VAR R2 : double; - VAR stderrest : double; - VAR NCases : integer; - VAR errorcode : boolean; - PrintAll : boolean; - AReport: TStrings); +procedure MReg(NoIndep: integer; const IndepCols: IntDyneVec; DepCol: integer; + const RowLabels: StrDyneVec; + const Means, Variances, StdDevs, BWeights, BetaWeights, BStdErrs, Bttests, tProbs: DblDyneVec; + out R2, StdErrEst: double; out NCases: integer; out ErrorCode: boolean; + PrintAll: boolean; AReport: TStrings); procedure Dynnonsymroots(var a : DblDyneMat; nv : integer; var nf : integer; c : real; @@ -132,7 +119,7 @@ procedure MReg2(NCases : integer; VAR BetaWeights : DblDyneVec; VAR Means : DblDyneVec; VAR Variances : DblDyneVec; - VAR errorcode : integer; + out errorcode : integer; out StdErrEst: double; out constant: double; probout : double; @@ -180,8 +167,8 @@ procedure MatPrint(const xmat: DblDyneMat; Rows,Cols: Integer; const Title: Stri procedure DynVectorPrint(var AVector: DblDyneVec; NoVars: integer; Title: string; var Labels: StrDyneVec; NCases: integer); overload; -procedure DynVectorPrint(var AVector: DblDyneVec; NoVars: integer; - Title: string; var Labels: StrDyneVec; NCases: integer; AReport: TStrings); overload; +procedure DynVectorPrint(const AVector: DblDyneVec; NoVars: integer; + Title: string; const Labels: StrDyneVec; NCases: integer; AReport: TStrings); overload; procedure scatplot(const x, y: DblDyneVec; NoCases: integer; const TitleStr, x_axis, y_axis: string; x_min, x_max, y_min, y_max: double; @@ -709,24 +696,11 @@ begin ErrorCode, PrintAll, OutputFrm.RichEdit.Lines); end; -procedure MReg(NoIndep : integer; - {var} IndepCols : IntDyneVec; - DepCol : integer; - {var} RowLabels : StrDyneVec; - {var} Means : DblDyneVec; - {var} Variances : DblDyneVec; - {var} StdDevs : DblDyneVec; - {var} BWeights : DblDyneVec; - {var} BetaWeights : DblDyneVec; - {var} BStdErrs : DblDyneVec; - {var} Bttests : DblDyneVec; - {var} tProbs : DblDyneVec; - var R2 : double; - var StdErrEst : double; - var NCases : integer; - var ErrorCode : boolean; - PrintAll : boolean; - AReport: TStrings); +procedure MReg(NoIndep: integer; const IndepCols: IntDyneVec; DepCol: integer; + const RowLabels: StrDyneVec; + const Means, Variances, StdDevs, BWeights, BetaWeights, BStdErrs, Bttests, tProbs: DblDyneVec; + out R2, StdErrEst: double; out NCases: integer; out ErrorCode: boolean; + PrintAll: boolean; AReport: TStrings); var i, j, N: integer; X: DblDyneMat; @@ -754,6 +728,7 @@ begin SetLength(ColLabels, NCases); // initialize + errcode := false; for i := 0 to NCases do begin for j := 0 to NoIndep do X[i, j] := 0; @@ -770,7 +745,6 @@ begin StdDevs[i] := 0.0; BWeights[i] := 0.0; BetaWeights[i] := 0.0; - errcode := false; for j := 0 to NoCases-1 do XT[i, j] := 0.0; for j := 0 to NoIndep do XTX[i, j] := 0.0; end; @@ -888,7 +862,7 @@ begin // Get standard errors, squared multiple correlation, tests of significance SSres := 0.0; for i := 0 to NoIndep do - SSres := SSres + (BWeights[i] * XTY[i]); + SSres := SSres + BWeights[i] * XTY[i]; SSres := SSY - SSres; resvar := SSres / (NCases - N); if resvar > 0.0 then StdErrEst := sqrt(resvar) else StdErrest := 0.0; @@ -1290,7 +1264,7 @@ procedure MReg2(NCases : integer; VAR BetaWeights : DblDyneVec; VAR Means : DblDyneVec; VAR Variances : DblDyneVec; - VAR errorcode : integer; + out errorcode : integer; out StdErrEst: double; out constant: double; probout : double; @@ -1900,10 +1874,10 @@ begin DynVectorPrint(AVector, NoVars, Title, Labels, NCases, OutputFrm.RichEdit.Lines); end; -procedure DynVectorPrint(var AVector: DblDyneVec; +procedure DynVectorPrint(const AVector: DblDyneVec; NoVars: integer; Title: string; - var Labels: StrDyneVec; + const Labels: StrDyneVec; NCases: integer; AReport: TStrings); var