Exploring 2014 Denver B-cycle Ridership
21 Feb 2016Denver, Colorado is considered to be one of the most bikeable cities in America. In addition to the fine bike lanes, bike trails, and mostly favorable weather (300 days of sunshine, says the possibly dubious but sunny claim), Denver is also a B-cycle city, with bicycle rental kiosks dotting the sidewalks near the city center. For this short study, I obtained Denver’s 2014 B-cycle trip data, and used it along with some other data sources to see if I could model hourly ridership across the Denver B-cycle network. My study indicated that most calendar and clock variables are highly significant when predicting ridership, and weather variables such as temperature and amount of cloud cover appear to be as well. This post details how I obtained the data, how I merged data from different sources, shows some explorations of the data, and finally shows how I created a regression model of system ridership.
About B-cycle
B-cycle is a public bicycle sharing company that operates in several cites, including Denver, Colorado. The premise is that users may “checkout” a bike from a kiosk, which is usually along a city sidewalk, under various short- to long-term access passes, depending on the user’s preference and anticipated usage. In Denver, most of the kiosks appear to have 10-20 “docks” where the bikes are stored until a user checks out the bike. After a user checks out a bike, they ride it for as long as they wish, and then check it back in any B-cycle kiosk. In 2014, Denver B-cycle operated 84 different kiosks, which are mostly clustered around the city center. At the end of the year, B-cycle posts their yearly trip data as an Excel spreadsheet on their company webpage. I used these data, along with data from a few other sources, to conduct this study. For more information, please see the Denver B-cycle homepage.
Data Acquisition and Merging
For this report, I obtained data from several sources and combined the data together, taking the following steps. Most of the initial data download and munging steps can be replicated by looking at the exploring_bcycle_data.Rmd file; most of these steps were too time-intensive to be carried out in a production-level script.
- Downloaded B-cycle 2014 Trip Data from the B-Cycle company information webpage. I did some date munging and changed variable names to ones that are more R-friendly.
- Obtained B-cycle kiosk data (kiosk name and address) by hand from the Denver B-cycle homepage.
- Created a list of the 6800 combinations of checkout kiosk/return kiosk. For each combination, I used the
mapdist
function from R’sggmap
package to find the approximate bicycling distance and time between each kiosk. Because of the large number of one-way streets in the Denver downtown area, where the kiosks are highly clustered, I chose to find each checkout-return pair’s distance separately, rather than finding a single distance for each pair regardless of direction of travel. This process took three days, because the Google Distance Matrix API (which themapdist
function uses) only allows 2500 calls a day. - Found the latitude and longitude for each station using the
geocode
function in theggmap
package. - Obtained an API key from forecast.io. Within R, in my exploratory
Rmd
file, I wrote a function to download the weather data from forecast.io. Each day’s hourly data comes in a separate JSON file; I saved each JSON file to a directory. - Within the production script, I merged different parts of the above data in different ways, depending on the specific task goals. The final merging was to merge aggregated hourly checkout data with the hourly weather data.
A Note about Holidays
For my study, I factored in City of Denver observed holidays. Denver city celebrates all the same holidays as the federal holidays, with the following exception: Columbus Day is not a city holiday, and is replaced by Cesar Chavez Day, usually in late March. I only factored in the major federal holidays that result in government and bank closures (with the exception above), and not the lesser holidays.
Basic Ridership Statistics
Number of Rides
The B-cycle data, as downloaded, contains 377,229 rows of “trip data.” Nominally, this means that 377,229 B-cycle trips were taken in 2014. Indeed, the 2014 Denver B-cycle annual report claims this to be the number of rides for the year.
However, over 1% of the rides (4279 rides) have the same checkout station as return station with a trip duration of only 1 minute (see Figure 1 below). I believe these should be filtered out because I believe the majority of these “rides” are likely people checking out a bike, and then deciding after a very short time that this particular bike doesn’t work for them. I believe that most of the same-kiosk rides under 5 minutes or so likely shouldn’t count, but only culled the ones that were one minute long.
I also filtered out 258 rides with an “invalid return” station. This could be any number of things, but since finding nominal distance for these rides is very difficult, I filtered these out as well.
With the above, I arrived at an estimate of 372,684 B-cycle rides in 2014.
Distance Traveled
As mentioned in bullet #3 in the Data Acquisition section, I used a Google Maps API in the ggmap
package to derive the between-station distance for each station pair and then for each ride. Because a large number of rides were returning to the same kiosk, meaning the minimum distance ridden cannot be estimated by Google Maps, I estimated the distance ridden by calculating the average speed of all the other rides (nominal distance ridden divided by the duration), and then applying this average speed to the same-kiosk trip durations, capping the trips at an arbitrary 5 miles. While it’s likely I am underestimating the total distance ridden by a fair amount (perhaps 25%), since many riders will not take the straight-line distance between two stations (especially tourists/non-commuters), I estimate riders rode at least 616,960 miles on B-cycle in 2014, with a more likely number 25% higher at 771,200 miles.
Most Popular and Least Popular Kiosks
Most Popular
The following ten kiosks are the most popular kiosks by number of total bike checkouts in 2014. The return kiosk popularity is very similar.
Least Popular
The following ten kiosks are the least popular kiosks by number of total bike checkouts in 2014.
Map of Station Popularity
I used the ggmap
package to create the following map showing the popularity of the various checkout kiosks (Figure 2). The size of the circle is proportional to the number of checkouts from that kiosk in 2014.
Checkouts Per Membership Type
B-cycle has a number of different membership passes. The following were the top 5 by number of checkouts in 2014.
Ridership by Calendar and Clock Variables
Ridership by Hour
To dive a little deeper into the data, I aggregated the data by taking the total number of bike checkouts for each hour of the year. All checkouts in a given hour were assigned to that specific hour (i.e. a checkout at 6:02 AM and a checkout at 6:56 AM both count as a checkout in the 6 AM hour).
I then totaled the number of checkouts in a given hour of the day – summing up over the entire year (so the 10 AM sum is the total number of riders checking out a bike in the 10 AM hour for the 365 days in 2014). Figure 3 below shows the total number of bike checkouts for each hour of the day, and Figure 4 shows the estimated distance ridden given the hour of checkout.
These figures show that most bike checkouts occur during the 4 PM and 5 PM hours, likely for the evening commute; however, people are more likely to ride a longer distance during the middle of the day – this may have more to do with the “tourist factor.”
Ridership by Hour and Weekday
I also looked to see if the above patterns held true each day of the week, or if the patterns were perhaps different on the weekend. Indeed, as Figure 5 below shows, the weekday patterns (days 2-6) are all fairly similar; the weekend patterns show a significantly different shape, with usage peaks occuring between 1 PM and 3 PM.
Ridership by Month
Another calendar factor I explored was the number of checkouts by month. Unsurprisingly, as Figure 6 shows, most bike checkouts occur during the summer months of June through August, and the fewest checkouts occur during the winter.
Merging with Weather
After looking at ridership as it relates to calendar and clock variables, I merged the data with hourly historical weather data. My hypothesis, based on observations of bicycle riding around Denver, is that in addition to ridership being affected by the time of day, ridership is also affected by the weather. We would likely expect more riders on warmer days (the monthly ridership statistics may be a proxy for this).
Checkouts vs. Temperature
One variable I plotted is the number of bike checkouts versus the temperature (Figure 7 below). I noted that the relationship between numbers of riders and temperature appeared to follow curve, rather than just a straight line. I fit a loess curve in ggplot
to visualize the curve; based on this, in my linear regression in the next section, I used temperature and temperature squared for my linear model fit.
In my linear model, I also considered humidity levels and cloud cover levels.
Days with Highest/Lowest Ridership
I also found the 10 days with the highest total number of rides, as well as the 10 days with the fewest number of rides. See tables below. Unsurprisingly, the days with highest ridership were mostly warm (but not overly hot) weekend days, and the days with the least ridership were cold weekend days. One reason for this effect may be that people who commute to/from work via B-cycle may be less affected by the weather in their decision to ride, while the “weekend warriors” who rent the B-cycles for pleasure are highly affected by the weather in their decision to ride.
Highest Ridership Days
Lowest Ridership Days
Linear Model
My final task in this short study was to attempt to create a linear regression model using a number of calendar variables and weather variables.
Setting Up Input Variables
To create this model, I forced the calendar variables to be “factor” variables. For example, it makes little sense to treat the months as actual integers – the integers denoting the months are stand-ins for the months’ names. Similarly, because peoples’ schedules do not follow a linear trajectory throughout the day, despite the increasing hours (the activity levels are more sinusoidal), it makes more sense to treat hour variables as individual factors. Likewise for weekday factors. I also have holiday factors – either 1 for holiday or 0 for not a holiday.
For the weather variables, I have temperature and temperature squared, since the ridership vs. temperature is not a straight linear relationship. I also used humidity (values between 0 and 1.0), and cloud cover (values between 0 and 1.0).
Model Output
Using the above inputs, I created a linear model. A summary of the linear fit shows the following output. An interpretation follows in the next section.
Model Findings
I have a few intepretations of the above model:
- The R-squared statistic of 0.7382 means that approximately 73.8% of the variation in the hourly ridership can be explained by the chosen variables and model.
- The residual standard error of 23.78 means that, for each hour, about 2/3 of the time the model will predict total system ridership within plus or minus 23.78 riders.
- Most of the calendar variables are highly significant predictors:
- All of the hours of the day from 5 AM onward are significant.
- All days of the week are significant predictors.
- Roughly half of the months are significant predictors.
- Holidays are weakly significant predictors. This isn’t surprising, since holidays aren’t one typical unit. For instance, there may be lower ridership on “family holidays” such as Christmas and Thanksgiving than there are for holidays where people are more out-and-about, such as July 4th and Memorial Day, no matter the weather conditions.
- Some weather variables are significant, others are not:
- Temperature and temperature squared are both highly significant predictors.
- Humidity is not a significant predictor of ridership.
- Proportion of cloud cover appears to be a signifant predictor, with a negative slope. That is, a fully cloudy day will have, on average, 4 few riders per hour than an otherwise identical day that is fully sunny.
Summary
Based on my short study of 2014 Denver B-cycle trip data, I found that we can create a linear model of trip ridership based on several calendar and clock variables merged with basic weather data. My study focused on total system ridership, on an hourly basis, rather than modeling specific checkout or return kiosks. Most calendar variables are highly significant when predicting ridership, and weather variables such as temperature and amount of cloud cover appear to be as well. Based on R-squared, approximately 73.8% of the variation in hourly ridership can be explained by the simple model.
Additional Areas of Study
I have many more ideas of ways that we could study this data, which I did not have time for in this particular project. The following are some of these ideas:
- Graph analysis – Which checkout/return kiosk routes most heavily used
- Kiosk predictive analytics – How to optimize the distribution of bikes at kiosks to make sure there are enough?
- Find a better method of predicting distances ridden.
- Trend analysis of ridership over more years than just 2014 – how is the program growing, and can we predict its growth in the near future?
- Break down hourly data into 15-minute increments for finer-grain resolution of ridership data – do we see a spike just before or just after the top of the hour during commuting times?
- Use autoregressive weather variables (like “lagged” temperature variables). Perhaps people may be less likely to use a B-cycle today if yesterday was very cold (even if today’s a bit warmer – but perhaps the opposite is true!).
- Model “interactions” between variables in the linear model. As it is, the variables are being modeled individually; however, there are likely significant interactions between variables that we should model (for instance, 75 degrees at 10 AM is different than 75 degrees at 9 PM with respect to ridership).
- Actually use some machine learning techniques to see if we can produce better predictions than the linear model, and test with training/validation/testing sets. I believe that if we tested some decision-tree methods (such as random forests or gbms), that we could likely get much higher predictive power than the linear model can give us.
About this Project, Source Code
I originally completed this project in August 2015 as my final project for University of Washington’s Methods for Data Analysis class, course #2 of 3 in the Data Science Certificate program. This blog post has only been slightly modified from my assignment submission. Source code for the analysis, in addition to other project files and data, can be found in my denver_bcycle repo on GitHub.