Skip to content

codoom1/BikeRental

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Modeling daily bike-rental dynamics

Code and data accompanying the published article:

Odoom, C., Boateng, A., Fobi Mensah, S., & Maposa, D. (2024). Modeling of the daily dynamics in bike rental system using weather and calendar conditions: A semi-parametric approach. Scientific African, 24, e02211. https://doi.org/10.1016/j.sciaf.2024.e02211

Companion data package: bikerentaldata downloads, prepares, validates, and loads the bike-rental data used by this analysis. It also standardizes historical trip data from Capital Bikeshare, Citi Bike, Divvy, and Bay Wheels for multi-city research.

Overview

This study examines how weather and calendar conditions are associated with daily Capital Bikeshare rentals in Washington, D.C. It uses generalized additive models with a quasi-Poisson response to model total, registered, and casual rentals. The processed dataset covers April 1, 2020 through May 31, 2023 and contains 1,156 daily observations.

Repository structure

.
├── R/
│   └── BikeRental.R          # Exploratory analysis and statistical models
├── data/
│   ├── DATA_LICENSE.md       # Dataset terms and attribution
│   └── paperbike_data.csv    # Processed analysis dataset
├── figures/                  # Plots generated by the analysis
├── CITATION.cff              # Machine-readable citation metadata
├── LICENSE                   # MIT license, limited to original code
└── README.md

The preprocessing script expects downloaded monthly trip files under data/raw/ and writes intermediate files to data/processed/. These directories are intentionally excluded from version control.

Requirements

The analysis was written in R. To restore the recorded package environment:

install.packages("renv")
renv::restore()

Alternatively, install the required analysis packages directly:

install.packages("remotes")
install.packages(c(
  "corrplot", "dbscan", "ggplot2", "mgcv", "tidyverse"
))
remotes::install_github("codoom1/BikeRentalData")

For all optional figures, formatted tables, and diagnostics, also install:

install.packages(c("AER", "gratia", "pander", "yarrr"))

The analysis continues without these optional packages and prints a message identifying the output that will be skipped.

Run the analysis

Clone the repository, set the repository root as your working directory, and run:

source("R/BikeRental.R")

The script reads data/paperbike_data.csv, fits the quasi-Poisson generalized additive models, and saves all generated plots under figures/ as publication-quality PNG files.

Dataset downloading and preprocessing now live in the companion bikerentaldata R package. After installing the package, rebuild the dataset with:

library(bikerentaldata)

build_bike_rental_data(
  start_date = "2020-04-01",
  end_date = "2023-05-31",
  raw_dir = "data/raw",
  weather_cache = "data/processed/weather_data.csv",
  output_file = "data/paperbike_data.csv"
)

Explore archive and station coverage with:

available_trip_data()
current_system_info()
summarize_trip_locations("data/raw")

For a multi-city study, version 0.4.0 can build one standardized trip table for Capital Bikeshare, Citi Bike, Divvy, and Bay Wheels:

multicity <- build_multicity_data(
  systems = c("capital", "citibike", "divvy", "baywheels"),
  start_date = "2024-01-01",
  end_date = "2024-12-31",
  data_dir = "data/multicity",
  calendar = TRUE,
  weather = TRUE,
  output_file = "data/multicity_2024.csv"
)

Use add_calendar_variables() or add_weather_variables() separately when you already have a standardized trip table.

The package downloads official monthly trip archives, aggregates trips, retrieves or reuses cached weather observations, joins records by date, adds calendar variables, validates the result, and writes data/paperbike_data.csv. Fresh package builds use Washington National Airport ASOS observations from the Iowa Environmental Mesonet, while the published dataset used Time and Date weather records; values may therefore differ slightly. The included processed dataset remains the recommended input for reproducing the published analysis.

Data dictionary

Variable Description
date Observation date
registered Number of registered/member rentals
casual Number of casual rentals
total_rentals Total registered and casual rentals
latitude, longitude Daily mean station coordinates
Temp Temperature in degrees Fahrenheit
Wind Wind speed
Humidity Relative humidity percentage
Barometer Atmospheric pressure
Visibility Visibility distance
Weather Daily weather category
Year, Month, day Calendar components
Weekday Weekday indicator
season Spring, summer, autumn, or winter
holiday Holiday indicator
workinday Working-day indicator in the source data

Bike-trip data originate from Capital Bikeshare, and historical weather observations originate from Time and Date.

Citation

If you use this repository, its code, or its processed data, please cite the paper:

@article{odoom2024bike,
  title   = {Modeling of the daily dynamics in bike rental system using
             weather and calendar conditions: A semi-parametric approach},
  author  = {Odoom, Christopher and Boateng, Alexander and
             Fobi Mensah, Sarah and Maposa, Daniel},
  journal = {Scientific African},
  volume  = {24},
  pages   = {e02211},
  year    = {2024},
  doi     = {10.1016/j.sciaf.2024.e02211}
}

GitHub and other citation-aware tools can also read the included CITATION.cff.

License

The original source code in R/ is available under the MIT License. This license does not apply to the dataset or the published article.

The processed dataset is governed by its source-data terms, including the Capital Bikeshare Data License Agreement. See data/DATA_LICENSE.md before redistributing or reusing the data.

The published article is separately distributed by the publisher under CC BY-NC-ND 4.0.

Contact

For questions about the dataset or analysis, contact Christopher Odoom at odoomchristopher22@gmail.com.

About

R code and processed data accompanying our published study of daily Capital Bikeshare rentals using weather and calendar conditions with semi-parametric generalized additive models.

Topics

Resources

License

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages