Professional Documents
Culture Documents
Time Series R Documentation
Time Series R Documentation
Require function is used to load the namespace of the package with name package and attach it
on the search list. Require is designed for use inside other functions; it returns FALSE and gives a
warning if the package does not exist. In this require function is used to call the forecast
function.
Forecast is a generic function for forecasting from time series or time series models. The
function invokes particular methods which depend on the class of the first argument.
data <- c(-16.01, -0.78, -1.4, 8.93, 12.52, 21.24, 25.07, 21.75, 14.01, 2.97, -1.32, -10.57,
-3.24, 3.01, 12.46, 20.51, 31.12, 32.18, 33.9, 32.48, 26.57, 19.45, 6.91, 12.18,
6.01, 16.13, 20.01, 35.75, 40.09, 43.55, 41.44, 44.81, 32.14, 24.99, 22.07, 23.31,
25.07, 29.13, 30.01, 49.83, 54.69, 52.67, 52.22, 56.67, 47.28, 48.22, 29.9, 35.45,
37.83, 36.92, 46.49, 59.86, 60.92, 65.24, 67.75, 63.65, 61.9, 42.83, 49.58, 43.44,
44.8, 51.46, 57.6, 64.89, 73.57, 76.69, 83.88, 80.61, 71.46, 55.33, 55.27, 58.8,
52.19, 57.19, 67.75, 72.16, 86.52, 97.44, 96.01, 96.18, 81.77, 78.53, 66.71, 73.01,
70.22, 80.39, 73.24, 87.83, 97.06, 98.4, 108.71, 98.65, 98.59, 82.25, 79.59, 76.79,
78.41, 80.78, 92.29, 99.15, 110.35, 121.04, 111.79, 116.9, 110.41, 105.29, 99.18,
98.3, 91.68, 98.62, 103.22, 108.61, 121.98, 123.29, 130.16, 126.84, 128.44, 113.76,
100.89, 100.21, 104.83, 113.69, 119.83, 123.34, 136.99, 137.27, 145.61, 134.64,
129.19, 125.83, 113.34, 116.76, 116.88, 117.75, 133.71, 132.49, 149.11, 156.46,
In this step we are creating the vector with all the data points.
plot(data, pch = 4)
plot function is used for plotting the objects in R. In this we are plotting all the data points
stored in variable data, against their indexes. We have used the pch options in order to specify
the symbols to data points.
plot(data.dec)
data.dec
## Holt Winters
plot(data.holt)
summary(LM)
plot(data.ts)
abline(LM$coefficients[1], b=LM$coefficients[2])
plot(data.ts)
summary(LM.dummy)
plot(data.ts)
plot.colors <- c("red", "blue", "green", "purple", "orange", "dark red", "dark green", "grey",
plot(data.ts)
X <- as.numeric(time(data.ts))
Y <- data
## Regular Regression
summary(LM.old)
points(data.DF$X, LM.old$fitted.values, pch = 4, col = "red")
summary(LM.forecast)
plot(data.ts)
points(x = time(pred.ts), y = LM.forecast$fitted.values, col="red", pch=4)
plot(forecast(LM.forecast, h=20))
cycle(data.ts)
for(i in 1:12)
if(i==1){
}else{
}
}
data <- c(166.4, 174.71, 293.77, 357.84, 357.82, 425.87, 388.27, 346.21, 338.53, 290.11, 277.15,
211.24, 209.29, 279.27, 237.39, 359.69, 376.88, 494.76, 500.57, 384.9, 378.02, 380.47,
261.44, 260.83, 247.85, 233.73, 404.03, 341.44, 503.14, 585.68, 618.4, 364.22, 463.31,
331.69, 327.31, 289.41, 309.69, 345.95, 344.65, 451.89, 589.75, 588.58, 569.15, 498.73,
523.76, 481.18, 374.4, 308.25, 284.93, 413.98, 394.31, 555.39, 583.05, 693.09, 757.77,
641.02, 550.38, 449.45, 371.99, 405.51, 401.7, 417.63, 556.9, 589.97, 716.86, 779.64,
827.88, 622.32, 596.16, 539.67, 527.61, 447.53, 365.81, 448.26, 498.53, 639.58, 829.51,
847.85, 938.71, 644.13, 698.87, 562.74, 506.27, 497.06, 489.94, 565.89, 617.32, 818.43,
694.08, 1038.64, 977.44, 898.57, 821.92, 520.79, 538.97, 454.86, 493.02, 642.99, 617.44,
899.6, 838.48, 1203.36, 1196.74, 909.78, 925.14, 691.49, 657.77, 557.33, 714.66, 595.66,
836.99, 874.48, 1123.95, 987.75, 1422.83, 1168.57, 991.16, 1011.82, 645.89, 798.4, 694.36,
809.15, 892.91, 1130.83, 1454.34, 1547.41, 1406.15, 1374.14, 964.71, 809.46, 680.92,
845.87, 721.14, 822.52, 1042.68, 1402.96, 1305.86, 1847.34, 1485.7, 1521.19, 1188.25,
In this step we have to create the vector with new data points.
plot(data.ts)
plot(data.dec)
## Holt Winters
holtwinters function is used to find the Unknown parameters which is determined by minimizing
the squared prediction error as data here exhibits Multiplicative seasonality.
plot(data.holt)
prediction for 4 years ahead. till 2012 we have data and next 4 years prediction is done via
predict
plot(data.trans)
plot(data.trans)
## Now Forecast
forc.mult <- forecast(LM.forecast, h=20)
plot(forc.mult)
## Cycles
for(i in 1:12)
if(i==1){
}else{