Learn R Programming

dLagM (version 1.0.2)

finiteDLMauto: Find the optimal lag length for finite DLMs

Description

A function that fits finite DLMs for a range of lag lengths and orders the fitted models according to a desired measure.

Usage

finiteDLMauto(formula , data, x, y, q.min = 1, q.max = 10, k.order = NULL, 
model.type = c("dlm","poly"), error.type = c("MASE","AIC","BIC","radj"), trace = FALSE)

Arguments

formula

A formula object for the model to be fitted. In the case of multiple predictor series, the model should be entered via a formula object.

data

A data.frame including all dependent and independent series. In the case of multiple predictor series, the data should be entered via the data argument.

x

A vector including the observations of predictor time series. This is not restricted to ts objects.

y

A vector including the observations of dependent time series. This is not restricted to ts objects.

q.min

An integer representing the lower limit of the range of lag lengths to be considered. If missing, it will be set to 1.

q.max

An integer representing the upper limit of the range of lag lengths to be considered. If missing, it will be set to 10.

k.order

An integer representing order of polynomial distributed lags.

model.type

The type of model to be fitted. If set to dlm, finite distributed lag models are fitted. If set to poly, polynomial distributed lag models are fitted.

error.type

The type of goodness-of-fit measure to be used for the selection of optimal lag length. If set to MASE, the optimal lag length is determined according to MASE. If set to AIC, the optimal lag length is determined according to AIC. If set to BIC, the optimal lag length is determined according to BIC. If set to radj, the optimal lag length is determined according to Adjusted R-square.

trace

If TRUE, prints all of the goodness-of-fit measures for all fitted models.

Value

Returns a data.frame including the values of goodness-of-fit measures and corresponding lag lengths.

Details

When there is only one predictor series, both of model and formula objects can be used. But when they are supplied, both x and y arguments should be NULL.

The variable names in formula must match with the names of variables in data argument and it must be in the form of a generic formula for R functions.

The argument data contains dependent series and independent series. Required lags of dependent series are generated by the dlm function automatically.

If q.max is entered greater than 20, its value will be adjusted to have a sample size of 20 for fitting the regression model for finite DLMs.

Examples

Run this code
# NOT RUN {
# Only one independent series
data(warming)
# Run the search over polynomial DLMs according to MASE values
finiteDLMauto(x = warming$NoMotorVehicles , y = warming$Warming ,
q.max = 12, k.order = 3, model.type = "poly",
error.type = "MASE", trace = TRUE)

# Run the search over finite DLMs according to AIC values
finiteDLMauto(x = warming$NoMotorVehicles , y = warming$Warming , 
q.min = 2, q.max = 12, model.type = "dlm", error.type = "AIC", 
trace = TRUE)

# Multiple independent series
data(M1Germany)
data = M1Germany[1:144,]
# Run the search over finite DLMs according to AIC values
finiteDLMauto(formula = logprice ~ interest + logm1, 
        data = data.frame(data), q.min = 2, q.max = 8, 
        model.type = "dlm", error.type = "AIC", trace = TRUE)
# }

Run the code above in your browser using DataLab