Quantcast
Viewing all articles
Browse latest Browse all 1015

Does weather cause accidents – part 1

By Adventures in Data

Scotland and other parts of the UK have some nicely curated open data on road traffic accidents. For individual cases, where and when they happened, how severe they were, the prevailing road conditions, which emergency services were involved and so on. It felt to me like this should be a very valuable resource and might help us learn about what the causes or maybe correlates of road traffic accidents are. This is partly inspired by Ben Moores work at http://blackspot.org.uk/.

One thought that sprang to mind was could we test the common belief that adverse weather conditions result in increased incidence and severity of road traffic accidents. The first part of this was to collect and blend some information on weather conditions for each crash recorded. In this blog, I will explain how I obtained / blended weather information relating to each road traffic incident.

The raw data can be found on Edinburgh City Council’s website or pinched from the github repository associated with this post, see the /data folder.

I used a very convenient service from http://forecast.io/ which I think is designed for weather app makers but I think it can be reasonably employed for small amounts of data plundering. Head to https://developer.forecast.io/ and get yourself a free API key which you will need for this. Most importantly we are using the Rforecastio package which is housed here thanks to hrbrmstr for providing it. Before starting you should install this with devtools::install_github("hrbrmstr/Rforecastio").

Now you’re ready to go fire up R and load in some libraries.

library(dplyr)
library(lubridate)
library(Rforecastio)

I had to set the scipen option to avoid an error (i’ll explain later on).

options(scipen = 100)

Next you want to read in the data and I am also going to sample 1000 rows. This is because the forecast API will let you make 1000 free API calls per …read more

Source:: r-bloggers.com


Viewing all articles
Browse latest Browse all 1015

Trending Articles