# blag: Functions to create lag values In gamlss.add: Extra Additive Terms for GAMLSS Models

## Description

The function `blag()` creates a basis for lag values of x, (a matrix of lag values of x). The function `llag()` creates a list with two components i) a basis matrix and ii) weights to be used as prior weights in any regression analysis. The function `wlag()` can take a "mlags" object (created by `blag()`) or a vector and returns a vector with ones and zeros. This can be used as prior weights in any analysis which uses `blag()`.

## Usage

 ```1 2 3 4``` ```blag(x, lags = 1, from.lag=0, omit.na = FALSE, value = NA, ...) llag(x, ...) wlag(x, lags = NULL) ```

## Arguments

 `x` For `blag()` and `llag()` x is the vector for creating lags. For `wlag()` x is an `mlags` object created by `blag()`. `lags` how many lags are required `from.lag` where the lags are starting from. The default values is zero which indicates that the `x` is also included as a first column. If you want `x` not to included in the matrix use `from.lag=1` `omit.na` if true the first "lag" rows of the resulting matrix are omitted `value` value : what values should be set in the beginning of the lags columns, by default is set to NA `...` additional arguments

## Details

Those three functions are design for helping a user to fit regression model using lags by generating the appropriate structures. The function `blag()` creates a basis for lag values of x. It assumed that time runs from the oldest to the newest observations. That is, the latest observations are the most recent ones. The function `wlag()` take a basis matrix of lags and creates a vector of weights which can be used as a prior weights for any regression type analysis which has the matrix as explanatory variable. The function `llag()` creates a list with the matrix base for lags and the appropriate weights.

## Value

The function `blag()` returns a "mlags" object (matrix of lag values). The function `llag()` returns a list with components:

 `matrix` The basis of the lag matrix `weights` The weights vector

The function `wlag()` returns a vector of prior weights having, The vector starts with zeros (as many as the number of lags) and continues with ones.

## Author(s)

Mikis Stasinopoulos <[email protected]>, Bob Rigby <[email protected]> Vlasios Voudouris <[email protected]>, Majid Djennad, Paul Eilers.

## References

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``` ```library(stats) y <- arima.sim(500, model=list(ar=c(.4,.3,.1))) X <- blag(y, lags=5, from.lag=1, value=0) head(X) w<-wlag(X) library(gamlss) m1<-gamlss(y~X, weights=w ) summary(m1) plot(y) lines(fitted(m1)~as.numeric(time(y)), col="blue") ```