-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.R
More file actions
232 lines (207 loc) · 9.15 KB
/
app.R
File metadata and controls
232 lines (207 loc) · 9.15 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
library(shiny)
library(fpp3)
library(markdown)
library(shinythemes)
ui <- navbarPage("COD TimeSeries App",
theme = shinytheme('darkly'),
tabPanel("Plots",
sidebarLayout(
sidebarPanel(
radioButtons("plotType", "Plot Types:",
c("Seasonality"= 's',
"Autocorrelation"= 'a',
"Decomposition x11"= 'd',
"Decomposition seats" = 'd2',
"Line Plot" = 'l')
)
),
mainPanel(
plotOutput("plot")
)
)
),
tabPanel("Simple Models",
sidebarLayout(
sidebarPanel(
radioButtons("plotType2", "Simple Models:",
c("Mean" = 'me',
"NAIVE" = 'na',
"Seasonal NAIVE" = 'sn',
"Drift" = 'dr')
)
),
mainPanel(
plotOutput("plot2")
)
)
),
tabPanel("Exponential Smoothing",
sidebarLayout(
sidebarPanel(
radioButtons("plotType3", "Listed Options:",
c("Holts" = 'Holts',
"Holts/Winters" = 'Holwin',
"More" = 'Ext'
)
)
),
mainPanel(
plotOutput("plot3")
)
)
),
tabPanel("ARIMA",
sidebarLayout(
sidebarPanel(
radioButtons("plotType4", "Listed Options:",
c("Auto-selected Parameters" = 'arima_auto',
"Manually Selected Parameters" = 'arima_man'
)
)
),
mainPanel(
plotOutput("plot4")
)
)
),
tabPanel("Data Summary",
verbatimTextOutput("summary")
),
navbarMenu("More",
tabPanel("Table",
DT::dataTableOutput("table")
),
tabPanel("About Plots",
fluidRow(
column(12,
"This data is the google search for the words 'Call of Duty' from 2004 to the present day.
The data is broken down by months and years."),
column(12,
"Interpretations of the plots:"),
column(12,
'-Seasonality plot helps to show if a seasonal pattern is occuring more clearly. In the graph we can notice there appears to be seasonality during the November month.'),
column(12,
"-Autocorrelation plot shows the correlation between a time series with a lagged version of itself. In this autocorrelation plot we can notice a lag of 6 and 12 being significant."),
column(12,
"-Decomposition plots a time series means separating it into it’s constituent components, which are a trend component, a seasonal component, and a irregular component. From the plots you can see the data is quite seasonal."),
column(12,
"-The line plot shows the data from 2004 to present with a line connecting each point of data.")
)),
tabPanel("Instructions",
fluidRow(
column(9,
'-To use this app just click on the top menu to navigate.'
),
column(9,
'-Under Plot tab you can select which plot you want to see for the data.'
),
column(9,
'-Under the Data Summary tab you can see the 5 number summary of the data.'
),
column(9,
'-Under the Exponential Smoothing tab you will see Holts/Winter/More.'
),
column(9,
'-Under the ARIMA tab you will see both a manual and auto selected ARIMA models.'
)
)
)
)
)
server <- function(input, output, session) {
calldata <- read.csv('CallofDutyData.csv')
calldata$Month <- ym(calldata$Month)
Calldata <- calldata
Calldata$Month <- yearmonth(calldata$Month)
Calldata <- tsibble(Calldata)
fit_m <- Calldata %>%
model(MEAN(Call.of.Duty...United.States.))
fit_n <- Calldata %>%
model(NAIVE(Call.of.Duty...United.States.))
fit_sn <- Calldata %>%
model(SNAIVE(Call.of.Duty...United.States.))
fit_dr <- Calldata %>%
model(NAIVE(Call.of.Duty...United.States. ~ drift()))
fit_Holts <- Calldata %>%
model(ETS(Call.of.Duty...United.States. ~ error("A") + trend("A") + season("N")))
fit_Holwin <- Calldata %>%
model(
additive = ETS(Call.of.Duty...United.States. ~ error("A") + trend("A") +season("A")),
multiplicative = ETS(Call.of.Duty...United.States. ~ error("M") + trend("A") +season("M"))
)
fit_extra <- Calldata %>%
model(
auto_ets = ETS(Call.of.Duty...United.States.),
manual_ets = ETS(Call.of.Duty...United.States. ~ error("A") + trend("A") + season("A")),
tslm = TSLM(Call.of.Duty...United.States. ~ trend() + season())
)
fit_ar1 <- Calldata %>%
model(ARIMA(Call.of.Duty...United.States.))
fit_ar2 <- Calldata %>%
model(ARIMA(Call.of.Duty...United.States. ~ pdq(0,1,2) + PDQ(1,1,0)))
output$plot <- renderPlot({
switch(
input$plotType,
s = gg_season(Calldata),
a = autoplot(ACF(Calldata)),
d = Calldata %>%
model(X_13ARIMA_SEATS(Call.of.Duty...United.States.~x11())) %>%
components() %>%
autoplot(),
d2 = Calldata %>%
model(X_13ARIMA_SEATS(Call.of.Duty...United.States.~seats())) %>%
components() %>%
autoplot(),
l = plot(calldata, type=input$plotType)
)
})
output$plot2 <- renderPlot({
switch(
input$plotType2,
me = fit_m %>%
forecast(h = 10) %>%
autoplot(Calldata),
na = fit_n %>%
forecast(h = 10) %>%
autoplot(Calldata),
sn = fit_sn %>%
forecast(h = 10) %>%
autoplot(Calldata),
dr = fit_dr %>%
forecast(h = 10) %>%
autoplot(Calldata)
)
})
output$plot3 <- renderPlot({
switch(
input$plotType3,
Holts = fit_Holts %>%
forecast(h = '5 years') %>%
autoplot(Calldata),
Holwin = fit_Holwin %>%
forecast(h = '5 years') %>%
autoplot(Calldata),
Ext = fit_extra %>%
forecast(h = '5 years') %>%
autoplot(Calldata)
)
})
output$plot4 <- renderPlot({
switch(
input$plotType4,
arima_auto = fit_ar1 %>%
forecast(h = '5 years') %>%
autoplot(Calldata),
arima_man = fit_ar2 %>%
forecast(h = '5 years') %>%
autoplot(Calldata)
)
})
output$summary <- renderPrint({
summary(calldata)
})
output$table <- DT::renderDataTable({
DT::datatable(calldata)
})
}
shinyApp(ui, server)