-
Notifications
You must be signed in to change notification settings - Fork 2
/
regression_bootstrap.R
227 lines (173 loc) · 8.48 KB
/
regression_bootstrap.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# Code to perform different statistical tests to analise the regression coefficients of PDI vs duration
# Author: Alfredo Hernández <[email protected]>
# Source base code -----------------------------------------
source("regression_base.R")
source("resampling_base.R")
# load("regression_analysis.RData")
# Get RAW data ---------------------------------------------
pdi.all <- as_tibble(data.table::fread('data/hurdat2-hadisst-1966-2016_pdis.csv')) %>%
mutate(storm.duration = measurements::conv_unit(storm.duration, "sec", "hr"))
pdi.natl <- pdi.all %>%
dplyr::filter(basin == "NATL")
pdi.epac <- pdi.all %>%
dplyr::filter(basin == "EPAC")
compute.flag <- F
# Load objects from disk -----------------------------------
if (!compute.flag) {
lm.coefs.list <- readRDS("objects/regression_lm_coefs_list.rds")
factors.lm.coefs.list <- readRDS("objects/regression_lm_coefs_fact_list.rds")
}
# Confidence interval for all storms -----------------------
if (compute.flag) {
# NATL
lm.coefs.natl.pdi <- summarise_lm_coefs("NATL", "storm.duration", "storm.pdi")
lm.coefs.natl.max.wind <- summarise_lm_coefs("NATL", "storm.duration", "max.wind")
lm.coefs.natl.mean.wind <- summarise_lm_coefs("NATL", "storm.duration", "mean.wind")
lm.coefs.natl.mean.sq.wind <- summarise_lm_coefs("NATL", "storm.duration", "mean.sq.wind")
# EPAC
lm.coefs.epac.pdi <- summarise_lm_coefs("EPAC", "storm.duration", "storm.pdi")
lm.coefs.epac.max.wind <- summarise_lm_coefs("EPAC", "storm.duration", "max.wind")
lm.coefs.epac.mean.wind <- summarise_lm_coefs("EPAC", "storm.duration", "mean.wind")
lm.coefs.epac.mean.sq.wind <- summarise_lm_coefs("EPAC", "storm.duration", "mean.sq.wind")
}
# Confidence interval for developing systems ---------------
if (compute.flag) {
# NATL
lm.coefs.natl.pdi.ds <- summarise_lm_coefs("NATL", "storm.duration", "storm.pdi", 33)
lm.coefs.natl.max.wind.ds <- summarise_lm_coefs("NATL", "storm.duration", "max.wind", 33)
lm.coefs.natl.mean.wind.ds <- summarise_lm_coefs("NATL", "storm.duration", "mean.wind", 33)
lm.coefs.natl.mean.sq.wind.ds <- summarise_lm_coefs("NATL", "storm.duration", "mean.sq.wind", 33)
# EPAC
lm.coefs.epac.pdi.ds <- summarise_lm_coefs("EPAC", "storm.duration", "storm.pdi", 33)
lm.coefs.epac.max.wind.ds <- summarise_lm_coefs("EPAC", "storm.duration", "max.wind", 33)
lm.coefs.epac.mean.wind.ds <- summarise_lm_coefs("EPAC", "storm.duration", "mean.wind", 33)
lm.coefs.epac.mean.sq.wind.ds <- summarise_lm_coefs("EPAC", "storm.duration", "mean.sq.wind", 33)
}
# Factors of CI --------------------------------------------
# Confidence interval for all storms -----------------------
if (compute.flag) {
# NATL
fact.natl.pdi <- summarise_lm_coefs("NATL", "storm.duration", "storm.pdi", metrics = "factor")
fact.natl.max.wind <- summarise_lm_coefs("NATL", "storm.duration", "max.wind", metrics = "factor")
fact.natl.mean.wind <- summarise_lm_coefs("NATL", "storm.duration", "mean.wind", metrics = "factor")
fact.natl.mean.sq.wind <- summarise_lm_coefs("NATL", "storm.duration", "mean.sq.wind", metrics = "factor")
# EPAC
fact.epac.pdi <- summarise_lm_coefs("EPAC", "storm.duration", "storm.pdi", metrics = "factor")
fact.epac.max.wind <- summarise_lm_coefs("EPAC", "storm.duration", "max.wind", metrics = "factor")
fact.epac.mean.wind <- summarise_lm_coefs("EPAC", "storm.duration", "mean.wind", metrics = "factor")
fact.epac.mean.sq.wind <- summarise_lm_coefs("EPAC", "storm.duration", "mean.sq.wind", metrics = "factor")
}
# Confidence interval for developing systems ---------------
if (compute.flag) {
# NATL
fact.natl.pdi.ds <- summarise_lm_coefs("NATL", "storm.duration", "storm.pdi", 33, metrics = "factor")
fact.natl.max.wind.ds <- summarise_lm_coefs("NATL", "storm.duration", "max.wind", 33, metrics = "factor")
fact.natl.mean.wind.ds <- summarise_lm_coefs("NATL", "storm.duration", "mean.wind", 33, metrics = "factor")
fact.natl.mean.sq.wind.ds <- summarise_lm_coefs("NATL", "storm.duration", "mean.sq.wind", 33, metrics = "factor")
# EPAC
fact.epac.pdi.ds <- summarise_lm_coefs("EPAC", "storm.duration", "storm.pdi", 33, metrics = "factor")
fact.epac.max.wind.ds <- summarise_lm_coefs("EPAC", "storm.duration", "max.wind", 33, metrics = "factor")
fact.epac.mean.wind.ds <- summarise_lm_coefs("EPAC", "storm.duration", "mean.wind", 33, metrics = "factor")
fact.epac.mean.sq.wind.ds <- summarise_lm_coefs("EPAC", "storm.duration", "mean.sq.wind", 33, metrics = "factor")
}
# Scatterplots (all storms) --------------------------------
# # NATL
# plot_scatterplot("NATL", "storm.duration", "storm.pdi")
# plot_scatterplot("NATL", "storm.duration", "max.wind")
# plot_scatterplot("NATL", "storm.duration", "mean.wind")
# plot_scatterplot("NATL", "storm.duration", "mean.sq.wind")
#
# # EPAC
# plot_scatterplot("EPAC", "storm.duration", "storm.pdi")
# plot_scatterplot("EPAC", "storm.duration", "max.wind")
# plot_scatterplot("EPAC", "storm.duration", "mean.wind")
# plot_scatterplot("EPAC", "storm.duration", "mean.sq.wind")
# Scatterplots (developing systems) ------------------------
# # NATL
# plot_scatterplot("NATL", "storm.duration", "storm.pdi", 33)
# plot_scatterplot("NATL", "storm.duration", "max.wind", 33)
# plot_scatterplot("NATL", "storm.duration", "mean.wind", 33)
# plot_scatterplot("NATL", "storm.duration", "mean.sq.wind", 33)
#
# # EPAC
# plot_scatterplot("EPAC", "storm.duration", "storm.pdi", 33)
# plot_scatterplot("EPAC", "storm.duration", "max.wind", 33)
# plot_scatterplot("EPAC", "storm.duration", "mean.wind", 33)
# plot_scatterplot("EPAC", "storm.duration", "mean.sq.wind", 33)
# Aggregate results ----------------------------------------
# Group data frames into a list
if (compute.flag) {
# rm(lm.coefs.list)
lm.coefs.list <- lapply(ls(patt='^lm.coefs.'), get)
# rm(factors.lm.coefs.list)
factors.lm.coefs.list <- lapply(ls(patt='^fact.'), get)
saveRDS(lm.coefs.list, "objects/regression_lm_coefs_list.rds")
saveRDS(factors.lm.coefs.list, "objects/regression_lm_coefs_fact_list.rds")
# rm(list=ls(pattern="^lm.coefs.epac"))
# rm(list=ls(pattern="^lm.coefs.natl"))
}
# NATL (all storms)
lm.coefs.list.natl <- lm.coefs.list[lapply(purrr::map(lm.coefs.list, ~dplyr::filter(.x, basin == "NATL", min.speed == 0)), nrow) > 0]
# NATL (all storms)
lm.coefs.list.epac <- lm.coefs.list[lapply(purrr::map(lm.coefs.list, ~dplyr::filter(.x, basin == "EPAC", min.speed == 0)), nrow) > 0]
# NATL (developing systems)
lm.coefs.list.natl.ds <- lm.coefs.list[lapply(purrr::map(lm.coefs.list, ~dplyr::filter(.x, basin == "NATL", min.speed == 33)), nrow) > 0]
# EPAC (developing systems)
lm.coefs.list.epac.ds <- lm.coefs.list[lapply(purrr::map(lm.coefs.list, ~dplyr::filter(.x, basin == "EPAC", min.speed == 33)), nrow) > 0]
# Summarise regression coefficients ------------------------
# NATL basin
lm.coefs.natl.pdi.ds <- lm.coefs.list.natl.ds[[4]]
cbind(lm.coefs.natl.pdi.ds[10:9], lm.coefs.natl.pdi.ds[1:2], round(lm.coefs.natl.pdi.ds[c(5,6,3,4,7,8)], 2)) %>% dplyr::arrange(metric)
# T statistics
rbind(
# PDI ~ duration OLS
get_t_statistics(
coefs.low = as.numeric(lm.coefs.list.natl.ds[[4]][1,3:7]),
coefs.high = as.numeric(lm.coefs.list.natl.ds[[4]][3,3:7])
),
# Duration ~ PDI OLS
get_t_statistics(
coefs.low = as.numeric(lm.coefs.list.natl.ds[[4]][5,3:7]),
coefs.high = as.numeric(lm.coefs.list.natl.ds[[4]][7,3:7])
)
)
rbind(
# PDI ~ duration Bootstrap
get_t_statistics(
coefs.low = as.numeric(lm.coefs.list.natl.ds[[4]][2,3:7]),
coefs.high = as.numeric(lm.coefs.list.natl.ds[[4]][4,3:7])
),
# Duration ~ PDI Bootstrap
get_t_statistics(
coefs.low = as.numeric(lm.coefs.list.natl.ds[[4]][6,3:7]),
coefs.high = as.numeric(lm.coefs.list.natl.ds[[4]][8,3:7])
)
)
# EPAC basin
lm.coefs.epac.pdi.ds <- lm.coefs.list.epac.ds[[4]]
cbind(lm.coefs.epac.pdi.ds[10:9], lm.coefs.epac.pdi.ds[1:2], round(lm.coefs.epac.pdi.ds[c(5,6,3,4,7,8)], 2)) %>% dplyr::arrange(metric)
# T statistics (EPAC)
rbind(
# PDI ~ duration OLS
get_t_statistics(
coefs.low = as.numeric(lm.coefs.list.epac.ds[[4]][1,3:7]),
coefs.high = as.numeric(lm.coefs.list.epac.ds[[4]][3,3:7])
),
# Duration ~ PDI OLS
get_t_statistics(
coefs.low = as.numeric(lm.coefs.list.epac.ds[[4]][5,3:7]),
coefs.high = as.numeric(lm.coefs.list.epac.ds[[4]][7,3:7])
)
)
rbind(
# PDI ~ duration Bootstrap
get_t_statistics(
coefs.low = as.numeric(lm.coefs.list.epac.ds[[4]][2,3:7]),
coefs.high = as.numeric(lm.coefs.list.epac.ds[[4]][4,3:7])
),
# Duration ~ PDI Bootstrap
get_t_statistics(
coefs.low = as.numeric(lm.coefs.list.epac.ds[[4]][6,3:7]),
coefs.high = as.numeric(lm.coefs.list.epac.ds[[4]][8,3:7])
)
)