nnetar(x, p, P=1, size, repeats=20, xreg=NULL, lambda=NULL, model=NULL, subset=NULL, scale.inputs=TRUE, ...)
"forecast"(object, h=ifelse(object$m > 1, 2 * object$m, 10), xreg=NULL, lambda=object$lambda, ...)
nnetar
. If model is passed, this same model is fitted to x
without re-estimating any parameters.x
. All observations are used by default.lambda
is not NULL
, scaling is applied after Box-Cox transformation.nnetar
generated by nnetar
.nnet
for nnetar
but ignored for forecast.nnetar
.nnetar
". forecast.nnetar
returns an object of class "forecast
".The function summary
is used to obtain and print a summary of the
results, while the function plot
produces a plot of the forecasts.The generic accessor functions fitted.values
and residuals
extract useful features of the value returned by nnetar
.An object of class "forecast"
is a list containing at least the following elements:
object
itself or the time series used to create the model stored as object
).x
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=frequency(x)
. If there are missing values in x
or xreg
), the corresponding rows (and any others which depend on them as lags) are omitted from the fit. A total of repeats
networks are fitted, each with random starting weights. These are then averaged when computing forecasts. The network is trained for one-step forecasting. Multi-step forecasts are computed recursively. For non-seasonal 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.
fcast <- forecast(fit)
plot(fcast)
## Arguments can be passed to nnet()
fit <- nnetar(lynx, decay=0.5, maxit=150)
plot(forecast(fit))
lines(lynx)
## Fit model to first 100 years of lynx data
fit <- nnetar(window(lynx,end=1920), decay=0.5, maxit=150)
plot(forecast(fit,h=14))
lines(lynx)
## Apply fitted model to later data, including all optional arguments
fit2 <- nnetar(window(lynx,start=1921), model=fit)
Run the code above in your browser using DataCamp Workspace