Skip to content
/ cppSim Public

Spatial interaction models in R, powered by C++

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

ischlo/cppSim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Dec 11, 2024
5009b72 · Dec 11, 2024

History

58 Commits
Jul 19, 2024
Dec 11, 2024
May 13, 2024
Jul 19, 2024
Dec 10, 2024
Jul 18, 2024
Dec 11, 2024
Dec 11, 2024
Dec 10, 2024
Oct 31, 2024
Oct 31, 2024
Dec 11, 2024
Feb 23, 2023
Feb 23, 2023
May 12, 2023
Jul 19, 2024
Dec 10, 2024
Dec 10, 2024
Feb 24, 2024
Jul 19, 2024
May 20, 2024

Repository files navigation


cppSim

DOI Lifecycle: stable arXiv

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

Not yet on CRAN, so please install the development version of cppSim with:

# install.packages(C("devtools","pak"))

devtools::install_github("ischlo/cppSim")
# 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:

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.

The accompanying code for the analysis is provided in the 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 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 1000 × 1000 OD matrix, the speed up is increasingly more significant as matrices get bigger.

[1] "/Users/cenv1069/Library/R/arm64/4.4/library/cppSim/extdata/benchmark_test.rds"

Citation

To cite package 'cppSim' in publications use:

  Schlosser I (2024). _cppSim: Fast and Memory Efficient Spatial
  Interaction Models_. R package version 0.2,
  https://github.com/ischlo/cppSim, <https://ischlo.github.io/cppSim/>.

A BibTeX entry for LaTeX users is

  @Manual{,
    title = {cppSim: Fast and Memory Efficient Spatial Interaction Models},
    author = {Ivann Schlosser},
    year = {2024},
    note = {R package version 0.2, https://github.com/ischlo/cppSim},
    url = {https://ischlo.github.io/cppSim/},
  }

About

Spatial interaction models in R, powered by C++

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Citation

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published