library(psych)
library(fpp2)
## Warning: package 'fpp2' was built under R version 3.5.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.5.3
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
## Loading required package: forecast
## Loading required package: fma
## Loading required package: expsmooth
describe(fdeaths)
## vars n mean sd median trimmed mad min max range skew
## X1 1 72 560.68 179.72 512 544.21 185.32 330 1141 811 0.78
## kurtosis se
## X1 -0.16 21.18
is.ts(fdeaths)
## [1] TRUE
plot(fdeaths, main="Monthly Deaths from Lung Diseases in the UK")
a=decompose(fdeaths, type=c("additive"))
m=decompose(fdeaths, type=c("multiplicative"))
plot(a)
plot(m)
forecasta=a$seasonal[7:66]+a$trend[7:66]+a$random[7:66]
errora=a$x[7:66]-forecasta
forecastm=m$seasonal[7:66]*m$trend[7:66]*m$random[7:66]
errorb=m$x[7:66]-forecastm
mse=c(mean(errora^2), mean(errorb^2))
me=c(mean(errora),madb=mean(errorb))
names(mse)=c("A", "M")
names(me)=c("A", "M")
mse
## A M
## 4.846761e-28 3.177321e-27
me
## A M
## -2.842171e-15 8.526513e-15
Additive has lower variance and bias, but both are good.