5
$\begingroup$

Could someone point me in the direction of creating an autoregressive distributed lag model in mathematica?

$\endgroup$
1
  • $\begingroup$ Please also see the "Related" questions shown in the sidebar to this question, particularly this one $\endgroup$
    – Verbeia
    Sep 18, 2013 at 12:26

1 Answer 1

12
$\begingroup$

There are basically two methods.

The first is to use the ARProcess function (or ARMAProcess or ARIMAProcess as needed) introduced in version 9. The answers to this question should be helpful. Here is a small example that modifies the example in the documentation to show how to plot the resulting TemporalData using DateListPlot rather than ListPlot: you have to extract the "Paths" attribute.

In[50]:= myAR = ARProcess[{0.9, -0.2, 0.15}, 0.8]   
Out[50]= ARProcess[{0.9, -0.2, 0.15}, 0.8]

In[51]:= data = RandomFunction[myAR, {1, 150}]   
Out[51]= TemporalData[1]

In[52]:= DateListPlot[data["Paths"], Joined -> True]

enter image description here

The older pre-version-9 way would be to use some version of FoldList. The trick is that if you are creating an $AR(p)$ process where $p>1$, you need to store the lags initially and then keep only the first elements in each intervening vector, like this

 oldfashioned = 
  First /@ FoldList[
    Join[{{0.9, -0.2, 0.15}.#1 + #2}, Most[#1]] &, {0., 0., 0.}, 
    RandomVariate[NormalDistribution[0, 0.8], 150]];

ListLinePlot[oldfashioned, Frame -> True]

enter image description here

The advantage of the old way using FoldList is that you don't have to assume Gaussian noise. Here is an example with Levy-stable noise:

stable = First /@ FoldList[ Join[{{0.9, -0.2, 0.15}.#1 + #2}, Most[#1]] &, {0., 0., 0.}, 
 RandomVariate[StableDistribution[1, 1.1, -0.096, -0.0001, 0.005],  150]];

ListLinePlot[stable, Frame -> True, PlotRange -> All]

enter image description here

If what you mean by "creating" a "model" is to estimate it from data, then I'd suggest the EstimatedProcess function. It does a pretty good job of estimating the AR parameters even with non-Gaussian noise and the "wrong" number of lags.

EstimatedProcess[stable, ARProcess[6]]

(* ARProcess[{0.902147, -0.223932,  0.248928, -0.0532185,
  -0.0262434, -0.00263604}, 0.00202357] *)

It does even better when you know the order of the underlying AR process.

EstimatedProcess[stable, ARProcess[3]]

 (* ARProcess[{0.889943, -0.214266, 0.185013}, 0.0020378] *)
$\endgroup$
4
  • $\begingroup$ Great thank you! $\endgroup$
    – ALEXANDER
    Sep 18, 2013 at 12:34
  • $\begingroup$ In this case you have used an autoregressive AR module, however I do not understand how to get Distributed lags in the model as well. $\endgroup$
    – ALEXANDER
    Sep 19, 2013 at 6:16
  • $\begingroup$ If you mean distributed lags of exogenous variables, then you need to respecify the FoldList approach to have more than one element in each iterate of the list in the last argument. $\endgroup$
    – Verbeia
    Sep 19, 2013 at 7:11
  • $\begingroup$ Could you give a example how it would look with two lags of expgenous variables.With the fold list and how a ARDL(2,2) model would look like? $\endgroup$
    – ALEXANDER
    Sep 22, 2013 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.