-
Notifications
You must be signed in to change notification settings - Fork 0
/
forecast.R
57 lines (33 loc) · 1.32 KB
/
forecast.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
library(forecast)
library(tseries)
count_ts <- ts(daily_data[,c('value)])
daily_data$cnt_ma <- ma(daily_data$clean_cnt, order = 7)
count_ma <- ts(na.omit(daily_data$cnt_ma), frequency = 30)
decomp <- stl(count_ma, s.window = "periodic")
deseasonal_cnt <- seasadj(decomp)
plot(decomp)
adf.test(count_ma, alternative = "stationary")
Acf(count_ma, main = '')
Acf(count_d1, main = 'Acf for differenced series')
Pacf(count_d1)
count_d1 <- diff(deseasonal_cnt, differences = 1)
plot(count_d1)
adf.test(count_d1, alternative = 'Stationary')
#seasonal false
auto.arima(deseasonal_cnt, seasonal = FALSE)
fit <- auto.arima(deseasonal_cnt, seasonal = FALSE)
tsdisplay(residuals(fit), lag.max = 45, main = '(1,1,1) model residuals')
fit2 >- arima(deseasonal_cnt, order = c(1,1,5))
tsdisplay(residuals(fit2) lag.max - 15, main = 'Seasonal Model Residuals')
fcast <- forecast(fit2, h = 60)
plot(fcast)
#seasonal true
fit_w_seasonality <- auto.arima(deseasonal_cnt, seasonal = TRUE)
seas_fcast <- forecast(fit_w_seasonality, h = 30)
plot(seas_fcast)
#hold
hold <- window(ts(deseasonal_cnt), start = 8)
fit_no_holdout <- arima(ts(deseasonal_cnt[-c(8:10)]), order = c(1,1,7))
fcast_no_holdout <- forecast (fit_No_holdout, h = 25)
plot(fcast_no_holdout, main = " ")
lines(ts(deseasonal_cnt))