-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
124 lines (76 loc) · 4.33 KB
/
README.Rmd
File metadata and controls
124 lines (76 loc) · 4.33 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
---
output: github_document
# bibliography: references.bib
---
------------------------------------------------------------------------
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
eval = FALSE,
comment = "",
# fig.path = "man/figures/README-",
out.width = "100%"
)
```
# cppSim
<!-- badges: start -->
<!-- [](https://doi.org/10.5281/zenodo.14367756) -->
[](https://CRAN.R-project.org/package=cppSim)
`r badger::badge_doi("10.1088/2632-072X/add257", "blue")`
[](https://lifecycle.r-lib.org/articles/stages.html#stable)

<!--  -->
<!-- [](https://arxiv.org/abs/2309.02112) -->
<!--  -->
<!-- badges: end -->
This aims at providing a set of fast, memory efficient functions to perform spatial interaction modelling, also called gravity modelling. Currently, the doubly and singly constrained models are implemented for canonical set of constraints. Future versions will aim to implement more origin and destination constraints as well. It was developed in the context of studying commuter flows by active travel (cycling & walking ) in Great Britain as part of a project at CASA, UCL.
## Installation
You can install the package from github or CRAN with:
``` r
install.packages("cppSim")
# # Or:
# install.packages("pak")
# pak::pak("ischlo/cppSim")
```
## Built in data sets
The package comes with sample data sets that allow to test the functions right away as well as see the type of input that is recommended.
- flows_test : using the official census data in England from 2011, it's a 983x983 matrix representing the flows of cyclists and pedestrians from each to each MSOA in London.
- distance_test : the distances between centroids of MSOAs. Computed with the London road network from OpenStreetMap and using the `cppRouting` package.
## Spatial interaction models
Refer to the vignette to find some theory on SIMs and a *naive* implementation in `R`.
## Example
Using the built-in data sets `flows_test` and `distance_test`, we can run a test by following the example This is a basic example which shows you how to solve a common problem:
```{r example, eval=FALSE}
library(cppSim)
## basic example code
data("flows_test")
data("distance_test")
model_test <- run_model(
flows = flows_test,
distance = distance_test
)
```
## Source
For an example of what can be done with this package, please refer to the publication on active travel spatial interaction models in London for which it was originally developed.
> [Schlosser, I., Maureira, V.M., Milton, R., Arcaute, E., Batty, M., 2023. Active-travel modelling: a methodological approach to networks for walking and cycling commuting analysis.](https://doi.org/10.1088/2632-072X/add257)
**Pre-print**: https://arxiv.org/abs/2309.02112
The accompanying code for the analysis is provided in the [`ischlo/quant_cycle_walk`](https://github.com/ischlo/quant_cycle_walk) repository.
## Dependencies
This package has some dependencies that might need manual installation, although the most important external ones have been provided with the source code.
### External
The package uses the [`armadillo`](https://arma.sourceforge.net) library, which is imported and linked automatically when the package is installed.
### Other
On the R side, it uses `Rcpp`[@eddelbuettel2011] and `RcppArmadillo`[@eddelbuettel2014].
## Performance
Compared to the equivalent functions implemented in pure R, it runs about x10 faster for a $\sim 1000 \times 1000$ OD matrix, the speed up is increasingly more significant as matrices get bigger.
```{r performance,eval=TRUE,include=TRUE,echo = FALSE}
bench <- system.file("extdata","benchmark_test.rds",package = "cppSim") |>
rlist::list.load()
print(bench)
```
## Citation
```{r eval=TRUE,echo=FALSE,include=TRUE}
citation("cppSim")
```
<!-- ## References -->