NNETAR  R Documentation 
Feedforward neural networks with a single hidden layer and lagged inputs for forecasting univariate time series.
NNETAR(formula, n_nodes = NULL, n_networks = 20, scale_inputs = TRUE, ...)
formula 
Model specification (see "Specials" section). 
n_nodes 
Number of nodes in the hidden layer. Default is half of the number of input nodes (including external regressors, if given) plus 1. 
n_networks 
Number of networks to fit with different random starting weights. These are then averaged when producing forecasts. 
scale_inputs 
If TRUE, inputs are scaled by subtracting the column means and dividing by their respective standard deviations. Scaling is applied after transformations. 
... 
Other arguments passed to 
A feedforward neural network is fitted with lagged values of the response as
inputs and a single hidden layer with size
nodes. The inputs are for
lags 1 to p
, and lags m
to mP
where
m
is the seasonal period specified.
If exogenous regressors are provided, its columns are also used as inputs.
Missing values are currently not supported by this model.
A total of repeats
networks are
fitted, each with random starting weights. These are then averaged when
computing forecasts. The network is trained for onestep forecasting.
Multistep forecasts are computed recursively.
For nonseasonal data, the fitted model is denoted as an NNAR(p,k) model, where k is the number of hidden nodes. This is analogous to an AR(p) model but with nonlinear functions. For seasonal data, the fitted model is called an NNAR(p,P,k)[m] model, which is analogous to an ARIMA(p,0,0)(P,0,0)[m] model but with nonlinear functions.
A model specification.
The AR
special is used to specify autoregressive components in each of the
nodes of the neural network.
AR(p = NULL, P = 1, period = NULL)
p  The order of the nonseasonal autoregressive (AR) terms. If p = NULL , an optimal number of lags will be selected for a linear AR(p) model via AIC. For seasonal time series, this will be computed on the seasonally adjusted data (via STL decomposition). 
P  The order of the seasonal autoregressive (SAR) terms. 
period  The periodic nature of the seasonality. This can be either a number indicating the number of observations in each seasonal period, or text to indicate the duration of the seasonal window (for example, annual seasonality would be "1 year"). 
Exogenous regressors can be included in an NNETAR model without explicitly using the xreg()
special. Common exogenous regressor specials as specified in common_xregs
can also be used. These regressors are handled using stats::model.frame()
, and so interactions and other functionality behaves similarly to stats::lm()
.
xreg(...)
...  Bare expressions for the exogenous regressors (such as log(x) )

Forecasting: Principles and Practices, Neural network models (section 11.3)
as_tsibble(airmiles) %>% model(nn = NNETAR(box_cox(value, 0.15)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.