5

3

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

5

3

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

12

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]
```

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]
```

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]
```

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] *)
```

Great thank you! – ALEXANDER – 2013-09-18T12:34:20.807

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. – ALEXANDER – 2013-09-19T06:16:28.353

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. – Verbeia – 2013-09-19T07:11:51.553

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? – ALEXANDER – 2013-09-22T11:07:31.793

Please also see the "Related" questions shown in the sidebar to this question, particularly this one

– Verbeia – 2013-09-18T12:26:46.100