Skip to content

Commit 75874cd

Browse files
author
Ellen Considine
committed
finished making table for rebuttal
1 parent 2fc7f83 commit 75874cd

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

heat_alerts/scripts/Rebuttal_code.R

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ sink()
6565

6666
## Summarize results:
6767

68+
WMW<- function(x, y){ #rl, nws
69+
wmw<- wilcox.test(x, y, paired = TRUE, alternative = "greater", exact=FALSE)
70+
metrics<- as.vector(c(round(median(x - y, na.rm=TRUE),3),
71+
wmw$statistic, round(wmw$p.value,5)))
72+
return(metrics)
73+
}
74+
75+
6876
results<- matrix(0, nrow=nrow(Best), ncol=2)
6977
results<- data.frame(results)
7078
names(results)<- c("County", "Eval")
@@ -77,15 +85,51 @@ for(i in 1:nrow(Best)){
7785
"_fips-", Best$County[i], "_fips_", Best$County[i], ".csv")))
7886
}
7987

88+
nws<- matrix(0, nrow=nrow(Best), ncol=2)
89+
nws<- data.frame(nws)
90+
names(nws)<- c("County", "Eval")
91+
92+
for(i in 1:nrow(Best)){
93+
nws[i,]<- c(Best$County[i],
94+
avg_return(by_year=FALSE, filename=paste0("Summer_results/ORL_NWS_eval_samp-R_obs-W_", prefix,
95+
"_fips_", Best$County[i], ".csv")))
96+
}
97+
98+
overall_2014.2016<- WMW(results$Eval, nws$Eval)
99+
100+
101+
results<- matrix(0, nrow=nrow(Best), ncol=2)
102+
results<- data.frame(results)
103+
names(results)<- c("County", "Eval")
104+
105+
for(i in 1:nrow(Best)){
106+
results[i,]<- c(Best$County[i],
107+
avg_return(by_year=FALSE, filename=paste0("Summer_results/ORL_RL_eval_samp-R_obs-W_", "December", "_",
108+
"a2c", "_F-", "none", "_Rstr-HI-", Best$OT[i],
109+
"_arch-", Best$NHL[i], "-", Best$NHU[i], "_ns-", Best$n_steps[i],
110+
"_fips-", Best$County[i], "_fips_", Best$County[i], ".csv")))
111+
}
112+
113+
nws<- matrix(0, nrow=nrow(Best), ncol=2)
114+
nws<- data.frame(nws)
115+
names(nws)<- c("County", "Eval")
80116

117+
for(i in 1:nrow(Best)){
118+
nws[i,]<- c(Best$County[i],
119+
avg_return(by_year=FALSE, filename=paste0("Summer_results/ORL_NWS_eval_samp-R_obs-W_", r_model,
120+
"_fips_", Best$County[i], ".csv")))
121+
}
81122

123+
overall_original<- WMW(results$Eval, nws$Eval)
82124

83125
## First examine distribution of heat index across years
84126

85127
data<- read_parquet("data/processed/states.parquet")
86128
Year<- year(data$Date)
87129

88130
Data<- data.frame(Year, QHI = data$quant_HI_county)
131+
QHI_medians<- aggregate(QHI ~ Year, Data, median)
132+
89133
ggplot(Data, aes(x = as.factor(Year), y = QHI, group=Year)) +
90134
geom_boxplot() +
91135
labs(x = "Year", y = "Quantile of Heat Index") +
@@ -115,6 +159,54 @@ for(i in 1:nrow(Best)){
115159
"_fips_", Best$County[i], ".csv")))
116160
}
117161

162+
wmw_2007<- WMW(results[,2], nws[,2])
163+
wmw_2011<- WMW(results[,3], nws[,3])
164+
wmw_2015<- WMW(results[,4], nws[,4])
165+
166+
## Across the later years:
167+
results<- matrix(0, nrow=nrow(Best), ncol=4)
168+
results<- data.frame(results)
169+
names(results)<- c("County", "2014", "2015", "2016")
170+
171+
for(i in 1:nrow(Best)){
172+
results[i,]<- c(Best$County[i],
173+
avg_return(by_year=TRUE, filename=paste0("Summer_results/ORL_RL_eval_samp-R_obs-W_", prefix, "_",
174+
"a2c", "_F-", "none", "_Rstr-HI-", Best$OT[i],
175+
"_arch-", Best$NHL[i], "-", Best$NHU[i], "_ns-", Best$n_steps[i],
176+
"_fips-", Best$County[i], "_fips_", Best$County[i], ".csv")))
177+
}
178+
179+
nws<- matrix(0, nrow=nrow(Best), ncol=4)
180+
nws<- data.frame(results)
181+
names(nws)<- c("County", "2014", "2015", "2016")
182+
183+
for(i in 1:nrow(Best)){
184+
nws[i,]<- c(Best$County[i],
185+
avg_return(by_year=TRUE, filename=paste0("Summer_results/ORL_NWS_eval_samp-R_obs-W_", prefix,
186+
"_fips_", Best$County[i], ".csv")))
187+
}
188+
189+
wmw_2014<- WMW(results[,2], nws[,2])
190+
wmw_2015_b<- WMW(results[,3], nws[,3])
191+
wmw_2016<- WMW(results[,4], nws[,4])
192+
193+
## Summarize in a table:
194+
DF<- data.frame(cbind(Model=c("Original", rep("", 3),
195+
"Sequential", rep("", 3)),
196+
Eval_year=c("2007,2011,2015", "2007", "2011", "2015",
197+
"2014-2016", "2014", "2015", "2016"),
198+
rbind(overall_original,
199+
wmw_2007, wmw_2011, wmw_2015,
200+
overall_2014.2016,
201+
wmw_2014, wmw_2015_b, wmw_2016
202+
)))
203+
row.names(DF)<- NULL
204+
DF$QHI_median<- c("",round(QHI_medians[c(2,6,10),2],3), "", round(QHI_medians[9:11,2],3))
205+
206+
names(DF)<- c("Model", "Eval. Period", "Median Diff.", "WMW stat", "p-value", "QHI Median")
207+
DF<- DF[,c("Model", "Eval. Period", "QHI Median", "Median Diff.", "p-value")]
208+
DF$`p-value`<- round(as.numeric(DF$`p-value`), 3)
209+
DF
118210

119211
## Reshape data to long format
120212
results_long<- results[,2:4] %>%

0 commit comments

Comments
 (0)