Beruflich Dokumente
Kultur Dokumente
library("zoo")
Amtrak.data <- read.csv("Amtrak data.csv")
ridership.ts <- ts(Amtrak.data$Ridership, start = c(1991, 1), end = c(2004, 3), freq = 12)
stepsAhead <- 12
nTrain <- length(ridership.ts) - stepsAhead
train.ts <- window(ridership.ts, start = c(1991, 1), end = c(1991, nTrain))
valid.ts <- window(ridership.ts, start = c(1991, nTrain + 1), end = c(1991, nTrain + stepsAhead))
library("forecast")
library("zoo")
American.ts <- ts(American.data$NEW.YORK...ATLANTA, start = c(2012, 1), end = c(2017, 5), freq =
12)
stepsAhead <- 13
attach(UdupiRainfall17)
American_valid.ts <- window(American.ts, start = c(2012, nTrain + 1), end = c(2012, nTrain +
stepsAhead))
plot(American.ts, ylab = "Ridership", xlab = "Time", bty = "l", xaxt = "n", main = "LAX - IAD")
lines(ma.centered, lwd = 2)
ses.opt
accuracy(ses.pred$mean, stepsAhead)
accuracy(ses.opt.pred$mean, stepsAhead)
#holt's
# triple smoothening
#data partitioning
stepsAhead <- 12
nTrain <- length(ridership.ts) - stepsAhead
train.ts <- window(ridership.ts, start = c(1991, 1), end = c(1991, nTrain))
valid.ts <- window(ridership.ts, start = c(1991, nTrain + 1), end = c(1991, nTrain + stepsAhead))
#axis resizing
axis(1, at = seq(1991, 2006, 1), labels = format(seq(1991, 2006, 1)))
lines(ridership.lm$fitted, lwd = 2)
lines(valid.ts)
lines(c(2004.25 - 3, 2004.25 - 3), c(0, 3500))
lines(c(2004.25, 2004.25), c(0, 3500))
text(1996.25, 2500, "Training")
text(2002.75, 2500, "Validation")
arrows(2004 - 3, 2450, 1991.25, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5 - 3, 2450, 2004, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
Output-
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1713.0288 27.0855 63.245 < 2e-16 ***
trend 1.2053 0.3175 3.796 0.000215 ***
---
Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1
Errors:
ME RMSE MAE MPE MAPE ACF1 Theil's U
Test set 168.8525 210.0252 191.5552 7.816868 9.054327 0.1975228 1.250612
Exponential Trend:
library("forecast")
#read amtrak data csv file
Amtrak.data <- read.csv("Amtrak data.csv")
ridership.ts <- ts(Amtrak.data$Ridership, start = c(1991, 1), end = c(2004, 3), freq = 12)
plot(ridership.ts)
#axis resizing
axis(1, at = seq(1991, 2006, 1), labels = format(seq(1991, 2006, 1)))
lines(ridership.lm$fitted, lwd = 2)
lines(valid.ts)
lines(c(2004.25 - 3, 2004.25 - 3), c(0, 3500))
lines(c(2004.25, 2004.25), c(0, 3500))
text(1996.25, 2500, "Training")
text(2002.75, 2500, "Validation")
arrows(2004 - 3, 2450, 1991.25, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5 - 3, 2450, 2004, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
Quadratic Trend:
library("forecast")
#read amtrak data csv file
Amtrak.data <- read.csv("Amtrak data.csv")
ridership.ts <- ts(Amtrak.data$Ridership, start = c(1991, 1), end = c(2004, 3), freq = 12)
plot(ridership.ts)
#data partitioning
stepsAhead <- 12
nTrain <- length(ridership.ts) - stepsAhead
train.ts <- window(ridership.ts, start = c(1991, 1), end = c(1991, nTrain))
valid.ts <- window(ridership.ts, start = c(1991, nTrain + 1), end = c(1991, nTrain + stepsAhead))
#axis resizing
axis(1, at = seq(1991, 2006, 1), labels = format(seq(1991, 2006, 1)))
lines(ridership.lm$fitted, lwd = 2)
lines(valid.ts)
lines(c(2004.25 - 3, 2004.25 - 3), c(0, 3500))
lines(c(2004.25, 2004.25), c(0, 3500))
text(1996.25, 2500, "Training")
text(2002.75, 2500, "Validation")
arrows(2004 - 3, 2450, 1991.25, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5 - 3, 2450, 2004, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.859e+03 3.778e+01 49.207 < 2e-16 ***
trend -4.679e+00 1.179e+00 -3.970 0.000113 ***
I(trend^2) 3.976e-02 7.714e-03 5.154 8.28e-07 ***
#data partitioning
stepsAhead <- 12
nTrain <- length(ridership.ts) - stepsAhead
train.ts <- window(ridership.ts, start = c(1991, 1), end = c(1991, nTrain))
valid.ts <- window(ridership.ts, start = c(1991, nTrain + 1), end = c(1991, nTrain + stepsAhead))
#axis resizing
axis(1, at = seq(1991, 2006, 1), labels = format(seq(1991, 2006, 1)))
lines(ridership.lm$fitted, lwd = 2)
lines(valid.ts)
lines(c(2004.25 - 3, 2004.25 - 3), c(0, 3500))
lines(c(2004.25, 2004.25), c(0, 3500))
text(1996.25, 2500, "Training")
text(2002.75, 2500, "Validation")
arrows(2004 - 3, 2450, 1991.25, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5 - 3, 2450, 2004, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
Output-
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1603.95 32.62 49.172 < 2e-16 ***
season2 -37.68 46.13 -0.817 0.415498
season3 262.86 46.13 5.698 7.27e-08 ***
season4 251.29 47.08 5.337 3.88e-07 ***
season5 282.53 47.08 6.001 1.70e-08 ***
season6 241.17 47.08 5.123 1.02e-06 ***
season7 345.63 47.08 7.341 1.79e-11 ***
season8 390.68 47.08 8.298 9.64e-14 ***
season9 57.65 47.08 1.224 0.222918
season10 197.16 47.08 4.188 5.06e-05 ***
season11 187.32 47.08 3.979 0.000113 ***
season12 231.46 47.08 4.916 2.52e-06 ***
#data partitioning
stepsAhead <- 12
nTrain <- length(ridership.ts) - stepsAhead
train.ts <- window(ridership.ts, start = c(1991, 1), end = c(1991, nTrain))
valid.ts <- window(ridership.ts, start = c(1991, nTrain + 1), end = c(1991, nTrain + stepsAhead))
#axis resizing
axis(1, at = seq(1991, 2006, 1), labels = format(seq(1991, 2006, 1)))
lines(ridership.lm$fitted, lwd = 2)
lines(valid.ts)
lines(c(2004.25 - 3, 2004.25 - 3), c(0, 3500))
lines(c(2004.25, 2004.25), c(0, 3500))
text(1996.25, 2500, "Training")
text(2002.75, 2500, "Validation")
arrows(2004 - 3, 2450, 1991.25, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5 - 3, 2450, 2004, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 7.37740 0.01843 400.245 < 2e-16 ***
season2 -0.02416 0.02607 -0.927 0.356
season3 0.15186 0.02607 5.826 3.97e-08 ***
season4 0.14566 0.02660 5.475 2.06e-07 ***
season5 0.16332 0.02660 6.139 8.69e-09 ***
season6 0.14055 0.02660 5.283 4.97e-07 ***
season7 0.19682 0.02660 7.398 1.32e-11 ***
season8 0.21992 0.02660 8.266 1.15e-13 ***
season9 0.03716 0.02660 1.397 0.165
season10 0.11732 0.02660 4.410 2.09e-05 ***
season11 0.11113 0.02660 4.177 5.27e-05 ***
season12 0.13588 0.02660 5.107 1.09e-06 ***
#data partitioning
stepsAhead <- 12
nTrain <- length(ridership.ts) - stepsAhead
train.ts <- window(ridership.ts, start = c(1991, 1), end = c(1991, nTrain))
valid.ts <- window(ridership.ts, start = c(1991, nTrain + 1), end = c(1991, nTrain + stepsAhead))
#axis resizing
axis(1, at = seq(1991, 2006, 1), labels = format(seq(1991, 2006, 1)))
lines(ridership.lm$fitted, lwd = 2)
lines(valid.ts)
lines(c(2004.25 - 3, 2004.25 - 3), c(0, 3500))
lines(c(2004.25, 2004.25), c(0, 3500))
text(1996.25, 2500, "Training")
text(2002.75, 2500, "Validation")
arrows(2004 - 3, 2450, 1991.25, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
arrows(2004.5 - 3, 2450, 2004, 2450, code = 3, length = 0.1, lwd = 1,angle = 30)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.666e+03 2.682e+01 62.111 < 2e-16 ***
trend -5.247e+00 5.867e-01 -8.942 2.83e-15 ***
I(trend^2) 4.376e-02 3.841e-03 11.393 < 2e-16 ***
season2 -3.886e+01 2.932e+01 -1.326 0.1873
season3 2.604e+02 2.932e+01 8.881 3.98e-15 ***
season4 2.674e+02 2.995e+01 8.931 3.01e-15 ***
season5 2.978e+02 2.995e+01 9.943 < 2e-16 ***
season6 2.554e+02 2.995e+01 8.529 2.88e-14 ***
season7 3.588e+02 2.995e+01 11.980 < 2e-16 ***
season8 4.026e+02 2.995e+01 13.445 < 2e-16 ***
season9 6.832e+01 2.995e+01 2.281 0.0241 *
season10 2.065e+02 2.995e+01 6.894 1.98e-10 ***
season11 1.952e+02 2.995e+01 6.517 1.36e-09 ***
season12 2.378e+02 2.995e+01 7.939 7.52e-13 ***
Errors:
ME RMSE MAE MPE MAPE ACF1 Theil's U
Test set -34.11391 50.59855 39.2566 -1.695392 1.937465 -0.04653612 0.3115289