Predicting Storms in 1794
Contributed by Michael Winfield. Michael is currently in the NYC Data Science Academy 12-week full time Data Science Bootcamp program taking place between April 11th to July 1st, 2016. This post is based on his second class project – building a Shiny App in R.
Click on images to enlarge.
The CLIWOC Dataset: Weather and Location Measurements from 1750-1850
The CLIWOC Dataset consists of 18th-19th century ship logs from European ships traveling around the world. Those ship logs – of course, organized by date – contain longitude and latitude measurements for a particular ship on a given date with corresponding temperature measurements and weather conditions. The dataset entries are in multiple languages and there is a fair amount of corruption (missing data), particularly in earlier years in the century’s worth of data.
To deal with the data corruption, I tried multiple approaches before I realized that the missing data was Missing Completely At Random. I had missing temperature measurements and missing positional data. With respect to missing temperature measurements, (a) I tried mean imputation, but, as one can imagine, that skewed the temperature readings; (b) next, I tried random imputation, but that resulted in temperature readings that make no sense for their time frame and geographic location; and, last, (c) I simply omitted the observations lacking temperature measurements, given that out of over 200,000 observations, this left me with over 50,000. With respect to missing positional data, I tried both random and mean imputation, but, as one can imagine, the random imputation created ship positions on land masses and the mean imputation clustered values in the most traveled ship lanes, thus obscuring the actual patterns in the dataset! I again opted for omitting corrupted observations, as this left me with over 50,000 observations, and the missing data was missing completely at random.
After dealing with the missing data issues, I took a step back and thought about my goal for my second project. For my second project, I wanted to create an interactive way of visualizing the location of occurrences of rain, storms, and fog. Looking at the dataset, I wondered: What is the most user friendly way to conceptualize ancient century ship logs recording position (longitude and latitude) and related records of weather and temperature? My first idea was to code an interactive map.
An interactive map, I reasoned, would:
- Allow the user to eyeball the geographic distribution of each type of weather condition, across a century’s worth of time.
- Determine quickly by selecting between drop-down items whether the geographic clustering of the positions of the weather events over a century’s worth of time was similar or different.
- Zoom in on and identify a particular weather event of a particular type and acquire knowledge of its corresponding temperature and date (for example, to learn that some of the storms have high temperatures and thus are tropical storms).
Beyond building that interactive feature, I also wanted to investigate temperature measurements in the dataset with greater focus. The questions I had were:
- How does temperature vary over the dataset?
Given that I had already taken care of data corruption, the graphs likely indicate a smaller number of ships taking temperature readings earlier in time. The variation in the range of temperatures observed likely indicates different ship travel patterns (e.g., different months of departure), and there is very little variation in the range of temperatures observed on a month-to-month basis.
This is likely a result of ships travelling from high temperature areas to high temperature areas.
- Where do particular temperature measurements cluster in this dataset?
The highest temperature observations cluster around the 0 in Latitude (the Equator) and 0, 50, and 100 for Longitude (all of which bisect population dense areas – North America, South America, Africa, and Europe).
- How does average temperature in this dataset vary with the various weather conditions on a month-to-month basis?
To answer this question, I built an animated slider barplot that plots average temperature readings in a given month over every year in 1750-1850 against the total occurrences of rain, storms, and fog in that month over all years. Through a quick 30-second animation, this portion of the app visually demonstrates that across a century’s worth of data, the amount of rain, fog, and storms varies on a month-to-month basis greatly, but average temperatures from month-to-month do not. The weather condition that varies the most on a monthly basis is rain.
Predicting 18th-Century Weather Conditions
Lastly, I wanted to test out logistic regressions for rain, storms, and fog to see if I could predict the occurrence of a given type of weather event based on this ancient dataset. I used David Roberts’ method of calculating the AUC in R, via use of the ROCR library.
Above is the code for the logistic regressions I conducted for the occurrence of a storm, rain, and fog, and below are their respective AUC calculations, all of which are above .5, meaning my models perform better than randomness (or a coin toss).