This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library(forecast)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## Loading required package: timeDate
## This is forecast 5.9
train <- read.csv('c:/users/wade/desktop/train.txt')

train1 <- train$TrainRev
par(mfrow=c(2,2))
plot.ts(train1, main="未做差分之時序圖", ylab= "台鐵每月營收", xlab = "月份")
Acf(train1, lag.max = 36, plot=TRUE, main = "Autocorrelation Function / Lag")
Pacf(train1, lag.max = 36, plot=TRUE, main = "Partial Autocorrelation Function / Lag")
qqnorm(train1, pch=20)
qqline(train1)

train2 <- diff(train1, lag = 1, differences = 1)
par(mfrow=c(2,2))
plot.ts(train2, main="一次差分後的時序圖 Y(1)", ylab= "台鐵每月營收", xlab = "月份")
Acf(train2, lag.max = 36, plot=TRUE, main = "Autocorrelation Function / Lag")
Pacf(train2, lag.max = 36, plot=TRUE, main = "Partial Autocorrelation Function / Lag")
qqnorm(train2, pch=20)
qqline(train2)

train3 <- diff(train1, lag = 12, differences = 1)
par(mfrow=c(2,2))
plot.ts(train3, main="一次差分後的時序圖 Y(12)", ylab= "台鐵每月營收", xlab = "月份")
Acf(train3, lag.max = 36, plot=TRUE, main = "Autocorrelation Function / Lag")
Pacf(train3, lag.max = 36, plot=TRUE, main = "Partial Autocorrelation Function / Lag")
qqnorm(train3, pch=20)
qqline(train3)

train4 <- diff(train2, lag = 12, differences = 1)
par(mfrow=c(2,2))
plot.ts(train4, main="一次差分後的時序圖 Y(1,12)", ylab= "台鐵每月營收", xlab = "月份")
Acf(train4, lag.max = 36, plot=TRUE, main = "Autocorrelation Function / Lag")
Pacf(train4, lag.max = 36, plot=TRUE, main = "Partial Autocorrelation Function / Lag")
qqnorm(train4, pch=20)
qqline(train4)

#未完待續
#fit <- Arima(train4, order = c(0,1,1), seasonal = list(order = c(0,1,1)))