Weather Anomaly Detection in R

April 25, 2015 No Comments detection

weather anomalies in Los Angeles

Our weather follows typical patterns over the course of a year: in most places, it is cold in the winter and hot in the summer. Based on historical records we can detect unusual weather.

Requirements

As is often required for statistical tasks, th R programming language need to be installed, as well as two packages:

Open your R console to install both packages.

Download Weather Data

Let’s download the weather dta from 2001 to 2014 recorded at LAX airport and BUR airport. These two airports are located 20 km (12 miles) from each other in Los Angeles, California.

Here we download, clean and save as a CSV file both airport weather records.

Sometimes values are missing. So we “cheat” using the lowest and highest temperature of the day, or the average of the previous day. This is a debatable solution but good enough for this test.

Merge Weather Data

Merging the histories means we only keep the records available at both airports.

Then we once again clean the data:

  • Removing “NA” values
  • Applying a moving average for smoothing

Unusual Weather at Los Angeles Airport

weather anomaly

Each slice of the graph shows a year.

As expected, the weather follows a yearly trend. It is usually cold in winter and hot in summer. But two anomalies didn’t follow this pattern:

  • In early winter 2008 the weather was 20°C instead of 15°C on average
  • In Q2 2014 the temperature reached 25°C instead of the typical 20°C

Normal Weather at BUR Airport

usual weather

This shows the weather records at Burbank Bob Hope Airport.

No anomalies were detected at this airport. The Twitter package also didn’t produce a graph showing any. So we draw it using the “plot” function.

Correlation Anomaly

diff-weather-anomaly

This is the temperature difference between the Los Angeles and Burbank airports.

Beginning in 2013, a difference of 5°C was recorded between both the airports. A 5°C difference is typical in the summer but not in the winter!

Monitor & detect anomalies with Anomaly.io

SIGN UP
help with term papers