Sales of new single family houses, USA, from Jan 1987 through Nov 1995

houses = read.csv("sales-of-new-onefamily-houses-us.csv")

library(fpp)
## Loading required package: forecast
## Warning: package 'forecast' was built under R version 3.3.2
## Loading required package: fma
## Warning: package 'fma' was built under R version 3.3.2
## Loading required package: expsmooth
## Loading required package: lmtest
## Warning: package 'lmtest' was built under R version 3.3.2
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 3.3.2
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: tseries
## Warning: package 'tseries' was built under R version 3.3.2
library(forecast)
library(xts)
## Warning: package 'xts' was built under R version 3.3.2
library(tseries)

str(houses)
## 'data.frame':    107 obs. of  2 variables:
##  $ Month                                                              : Factor w/ 107 levels "1987-01","1987-02",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ Sales.of.new.one.family.houses..USA..from.Jan.1987.through.Nov.1995: int  53 59 73 72 62 58 55 56 52 52 ...
head(houses)
##     Month
## 1 1987-01
## 2 1987-02
## 3 1987-03
## 4 1987-04
## 5 1987-05
## 6 1987-06
##   Sales.of.new.one.family.houses..USA..from.Jan.1987.through.Nov.1995
## 1                                                                  53
## 2                                                                  59
## 3                                                                  73
## 4                                                                  72
## 5                                                                  62
## 6                                                                  58
tail (houses)
##       Month
## 102 1995-06
## 103 1995-07
## 104 1995-08
## 105 1995-09
## 106 1995-10
## 107 1995-11
##     Sales.of.new.one.family.houses..USA..from.Jan.1987.through.Nov.1995
## 102                                                                  64
## 103                                                                  64
## 104                                                                  63
## 105                                                                  55
## 106                                                                  54
## 107                                                                  44
names(houses)[2]<-c("sales")

train = houses[1:86,]
test = houses[87:107,]

time series

ts.train = ts(train$sales,frequency=12,start=c(1987,1))
plot(ts.train)

ts.test = ts(test$sales, frequency=12, start=c(1994,3))
plot(ts.test)

NNAR Model -> 1,1,2 = 1 lag, 1 seasonal lag, 2 hidden nodes

mynnet = nnetar(ts.train)
mynnet
## Series: ts.train 
## Model:  NNAR(1,1,2)[12] 
## Call:   nnetar(y = ts.train)
## 
## Average of 20 networks, each of which is
## a 2-2-1 network with 9 weights
## options were - linear output units 
## 
## sigma^2 estimated as 20.89

Forecast

fcast.nnet<-forecast(mynnet, h=21)
plot(fcast.nnet)
lines(ts.test, col="red")

acc.nnet<-accuracy(fcast.nnet, ts.test)
acc.nnet
##                        ME     RMSE      MAE        MPE      MAPE      MASE
## Training set  0.002035723 4.570407 3.548726 -0.9782593  7.458314 0.5326688
## Test set     -0.167535413 7.200123 5.928809 -2.2875423 11.077497 0.8899226
##                   ACF1 Theil's U
## Training set 0.2189527        NA
## Test set     0.4178716  1.021274