Learn R Programming

narfima (version 0.1.0)

auto_narfima: Fitting a NARFIMA Model

Description

This function fits a Neural AutoRegressive Fractionally Integrated Moving Average (NARFIMA) model to univariate time series. The model uses p Autoregressive terms, q moving average terms, and a single hidden layer with size nodes. If p, q, or size are not specified, they are automatically determined:

  • p is set to the number of significant Autoregressive coefficients estimated from an AR model.

  • q is set to the order of the moving average component from an ARFIMA model fitted to the residuals.

  • size is set to the floor of half the sum of p and q: $$size = \lfloor\frac{p + q}{2}\rfloor.$$

Exogenous variables can be included via xreg. If er is not provided, it is computed from an ARFIMA model fitted to y. When y or xreg have missing values, the corresponding rows and any dependent lagged rows are removed before fitting the model. Multiple neural network models are fitted, each initialized with random weights, and the final model is obtained by averaging their outputs. Optionally, Box-Cox transformations can be applied to stabilize variance, and inputs can be scaled to improve model convergence.

Usage

auto_narfima(
  y,
  er,
  xreg = NULL,
  p,
  q,
  P = 1,
  size,
  skip,
  repeats = 1000,
  lambda = 0.5,
  lambdae = 0.5,
  scale.inputs = TRUE,
  ...
)

Value

Returns an object of class "narfima", containing the following components:

series

The name of the input series.

method

A string describing the model parameters.

model

The fitted NARFIMA model.

fitted

The fitted values from the model.

residuals

The residuals from the model.

m

The seasonal frequency of the input series.

p

The number of Autoregressive terms used.

q

The number of moving average terms used.

P

The number of seasonal lags used.

size

The number of nodes in the hidden layer used in the neural network.

skip

Indicates if the direct connections were used in the neural network.

lambda

The Box-Cox transformation parameter for the input series.

scaley

Scaling parameters for the input series.

lags

The lags used for the input series.

lambdae

The Box-Cox transformation parameter for the error term.

scalee

Scaling parameters for the error term.

lagse

The lags used for the error term.

scalexreg

Scaling parameters for the exogenous variables, if provided.

y

The input time series.

e

The transformed residual series

xreg

The exogenous variables used in the model, if provided.

nnetargs

Additional arguments passed to the neural network function.

Arguments

y

A numeric vector or time series of class ts.

er

A numeric vector or time series object representing the series of residuals. If missing, it will be calculated from an ARFIMA model with exogenous variable (if provided).

xreg

An optional numeric matrix of exogenous variables to be included in the model (default is NULL).

p

Integer indicating the number of lags of the input series y.

q

Integer indicating the number of lags of the errors er.

P

Integer indicating the number of seasonal lags of the input series y (default is 1).

size

Integer specifying the number of nodes of the feed-forward neural networks with a single hidden layer.

skip

Logical value indicating whether to use the direct connections in the neural network (default is TRUE).

repeats

Integer specifying the number of times to fit the neural network model (default is 1000).

lambda

Numeric value for the Box-Cox transformation parameter of y (default is 0.5).

lambdae

Numeric value for the Box-Cox transformation parameter of er (default is 0.5).

scale.inputs

Logical value indicating whether to standardize the inputs before fitting the model (default is TRUE).

...

Additional arguments passed to auto_narfima.

Examples

Run this code
h <- 3

data <- EuStockMarkets[(nrow(EuStockMarkets) - 53):nrow(EuStockMarkets),4]

train <- data[1:(length(data) - h)]
test <- data[(length(data) - h + 1):length(data)]

narfima_model <- auto_narfima(train)

Run the code above in your browser using DataLab