forked from etlundquist/holtwint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.r
More file actions
20 lines (15 loc) · 694 Bytes
/
Copy pathtesting.r
File metadata and controls
20 lines (15 loc) · 694 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
library(tidyr)
library(ggplot2)
setwd('~/Repositories/holtwint')
df <- read.table('sampledata.csv', sep = ',', header = FALSE)
df$month <- seq_along(df$V1)
names(df) <- c('passengers', 'month')
ts <- ts(as.vector(df$passengers), frequency = 12)
ggplot(data = df[1:48,]) + geom_line(aes(x = month, y = passengers)) + scale_x_discrete(breaks = seq(0, 50, 1))
initfit <- lm(passengers ~ month, data = df[1:48,])
summary(initfit)
fit <- HoltWinters(ts, seasonal = 'multiplicative', start.periods = 4)
round(fit$alpha, 3); round(fit$beta, 3); round(fit$gamma, 3)
round(fit$coefficients, 3); round(fit$SSE/nrow(df), 3)
pr24 <- predict(fit, n.ahead = 24, prediction.interval = FALSE)
round(pr24)