-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path07-appendix.Rmd
179 lines (131 loc) · 5.53 KB
/
07-appendix.Rmd
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
`r if(knitr:::is_latex_output()) '\\appendix'`
`r if(!knitr:::is_latex_output()) '# (APPENDIX) Appendix {-}'`
# Code {#aa}
\begin{wrapfigure}{R}{.35\textwidth}
\begin{center}
\includegraphics[width=.3\textwidth]{figures/hexagon.png}
\end{center}
\end{wrapfigure}
All the R code used in this thesis, as well as the nested SQL code, is bundled in the `dockless` package [@dockless]. Its source code, including documentation for each function, can be found on GitHub, through the following link: https://github.com/luukvdmeer/dockless. An R version of at least 2.10 is required. The package is optimized for the case study in San Francisco, but can easily be adapted to other systems.
The JUMP Bikes database is not openly accessible. Therefore, to query the data, and pre-process them on the database server, database credentials are needed. Please contact the author for more information. However, to enable reproducibility, all necessary pre-processed datasets have been included in the package. These are the following:
* `distancedata_centroids`: an object of class `dockless_dfc` containing the distance data for all 249 grid cell centroids, during the training period.
* `distancedata_modelpoints`: an object of class `dockless_dfc` containing the distance data for all 4 model points, during the training period.
* `distancedata_testpoints`: an object of class `dockless_dfc` containing the distance data for all 500 test points, during the test period, and the two weeks before.
* `usagedata_train`: an object of class `sf` with POINT geometry, containing all calculated pick-ups during the training period.
* `usagedata_test`: an object of class `sf` with POINT geometry, containing all calculated pick-ups during the test period.
* `testpoints`: an object of class `sf` with POINT geometry, containing all location-timestamp combinations of the 500 test points.
* `systemarea`: an object of class `sf` with POLYGON geometry, containing the geographical outline of the JUMP Bikes system area in San Francisco.
The `dockless` package can be downloaded from github with the following code. Please make sure that the `devtools` package is installed in advance.\
```{r, echo = TRUE, eval = FALSE}
devtools::install_github('luukvdmeer/dockless')
```
Then, the complete analysis can be reproduced as follows. Furthermore, reproducible scripts for all tables and figures in chapter 5 can be found through the following link: https://github.com/luukvdmeer/dockless/tree/master/scripts \
```{r, echo = TRUE, eval = FALSE}
require(dockless)
require(sf)
## ----------------------- CLUSTER LOOP --------------------------
# Create grid
gridcells = dockless::create_grid(
area = systemarea,
cellsize = c(500, 500)
)
# Calculate grid cell centroids
gridcentroids = gridcells %>%
dockless::project_sf() %>%
sf::st_centroid() %>%
sf::st_transform(crs = 4326)
# Usage intensity per grid cell
gridcells$intensity = dockless::usage_intensity(
usage = usagedata_train,
grid = gridcells
)
# Add intensity information to grid cell centroids
gridcentroids$intensity = gridcells$intensity
# Cluster
clusters = dockless::spatial_cluster(
data = distancedata_centroids,
grid = gridcells,
area = systemarea,
K = c(3:10),
omega = seq(0, 1, 0.1)
)
# Add cluster information to grid cells and grid cell centroids
gridcells$cluster = clusters$indices
gridcentroids$cluster = clusters$indices
# Create model points
modelpoints = dockless::create_modelpoints(
centroids = gridcentroids
)
## ------------------------ MODEL LOOP ---------------------------
# Build models
models = dockless::build_models(
data = distancedata_modelpoints,
auto_seasonality = TRUE,
seasons = list(NULL, 96, 672, c(96, 672))
)
## ---------------------- FORECAST LOOP --------------------------
# Forecast test points with DBAFS and NFS
forecasts_dbafs = dockless::forecast_multiple(
data = distancedata_testpoints,
method = 'DBAFS',
points = testpoints,
models = models
)
forecasts_nfs = dockless::forecast_multiple(
data = distancedata_testpoints,
method = 'NFS',
points = testpoints
)
# Calculate RMSE's
errors_dbafs = dockless::evaluate(
forecasts_dbafs,
type = 'RMSE',
clusters = testpoints$cluster
)
errors_nfs = dockless::evaluate(
forecasts_nfs,
type = 'RMSE',
clusters = testpoints$cluster
)
```
<!-- \clearpage -->
<!-- \shipout\null -->
<!-- \stepcounter{page} -->
# Models {#ab}
This appendix provides more detailed information about the models that were fitted to the non-seasonal historical data of each model point. This information includes parameter estimates, error variance, Gaussian log-likelihood, and information criteria such as AIC. For those model points where seasonality was detected, the decomposition plots are provided as well.
## Bayview model point
**Model**
```{r, warning = FALSE, message = FALSE}
require(forecast)
(readRDS('data/models.rds'))[[1]]
```
\newpage
## Downtown model point
**Decomposition plot**
```{r}
knitr::include_graphics('figures/stlplot_model2.png', auto_pdf = TRUE)
```
**Model**
```{r, warning = FALSE, message = FALSE}
((readRDS('data/models.rds'))[[2]])$model
```
\newpage
## Residential model point
**Decomposition plot**
```{r}
knitr::include_graphics('figures/stlplot_model3.png', auto_pdf = TRUE)
```
**Model**
```{r, warning = FALSE, message = FALSE}
((readRDS('data/models.rds'))[[3]])$model
```
\newpage
## Presidio model point
**Decomposition plot**
```{r, }
knitr::include_graphics('figures/stlplot_model4.png', auto_pdf = TRUE)
```
**Model**
```{r, warning = FALSE, message = FALSE}
((readRDS('data/models.rds'))[[4]])$model
```