-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChinooks.R
60 lines (48 loc) · 1.76 KB
/
Chinooks.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
###################################
#
# Are Chinooks more common now (in Calgary)?
#
###################################
# M Chernos December 2015
library('dplyr')
library('lubridate')
library('ggplot2')
# Function to convert factors to numeric
f2n = function(x){as.numeric(as.character(x))}
# Read the data
yyc = read.csv('calgary_intl1.csv')
# Daily difference
yyc$Tdiff = c(NA, diff(f2n(yyc$maxT),1) )
# Chinook defined as:
mT = 5 # Daily maxT > 0
mnts = c(11,12,1,2,3) # - Nov - March
tdif = 5 # - Tdiff > 5 C
chinooks = yyc %>%
filter(Month %in% mnts & f2n(maxT) > mT & Tdiff > tdif) %>%
group_by(Year) %>%
summarize(Chinook_Days = length(Tdiff))
ggplot(data = chinooks, aes(x = Year, y = Chinook_Days)) +
geom_line(color = 'grey30') +
stat_smooth(data = subset(chinooks, Year > 1959), method = 'lm', color = 'red') +
stat_smooth(data = subset(chinooks, Year < 1960), method = 'lm', color = 'darkgreen') +
stat_smooth(se = F) +
theme_bw() +
labs(x = '', y = 'Chinook Days',
title = paste('T Diff =', tdif ,'C, Daily Max T =', mT,'C'))
# Check Significance of post-1960 linear regressions
summary(lm(data = subset(chinooks, Year > 1959), formula = Year~Chinook_Days))
summary(lm(data = subset(chinooks, Year > 1939), formula = Year~Chinook_Days))
# Mann-Kendall Tests
library('Kendall')
MannKendall(chinooks$Chinook_Days)
MannKendall(chinooks$Chinook_Days[chinooks$Year<1960])
MannKendall(chinooks$Chinook_Days[chinooks$Year>1959])
# test 10 year periods:
minyear = seq(1910,1990,10)
pval = c()
tau = c()
for (i in 1:length(minyear)){
pval[i] = MannKendall(chinooks$Chinook_Days[chinooks$Year>minyear[i]])$sl
tau[i] = MannKendall(chinooks$Chinook_Days[chinooks$Year>minyear[i]])$tau
}
data.frame(minyear, tau, pval)