Climate Change by US State

In this post I’m going to take a look at some data from Berkeley Earth that I obtained from this page on kaggle.com. It’s important to understand the content of these files: Berkeley Earth has produced time series of monthly average temperatures over long periods of time for various land surface locations around the globe. They use a technique called kriging that allows them to combine data from multiple nearby sites to produce more accurate estimates of the actual temperature over time at a given location. The important point is that these adjusted temperatures do not necessarily correspond to measured temperatures at any particular location. The statistical procedure they use is intended to correct for the numerous factors that affect the accuracy of site temperature measurements: urban heat island effects, and changes in weather station location, instrumentation, time of day at which temperatures are measured, etc. A more complete discussion of this topic can be found here.

Ciudad de Guatemala

I realize that the temperature history of a single location says little about climate change on a global scale, but it was interesting nevertheless to see that one of the available files contains monthly temperature data for Guatemala City going all the way back to 1836. My wife grew up in that city, and we visit there often. They call Guatemala the Land of Eternal Spring, but people say the climate is changing. Is it?  Here’s some code:

require(tidyverse)
require(lubridate)
setwd("C:/Users/.../Dropbox/Projects/T_history")
monLen <- c(31,28,31,30,31,30,31,31,30,31,30,31)
alldata <- read_csv("GlobalLandTemperaturesByCity.csv")
mycity <- alldata %>%
  filter(City == "Guatemala",!is.na(AverageTemperature))
annual <- mycity %>% group_by(yr=year(dt)) %>%
  summarise(number=n(),
     av=ifelse(number==12,
     1.8*weighted.mean(AverageTemperature,monLen)+32,NA)) %>%
  filter(!is.na(av))

This is a pretty simple script. I read in the data, filter on Guatemala, and group by year. For those years that contain data for all 12 months, I take a weighted average of the monthly temperatures to get an annual mean. This could be improved slightly by adding an additional day in February for leap years, but I don’t think that will change much. As textbook writers are fond of saying, “this is left as an exercise for the interested reader”.

Producing a plot of temperature over time is a straightforward application of ggplot:

ggplot(annual,aes(x=yr,y=av)) +
  geom_point() + geom_smooth() +
  labs(title="Temperature History of Guatemala City, Guatemala",x="Year",
       y= expression("Annual Mean Temperature " ( degree*F)))

Here is how it looks. The blue line is a non-parametric curve fit to the data produced by loess:

Evidently, Guatemala City’s annual mean temperature fluctuates quite a bit, but there has been a definite upward trend over the past 150 years. Looking at just what has occurred since 1900, it appears that the mean temperature has gone up by about 1.8 degrees Fahrenheit. That isn’t a lot, but could be enough to alter the growing cycle of certain crops. To get a more complete picture of climate change one would also have to look at rainfall and perhaps other variables.

US States

My next objective was to produce a map of US States shaded by the rise in annual mean temperature each one has experienced over time. The file GlobalLandTemperaturesByState.csv from Berkeley Earth contains mean monthly temperatures for all 50 US States and the District of Columbia, in some cases going back to the mid-1700s. I found that after 1901, all 12 months were available for each State, so I used 1901 as the baseline. Here is the code:

library(ggmap)
library(maps)
library(mapdata)

delT <- function(tSeries) {
  ySer <- 1901:2012
  smoothie <- loess(tSeries ~ ySer)
  newT <- predict(smoothie,data.frame(ySer=c(1901,2012)),se=FALSE)
  degC <- newT[2] - newT[1]
  return(1.8*degC)
}

states <- read_csv("GlobalLandTemperaturesByState.csv") %>%
  mutate(yr = year(dt)) %>%
  filter(Country == "United States",yr >=1901,
         yr<2013,State != "Alaska",State != "Hawaii",          State != "District Of Columbia") %>%
  mutate(State = replace(State,State == "Georgia (State)","Georgia"))

sumdat <- states %>% group_by(State,yr) %>%
  summarise(av=weighted.mean(AverageTemperature,monLen))

tRise <- sumdat %>% group_by(State) %>% summarise(increase = delT(av)) %>%
  rename(region=State) %>%
  mutate(region = tolower(region))

Most of this script is concerned with cleaning and preparing the data. That begins on line 13. First, it turns out that the file contains data for individual States of other countries, so I select (line 15) only the data from the United States, and only data between 1901 and 2012 (2013 is not complete in this set). Then I remove Alaska, Hawaii and the District of Columbia because I’m only interested in a map of the lower 48. Perhaps to differentiate it from the former Soviet Republic, the state of Georgia is coded as “Georgia (State)”, so that had to be changed as well (line 18).

With clean data, I generated (lines 19-20) another data frame called sumdat, which contains the weighted mean for each State and each year. One way to obtain the increase in annual mean temperature for each State would be to simply subtract the mean for 1901 from the mean for 2012. But as is evident from the plot for Guatemala City, there is a great deal of annual variation in mean temperature. Therefore to calculate the rise over the period, I used the loess function to develop a non-parametric curve fit, and then subtracted the prediction for 1901 from the prediction for 2012. This is what the function delT does in lines 5-11. The data frame tRise then contains the estimated temperature rise from 1901-2012 for each State. One last tweak (line 24) was to make the names of all the States lowercase, as required by ggmap. Then to generate the figure I used the following:

us <- map_data("state")
gg <- ggplot() +
  geom_map(data=us, map=us,
           aes(x=long, y=lat, map_id=region),
           fill="#ffffff", color="#ffffff", size=0.15) +
  geom_map(data=tRise, map=us,
           aes(fill=increase, map_id=region),
           color="#ffffff", size=0.15) +
  scale_fill_continuous(low='thistle2', high='darkred',
           guide='colorbar') +
  coord_map("albers", lat0 = 39, lat1 = 45) +
  theme(panel.border = element_blank()) +
  theme(panel.background = element_blank()) +
  theme(axis.ticks = element_blank()) +
  theme(axis.text = element_blank()) +
  labs(x=NULL,y=NULL,
       title = expression("Increase in Statewide Mean Annual Temperature (1901-2013) " ( degree*F)))
gg

This produces the following figure:
The figure shows that annual mean temperature has risen more quickly in northern states than in southern ones.

2 thoughts on “Climate Change by US State

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s