This code below shows my Discussion Week 2 Assignment. I worked with the Financial Times Index leading equity prices (quarterly) 1960-1971.
library(forecast)
## Warning: package 'forecast' was built under R version 3.4.2
## Warning in as.POSIXlt.POSIXct(Sys.time()): unknown timezone 'zone/tz/2018c.
## 1.0/zoneinfo/America/New_York'
library(fpp)
## Loading required package: fma
## Loading required package: expsmooth
## Loading required package: lmtest
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: tseries
library(car)
## Warning: package 'car' was built under R version 3.4.3
library(MASS)
##
## Attaching package: 'MASS'
## The following objects are masked from 'package:fma':
##
## cement, housing, petrol
library(readr)
library(tseries)
mydata <- read_csv("~/Desktop/financial-times-index-leading-eq.csv")
## Parsed with column specification:
## cols(
## Quarter = col_character(),
## `Financial Times index leading equity prices (quarterly) 1960 ? 1971` = col_double()
## )
View(mydata)
attach(mydata)
index=`Financial Times index leading equity prices (quarterly) 1960 ? 1971`
Plotted data.
Build an additive and multiplicative model.
#decompose
decA<-decompose(myts,type="additive")
decM<-decompose(myts,type="multiplicative")
#plot
plot(decA)
plot(decM)
#show decomposition seasonal, time series, and random componants
decA$seasonal
## Qtr1 Qtr2 Qtr3 Qtr4
## 1 2.322159 5.061932 -6.339205 -1.044886
## 2 2.322159 5.061932 -6.339205 -1.044886
## 3 2.322159 5.061932 -6.339205 -1.044886
## 4 2.322159 5.061932 -6.339205 -1.044886
## 5 2.322159 5.061932 -6.339205 -1.044886
## 6 2.322159 5.061932 -6.339205 -1.044886
## 7 2.322159 5.061932 -6.339205 -1.044886
## 8 2.322159 5.061932 -6.339205 -1.044886
## 9 2.322159 5.061932 -6.339205 -1.044886
## 10 2.322159 5.061932 -6.339205 -1.044886
## 11 2.322159 5.061932 -6.339205 -1.044886
## 12 2.322159 5.061932 -6.339205 -1.044886
decA$trend
## Qtr1 Qtr2 Qtr3 Qtr4
## 1 NA NA 317.9375 322.3250
## 2 325.4000 321.9375 316.9875 306.2375
## 3 293.4625 287.1000 284.8875 287.1375
## 4 293.0750 303.3750 315.6000 324.9125
## 5 337.4500 346.1625 347.4125 347.5875
## 6 342.3750 337.5625 338.5375 342.0500
## 7 344.0625 337.9375 328.3750 322.4500
## 8 325.4750 342.8125 366.3750 392.4500
## 9 423.5250 451.4375 473.2625 479.9875
## 10 462.3000 434.6375 410.2000 389.4625
## 11 375.3000 366.2750 352.5000 345.6375
## 12 356.1750 374.7250 NA NA
decA$random
## Qtr1 Qtr2 Qtr3 Qtr4
## 1 NA NA 9.40170455 -8.38011364
## 2 -4.02215909 22.30056818 -0.24829545 -9.39261364
## 3 5.41534091 -6.36193182 -6.84829545 -2.49261364
## 4 0.30284091 0.86306818 -13.56079545 18.13238636
## 5 -4.67215909 -6.82443182 19.82670455 -0.04261364
## 6 -4.09715909 -2.32443182 -8.89829545 4.59488636
## 7 2.91534091 16.70056818 -2.03579545 -21.50511364
## 8 -9.29715909 -4.77443182 0.76420455 6.39488636
## 9 -16.74715909 4.60056818 24.47670455 11.55738636
## 10 26.37784091 -6.69943182 -25.86079545 -5.81761364
## 11 25.77784091 -16.63693182 -3.16079545 0.80738636
## 12 -28.09715909 -6.98693182 NA NA
decM$seasonal
## Qtr1 Qtr2 Qtr3 Qtr4
## 1 1.0063958 1.0161365 0.9811684 0.9962992
## 2 1.0063958 1.0161365 0.9811684 0.9962992
## 3 1.0063958 1.0161365 0.9811684 0.9962992
## 4 1.0063958 1.0161365 0.9811684 0.9962992
## 5 1.0063958 1.0161365 0.9811684 0.9962992
## 6 1.0063958 1.0161365 0.9811684 0.9962992
## 7 1.0063958 1.0161365 0.9811684 0.9962992
## 8 1.0063958 1.0161365 0.9811684 0.9962992
## 9 1.0063958 1.0161365 0.9811684 0.9962992
## 10 1.0063958 1.0161365 0.9811684 0.9962992
## 11 1.0063958 1.0161365 0.9811684 0.9962992
## 12 1.0063958 1.0161365 0.9811684 0.9962992
decM$trend
## Qtr1 Qtr2 Qtr3 Qtr4
## 1 NA NA 317.9375 322.3250
## 2 325.4000 321.9375 316.9875 306.2375
## 3 293.4625 287.1000 284.8875 287.1375
## 4 293.0750 303.3750 315.6000 324.9125
## 5 337.4500 346.1625 347.4125 347.5875
## 6 342.3750 337.5625 338.5375 342.0500
## 7 344.0625 337.9375 328.3750 322.4500
## 8 325.4750 342.8125 366.3750 392.4500
## 9 423.5250 451.4375 473.2625 479.9875
## 10 462.3000 434.6375 410.2000 389.4625
## 11 375.3000 366.2750 352.5000 345.6375
## 12 356.1750 374.7250 NA NA
decM$random
## Qtr1 Qtr2 Qtr3 Qtr4
## 1 NA NA 1.0290103 0.9743652
## 2 0.9884537 1.0677632 0.9980126 0.9695049
## 3 1.0198435 0.9796636 0.9720144 0.9913489
## 4 1.0025446 1.0033398 0.9549283 1.0565010
## 5 0.9867251 0.9791090 1.0587609 1.0005742
## 6 0.9884934 0.9921005 0.9733194 1.0141317
## 7 1.0087706 1.0474951 0.9931991 0.9335214
## 8 0.9723508 0.9849450 1.0036843 1.0173975
## 9 0.9598019 1.0051837 1.0582530 1.0256975
## 10 1.0553312 0.9804120 0.9391881 0.9860286
## 11 1.0680424 0.9530196 0.9917254 1.0030248
## 12 0.9217386 0.9790642 NA NA
#for additive, show proof summing all these components together will equal the original data set
pa.myts = decA$seasonal+decA$trend+decA$random
pa.myts
## Qtr1 Qtr2 Qtr3 Qtr4
## 1 NA NA 321.0 312.9
## 2 323.7 349.3 310.4 295.8
## 3 301.2 285.8 271.7 283.6
## 4 295.7 309.3 295.7 342.0
## 5 335.1 344.4 360.9 346.5
## 6 340.6 340.3 323.3 345.6
## 7 349.3 359.7 320.0 299.9
## 8 318.5 343.1 360.8 397.8
## 9 409.1 461.1 491.4 490.5
## 10 491.0 433.0 378.0 382.6
## 11 403.4 354.7 343.0 345.4
## 12 330.4 372.8 NA NA
myts
## Qtr1 Qtr2 Qtr3 Qtr4
## 1 323.8 314.1 321.0 312.9
## 2 323.7 349.3 310.4 295.8
## 3 301.2 285.8 271.7 283.6
## 4 295.7 309.3 295.7 342.0
## 5 335.1 344.4 360.9 346.5
## 6 340.6 340.3 323.3 345.6
## 7 349.3 359.7 320.0 299.9
## 8 318.5 343.1 360.8 397.8
## 9 409.1 461.1 491.4 490.5
## 10 491.0 433.0 378.0 382.6
## 11 403.4 354.7 343.0 345.4
## 12 330.4 372.8 409.2 427.6
#for multiplicative, show proof multiplying all these components together will equal the original data set
pm.myts = decM$seasonal*decM$trend*decM$random
pm.myts
## Qtr1 Qtr2 Qtr3 Qtr4
## 1 NA NA 321.0 312.9
## 2 323.7 349.3 310.4 295.8
## 3 301.2 285.8 271.7 283.6
## 4 295.7 309.3 295.7 342.0
## 5 335.1 344.4 360.9 346.5
## 6 340.6 340.3 323.3 345.6
## 7 349.3 359.7 320.0 299.9
## 8 318.5 343.1 360.8 397.8
## 9 409.1 461.1 491.4 490.5
## 10 491.0 433.0 378.0 382.6
## 11 403.4 354.7 343.0 345.4
## 12 330.4 372.8 NA NA
myts
## Qtr1 Qtr2 Qtr3 Qtr4
## 1 323.8 314.1 321.0 312.9
## 2 323.7 349.3 310.4 295.8
## 3 301.2 285.8 271.7 283.6
## 4 295.7 309.3 295.7 342.0
## 5 335.1 344.4 360.9 346.5
## 6 340.6 340.3 323.3 345.6
## 7 349.3 359.7 320.0 299.9
## 8 318.5 343.1 360.8 397.8
## 9 409.1 461.1 491.4 490.5
## 10 491.0 433.0 378.0 382.6
## 11 403.4 354.7 343.0 345.4
## 12 330.4 372.8 409.2 427.6
Using the mean error, evaluate if additive or multiplicative is the better model.
#additive
mea = mean(na.omit(decA$random))
mea
## [1] -0.5585227
# -0.5585227
#multiplicative
mem = mean(na.omit(decM$random))
mem
## [1] 0.9974633
# 0.9974633
Through these calculations, I believe that the additive model is the better model for the Financial Times Index leading equity prices. It has a mean error closer to 0.
When given the decision to use additive or multiplicative for forecasting, I would use additive. This is based on the low mean error.