Skip to content
Numerical Method , home
Menu

Forum Numerical Method Statistics

Question about VARMA forecast

  1. ozcanalpParticipant 2014-08-15 at 12:55 pm

    Hi,

    I have an example for a bivariate series with n=2, p=2, and q=0 and i wanna estimate N+1. value by fitting an VARMA model. I’ve used suanshu.net-2.6.0 for the below code. I’ve fitted a model but i got an exception on this line instance = new VARMAForecastOneStep(X_T, varmaModel); and i don’t know how to estimate the next term. I’m new with Suanshu and any help or advise will be appreciated.

    Exception :

    at com.numericalmethod.suanshu.misc.ArgumentAssertion.assertTrue(Boolean condition, String errorMessage, Object[] args) at com.numericalmethod.suanshu.stats.timeseries.linear.multivariate.stationaryprocess.arma.VARMAAutoCovariance..ctor(VARMAModel model, Int32 nLags) at com.numericalmethod.suanshu.stats.timeseries.linear.multivariate.stationaryprocess.arma.VARMAForecastOneStep..ctor(MultivariateIntTimeTimeSeries Xt, VARMAModel model)

    code: X_T = new MultivariateSimpleTimeSeries( new double[][]{ new double[]{1, 50}, new double[]{2, 60}, new double[]{3, 70}, new double[]{4, 80}, new double[]{5, 90}, new double[]{6, 100}, new double[]{7, 110}, new double[]{8, 120}, new double[]{9, 130}, new double[]{10, 140}, new double[]{11, 150}, new double[]{12, 160}, new double[]{13, 170}, new double[]{14, 180}, new double[]{15, 190}, new double[]{16, 200}, new double[]{17, 210}, new double[]{18, 220}, new double[]{19, 230}, new double[]{20, 240}

    });
    
    VARFitting fitting = new VARFitting(X_T, 2);
    
    VARMAModel varmaModel = fitting.getVARMA();
    VARMAForecastOneStep instance = null;
    try
    {
    instance = new VARMAForecastOneStep(X_T, varmaModel);
    int T = X_T.size();
    Vector xTHat = instance.xHat(T + 1);
    Matrix V = instance.covariance(T);
    Console.Write(“Predictor at time ” + T + “: ” + xTHat + “, covariance of errors: ” + V);
    Console.Write(“\n”);
    }catch(Exception e){
    Console.WriteLine(“\nStackTrace —\n{0}”, e.StackTrace);
    }
    
  2. hao.dingParticipant 2014-08-19 at 8:09 am

    Hi ozcanalp,

    Sorry for the late reply.

    The model that is passed to VARMAForecastOneStep should be a zero mean model. You can get the demeaned model easily by (following your code): varmaModel.getDemeanedModel(). Therefore, changing “instance = new VARMAForecastOneStep(X_T, varmaModel);” to “instance = new VARMAForecastOneStep(X_T, varmaModel.getDemeanedModel());”

    should solve your problem. And finally add the mean back to get the forecast of the original VARMA model.

    Please let me know if there is anything else I can help.

    Best wishes, Ding Hao

    • This reply was modified 2 years, 5 months ago by hao.ding.
  3. ozcanalpParticipant 2014-08-19 at 10:17 am

    Thank you very much Ding Hao,

    I have one more question about “public VARFitting(MultivariateIntTimeTimeSeries mts,int p)”. How can I estimate p value by using akaike information criterion. For example if I used ARIMA model below code is ok for me. But how can I estimate p value for VARMA model by using akaike information criterion?

    Best wishes, ozcanalp

    double[] inputNumbers = new double[] { 2, 3, 4 };
    int P_VALUE = 2;
    int D_VALUE = 1;
    int Q_VALUE = 3;
    
    int p = P_VALUE;
    int d = D_VALUE;
    int q = Q_VALUE;
    
    ARIMAModel arima = null;
    
    double maxAic = 0;
    double actualAic = 0;
    int maxp = 10;
    int maxd = 10;
    int maxq = 10;
    
    ConditionalSumOfSquares csos = new ConditionalSumOfSquares(inputTimeSeries, p, d, q);
    
    for(int ii=0;ii<=3;ii++){
    for(int jj=0;jj<=2;jj++){
    for(int kk=0;kk<=3;kk++){
    
    p = ii;
    d = jj;
    q = kk;
    
    csos = new ConditionalSumOfSquares(inputTimeSeries, p, d, q);
    
    actualAic = csos.AIC();
    
    if(actualAic > maxAic){
    maxAic = actualAic;
    
    maxp = p;
    maxd = d;
    maxq = q;
    
    csos = new ConditionalSumOfSquares(inputTimeSeries, p, d, q);
    }
    }
    }
    }
    Console.Write(“\n”);
    Console.Write(“maxp: ” + maxp + “,” + maxd + “,” + maxq);
    Console.Write(“\n”);
    
    arima = csos.getModel();
    IntTimeTimeSeries xt = new SimpleTimeSeries(inputTimeSeries);
    
    ARIMAForecast instance = new ARIMAForecast(xt, arima);
    
    ARIMAForecast.Forecast frc = instance.next();
    double next = frc.xHat();
    double err = frc.var();
    
  4. hao.dingParticipant 2014-08-21 at 5:02 am

    Hi ozcanalp,

    for the AIC of VARMA model, please see p388 of the paper here.

    Basically speaking AIC can be computed as the norm of covariance matrix of VARMA residuals plus a penalty of order p, number of variables n, and length T.

    • This reply was modified 2 years, 5 months ago by hao.ding.
  5. ozcanalpParticipant 2014-08-21 at 6:01 am

    Thank you very much Ding Hao,

    I want to perform pairwise Granger causality wald tests after VAR but I can’t find any function for The Granger causality test F statistics in the suanshu package.How can I determine the first series does not case the second series or the second series does not cause the first series by using Granger causality test. Can you help me ?

    Best wishes,

    ozcanalp

  6. hao.dingParticipant 2014-08-21 at 6:46 am

    Hi ozcanalp,

    For the Granger causality test, here is an interesting article. It describes procedure step by step. Hope this helps.

  7. ozcanalpParticipant 2014-11-05 at 8:37 am

    Thank you very much Ding Hao,

    When I’ve fitted a model, i got an {“no solution to this system of linear equations”} exception on this line “VARFitting fitting = new VARFitting(X_T, 2);”. How can I fit the model? My code and exception are given below. any help or advise will be appreciated.

    code:

    X_T = new MultivariateSimpleTimeSeries( new double[][]{ new double[]{0, 0}, new double[]{0, 0.008}, new double[]{0, 0.269}, new double[]{0, 0.008}, new double[]{0, 0.009}, new double[]{0, 0.002}, new double[]{0, 0.005}, new double[]{0, 0.009}, new double[]{0.005, 0.008}, new double[]{0.006, 0.003}

    });
    
    try
    {
    VARFitting fitting = new VARFitting(X_T, 2);
    
    VARMAModel varmaModel = fitting.getVARMA();
    VARMAForecastOneStep instance = null;
    
    instance = new VARMAForecastOneStep(X_T, varmaModel.getDemeanedModel());
    int T = X_T.size();
    Vector xTHat = instance.xHat(T + 1);
    Matrix V = instance.covariance(T);
    Console.Write(“Predictor at time ” + (T+1) + “: ” + xTHat + “, covariance of errors: ” + V);
    Console.Write(“\n”);
    }catch(Exception e){
    
    Console.WriteLine(“\nStackTrace —\n{0}”, e.StackTrace);
    
    }
    

    Exception :

    at com.numericalmethod.suanshu.algebra.linear.matrix.doubles.linearsystem.BackwardSubstitution.new(UpperTriangularMatrix , Vector , Double ) at com.numericalmethod.suanshu.algebra.linear.matrix.doubles.linearsystem.BackwardSubstitution.solve(UpperTriangularMatrix U, Vector b, Double epsilon) at com.numericalmethod.suanshu.algebra.linear.matrix.doubles.linearsystem.OLSSolverByQR.solve(LSProblem problem) at com.numericalmethod.suanshu.stats.regression.linear.ols.OLSRegression..ctor(LMProblem problem, Double epsilon) at com.numericalmethod.suanshu.stats.regression.linear.ols.OLSRegression..ctor(LMProblem problem) at com.numericalmethod.suanshu.stats.timeseries.linear.multivariate.stationaryprocess.arma.VARFitting.new(MultivariateIntTimeTimeSeries , Int32 ) at com.numericalmethod.suanshu.stats.timeseries.linear.multivariate.stationaryprocess.arma.VARFitting.true(MultivariateIntTimeTimeSeries , Int32 ) at com.numericalmethod.suanshu.stats.timeseries.linear.multivariate.stationaryprocess.arma.VARFitting..ctor(MultivariateIntTimeTimeSeries mts, Int32 p) at MultivariateTimeSeries.MultiLinearTimeSeries.run() in \Visual Studio 2010\Projects\MultivariateTimeSeries\MultivariateTimeSeries\MultiLinearTimeSeries.cs:line 323

  8. hao.dingParticipant 2014-11-05 at 8:55 am

    Your data is ill-defined. For example, you have two time series, one of them is:0,0,0,0,0,0,0,0,0.005,0.006. It seems very odd to me. And it is very likely that it will cause numerical problems in computations.