CovarianceMatrix: Array;
The CovarianceMatrix property returns the values of the covariance matrix.
It is required to use an array of Double values.
To execute the example, add a link to the Stat system assembly.
Sub UserProc;
Var
LIML: SmLIML;
can, fra, ger, ita, jpn: Array[15] Of Double;
x: ISlSerie;
CoefInt: IIntercept;
ModelCoef: ICoefficients;
i, j, res, FittedLength, ForecastValue, ConfidenceLevel: Integer;
str: String;
d0: Double;
Begin
LIML := New SmLIML.Create;
// Set values for variables
can[00] := 6209; fra[00] := 4110; ger[00] := 3415; ita[00] := 2822; jpn[00] := 1475;
can[01] := 6385; fra[01] := 4280; ger[01] := 3673; ita[01] := 3023; jpn[01] := 1649;
can[02] := 6752; fra[02] := 4459; ger[02] := 4013; ita[02] := 3131; jpn[02] := 1787;
can[03] := 6837; fra[03] := 4545; ger[03] := 4278; ita[03] := 3351; jpn[03] := 1884;
can[04] := 6495; fra[04] := 4664; ger[04] := 4577; ita[04] := 3463; jpn[04] := 1972;
can[05] := 6907; fra[05] := 4861; ger[05] := 5135; ita[05] := 3686; jpn[05] := 2108;
can[06] := 7349; fra[06] := 5195; ger[06] := 5388; ita[06] := 3815; jpn[06] := 2249;
can[07] := 7213; fra[07] := 5389; ger[07] := 5610; ita[07] := 3960; jpn[07] := 2394;
can[08] := 7061; fra[08] := Double.Nan; ger[08] := 5787; ita[08] := 4119; jpn[08] := 2505;
can[09] := 7180; fra[09] := 5610; ger[09] := 6181; ita[09] := 4351; jpn[09] := 2714;
can[10] := Double.Nan; fra[10] := 5948; ger[10] := 6633; ita[10] := 4641; jpn[10] := Double.Nan;
can[11] := Double.Nan; fra[11] := 6218; ger[11] := 6910; ita[11] := 5008; jpn[11] := Double.Nan;
can[12] := Double.Nan; fra[12] := 6521; ger[12] := 7146; ita[12] := 5305; jpn[12] := Double.Nan;
can[13] := 7722; fra[13] := 6788; ger[13] := 7248; ita[13] := 5611; jpn[13] := Double.Nan;
can[14] := 8088; fra[14] := 7222; ger[14] := 7689; ita[14] := 5693; jpn[14] := 4486;
// sample period
LIML.ModelPeriod.FirstPoint := 1;
LIML.ModelPeriod.LastPoint := 10;
// forecast
LIML.Forecast.LastPoint := 15;
// source series
LIML.Explained.Value := can;
// explanatory series
LIML.Explanatories.Clear;
x := LIML.Explanatories.Add;
x.Value := fra;
x := LIML.Explanatories.Add;
x.Value := ger;
// constant in regressors
LIML.ModelCoefficients.Intercept.Mode := InterceptMode.AutoEstimate;
// instrumental series
LIML.Instrumental.Clear;
x := LIML.Instrumental.Add;
x.Value := ita;
x := LIML.Instrumental.Add;
x.Value := jpn;
// constant in instrumental variables
LIML.UseConstantAsInstrument := True;
// using of the K-class estimation method
LIML.UseKClass := True;
// K parameter for K-class method
LIML.KClass := 0.01;
// missing data method
LIML.MissingData.Method := MissingDataMethod.Casewise;
// model calculation
res := LIML.Execute;
CoefInt := LIML.ModelCoefficients.Intercept;
ModelCoef := LIML.ModelCoefficients.Coefficients;
FittedLength := LIML.Fitted.Length;
ForecastValue := LIML.Forecast.Value.Length;
Debug.WriteLine(LIML.Errors);
For i := 0 To LIML.WarningsCount - 1 Do
Debug.WriteLine(LIML.Warnings[i]);
End For;
Debug.WriteLine("===Model coefficient estimates===");
If CoefInt.Mode > 0 Then
Debug.WriteLine("Estimates of constant");
Debug.Indent;
Debug.WriteLine(CoefInt.Estimate.ToString + " " +
CoefInt.StandardError.ToString + " " +
CoefInt.TStatistic.ToString + " " +
CoefInt.Probability.ToString);
Debug.Unindent;
End If;
If ModelCoef.Estimate.Length > 0 Then
Debug.WriteLine("Coefficient estimations:");
Debug.Indent;
Debug.WriteLine("Estimated values of coefficients: ");
For i := 0 To ModelCoef.Estimate.Length - 1 Do
Debug.WriteLine(ModelCoef.Estimate[i].ToString + " "
+ ModelCoef.StandardError[i].ToString + " "
+ ModelCoef.TStatistic[i].ToString + " "
+ ModelCoef.Probability[i].ToString);
End For;
Debug.Unindent;
End If;
Debug.WriteLine("Summary statistics of regression");
Debug.Indent;
Debug.WriteLine("Determination coefficient: " + LIML.SummaryStatistics.R2.ToString);
Debug.WriteLine("Adjusted determination coefficient: " + LIML.SummaryStatistics.AdjR2.ToString);
Debug.WriteLine("Standard regression error: " + LIML.SummaryStatistics.SE.ToString);
Debug.WriteLine("Residual sum of squares: " + LIML.SummaryStatistics.SSR.ToString);
Debug.WriteLine("Durbin-Watson statistic: " + LIML.SummaryStatistics.DW.ToString);
Debug.Unindent;
Debug.WriteLine("Covariance matrix");
For i := 0 To LIML.CovarianceMatrix.GetUpperBound(2) Do
str := "";
For j := 0 To LIML.CovarianceMatrix.GetUpperBound(1) Do
str := str + " " + (LIML.CovarianceMatrix[j, i] As Double).ToString;
End For;
Debug.WriteLine(str);
End For;
Debug.WriteLine("Modeling series");
Debug.Indent;
For i := 0 To FittedLength - 1 Do
Debug.Write(i.ToString + " ");
Debug.WriteLine(LIML.Fitted[i]);
End For;
Debug.Unindent;
Debug.WriteLine("Residual series");
Debug.Indent;
For i := 0 To LIML.Residuals.Length - 1 Do
Debug.Write(i.ToString + " ");
Debug.WriteLine(LIML.Residuals[i]);
End For;
Debug.Unindent;
Debug.WriteLine("Forecast results");
Debug.Indent;
For i := FittedLength To ForecastValue - 1 Do
d0 := LIML.Forecast.Value[i];
Debug.Write(i.ToString + " ");
Debug.WriteLine(d0);
End For;
Debug.Unindent;
Debug.WriteLine("Upper confidence limit:");
ConfidenceLevel := LIML.Forecast.UpperConfidenceLevel.Length;
Debug.Indent;
For i := FittedLength To ConfidenceLevel - 1 Do
d0 := LIML.Forecast.UpperConfidenceLevel[i];
Debug.WriteLine(i.ToString + " " + d0.ToString);
End For;
Debug.Unindent;
Debug.WriteLine("Lower confidence limit");
ConfidenceLevel := LIML.Forecast.LowerConfidenceLevel.Length;
Debug.Indent;
For i := FittedLength To ConfidenceLevel - 1 Do
d0 := LIML.Forecast.LowerConfidenceLevel[i];
Debug.WriteLine(i.ToString + " " + d0.ToString);
End For;
Debug.Unindent;
End Sub UserProc;
After executing the example the following settings are determined:
Sample period.
Forecast parameters.
K parameter for K-class method.
The console window displays coefficient estimates, their characteristics and a series of auxiliary regression residuals, covariance matrix and forecast results.
See also: