The function `la()`

can be used for fitting penalised lags for explanatory variables.

1 2 3 4 5 |

`x` |
the name of the explanatory variable |

`y` |
internally evaluated (iterative working variable) |

`w` |
internally evaluated (iterative weights) |

`xeval` |
internally evaluated no need for specification here |

`control` |
a list of a number of control parameters for the fitting function |

`lags` |
the number of lags |

`from.lag` |
from which lag value to start, the default is zero which means include the original |

`df` |
use this if you want to fix the degrees of freedom |

`lambda` |
use this if you would like to fix the smoothing parameter |

`start.lambda` |
initial starting value for lambda |

`order` |
the order of the penalty |

`plot` |
whether you would like a plot of the data |

`method` |
method of fitting if lambda or df are not specified |

`k` |
the penally used if method "GAIC" is used |

`...` |
for further arguments |

The idea of penalised lags is that we use a large amount of lags but we penalised their fitted coefficients and therefore we use few degrees of freedom.
The penally and method of fitting are the same as in the `pb()`

function of `gamlss`

. This function does not do the fitting this is achieved by the function `gamlss.la()`

which uses the function `penLags`

for the fitting

a vector of zeros is returned, endowed with a number of attributes. The vector itself is used in the construction of the model matrix (contributing nothing), while the attributes are needed for the back-fitting algorithms of the additive fit.

Note that an appropriate prior weight is needed in the gamlss fit

Mikis Stasinopoulos mikis.stasinopoulos@gamlss.org, Bob Rigby, Vlasios Voudouris, Majid Djennad, and Paul Eilers.

Benjamin M. A., Rigby R. A. and Stasinopoulos D.M. (2003) Generalised Autoregressive Moving Average Models. *J. Am. Statist. Ass.*, 98, 214-223.

Rigby, R. A. and Stasinopoulos D. M. (2005). Generalized additive models for location, scale and shape,(with discussion),
*Appl. Statist.*, **54**, part 3, pp 507-554.

Stasinopoulos D. M., Rigby R.A. and Akantziliotou C. (2006) Instructions on how to use the GAMLSS package in R. Accompanying documentation in the current GAMLSS help files, (see also http://www.gamlss.org/).

Stasinopoulos D. M. Rigby R.A. (2007) Generalized additive models for location scale and shape (GAMLSS) in R.
*Journal of Statistical Software*, Vol. **23**, Issue 7, Dec 2007, http://www.jstatsoft.org/v23/i07.

`penLags`

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | ```
## the data
dax <- EuStockMarkets[,"DAX"]
plot(dax)
## using a penalised autorgressive model
w <- wlag(dax, lag=20)
m1 <- gamlss(dax~ la(dax, lags=20, order=1, from.lag=1), weights=w)
lines(fitted(m1)~as.numeric(time(dax)), col=2)
wp(m1, ylim.all=1) # not very good model
## Not run:
## Try modelling the variance
m2 <- gamlss(dax~ la(dax, lags=20, order=1, from.lag=1),
sigma.fo=~la(dax^2, lags=10, order=1, from.lag=1), weights=w)
wp(m2, ylim.all=1)# maybe the tails
m3 <- gamlss(dax~ la(dax, lags=20, order=1, from.lag=1),
sigma.fo=~la(dax^2, lags=10, order=1, from.lag=1),
weights=w, family=TF)
wp(m3, ylim.all=1) # better model
plot(m3, ts=TRUE) # autocorrelation OK
## using FTSE to precict DAX
ftse <- EuStockMarkets[,"FTSE"]
# fitting using penLags
l1 <- penLags(dax, ftse, lags=30, plot=TRUE)
# similar model within gamlss
w <- wlag(ftse, lag=30)
g1 <- gamlss(dax~ la(ftse, lags=30, order=1), weights=w)
lines(fitted(m1)~as.numeric(time(dax)))
op <- par(mfrow=c(2,1))
# plotting the fitted coeficints of the AR terms
plot(coef(l1, "AR"), type="h")
plot(coef(g1$mu.coefSmo[[1]])[-1], type="h")
par(op)
g2 <- gamlss(dax~ la(ftse, lags=30, order=1)+la(dax, lags=20, order=1, from.lag=1) , weights=w)
g3 <- gamlss(dax~ la(ftse, lags=30, order=1)+la(dax, lags=20, order=1, from.lag=1) ,
sigma.fo=~la(dax^2, lags=10, order=1, from.lag=1), weights=w)
## End(Not run)
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

All documentation is copyright its authors; we didn't write any of that.