CalcInitMode: ARMAInitType;
The CalcInitMode property selects method of determining initial approximations.
This property is relevant if the model includes exogenous variables or a constant.
To execute the example, add a link to the Stat system assembly.
Sub UserProc;
Var
lr: ISmLinearRegress;
W: Array[12] Of Double;
X: array[20] Of Double;
ARMA: ISlARMA;
AR, MA: Array[1] Of Integer;
Inits: Array[1] Of Double;
res: Integer;
d: Double;
CoefficientsAR, CoefficientsMA, CoefficientsX: ICoefficients;
ModelCoefficients: IModelCoefficients;
Begin
lr := New SmLinearRegress.Create;
// explained series values
w[0] := 2; w[4] := -1.9; w[8] := -0.7;
w[1] := 0.8; w[5] := Double.Nan; w[9] := Double.Nan;
w[2] := -0.3; w[6] := 3.2; w[10] := 4.3;
w[3] := -0.3; w[7] := 1.6; w[11] := 1.1;
lr.Explained.Value := w;
// explanatory series values
x[0] := Double.Nan; x[10] := 11;
x[1] := 2; x[11] := 12;
x[2] := 3; x[12] := 13;
x[3] := 4; x[13] := Double.Nan;
x[4] := 5; x[14] := 15;
x[5] := 6; x[15] := 16;
x[6] := Double.Nan; x[16] := 17;
x[7] := 8; x[17] := Double.Nan;
x[8] := 9; x[18] := 19;
x[9] := 10; x[19] := 20;
// sample period
lr.ModelPeriod.FirstPoint := 1;
lr.ModelPeriod.LastPoint := 12;
lr.Forecast.LastPoint := 19;
// missing data treatment method
lr.MissingData.Method := MissingDataMethod.AnyValue;
// exogenous variable is used in model
lr.Explanatories.Clear;
lr.Explanatories.Add.Value := X;
// initial approximation of exogenous variable
lr.Explanatories.Item(0).InitValue := 0.7;
ModelCoefficients := lr.ModelCoefficients;
// constant is used in model
ModelCoefficients.Intercept.Mode := InterceptMode.AutoEstimate;
// initial approximation for constant
ModelCoefficients.Intercept.InitValue := 3;
ARMA := lr.ARMA;
// autoregression order
AR[0] := 2;
ARMA.OrderAR := AR;
// moving average order
MA[0] := 1;
ARMA.OrderMA := MA;
// initial approximation definition method
ARMA.CalcInitMode := ARMAInitType.Manual;
// initial approximation of autoregression
Inits[0] := 0.2;
ARMA.InitAR := Inits;
// initial approximations of moving average
Inits[0] := 0.3;
ARMA.InitMA := Inits;
// optimization method
ARMA.EstimationMethod := ARMAEstimationMethodType.GaussNewton;
//number of iterations for optimization method
ARMA.MaxIteration := 50;
//accuracy for optimization method
ARMA.Tolerance := 0.1;
// model calculation
res := lr.Execute;
Debug.WriteLine(lr.Errors);
If (res = 0) Then
// autoregression coefficients
Debug.WriteLine("Autoregression coefficients estimates");
CoefficientsAR := ARMA.CoefficientsAR;
d := CoefficientsAR.Estimate[0];
Debug.WriteLine(" Value: " + d.ToString);
d := CoefficientsAR.StandardError[0];
Debug.WriteLine(" Standard error: " + d.ToString);
d := CoefficientsAR.TStatistic[0];
Debug.WriteLine(" t-statistic: " + d.ToString);
d := CoefficientsAR.Probability[0];
Debug.WriteLine(" Probability: " + d.ToString);
// moving average coefficients
Debug.WriteLine("Estimates of moving average coefficients");
CoefficientsMA := ARMA.CoefficientsMA;
d := CoefficientsMA.Estimate[0];
Debug.WriteLine(" Value: " + d.ToString);
d := CoefficientsMA.StandardError[0];
Debug.WriteLine(" Standard error: " + d.ToString);
d := CoefficientsMA.TStatistic[0];
Debug.WriteLine(" t-statistic: " + d.ToString);
d := CoefficientsMA.Probability[0];
Debug.WriteLine(" Probability: " + d.ToString);
// exogenous variable coefficients
Debug.WriteLine("Estimates of coefficients X:");
CoefficientsX := ModelCoefficients.Coefficients;
d := CoefficientsX.Estimate[0];
Debug.WriteLine(" Value: " + d.ToString);
d := CoefficientsX.StandardError[0];
Debug.WriteLine(" Standard error: " + d.ToString);
d := CoefficientsX.TStatistic[0];
Debug.WriteLine(" t-statistic: " + d.ToString);
d := CoefficientsX.Probability[0];
Debug.WriteLine(" Probability: " + d.ToString);
// constant
d := ModelCoefficients.Intercept.Estimate;
Debug.WriteLine("Constant: " + d.ToString);
End If;
End Sub UserProc;
After executing the example a linear regression model with the following parameters is created:
Initial approximations are specified manually.
The Quasi-Newton method is used as an optimization method.
Maximum iterations for model calculation is 50.
Autoregression order equals to 2.
Moving average order equals to 1.
Calculation accuracy equals to 0.1.
The console window displays model coefficients estimates and the constant value.
See also: