INonLinearRegressionExplanatories.Add

Fore Syntax

Add: INonLinearRegressionExplanatory;

Fore.NET Syntax

Add: Prognoz.Platform.Interop.Stat.INonLinearRegressionExplanatory;

Description

The Add method adds an explanatory series to the collection.

Fore Example

Add a link to the Stat system assembly.

Sub UserProc;
Var
    NLr: ISmNonLinearLeastSquare;
    ar: Array[0..6Of Double;
    ar2: Array[0..8Of Double;
    ar3: Array[0..8Of Double;
    InitEst: Array[0..1Of Double;
    Per: IStatPeriod;
    res, i: Integer;
    MC: ISlConstCoefficients;
    Regs: INonLinearRegressionExplanatories;
Begin
    NLr := New SmNonLinearLeastSquare.Create;
    // Set values for variables
    ar[0] := 100; ar2[0] := 120; ar3[0] := 122;
    ar[1] := 111; ar2[1] := 125; ar3[1] := 127;
    ar[2] := 123; ar2[2] := 124; ar3[2] := 130;
    ar[3] := 113; ar2[3] := 130; ar3[3] := 135;
    ar[4] := 119; ar2[4] := 133; ar3[4] := 140;
    ar[5] := 121; ar2[5] := 129; ar3[5] := 149;
    ar2[6] := 139; ar3[6] := 150;
    ar2[7] := 140; ar3[7] := 155;
    // Set explained variable
    NLr.Explained.Value := ar;
    // Determine parameters of regressor collection for non-linear OLS
    Regs := NLr.Explanatories;
    // Add explanatory series to the collection
    Regs.Add.Serie.Value := ar2;
    Regs.Add.Serie.Value := ar3;
    // Determine calculated function
    NLr.FunctionString := "A1 + A2 * " + Regs.Item(0).VariableName + " * " + Regs.Item(1).VariableName;
    // Determine coefficient order
    NLr.CoefficientsOrder := "A1;A2";
    // Define parameters of sample period
    Per := NLr.ModelPeriod;
    Per.FirstPoint := 1;
    Per.LastPoint := 5;
    // Determine forecasting series parameters
    NLr.Forecast.LastPoint := 9;
    // Determine maximum number of iterations
    NLr.MaxIteration := 100;
    // Determine whether analytical derivatives are used on solution search
    NLr.UseDerivatives := False;
    // Determine accuracy
    NLr.Tolerance := 0.003;
    // Determine initial approximations
    InitEst[0] := 0.5;
    InitEst[1] := 1.0;
    Nlr.InitApproximation := InitEst;
    // Run calculation and show results
    res := NLr.Execute;
    If res <> 0 Then
        Debug.WriteLine(NLr.Errors);
        Else
            Debug.WriteLine("== Coefficients ==");
            Debug.WriteLine("A1");
            MC := NLr.ModelCoefficients("A1");
            Debug.WriteLine("value: " + MC.Estimate.ToString);
            Debug.WriteLine("probability: " + MC.Probability.ToString);
            Debug.WriteLine("A2");
            MC := NLr.ModelCoefficients("A2");
            Debug.WriteLine("value: " + MC.Estimate.ToString);
            Debug.WriteLine("probability: " + MC.Probability.ToString);
            Debug.WriteLine("== Modeling series ==");
            For i := 0 To NLr.Fitted.Length - 1 Do
                Debug.WriteLine(NLr.Fitted[i]);
            End For;
    End If;
End Sub UserProc;

After executing the example the console window displays calculation results: coefficients, their values and probabilities, and a modeling series.

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Imports Prognoz.Platform.Interop.Stat;
]
Public Shared Sub Main(Params: StartParams);
Var
    NLr: ISmNonLinearLeastSquare;
    ar: Array[0..6Of Double;
    ar2: Array[0..8Of Double;
    ar3: Array[0..8Of Double;
    InitEst: Array[0..1Of Double;
    Per: IStatPeriod;
    res, i: Integer;
    MC: ISlConstCoefficients;
    Regs: INonLinearRegressionExplanatories;
    Fitted: System.Array;
Begin
        NLr := New SmNonLinearLeastSquare.Create();
    // Set values for variables
    ar[0] := 100; ar2[0] := 120; ar3[0] := 122;
    ar[1] := 111; ar2[1] := 125; ar3[1] := 127;
    ar[2] := 123; ar2[2] := 124; ar3[2] := 130;
    ar[3] := 113; ar2[3] := 130; ar3[3] := 135;
    ar[4] := 119; ar2[4] := 133; ar3[4] := 140;
    ar[5] := 121; ar2[5] := 129; ar3[5] := 149;
    ar2[6] := 139; ar3[6] := 150;
    ar2[7] := 140; ar3[7] := 155;
    // Set explained variable
    NLr.Explained.Value := ar;
    // Determine parameters of regressor collection for non-linear OLS
    Regs := NLr.Explanatories;
    // Add explanatory series to the collection
    Regs.Add().Serie.Value := ar2;
    Regs.Add().Serie.Value := ar3;
    // Determine calculated function
    NLr.FunctionString := "A1 + A2 * " + Regs.Item[0].VariableName + " * " + Regs.Item[1].VariableName;
    // Determine coefficient order
    NLr.CoefficientsOrder := "A1;A2";
    // Define parameters of sample period
    Per := NLr.ModelPeriod;
    Per.FirstPoint := 1;
    Per.LastPoint := 5;
    // Determine forecasting series parameters
    NLr.Forecast.LastPoint := 9;
    // Determine maximum number of iterations
    NLr.MaxIteration := 100;
    // Determine whether analytical derivatives are used on solution search
    NLr.UseDerivatives := False;
    // Determine accuracy
    NLr.Tolerance := 0.003;
    // Determine initial approximations
    InitEst[0] := 0.5;
    InitEst[1] := 1.0;
    Nlr.InitApproximation := InitEst;
    // Run calculation and show results
    res := NLr.Execute();
    If res <> 0 Then
        System.Diagnostics.Debug.WriteLine(NLr.Errors);
        Else
            System.Diagnostics.Debug.WriteLine("== Coefficients ==");
            System.Diagnostics.Debug.WriteLine("A1");
            MC := NLr.ModelCoefficients["A1"];
            System.Diagnostics.Debug.WriteLine("value: " + MC.Estimate.ToString());
            System.Diagnostics.Debug.WriteLine("probability: " + MC.Probability.ToString());
            System.Diagnostics.Debug.WriteLine("A2");
            MC := NLr.ModelCoefficients["A2"];
            System.Diagnostics.Debug.WriteLine("value: " + MC.Estimate.ToString());
            System.Diagnostics.Debug.WriteLine("probability: " + MC.Probability.ToString());
            System.Diagnostics.Debug.WriteLine("== Modeling series ==");
            Fitted := NLr.Fitted;
            For i := 0 To NLr.Fitted.Length - 1 Do
                System.Diagnostics.Debug.WriteLine(Fitted[i]);
            End For;
    End If;
End Sub;

See also:

INonLinearRegressionExplanatories