Questions About Weather

Harold Nelson

2/19/2022

Setup

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.5     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.4     ✓ stringr 1.4.0
## ✓ readr   2.0.2     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
load("oly_airport.Rdata")

Question 1

Are we experiencing a drought during the months of May through August? Try it yourself before you look at my solution.m

Answer

I did it by looking at a time-series of z-scores instead of raw data. If I saw recent numbers below -3, I’d know something was going on.

I also did a histogram of the raw data.

rain_5_8 = oly_airport %>% 
  select(DATE,PRCP) %>% 
  mutate(mo = month(DATE),
         yr = year(DATE) )%>% 
  filter(mo >= 5 & mo <= 8) %>% 
  group_by(yr) %>% 
  summarize(rain = sum(PRCP)) %>% 
  ungroup() %>% 
  mutate(mrain = mean(rain),
         sdrain  = sd(rain),
         z_score = (rain - mean(rain))/sdrain) 

head(rain_5_8)
## # A tibble: 6 × 5
##      yr  rain mrain sdrain z_score
##   <dbl> <dbl> <dbl>  <dbl>   <dbl>
## 1  1941  5.86  5.36   2.03   0.245
## 2  1942  5.61  5.36   2.03   0.122
## 3  1943  4.87  5.36   2.03  -0.243
## 4  1944  2.29  5.36   2.03  -1.52 
## 5  1945  3.65  5.36   2.03  -0.845
## 6  1946  5.81  5.36   2.03   0.221
rain_5_8 %>% 
  ggplot(aes(x = yr, y = z_score)) +
      geom_point() +
      geom_line(size = .1) 

The lowest z-score was actually in 2018, but it was only -2, no indication of drought. The two most recent years, 20 and 21, have z-scores near zero.

Here’s the histogram.

rain_5_8 %>% 
  ggplot(aes(x = rain)) +
      geom_histogram( )
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Question 2

How many perfect days do we get in a year? The suggestion was that a perfect day would have a maximum temperature of 75 and would have no rain. Try to answer this question yourself before you look at my solution.

Answer

Here is some code to get the counts of perfect days in a year.

oly_airport %>% 
  filter(TMAX == 75 & PRCP == 0) %>% 
  group_by(yr) %>% 
  summarize(count = n()) %>% 
  filter(count > 0) %>% 
  ungroup() %>% 
  ggplot(aes(x = factor(count))) + 
  geom_bar()

The most commmon year count is six. There have been years with only one.

Curiosity

I got curious about which months have perfect days. I suspect they happen mostly in July and August. Try to do this yourself before you look at my solution.

Answer

Here’s the code.

oly_airport %>% 
  filter(TMAX == 75 & PRCP == 0) %>% 
  ggplot(aes(x = mo)) + 
  geom_bar()

August has more perfect days than any other month, with July coming in as a close second. June and September are very similar.