transport911 <- read.csv("/Users/wendyhayes/Desktop/MBA 678-Predictive Analytics/Sept11Travel_Updated.csv")
str(transport911)
## 'data.frame': 172 obs. of 4 variables:
## $ Month: Factor w/ 172 levels "1-Apr","1-Aug",..: 86 75 119 42 130 108 97 53 163 152 ...
## $ Air : int 35153577 32965187 39993913 37981886 38419672 42819023 45770315 48763670 38173223 39051877 ...
## $ Rail : int 454115779 435086002 568289732 568101697 539628385 570694457 618571581 609210368 488444939 514253920 ...
## $ VMT : num 163 153 178 179 189 ...
transport911air.ts <- ts(transport911$Air, start=c(1990,1), end=c(2004,4), freq = 12)
summary(transport911air.ts)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 29670000 42660000 49460000 49260000 55360000 69000000
plot(transport911air.ts, xlab="Time", ylab="Air Miles Traveled", ylim=c(29670000, 69000000), bty="l")
transport911Rail.ts <- ts(transport911$Rail, start=c(1990,1), end=c(2004,4), freq = 12)
summary(transport911Rail.ts)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 326900000 440200000 477100000 482800000 537700000 664000000
plot(transport911Rail.ts, xlab="Time", ylab="Rail Miles Traveled", ylim=c(326900000, 664000000), bty="l")
transport911Car.ts <- ts(transport911$VMT, start=c(1990,1), end=c(2004,4), freq = 12)
summary(transport911Car.ts)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 153.2 192.9 209.7 210.3 229.8 261.3
plot(transport911Car.ts, xlab="Time", ylab="Car Miles Traveled", ylim=c(153.2, 261.3), bty="l")
Air911 <- window(transport911air.ts,1995,c(2001,8))
plot(Air911, ylab="Air Travel Miles",ylim=c(min(transport911air.ts),max(transport911air.ts)), bty="l")
quarterly <- aggregate(Air911,nfrequency=4, FUN=sum)
plot(quarterly, bty="l")
library(forecast)
## 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: timeDate
## This is forecast 7.3
miles <- tslm(quarterly~trend)
summary(miles)
##
## Call:
## tslm(formula = quarterly ~ trend)
##
## Residuals:
## Min 1Q Median 3Q Max
## -13289365 -7370567 -2153420 7331377 15908917
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 136299691 4057275 33.594 < 2e-16 ***
## trend 1697426 262718 6.461 1.11e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 10050000 on 24 degrees of freedom
## Multiple R-squared: 0.635, Adjusted R-squared: 0.6197
## F-statistic: 41.74 on 1 and 24 DF, p-value: 1.109e-06
lines(miles$fitted, lwd=2)
#####With an R-square value in the low 60s, this is a pretty good fit. The next check was to see the overall impact the September 11th incident had on air travel.
quarterly <- aggregate(transport911air.ts,nfrequency=4, FUN=sum)
plot(quarterly, bty="l")
miles <- tslm(quarterly~trend)
summary(miles)
##
## Call:
## tslm(formula = quarterly ~ trend)
##
## Residuals:
## Min 1Q Median 3Q Max
## -31619784 -9925875 -1516367 9227172 27670090
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 114352086 3460507 33.05 < 2e-16 ***
## trend 1144819 103789 11.03 1.48e-15 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 12890000 on 55 degrees of freedom
## Multiple R-squared: 0.6887, Adjusted R-squared: 0.683
## F-statistic: 121.7 on 1 and 55 DF, p-value: 1.481e-15
lines(miles$fitted, lwd=2)
appliances <- read.csv("/Users/wendyhayes/Desktop/MBA 678-Predictive Analytics/ApplianceShipments.csv")
appliances.ts <- ts(appliances$Shipments, start=c(1985,1), end=c(1989,4), freq=4)
str(appliances.ts)
## Time-Series [1:20] from 1985 to 1990: 4009 4123 4493 4595 4245 4321 4522 4806 4799 4900 ...
plot(appliances.ts, ylab="Shipments",ylim=c(min(appliances.ts),max(appliances.ts)),bty="l", type="b")
sold <- tslm(appliances.ts~trend)
lines(sold$fitted, lwd=2)
shampoo <- read.csv("/Users/wendyhayes/Desktop/MBA 678-Predictive Analytics/ShampooSales.csv")
str(shampoo)
## 'data.frame': 36 obs. of 2 variables:
## $ Month : Factor w/ 36 levels "Apr-95","Apr-96",..: 13 10 22 1 25 19 16 4 34 31 ...
## $ Shampoo.Sales: num 266 146 183 119 180 ...
shampoo.ts <- ts(shampoo$Shampoo.Sales, start=c(1995,1), end=c(1997,12), freq = 12)
summary(shampoo.ts)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 119.3 192.5 280.2 312.6 411.1 682.0
plot(shampoo.ts, ylab="Shampoo Sales",ylim=c(min(shampoo.ts),max(shampoo.ts)),bty="l", type="b")
shampoosales <- tslm(shampoo.ts~trend)
lines(shampoosales$fitted, lwd=2)
#####I decided to look at an aggregate to see if anything stood out in terms of seasonality:
quarterly <- aggregate(shampoo.ts,nfrequency=4, FUN=sum)
plot(quarterly, bty="l")
sales <- tslm(quarterly~trend)
lines(sales$fitted, lwd=2)
shampoo <- window(shampoo.ts,1996,c(1997,6))
plot(shampoo, ylab="Shampoo Sales",ylim=c(min(shampoo.ts),max(shampoo.ts)), bty="l")
sold <- tslm(shampoo~trend)
summary(sold)
##
## Call:
## tslm(formula = shampoo ~ trend)
##
## Residuals:
## Min 1Q Median 3Q Max
## -73.846 -37.629 -0.824 29.156 107.002
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 164.302 23.886 6.879 3.71e-06 ***
## trend 15.030 2.207 6.811 4.18e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 48.57 on 16 degrees of freedom
## Multiple R-squared: 0.7435, Adjusted R-squared: 0.7275
## F-statistic: 46.39 on 1 and 16 DF, p-value: 4.183e-06
lines(sold$fitted, lwd=2)