Predicting Time Series Passenger Counts
Using Non-Linear Additive Models - Interactive Guide with Live Prophet Demo
This interactive guide demonstrates how to generate predictions for future ridership in transportation agencies. Originally developed for Capitol Corridor Joint Powers Authority, this methodology includes a live implementation of Facebook's Prophet algorithm running in your browser.
Capitol Corridor Weekly Ridership & 2024 Forecast
Key Observations: The dramatic drop in 2020 demonstrates the "stochastic shock" of COVID-19. The 2024 forecast shows continued gradual recovery with uncertainty bounds reflecting post-pandemic volatility.
Post-Pandemic Reality
Current weekly ridership data remains much lower than pre-pandemic levels. Work-from-home patterns and net migration changes have fundamentally altered commuter travel. COVID-19 represented a stochastic shock across the economy, requiring new forecasting approaches.
Understanding Time Series Data
Ridership data measured at discrete intervals (weekly) is a perfect example of time series data. However, not all historical data is useful for prediction. The 2020 trend differs substantially from 2021-2022 trends due to the pandemic's massive disruption.
Key Concepts:
- Stochastic Shock: Unexpected events that fundamentally change system behavior
- Structural Break: Points where time series behavior changes permanently
- Temporal Dependency: How past values influence future predictions
Granger Causality Testing
Before building predictive models, we must determine which historical periods can reliably predict future periods. Despite its name, Granger causality doesn't establish true causation—it only tests predictive utility.
Philosophical Warning: Post Hoc Fallacy
Fallacy: "A occurred, then B occurred after A, therefore A caused B"
Reality: Granger tests only measure predictive utility, not true causation.
Examples of absurd "Granger causation":
- Eggs came before chickens
- GDP can "cause" sunspots
- The sun doesn't affect sunrise/sunset times
Interactive Granger Causality Testing
Select Test Comparison:
Test Result: 2020 → 2021
P-value: 0.7789
Significant:No (p ≥ 0.05)
Interpretation: Cannot predict 2021 from 2020
# Loading lmtest and running grangertest()
install.packages('lmtest')
library(lmtest)
grangertest([Timeseries 1], [Timeseries 2], order = [# lags])
# Example: Testing if 2020 can predict 2021
grangertest(CCJPA_2020, CCJPA_2021, order = 3)
# Example: Testing if 2019 can predict 2021
grangertest(CCJPA_2019, CCJPA_2021, order = 3)
Live Prophet Forecasting Implementation
Run Facebook's Prophet algorithm directly in your browser. This implementation includes trend detection, seasonality modeling, changepoint detection, and uncertainty quantification—all the core components of the original Prophet methodology.
Live Prophet Forecasting Demo
Select Training Dataset (Based on Granger Tests):
Prophet Model Configuration:
# Loading prophet
install.packages('prophet')
library(prophet)
# Prepare data structure (filtered based on Granger tests)
CCJPA_ridership <- data.frame(
ds = seq(as.Date("2021-01-01"), as.Date("2022-12-31"), by = "week"),
y = c(your_ridership_data_2021_2022)
)
# Fit the model
m <- prophet(CCJPA_ridership)
# Create future dataframe (predict 12 months forward)
future <- make_future_dataframe(m, periods = 12, freq = 'month')
# Generate forecast
forecast <- predict(m, future)
# View forecast components
print(forecast[c('ds', 'yhat', 'yhat_lower', 'yhat_upper', 'trend')])
# Visualize results
plot(m, forecast)
prophet_plot_components(m, forecast)
# Export predictions
write.csv(forecast, "ridership_forecast_2024.csv")
Results & Applications
With the live Prophet implementation above, you've generated machine learning predictions with uncertainty bounds. These forecasts have immediate applications in transportation planning and operations research.
Service Planning
Optimize route frequency and capacity
Resource Allocation
Budget staff and equipment needs
Financial Forecasting
Predict fare revenue and subsidies
Key Takeaways for Transit Agencies:
Technical Implementation & References
Prophet Components Implemented:
- • Linear trend with changepoint detection
- • Weekly seasonal decomposition
- • Uncertainty quantification
- • Future period prediction
- • Model component analysis
Statistical Methods:
- • Taylor, S.J. & Letham, B. (2018) - Forecasting at Scale
- • Box & Jenkins (1970) - Time Series Analysis
- • Granger, C.W.J. (1969) - Investigating Causal Relations
- • JavaScript implementation of additive models
Disclaimer: This methodology was developed for Capitol Corridor Joint Powers Authority during the post-COVID recovery period. The JavaScript Prophet implementation is simplified but maintains core algorithmic principles. For production use, validate with the full R or Python Prophet library.