Global Warming (Temperature Deviations)

Jian Shun | Sep 19, 2022

Climate change and temperature anomalies

In this example, we draw upon data from the Combined Land-Surface Air and Sea-Surface Water Temperature Anomalies in the Northern Hemisphere at NASA’s Goddard Institute for Space Studies.

For this study, I use the base period of 1951-1980, as stipulated by NASA - this is the reference period from which we define temperature anomalies.

weather <- 
  read_csv("https://data.giss.nasa.gov/gistemp/tabledata_v4/NH.Ts+dSST.csv", 
           skip = 1, 
           na = "***")

Data Manipulation

# Create tidyweather data
tidyweather <- weather %>% 
  select(-c("J-D", "D-N", "DJF", "JJA", "MAM", "SON")) %>% 
  pivot_longer(cols = -Year, names_to = "month", values_to = "delta")

Plotting scatterplot of anomalies and trendline

# Set date format tidyweather data
tidyweather <- tidyweather %>%
  mutate(date = ymd(paste(as.character(Year), month, "1")),
         month = month(date, label=TRUE),
         year = year(date))

# Plot weather anomalies
ggplot(tidyweather, aes(x=date, y = delta))+
  geom_point()+
  geom_smooth(color="red") +
  theme_bw() +
  labs (
    title = "Weather Anomalies"
  )

Observation:

The effect of increasing temperature is more pronounced in the winter months - starting from the end of fall until the start of spring. We see this from the higher values within the winter months over the other months across time. This reflects the effects of global warming/climate change throughout the last decade.

Creating time intervals

I now create time intervals 30 years apart to make comparisons across time.

# Assign periods
comparison <- tidyweather %>% 
  filter(Year>= 1881) %>%     #remove years prior to 1881
  #create new variable 'interval', and assign values based on criteria below:
  mutate(interval = case_when(
    Year %in% c(1881:1920) ~ "1881-1920",
    Year %in% c(1921:1950) ~ "1921-1950",
    Year %in% c(1951:1980) ~ "1951-1980",
    Year %in% c(1981:2010) ~ "1981-2010",
    TRUE ~ "2011-present"
  ))

Plot density plots of temperature anomalies visualised across intervals

# Create density plot of monthly deviation based off each interval period
ggplot(comparison, aes(delta, fill = interval, alpha = 0.1)) +
  geom_density() +
  labs(title = "Denisty plots of monthly deviations", subtitle = "Separated by Intervals", x = "Delta", y = "Density") +
  theme(plot.title = element_text(size = 14, hjust = 0.5),
        plot.subtitle = element_text(size = 12, hjust = 0.5),
        axis.title = element_text(size = 12),
        axis.text = element_text(size = 10)
)

Observation:

From 1881 until 1980, we did not observe huge anomalies in terms of temperature delta from the base period (1951-1980). However, this was not reflected past 1980; temperatures began rising more drastically from 1981-present. More strikingly, the average delta for the last period is around 0.5 higher than that of the previous period (1981-2010). This hints at even higher average deviations in future that come faster unless a downward pressure is exerted on temperature increases through climate change measures.

Average temperature anomaly analysis

# Create yearly averages
average_annual_anomaly <- comparison %>%
  group_by(Year) %>% 
  summarise(mean_delta_year = mean(delta))

# plot mean annual delta across years:
ggplot(average_annual_anomaly, aes(x = Year, y= mean_delta_year)) +
  geom_point() +
  geom_smooth(colour = "red", method = "loess") +
  theme_bw() +
  labs (
    title = "Yearly Weather Anomalies",
    y = "Mean annual delta"
  )

#Fit the best fit line, using LOESS method
#change theme to theme_bw() to have white background + black frame around plot

Observation:

Like what we were hinting at earlier, the yearly anomalies over the past 4 decades (starting from 1980) have followed a relatively exponential upward trend. During the 1980s, the average yearly delta was between 0 and 0.5 whereas this average has climbed past 1.5 in the most recent years. This increase of 1 degree overall has not been witnessed in the century prior to 1980, thus emphasising the magnitude of the rapidly worsening global warming phenomenon.

Creating Confidence Intervals for temperature anomalies

Here, I calculate a 95% confidence interval for temperature anomalies within the time period from 2011 to present.

# Formula method of CI calculation
formula_ci <- comparison %>%
  filter(interval == "2011-present") %>%
  drop_na() %>% 
  summarise(mean_delta = mean(delta),
                     sd_delta = sd(delta),
                     count = n(),
                     t_critical = qt(0.975, count-1),
                     se_delta = sd_delta / sqrt(count),
                     margin_of_error = t_critical * se_delta,
                     delta_low  = mean_delta - margin_of_error,
                     delta_high  = mean_delta + margin_of_error
            )
# Print out formula_CI
formula_ci
## # A tibble: 1 × 8
##   mean_delta sd_delta count t_critical se_delta margin_of_error delta_…¹ delta…²
##        <dbl>    <dbl> <int>      <dbl>    <dbl>           <dbl>    <dbl>   <dbl>
## 1       1.07    0.266   139       1.98   0.0226          0.0446     1.02    1.11
## # … with abbreviated variable names ¹​delta_low, ²​delta_high
library(infer)
# Bootstrap method of CI calculation using Infer package
infer_bootstrap_ci <- comparison %>%
  filter(interval == "2011-present") %>%
  specify(response = delta) %>%
  generate(reps = 1000,  type = "bootstrap") %>% 
  calculate(stat = "mean", na.rm = TRUE) %>% 
  get_confidence_interval(level = .95)
# Print out bootstrap CI using Infer package
infer_bootstrap_ci
## # A tibble: 1 × 2
##   lower_ci upper_ci
##      <dbl>    <dbl>
## 1     1.02     1.11

Analysis:

The results give an interesting insight into the sea and land temperature differences during the 2011 - present time interval. The mean of the temperature delta is around 1.06 degrees. By means of a confidence interval calculation we can state with 95% certainty that the mean temperature delta is between 1.02 and 1.11 degrees for this time period. As there is no underlying distribution, we used the t-statistics and a degrees of freedom of n-1 to calculate the critical values required for a confidence interval calculation. We confirmed this estimate by using a bootstrapping method that manually created the confidence intervals and provided a lower bound of 1.02 degrees and a upper bound of 1.11 degrees.

comments powered by Disqus