-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject2.html
More file actions
811 lines (754 loc) · 64.2 KB
/
Copy pathProject2.html
File metadata and controls
811 lines (754 loc) · 64.2 KB
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<meta name="author" content="DamiÃf Valero" />
<title>Human and Economic Consequences of Atmospheric Phenomena</title>
<script src="Project2_files/jquery-1.11.0/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="Project2_files/bootstrap-3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="Project2_files/bootstrap-3.3.1/js/bootstrap.min.js"></script>
<script src="Project2_files/bootstrap-3.3.1/shim/html5shiv.min.js"></script>
<script src="Project2_files/bootstrap-3.3.1/shim/respond.min.js"></script>
<style type="text/css">code{white-space: pre;}</style>
<link rel="stylesheet"
href="Project2_files/highlight/default.css"
type="text/css" />
<script src="Project2_files/highlight/highlight.js"></script>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</style>
<script type="text/javascript">
if (window.hljs && document.readyState && document.readyState === "complete") {
window.setTimeout(function() {
hljs.initHighlighting();
}, 0);
}
</script>
</head>
<body>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
height: auto;
}
</style>
<div class="container-fluid main-container">
<div id="header">
<h1 class="title">Human and Economic Consequences of Atmospheric Phenomena</h1>
<h4 class="author"><em>DamiÃf Valero</em></h4>
<h4 class="date"><em>Tuesday, July 21, 2015</em></h4>
</div>
<div id="synopsys" class="section level2">
<h2>Synopsys</h2>
<p>This document presents the study of the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database. This database tracks characteristics of major storms and weather events in the United States, including when and where they occur, as well as estimates of any fatalities, injuries, and property damage.</p>
<p>This project focuses on identifying which types of events are most harmful with respect to population health and which types of events have the greatest economic consequences. For answering this questions, the document will be divided in two parts: Data Processing, which includes reading, cleaning and transforming the data, and Results, which consists on presenting the tables and plots to answer the questions.</p>
<p>The experiments used to answer this two questions and the code for creating them is provided in order to be fully reproducible.</p>
</div>
<div id="data-processing" class="section level2">
<h2>1. Data Processing</h2>
<div id="data-reading" class="section level3">
<h3>1.1. Data reading</h3>
<p>To start the project, the first step is to download the Storm dataset from the following <a href="https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2">link</a>. After that, the data can be imported into R using the function <em>read.csv</em> and its parameters:</p>
<pre class="r"><code># Clean the workspace
rm(list=ls())
gc()</code></pre>
<pre><code>## used (Mb) gc trigger (Mb) max used (Mb)
## Ncells 282709 15.1 407500 21.8 350000 18.7
## Vcells 502006 3.9 905753 7.0 785821 6.0</code></pre>
<pre class="r"><code>library(knitr)</code></pre>
<pre><code>## Warning: package 'knitr' was built under R version 3.1.3</code></pre>
<pre class="r"><code>library(dplyr)</code></pre>
<pre><code>##
## Attaching package: 'dplyr'
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union</code></pre>
<pre class="r"><code>library(plyr)</code></pre>
<pre><code>## -------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## -------------------------------------------------------------------------
##
## Attaching package: 'plyr'
##
## The following objects are masked from 'package:dplyr':
##
## arrange, count, desc, failwith, id, mutate, rename, summarise,
## summarize</code></pre>
<pre class="r"><code>library(ggplot2)
library(scales)
setwd("C:/Users/Damià/Desktop/Data science specialization/5.Reproducible Research/Project 2")
data <- read.csv(bzfile("repdata-data-StormData.csv.bz2","rt"),
header=TRUE, nrow=902297,
colClasses = c("numeric", "character", "character", "character","numeric",
"character","character","character","numeric","character",
"character","character","character","numeric","character",
"numeric","character","character","numeric","numeric",
"character","numeric","numeric","numeric","numeric",
"character","numeric","character","character","character",
"character","numeric","numeric","numeric","numeric",
"character","numeric"))</code></pre>
</div>
<div id="data-cleaning" class="section level3">
<h3>1.2. Data Cleaning</h3>
<p>Although this part could be really long and detailed, I consider this not the purpose of the project, and due to lack of time the cleaning part will not be complex. One of the aims is to reduce the amount of data in order to process it faster. The approach is described as follows:</p>
<ol style="list-style-type: decimal">
<li>Projection: The first strategy is to reduce the number of columns. As this project focuses on studying the human and economic effect of the athmospheric phenomenas, the next columns will be choosen for the analysis: <strong>BGN_DATE, EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP</strong>.</li>
</ol>
<pre class="r"><code>data <- data[,c("BGN_DATE", "EVTYPE", "FATALITIES", "INJURIES", "PROPDMG", "PROPDMGEXP", "CROPDMG", "CROPDMGEXP")]
#General information about the data
str(data)</code></pre>
<pre><code>## 'data.frame': 902297 obs. of 8 variables:
## $ BGN_DATE : chr "4/18/1950 0:00:00" "4/18/1950 0:00:00" "2/20/1951 0:00:00" "6/8/1951 0:00:00" ...
## $ EVTYPE : chr "TORNADO" "TORNADO" "TORNADO" "TORNADO" ...
## $ FATALITIES: num 0 0 0 0 0 0 0 0 1 0 ...
## $ INJURIES : num 15 0 2 2 2 6 1 0 14 0 ...
## $ PROPDMG : num 25 2.5 25 2.5 2.5 2.5 2.5 2.5 25 25 ...
## $ PROPDMGEXP: chr "K" "K" "K" "K" ...
## $ CROPDMG : num 0 0 0 0 0 0 0 0 0 0 ...
## $ CROPDMGEXP: chr "" "" "" "" ...</code></pre>
<pre class="r"><code>summary(data)</code></pre>
<pre><code>## Warning: cerrando la conenexion 5 (repdata-data-StormData.csv.bz2) que no
## esta siendo utilizada</code></pre>
<pre><code>## BGN_DATE EVTYPE FATALITIES
## Length:902297 Length:902297 Min. : 0.0000
## Class :character Class :character 1st Qu.: 0.0000
## Mode :character Mode :character Median : 0.0000
## Mean : 0.0168
## 3rd Qu.: 0.0000
## Max. :583.0000
## INJURIES PROPDMG PROPDMGEXP
## Min. : 0.0000 Min. : 0.00 Length:902297
## 1st Qu.: 0.0000 1st Qu.: 0.00 Class :character
## Median : 0.0000 Median : 0.00 Mode :character
## Mean : 0.1557 Mean : 12.06
## 3rd Qu.: 0.0000 3rd Qu.: 0.50
## Max. :1700.0000 Max. :5000.00
## CROPDMG CROPDMGEXP
## Min. : 0.000 Length:902297
## 1st Qu.: 0.000 Class :character
## Median : 0.000 Mode :character
## Mean : 1.527
## 3rd Qu.: 0.000
## Max. :990.000</code></pre>
<ol start="2" style="list-style-type: decimal">
<li>Selection : This strategy consists on reducing the number of rows. Knowing that there are 2 different questions to be answered, the Storm data will be divided in two datasets. The first one will exclude all the rows with injuries <= <strong>0</strong>. The second dataset will exclude all the rows with PROPDMGEXP = <strong>“”, ? and -</strong>, understanding that this values are NULL or just a little amount of money and also PROPDMG is greater than CROPDMG (eliminating both a lot of rows containing high values of PROPDMG are lost), based on <a href="https://rstudio-pubs-static.s3.amazonaws.com/58957_37b6723ee52b455990e149edde45e5b6.html">Source</a>.</li>
</ol>
<pre class="r"><code>data_human <- filter(data, INJURIES > 0)[,c("BGN_DATE", "EVTYPE","FATALITIES", "INJURIES")]
data_money <- filter(data, !(PROPDMGEXP %in% c("","?","-")))
data_money <- filter(data_money, !(CROPDMGEXP %in% c("","?")))[,c("BGN_DATE", "EVTYPE","PROPDMG", "PROPDMGEXP", "CROPDMG", "CROPDMGEXP")]
remove(data)</code></pre>
</div>
<div id="data-processing-1" class="section level3">
<h3>1.3. Data Processing</h3>
<p>This part consists on modifying some values and columns in order to get profitable data that could be used to obtain results in the next parts.</p>
<div id="dates" class="section level4">
<h4>Dates</h4>
<pre class="r"><code>data_human$BGN_DATE <- strptime(data_human$BGN_DATE, "%m/%d/%Y %H:%M:%S")
data_money$BGN_DATE <- strptime(data_money$BGN_DATE, "%m/%d/%Y %H:%M:%S")</code></pre>
</div>
<div id="damage" class="section level4">
<h4>Damage</h4>
<p>This variable is recorded in two columns of the Storm data. Registered as dollar amounts, sometimes stimated, and are rounded to three significant digits, followed by an alphabetical character signifying the magnitude of the number, i.e., 1.55B for $1,550,000,000.</p>
<p>Looking at the magnitude column, the next values can be found:</p>
<pre class="r"><code>data_money$PROPDMGEXP <- as.factor(data_money$PROPDMGEXP)
data_money$CROPDMGEXP <- as.factor(data_money$CROPDMGEXP)
levels(data_money$PROPDMGEXP)</code></pre>
<pre><code>## [1] "0" "3" "5" "B" "K" "m" "M"</code></pre>
<pre class="r"><code>levels(data_money$CROPDMGEXP)</code></pre>
<pre><code>## [1] "0" "B" "k" "K" "m" "M"</code></pre>
<p>The next approach is taken, based on this <a href="https://rstudio-pubs-static.s3.amazonaws.com/58957_37b6723ee52b455990e149edde45e5b6.html">Source</a>. The next values will be changed:</p>
<ul>
<li>H,h = hundreds = 100</li>
<li>K,k = kilos = thousands = 1,000</li>
<li>M,m = millions = 1,000,000</li>
<li>B,b = billions = 1,000,000,000</li>
<li>numeric 0..8 = 10</li>
<li>(+) = 1</li>
</ul>
<p>As the values of CROPDMGEXP were not eliminated, the values of the exponent will be 0, so the effect is minimum.</p>
<p>Finally, a <em>Damage</em> value is created, grouping both PROP and CROP variables, as in this case we are evaluating just the economic impact, mesured in dollars.</p>
<pre class="r"><code>data_money$PROPDMGEXP <- as.character(data_money$PROPDMGEXP)
data_money$PROPDMGEXP<-revalue(data_money$PROPDMGEXP,
c("0"=10,"3"=10,"5"=10,"K"=1000,"M"=1000000,
"m"=1000000,"B"=1000000000))
data_money$PROPDMGEXP <- as.numeric(data_money$PROPDMGEXP)
data_money$CROPDMGEXP <- as.character(data_money$CROPDMGEXP)
data_money$CROPDMGEXP<-revalue(data_money$CROPDMGEXP,
c("0"=10,"K"=1000,"k"=1000,"M"=1000000,
"m"=1000000))
data_money$CROPDMGEXP <- as.numeric(data_money$CROPDMGEXP)</code></pre>
<pre><code>## Warning: NAs introducidos por coerción</code></pre>
<pre class="r"><code>data_money <- data_money[complete.cases(data_money$CROPDMGEXP),]
data_money <- mutate(data_money, cost = (data_money$PROPDMG * data_money$PROPDMGEXP +
data_money$CROPDMG * data_money$CROPDMGEXP))</code></pre>
</div>
</div>
<div id="harmful-events-for-population-health" class="section level3">
<h3>1.3.1. Harmful events for population health</h3>
<p>This part will prepare the data for extracting the results about the first question.</p>
<pre class="r"><code>#Data frame with the number of fatalities depending on the type of event:
Fatalities_per_event <- as.data.frame(tapply(data_human$FATALITIES, data_human$EVTYPE, sum))
Fatalities_per_event[,1] <- as.numeric(Fatalities_per_event[,1])
Fatalities_per_event[,2] <- rownames(Fatalities_per_event)
colnames(Fatalities_per_event) <- c("Deads","Type_of_event")
rownames(Fatalities_per_event) <- NULL
#Data frame with the number of inujuries depending on the type of event:
Injuries_per_event <- as.data.frame(tapply(data_human$INJURIES, data_human$EVTYPE, sum))
Injuries_per_event[,1] <- as.numeric(Injuries_per_event[,1])
Injuries_per_event[,2] <- rownames(Injuries_per_event)
colnames(Injuries_per_event) <- c("Injuries","Type_of_event")
rownames(Injuries_per_event) <- NULL
#Final dataframe with both injuries and deads
Human_damage <- merge(Fatalities_per_event, Injuries_per_event)
#Table:
Human_damage</code></pre>
<pre><code>## Type_of_event Deads Injuries
## 1 AVALANCHE 52 170
## 2 BLACK ICE 1 24
## 3 BLIZZARD 48 805
## 4 blowing snow 1 1
## 5 BLOWING SNOW 1 13
## 6 BRUSH FIRE 0 2
## 7 COASTAL FLOOD 0 2
## 8 COASTAL FLOODING/EROSION 0 5
## 9 Coastal Storm 0 1
## 10 COASTAL STORM 1 1
## 11 COLD 8 48
## 12 COLD/WIND CHILL 3 12
## 13 DENSE FOG 14 342
## 14 DROUGHT 0 4
## 15 DRY MICROBURST 0 28
## 16 DRY MIRCOBURST WINDS 0 1
## 17 Dust Devil 0 1
## 18 DUST DEVIL 0 42
## 19 DUST STORM 19 440
## 20 EXCESSIVE HEAT 402 6525
## 21 EXCESSIVE RAINFALL 2 21
## 22 EXCESSIVE SNOW 0 2
## 23 EXTREME COLD 25 231
## 24 EXTREME COLD/WIND CHILL 12 24
## 25 EXTREME HEAT 0 155
## 26 EXTREME WINDCHILL 2 5
## 27 FALLING SNOW/ICE 0 1
## 28 FLASH FLOOD 171 1777
## 29 FLASH FLOODING 0 8
## 30 FLOOD 104 6789
## 31 FLOOD/FLASH FLOOD 3 15
## 32 FLOODING 2 2
## 33 FOG 38 734
## 34 FOG AND COLD TEMPERATURES 1 1
## 35 FREEZING DRIZZLE 2 15
## 36 FREEZING RAIN 2 23
## 37 FROST 1 3
## 38 FUNNEL CLOUD 0 3
## 39 GLAZE 7 216
## 40 GLAZE/ICE STORM 0 15
## 41 GUSTY WIND 0 1
## 42 Gusty winds 0 2
## 43 Gusty Winds 0 1
## 44 GUSTY WINDS 1 8
## 45 HAIL 3 1361
## 46 HAZARDOUS SURF 0 1
## 47 HEAT 73 2100
## 48 Heat Wave 0 70
## 49 HEAT WAVE 22 309
## 50 HEAT WAVE DROUGHT 4 15
## 51 HEAVY RAIN 39 251
## 52 HEAVY RAINS 0 4
## 53 HEAVY SNOW 51 1021
## 54 Heavy snow shower 0 2
## 55 HEAVY SNOW/BLIZZARD/AVALANCHE 0 1
## 56 HEAVY SNOW/ICE 0 10
## 57 HEAVY SURF 1 40
## 58 HEAVY SURF/HIGH SURF 8 48
## 59 HIGH 0 1
## 60 HIGH SEAS 2 8
## 61 High Surf 1 4
## 62 HIGH SURF 28 152
## 63 HIGH WIND 102 1137
## 64 HIGH WIND 48 0 1
## 65 HIGH WIND AND SEAS 3 20
## 66 HIGH WIND/HEAVY SNOW 0 1
## 67 HIGH WINDS 12 302
## 68 HIGH WINDS/COLD 0 4
## 69 HIGH WINDS/SNOW 3 6
## 70 HURRICANE 14 46
## 71 HURRICANE-GENERATED SWELLS 0 2
## 72 Hurricane Edouard 0 2
## 73 HURRICANE EMILY 0 1
## 74 HURRICANE ERIN 0 1
## 75 HURRICANE OPAL 0 1
## 76 HURRICANE/TYPHOON 32 1275
## 77 ICE 3 137
## 78 ICE ROADS 0 1
## 79 ICE STORM 35 1975
## 80 ICE STORM/FLASH FLOOD 0 2
## 81 ICY ROADS 5 31
## 82 LANDSLIDE 21 52
## 83 LANDSLIDES 1 1
## 84 LIGHT SNOW 1 2
## 85 LIGHTNING 283 5230
## 86 LIGHTNING AND THUNDERSTORM WIN 0 1
## 87 LIGHTNING INJURY 0 1
## 88 Marine Accident 1 2
## 89 MARINE HIGH WIND 1 1
## 90 MARINE MISHAP 1 5
## 91 MARINE STRONG WIND 3 22
## 92 MARINE THUNDERSTORM WIND 7 26
## 93 MARINE TSTM WIND 2 8
## 94 MIXED PRECIP 1 26
## 95 Mudslide 0 2
## 96 NON-SEVERE WIND DAMAGE 0 7
## 97 NON TSTM WIND 0 1
## 98 OTHER 0 4
## 99 RAIN/SNOW 3 2
## 100 RECORD HEAT 0 50
## 101 RIP CURRENT 50 232
## 102 RIP CURRENTS 32 297
## 103 RIVER FLOOD 0 2
## 104 River Flooding 0 1
## 105 ROGUE WAVE 0 2
## 106 ROUGH SEAS 2 5
## 107 ROUGH SURF 2 1
## 108 SMALL HAIL 0 10
## 109 Snow 0 2
## 110 SNOW 3 29
## 111 SNOW AND ICE 0 1
## 112 SNOW SQUALL 0 35
## 113 SNOW/HIGH WINDS 0 36
## 114 STORM SURGE 2 38
## 115 STORM SURGE/TIDE 0 5
## 116 STRONG WIND 25 280
## 117 STRONG WINDS 1 21
## 118 THUNDERSNOW 1 1
## 119 THUNDERSTORM 0 12
## 120 THUNDERSTORM WINDS 0 10
## 121 THUNDERSTORM WIND 54 1488
## 122 THUNDERSTORM WINDS 25 908
## 123 THUNDERSTORM WINDS 13 0 1
## 124 THUNDERSTORM WINDS/HAIL 0 1
## 125 THUNDERSTORM WINDSS 0 4
## 126 THUNDERSTORMS WINDS 0 1
## 127 THUNDERSTORMW 0 27
## 128 TIDAL FLOODING 0 1
## 129 TORNADO 5227 91346
## 130 TORNADO F2 0 16
## 131 TORNADO F3 0 2
## 132 Torrential Rainfall 0 4
## 133 TROPICAL STORM 12 340
## 134 TROPICAL STORM GORDON 8 43
## 135 TSTM WIND 199 6957
## 136 TSTM WIND (G40) 0 1
## 137 TSTM WIND (G45) 0 3
## 138 TSTM WIND/HAIL 3 95
## 139 TSUNAMI 32 129
## 140 TYPHOON 0 5
## 141 UNSEASONABLY WARM 0 17
## 142 URBAN/SML STREAM FLD 9 79
## 143 WARM WEATHER 0 2
## 144 WATERSPOUT 0 29
## 145 WATERSPOUT TORNADO 0 1
## 146 WATERSPOUT/TORNADO 3 42
## 147 WILD FIRES 3 150
## 148 WILD/FOREST FIRE 7 545
## 149 WILDFIRE 55 911
## 150 WIND 11 86
## 151 WINDS 0 1
## 152 WINTER STORM 85 1321
## 153 WINTER STORM HIGH WINDS 1 15
## 154 WINTER STORMS 10 17
## 155 WINTER WEATHER 14 398
## 156 WINTER WEATHER MIX 0 68
## 157 WINTER WEATHER/MIX 17 72
## 158 WINTRY MIX 0 77</code></pre>
<p>Taking a look at the final list, it can be seen that there are events that are part of the same family, and events written different that mean the same: for instance " BLOWING SNOW" and “blowing snow” are the same, and “WINTER STORM” and “WINTER WEATHER” can pertain to the same class.</p>
<p>The next step to extract useful knowledge is to use Entity Resolution Techniques (task of identifying and linking/grouping different manifestations of the same real world object). In this case, a simple approach will be applied: a new factor column including the different groups of events will be created. The following groups will be created:</p>
<ul>
<li><p><strong>Snow</strong> : AVALANCHE, BLACK ICE, BLIZZARD, blowing snow, BLOWING SNOW, EXCESSIVE SNOW, FALLING SNOW/ICE, FROST, GLAZE, GLAZE/ICE STORM, HAIL, HEAVY SNOW, Heavy snow shower, HEAVY SNOW/BLIZZARD/AVALANCHE, HEAVY SNOW/ICE, ICE, ICE ROADS, ICE STORM, ICE STORM/FLASH FLOOD, ICY ROADS, LIGHT SNOW, RAIN/SNOW, SMALL HAIL, Snow, SNOW, SNOW AND ICE, SNOW SQUALL, SNOW/HIGH WINDS, THUNDERSNOW, WINTER WEATHER, WINTER WEATHER MIX, WINTER WEATHER/MIX, WINTRY MIX,FREEZE, FREEZING FOG, FROST/FREEZE, GLAZE ICE, HAIL 100, HAIL/WIND, HAIL/WINDS, HEAVY SNOW/HIGH WINDS & FLOOD, LAKE-EFFECT SNOW, MARINE HAIL.</p></li>
<li><p><strong>Fire</strong> : BRUSH FIRE, WILD FIRES, WILD/FOREST FIRE, WILDFIRE, DENSE SMOKE</p></li>
<li><p><strong>Landslide</strong>: LANDSLIDE, LANDSLIDES, Mudslide.</p></li>
<li><p><strong>Sea</strong> : HAZARDOUS SURF, HEAVY SURF, HEAVY SURF/HIGH SURF, HIGH, HIGH SEAS, High Surf, HIGH SURF, Marine Accident, MARINE MISHAP, RIP CURRENT, RIP CURRENTS, ROGUE WAVE, ROUGH SEAS, ROUGH SURF, TSUNAMI, WATERSPOUT, ASTRONOMICAL HIGH TIDE, ASTRONOMICAL LOW TIDE.</p></li>
<li><p><strong>Lightning</strong>: LIGHTNING, LIGHTNING AND THUNDERSTORM WIN, LIGHTNING INJURY.</p></li>
<li><p><strong>Cold</strong> : COLD, EXTREME COLD, EXTREME WINDCHILL .</p></li>
<li><p><strong>Wind</strong> : COLD/WIND CHILL, DRY MIRCOBURST WINDS, EXTREME COLD/WIND CHILL, FUNNEL CLOUD, GUSTY WIND, Gusty winds, Gusty Winds, GUSTY WINDS, HIGH WIND, HIGH WIND 48, HIGH WIND AND SEAS, HIGH WIND/HEAVY SNOW, HIGH WINDS, HIGH WINDS/COLD, HIGH WINDS/SNOW, MARINE HIGH WIND, MARINE STRONG WIND, MARINE THUNDERSTORM WIND, MARINE TSTM WIND, NON-SEVERE WIND DAMAGE, NON TSTM WIND, STRONG WIND, STRONG WINDS, THUNDERSTORM WINDS, THUNDERSTORM WIND,THUNDERSTORM WINDS, THUNDERSTORM WINDS 13, THUNDERSTORM WINDS/HAIL, THUNDERSTORM WINDSS, THUNDERSTORMS WINDS, TSTM WIND, TSTM WIND (G40), TSTM WIND (G45), TSTM WIND/HAIL, WIND, WINDS,</p></li>
</ul>
<p>HIGH WINDS HEAVY RAINS, SEVERE THUNDERSTORM WINDS, THUDERSTORM WINDS, THUNDERSTORM HAIL, THUNDERSTORM WINDS HAIL, THUNDERSTORM WINDS LIGHTNING, THUNDERSTORM WINDS/ FLOOD, THUNDERSTORMS WIND, WIND DAMAGE.</p>
<ul>
<li><p><strong>Tornado</strong>: TORNADO, HURRICANE, HURRICANE-GENERATED SWELLS, Hurricane Edouard, HURRICANE EMILY, HURRICANE ERIN, HURRICANE OPAL, HURRICANE/TYPHOON, TORNADO F2, TORNADO F3, TYPHOON, WATERSPOUT TORNADO, WATERSPOUT/TORNADO, COLD AIR TORNADO, GUSTNADO, HURRICANE FELIX, HURRICANE OPAL/HIGH WINDS, TORNADO F0, TORNADOES, TSTM WIND, HAIL.</p></li>
<li><p><strong>Fog</strong>: DENSE FOG, FOG, FOG AND COLD TEMPERATURES.</p></li>
<li><p><strong>Dust</strong> : Dust Devil, DUST DEVIL, DUST STORM, DUST STORM/HIGH WINDS</p></li>
<li><p><strong>Heat</strong> : DROUGHT, DRY MICROBURST, EXCESSIVE HEAT, EXTREME HEAT, HEAT, Heat Wave, HEAT WAVE, HEAT WAVE DROUGHT, RECORD HEAT, UNSEASONABLY WARM, WARM WEATHER.</p></li>
<li><p><strong>Flood and Storm</strong> : COASTAL FLOOD, COASTAL FLOODING/EROSION, FLASH FLOOD, FLASH FLOODING, FLOOD, FLOOD/FLASH FLOOD, FLOODIN, Coastal Storm, COASTAL STORM, EXCESSIVE RAINFALL, FREEZING DRIZZLE, FREEZING RAIN, HEAVY RAIN, HEAVY RAINS, MIXED PRECIP, RIVER FLOOD, River Flooding, STORM SURGE, STORM SURGE/TIDE, THUNDERSTORM, THUNDERSTORMW, TIDAL FLOODING, Torrential Rainfall, TROPICAL STORM, TROPICAL STORM GORDON, URBAN/SML STREAM FLD, WINTER STORM, WINTER STORM HIGH WINDS, WINTER STORMS, COASTAL FLOODING, FLASH FLOOD/FLOOD, FLASH FLOODING/FLOOD, FLOODS, FLOODING, HEAVY RAINS/FLOODING, ICE JAM FLOODING, LAKESHORE FLOOD, RIVER FLOODING, TROPICAL DEPRESSION, TROPICAL STORM DEAN, TROPICAL STORM JERRY, URBAN FLOOD, URBAN FLOODING, SEVERE THUNDERSTORMS.</p></li>
<li><p><strong>Other</strong>: OTHER.</p></li>
</ul>
<pre class="r"><code>Human_damage$Event<-revalue(Human_damage$Type_of_event,
c("AVALANCHE"="Snow", "BLACK ICE"="Snow", "BLIZZARD"="Snow", "blowing snow"="Snow","BLOWING SNOW"="Snow", "EXCESSIVE SNOW"="Snow", "FALLING SNOW/ICE"="Snow", "FROST"="Snow", "GLAZE"="Snow", "GLAZE/ICE STORM"="Snow", "HAIL"="Snow", "HEAVY SNOW"="Snow", "Heavy snow shower"="Snow", "HEAVY SNOW/BLIZZARD/AVALANCHE"="Snow", "HEAVY SNOW/ICE"="Snow", "ICE"="Snow", "ICE ROADS"="Snow", "ICE STORM"="Snow", "ICE STORM/FLASH FLOOD"="Snow", "ICY ROADS"="Snow", "LIGHT SNOW"="Snow", "RAIN/SNOW"="Snow", "SMALL HAIL"="Snow", "Snow"="Snow", "SNOW"="Snow", "SNOW AND ICE"="Snow", "SNOW SQUALL"="Snow", "SNOW/HIGH WINDS"="Snow", "THUNDERSNOW"="Snow", "WINTER WEATHER"="Snow", "WINTER WEATHER MIX"="Snow", "WINTER WEATHER/MIX"="Snow", "WINTRY MIX"="Snow",
"BRUSH FIRE"="Fire", "WILD FIRES"="Fire", "WILD/FOREST FIRE"="Fire", "WILDFIRE"="Fire",
"LANDSLIDE"="Landslide", "LANDSLIDES"="Landslide", "Mudslide"="Landslide",
"HAZARDOUS SURF"="Sea", "HEAVY SURF"="Sea", "HEAVY SURF/HIGH SURF"="Sea", "HIGH"="Sea", "HIGH SEAS"="Sea", "High Surf"="Sea", "HIGH SURF"="Sea", "Marine Accident"="Sea", "MARINE MISHAP"="Sea", "RIP CURRENT"="Sea", "RIP CURRENTS"="Sea", "ROGUE WAVE"="Sea", "ROUGH SEAS"="Sea", "ROUGH SURF"="Sea", "TSUNAMI"="Sea", "WATERSPOUT"="Sea",
"LIGHTNING"="Lightning", "LIGHTNING AND THUNDERSTORM WIN"="Lightning", "LIGHTNING INJURY"="Lightning",
"COLD"="Cold", "EXTREME COLD"="Cold", "EXTREME WINDCHILL"="Cold",
"LIGHTNING"="Lightning", "LIGHTNING AND THUNDERSTORM WIN"="Lightning", "LIGHTNING INJURY"="Lightning",
"COLD"="Cold", "EXTREME COLD"="Cold", "EXTREME WINDCHILL"="Cold",
"COLD/WIND CHILL"="Wind", "DRY MIRCOBURST WINDS"="Wind", "EXTREME COLD/WIND CHILL"="Wind", "FUNNEL CLOUD"="Wind", "GUSTY WIND"="Wind", "Gusty winds"="Wind", "Gusty Winds"="Wind", "GUSTY WINDS"="Wind", "HIGH WIND"="Wind", "HIGH WIND 48"="Wind", "HIGH WIND AND SEAS"="Wind", "HIGH WIND/HEAVY SNOW"="Wind", "HIGH WINDS"="Wind", "HIGH WINDS/COLD"="Wind", "HIGH WINDS/SNOW"="Wind", "MARINE HIGH WIND"="Wind", "MARINE STRONG WIND"="Wind", "MARINE THUNDERSTORM WIND"="Wind", "MARINE TSTM WIND"="Wind", "NON-SEVERE WIND DAMAGE"="Wind", "NON TSTM WIND"="Wind", "STRONG WIND"="Wind", "STRONG WINDS"="Wind", "THUNDERSTORM WINDS"="Wind", "THUNDERSTORM WIND"="Wind","THUNDERSTORM WINDS"="Wind", "THUNDERSTORM WINDS 13"="Wind", "THUNDERSTORM WINDS/HAIL"="Wind", "THUNDERSTORM WINDSS"="Wind", "THUNDERSTORMS WINDS"="Wind", "TSTM WIND"="Wind", "TSTM WIND (G40)"="Wind", "TSTM WIND (G45)"="Wind", "TSTM WIND/HAIL"="Wind", "WIND"="Wind", "WINDS"="Wind",
"TORNADO"="Tornado", "HURRICANE"="Tornado", "HURRICANE-GENERATED SWELLS"="Tornado", "Hurricane Edouard"="Tornado", "HURRICANE EMILY"="Tornado", "HURRICANE ERIN"="Tornado", "HURRICANE OPAL"="Tornado", "HURRICANE/TYPHOON"="Tornado", "TORNADO F2"="Tornado", "TORNADO F3"="Tornado", "TYPHOON"="Tornado", "WATERSPOUT TORNADO"="Tornado", "WATERSPOUT/TORNADO"="Tornado",
"DENSE FOG"="Fog", "FOG"="Fog", "FOG AND COLD TEMPERATURES"="Fog",
"Dust Devil"="Dust", "DUST DEVIL"="Dust", "DUST STORM"="Dust",
"DROUGHT" ="Heat", "DRY MICROBURST" ="Heat", "EXCESSIVE HEAT" ="Heat", "EXTREME HEAT" ="Heat", "HEAT" ="Heat", "Heat Wave" ="Heat", "HEAT WAVE" ="Heat", "HEAT WAVE DROUGHT" ="Heat", "RECORD HEAT" ="Heat", "UNSEASONABLY WARM" ="Heat", "WARM WEATHER" ="Heat",
"COASTAL FLOOD"="Storm/Flood", "COASTAL FLOODING/EROSION"="Storm/Flood", "FLASH FLOOD"="Storm/Flood", "FLASH FLOODING"="Storm/Flood", "FLOOD"="Storm/Flood", "FLOOD/FLASH FLOOD"="Storm/Flood", "FLOODIN"="Storm/Flood", "Coastal Storm"="Storm/Flood", "COASTAL STORM"="Storm/Flood", "EXCESSIVE RAINFALL"="Storm/Flood", "FREEZING DRIZZLE"="Storm/Flood", "FREEZING RAIN"="Storm/Flood", "HEAVY RAIN"="Storm/Flood", "HEAVY RAINS"="Storm/Flood", "MIXED PRECIP"="Storm/Flood", "RIVER FLOOD"="Storm/Flood", "River Flooding"="Storm/Flood", "STORM SURGE"="Storm/Flood", "STORM SURGE/TIDE"="Storm/Flood", "THUNDERSTORM"="Storm/Flood", "THUNDERSTORMW"="Storm/Flood", "TIDAL FLOODING"="Storm/Flood", "Torrential Rainfall"="Storm/Flood", "TROPICAL STORM"="Storm/Flood", "TROPICAL STORM GORDON"="Storm/Flood", "URBAN/SML STREAM FLD"="Storm/Flood", "WINTER STORM"="Storm/Flood", "WINTER STORM HIGH WINDS"="Storm/Flood", "WINTER STORMS"="Storm/Flood",
"OTHER"="Other"))</code></pre>
<pre><code>## The following `from` values were not present in `x`: LIGHTNING, LIGHTNING AND THUNDERSTORM WIN, LIGHTNING INJURY, COLD, EXTREME COLD, EXTREME WINDCHILL, FLOODIN</code></pre>
<p>Now it is possible to create a more generic dataset:</p>
<pre class="r"><code>#Data frame with the number of fatalities depending on the type of event:
Fatalities_per_event2 <- as.data.frame(tapply(Human_damage$Deads, Human_damage$Event, sum))
Fatalities_per_event2[,1] <- as.numeric(Fatalities_per_event2[,1])
Fatalities_per_event2[,2] <- rownames(Fatalities_per_event2)
colnames(Fatalities_per_event2) <- c("Deads","Event")
rownames(Fatalities_per_event2) <- NULL
#Data frame with the number of inujuries depending on the type of event:
Injuries_per_event2 <- as.data.frame(tapply(Human_damage$Injuries, Human_damage$Event, sum))
Injuries_per_event2[,1] <- as.numeric(Injuries_per_event2[,1])
Injuries_per_event2[,2] <- rownames(Injuries_per_event2)
colnames(Injuries_per_event2) <- c("Injuries","Event")
rownames(Injuries_per_event2) <- NULL
#Final dataframe with both injuries and deads
Human_damage2 <- merge(Fatalities_per_event2, Injuries_per_event2)
#Table
Human_damage2</code></pre>
<pre><code>## Event Deads Injuries
## 1 Cold 35 284
## 2 Dust 19 483
## 3 Fire 65 1608
## 4 FLOODING 2 2
## 5 Fog 53 1077
## 6 Heat 501 9275
## 7 Landslide 22 55
## 8 Lightning 283 5232
## 9 Other 0 4
## 10 Sea 160 956
## 11 Snow 247 6524
## 12 Storm/Flood 452 10843
## 13 Tornado 5276 92740
## 14 Wind 467 11445</code></pre>
</div>
<div id="economic-consequences-due-to-atmospheric-phenomena" class="section level3">
<h3>1.3.2. Economic consequences due to atmospheric phenomena</h3>
<p>This part will prepare the data for extracting the results about the second question.</p>
<pre class="r"><code>#Data frame with the cost in dollars depending on the type of event:
Money_damage <- as.data.frame(tapply(data_money$cost, data_money$EVTYPE, sum))
Money_damage[,1] <- as.numeric(Money_damage[,1])
Money_damage[,2] <- rownames(Money_damage)
colnames(Money_damage) <- c("Cost","Type_of_event")
rownames(Money_damage) <- NULL
#Table
Money_damage</code></pre>
<pre><code>## Cost Type_of_event
## 1 5000 ASTRONOMICAL HIGH TIDE
## 2 320000 ASTRONOMICAL LOW TIDE
## 3 2385800 AVALANCHE
## 4 207041000 BLIZZARD
## 5 167580560 COASTAL FLOOD
## 6 25356000 COASTAL FLOODING
## 7 100 COLD AIR TORNADO
## 8 2590000 COLD/WIND CHILL
## 9 2842000 DENSE FOG
## 10 100000 DENSE SMOKE
## 11 1886417000 DROUGHT
## 12 123000 DRY MICROBURST
## 13 381130 DUST DEVIL
## 14 5749000 DUST STORM
## 15 550000 DUST STORM/HIGH WINDS
## 16 493803200 EXCESSIVE HEAT
## 17 4610000 EXTREME COLD
## 18 7038000 EXTREME COLD/WIND CHILL
## 19 8715885664 FLASH FLOOD
## 20 271505000 FLASH FLOOD/FLOOD
## 21 71138050 FLASH FLOODING
## 22 1925000 FLASH FLOODING/FLOOD
## 23 138007444500 FLOOD
## 24 163434000 FLOOD/FLASH FLOOD
## 25 64320500 FLOODING
## 26 550000 FLOODS
## 27 32000 FOG
## 28 5500000 FOREST FIRES
## 29 675000 FREEZE
## 30 2182000 FREEZING FOG
## 31 1100000 Frost/Freeze
## 32 941281000 FROST/FREEZE
## 33 65100 FUNNEL CLOUD
## 34 305300 GLAZE ICE
## 35 52600 GUSTNADO
## 36 345000 GUSTY WINDS
## 37 10045596890 HAIL
## 38 15000 HAIL 100
## 39 550 HAIL/WIND
## 40 550000 HAIL/WINDS
## 41 2390000 HEAT
## 42 310000 HEAT WAVE
## 43 250000 HEAT WAVE DROUGHT
## 44 375287730 HEAVY RAIN
## 45 15000000 Heavy Rain/High Surf
## 46 71500000 HEAVY RAINS
## 47 5073000 HEAVY RAINS/FLOODING
## 48 309935100 HEAVY SNOW
## 49 1520000 HEAVY SNOW/HIGH WINDS & FLOOD
## 50 0 HEAVY SURF/HIGH SURF
## 51 83017500 HIGH SURF
## 52 3057666640 HIGH WIND
## 53 50000 HIGH WIND AND SEAS
## 54 111505550 HIGH WINDS
## 55 7510000 HIGH WINDS HEAVY RAINS
## 56 117500000 HIGH WINDS/COLD
## 57 12405268000 HURRICANE
## 58 262010000 HURRICANE ERIN
## 59 1000000 HURRICANE FELIX
## 60 2187000000 HURRICANE OPAL
## 61 110000000 HURRICANE OPAL/HIGH WINDS
## 62 21958167800 HURRICANE/TYPHOON
## 63 10000000 ICE JAM FLOODING
## 64 924651300 ICE STORM
## 65 47000 ICY ROADS
## 66 40035000 LAKE-EFFECT SNOW
## 67 7540000 LAKESHORE FLOOD
## 68 170320500 LANDSLIDE
## 69 320786130 LIGHTNING
## 70 4000 MARINE HAIL
## 71 1140010 MARINE HIGH WIND
## 72 403330 MARINE STRONG WIND
## 73 486400 MARINE THUNDERSTORM WIND
## 74 1000 RIP CURRENT
## 75 108369000 RIVER FLOOD
## 76 134010000 River Flooding
## 77 55000 RIVER FLOODING
## 78 100000 SEICHE
## 79 29150000 SEVERE THUNDERSTORM WINDS
## 80 17500000 SEVERE THUNDERSTORMS
## 81 0 SLEET
## 82 540000 SMALL HAIL
## 83 11000 SNOW
## 84 2920000 STORM SURGE
## 85 4641493000 STORM SURGE/TIDE
## 86 184200560 STRONG WIND
## 87 55000 THUDERSTORM WINDS
## 88 55000 THUNDERSTORM HAIL
## 89 3813647990 THUNDERSTORM WIND
## 90 466284200 THUNDERSTORM WINDS
## 91 97000 THUNDERSTORM WINDS HAIL
## 92 15000 THUNDERSTORM WINDS LIGHTNING
## 93 40000 THUNDERSTORM WINDS/ FLOOD
## 94 50000 THUNDERSTORM WINDS/HAIL
## 95 1774550 THUNDERSTORM WINDSS
## 96 10000 THUNDERSTORMS
## 97 15000 THUNDERSTORMS WIND
## 98 6000 THUNDERSTORMS WINDS
## 99 16570328280 TORNADO
## 100 17400 TORNADO F0
## 101 1602500000 TORNADOES, TSTM WIND, HAIL
## 102 1302000 TROPICAL DEPRESSION
## 103 1508302350 TROPICAL STORM
## 104 450000 TROPICAL STORM DEAN
## 105 1000000 TROPICAL STORM GORDON
## 106 20600000 TROPICAL STORM JERRY
## 107 1155590110 TSTM WIND
## 108 28642000 TSTM WIND/HAIL
## 109 144082000 TSUNAMI
## 110 16555000 TYPHOON
## 111 4263500 URBAN FLOOD
## 112 4031500 URBAN FLOODING
## 113 12096700 URBAN/SML STREAM FLD
## 114 0 VOLCANIC ASHFALL
## 115 5206200 WATERSPOUT
## 116 147549200 WILD/FOREST FIRE
## 117 32000 WILD/FOREST FIRES
## 118 3684468370 WILDFIRE
## 119 1000000 WILDFIRES
## 120 15000 WIND DAMAGE
## 121 5500 WINDS
## 122 1041568200 WINTER STORM
## 123 65000000 WINTER STORM HIGH WINDS
## 124 1000000 WINTER STORMS
## 125 34897500 WINTER WEATHER</code></pre>
<p>The same approach as the human health question will be applied in order to group the types of events. Some of them will be added to the previous list, as they are not in the population dataset.</p>
<pre class="r"><code>Money_damage$Event<-revalue(Money_damage$Type_of_event,
c("AVALANCHE"="Snow", "BLACK ICE"="Snow", "BLIZZARD"="Snow", "blowing snow"="Snow","BLOWING SNOW"="Snow", "EXCESSIVE SNOW"="Snow", "FALLING SNOW/ICE"="Snow", "FROST"="Snow", "GLAZE"="Snow", "GLAZE/ICE STORM"="Snow", "HAIL"="Snow", "HEAVY SNOW"="Snow", "Heavy snow shower"="Snow", "HEAVY SNOW/BLIZZARD/AVALANCHE"="Snow", "HEAVY SNOW/ICE"="Snow", "ICE"="Snow", "ICE ROADS"="Snow", "ICE STORM"="Snow", "ICE STORM/FLASH FLOOD"="Snow", "ICY ROADS"="Snow", "LIGHT SNOW"="Snow", "RAIN/SNOW"="Snow", "SMALL HAIL"="Snow", "Snow"="Snow", "SNOW"="Snow", "SNOW AND ICE"="Snow", "SNOW SQUALL"="Snow", "SNOW/HIGH WINDS"="Snow", "THUNDERSNOW"="Snow", "WINTER WEATHER"="Snow", "WINTER WEATHER MIX"="Snow", "WINTER WEATHER/MIX"="Snow", "WINTRY MIX"="Snow","FREEZE"="Snow", "FREEZING FOG"="Snow", "FROST/FREEZE"="Snow", "GLAZE ICE"="Snow", "HAIL 100"="Snow", "HAIL/WIND"="Snow", "HAIL/WINDS"="Snow", "HEAVY SNOW/HIGH WINDS & FLOOD"="Snow", "LAKE-EFFECT SNOW"="Snow", "MARINE HAIL"="Snow", "SLEET"="Snow",
"BRUSH FIRE"="Fire", "WILD FIRES"="Fire", "WILD/FOREST FIRE"="Fire", "WILDFIRE"="Fire","FOREST FIRES"="Fire", "WILD/FOREST FIRES"="Fire", "WILDFIRES"="Fire",
"LANDSLIDE"="Landslide", "LANDSLIDES"="Landslide", "Mudslide"="Landslide",
"HAZARDOUS SURF"="Sea", "HEAVY SURF"="Sea", "HEAVY SURF/HIGH SURF"="Sea", "HIGH"="Sea", "HIGH SEAS"="Sea", "High Surf"="Sea", "HIGH SURF"="Sea", "Marine Accident"="Sea", "MARINE MISHAP"="Sea", "RIP CURRENT"="Sea", "RIP CURRENTS"="Sea", "ROGUE WAVE"="Sea", "ROUGH SEAS"="Sea", "ROUGH SURF"="Sea", "TSUNAMI"="Sea", "WATERSPOUT"="Sea", "ASTRONOMICAL HIGH TIDE"="Sea", "ASTRONOMICAL LOW TIDE"="Sea",
"LIGHTNING"="Lightning", "LIGHTNING AND THUNDERSTORM WIN"="Lightning", "LIGHTNING INJURY"="Lightning",
"COLD"="Cold", "EXTREME COLD"="Cold", "EXTREME WINDCHILL"="Cold",
"LIGHTNING"="Lightning", "LIGHTNING AND THUNDERSTORM WIN"="Lightning", "LIGHTNING INJURY"="Lightning",
"COLD"="Cold", "EXTREME COLD"="Cold", "EXTREME WINDCHILL"="Cold",
"COLD/WIND CHILL"="Wind", "DRY MIRCOBURST WINDS"="Wind", "EXTREME COLD/WIND CHILL"="Wind", "FUNNEL CLOUD"="Wind", "GUSTY WIND"="Wind", "Gusty winds"="Wind", "Gusty Winds"="Wind", "GUSTY WINDS"="Wind", "HIGH WIND"="Wind", "HIGH WIND 48"="Wind", "HIGH WIND AND SEAS"="Wind", "HIGH WIND/HEAVY SNOW"="Wind", "HIGH WINDS"="Wind", "HIGH WINDS/COLD"="Wind", "HIGH WINDS/SNOW"="Wind", "MARINE HIGH WIND"="Wind", "MARINE STRONG WIND"="Wind", "MARINE THUNDERSTORM WIND"="Wind", "MARINE TSTM WIND"="Wind", "NON-SEVERE WIND DAMAGE"="Wind", "NON TSTM WIND"="Wind", "STRONG WIND"="Wind", "STRONG WINDS"="Wind", "THUNDERSTORM WINDS"="Wind", "THUNDERSTORM WIND"="Wind","THUNDERSTORM WINDS"="Wind", "THUNDERSTORM WINDS 13"="Wind", "THUNDERSTORM WINDS/HAIL"="Wind", "THUNDERSTORM WINDSS"="Wind", "THUNDERSTORMS WINDS"="Wind", "TSTM WIND"="Wind", "TSTM WIND (G40)"="Wind", "TSTM WIND (G45)"="Wind", "TSTM WIND/HAIL"="Wind", "WIND"="Wind", "WINDS"="Wind", "HIGH WINDS HEAVY RAINS"="Wind", "SEVERE THUNDERSTORM WINDS"="Wind", "THUDERSTORM WINDS"="Wind", "THUNDERSTORM HAIL"="Wind", "THUNDERSTORM WINDS HAIL"="Wind", "THUNDERSTORM WINDS LIGHTNING"="Wind", "THUNDERSTORM WINDS/ FLOOD"="Wind", "THUNDERSTORMS WIND"="Wind", "WIND DAMAGE"="Wind",
"TORNADO"="Tornado", "HURRICANE"="Tornado", "HURRICANE-GENERATED SWELLS"="Tornado", "Hurricane Edouard"="Tornado", "HURRICANE EMILY"="Tornado", "HURRICANE ERIN"="Tornado", "HURRICANE OPAL"="Tornado", "HURRICANE/TYPHOON"="Tornado", "TORNADO F2"="Tornado", "TORNADO F3"="Tornado", "TYPHOON"="Tornado", "WATERSPOUT TORNADO"="Tornado", "WATERSPOUT/TORNADO"="Tornado", "COLD AIR TORNADO"="Tornado", "GUSTNADO"="Tornado", "HURRICANE FELIX"="Tornado", "HURRICANE OPAL/HIGH WINDS"="Tornado", "TORNADO F0"="Tornado", "TORNADOES, TSTM WIND, HAIL" = "Tornado",
"DENSE FOG"="Fog", "FOG"="Fog", "FOG AND COLD TEMPERATURES"="Fog","FREEZING FOG"="Fog",
"Dust Devil"="Dust", "DUST DEVIL"="Dust", "DUST STORM"="Dust", "DENSE SMOKE"="Dust", "DUST STORM/HIGH WINDS"="Dust", "VOLCANIC ASHFALL"="Dust",
"DROUGHT" ="Heat", "DRY MICROBURST" ="Heat", "EXCESSIVE HEAT" ="Heat", "EXTREME HEAT" ="Heat", "HEAT" ="Heat", "Heat Wave" ="Heat", "HEAT WAVE" ="Heat", "HEAT WAVE DROUGHT" ="Heat", "RECORD HEAT" ="Heat", "UNSEASONABLY WARM" ="Heat", "WARM WEATHER" ="Heat",
"COASTAL FLOOD"="Storm/Flood", "COASTAL FLOODING/EROSION"="Storm/Flood", "FLASH FLOOD"="Storm/Flood", "FLASH FLOODING"="Storm/Flood", "FLOOD"="Storm/Flood", "FLOOD/FLASH FLOOD"="Storm/Flood", "FLOODIN"="Storm/Flood", "Coastal Storm"="Storm/Flood", "COASTAL STORM"="Storm/Flood", "EXCESSIVE RAINFALL"="Storm/Flood", "FREEZING DRIZZLE"="Storm/Flood", "FREEZING RAIN"="Storm/Flood", "HEAVY RAIN"="Storm/Flood", "HEAVY RAINS"="Storm/Flood", "MIXED PRECIP"="Storm/Flood", "RIVER FLOOD"="Storm/Flood", "River Flooding"="Storm/Flood", "STORM SURGE"="Storm/Flood", "STORM SURGE/TIDE"="Storm/Flood", "THUNDERSTORM"="Storm/Flood", "THUNDERSTORMW"="Storm/Flood", "TIDAL FLOODING"="Storm/Flood", "Torrential Rainfall"="Storm/Flood", "TROPICAL STORM"="Storm/Flood", "TROPICAL STORM GORDON"="Storm/Flood", "URBAN/SML STREAM FLD"="Storm/Flood", "WINTER STORM"="Storm/Flood", "WINTER STORM HIGH WINDS"="Storm/Flood", "WINTER STORMS"="Storm/Flood", "COASTAL FLOODING"="Storm/Flood", "FLASH FLOOD/FLOOD"="Storm/Flood", "FLASH FLOODING/FLOOD"="Storm/Flood", "FLOODS"="Storm/Flood", "FLOODING"="Storm/Flood", "HEAVY RAINS/FLOODING"="Storm/Flood", "ICE JAM FLOODING"="Storm/Flood", "LAKESHORE FLOOD"="Storm/Flood", "RIVER FLOODING"="Storm/Flood", "TROPICAL DEPRESSION"="Storm/Flood", "TROPICAL STORM DEAN"="Storm/Flood", "TROPICAL STORM JERRY"="Storm/Flood", "URBAN FLOOD"="Storm/Flood", "URBAN FLOODING"="Storm/Flood", "SEVERE THUNDERSTORMS"="Storm/Flood", "Heavy Rain/High Surf" = "Storm/Flood", "SEICHE" = "Storm/Flood", "THUNDERSTORMS"= "Storm/Flood"))</code></pre>
<pre><code>## The following `from` values were not present in `x`: BLACK ICE, blowing snow, BLOWING SNOW, EXCESSIVE SNOW, FALLING SNOW/ICE, FROST, GLAZE, GLAZE/ICE STORM, Heavy snow shower, HEAVY SNOW/BLIZZARD/AVALANCHE, HEAVY SNOW/ICE, ICE, ICE ROADS, ICE STORM/FLASH FLOOD, LIGHT SNOW, RAIN/SNOW, Snow, SNOW AND ICE, SNOW SQUALL, SNOW/HIGH WINDS, THUNDERSNOW, WINTER WEATHER MIX, WINTER WEATHER/MIX, WINTRY MIX, BRUSH FIRE, WILD FIRES, LANDSLIDES, Mudslide, HAZARDOUS SURF, HEAVY SURF, HIGH, HIGH SEAS, High Surf, Marine Accident, MARINE MISHAP, RIP CURRENTS, ROGUE WAVE, ROUGH SEAS, ROUGH SURF, LIGHTNING AND THUNDERSTORM WIN, LIGHTNING INJURY, COLD, EXTREME WINDCHILL, LIGHTNING, LIGHTNING AND THUNDERSTORM WIN, LIGHTNING INJURY, COLD, EXTREME COLD, EXTREME WINDCHILL, DRY MIRCOBURST WINDS, GUSTY WIND, Gusty winds, Gusty Winds, HIGH WIND 48, HIGH WIND/HEAVY SNOW, HIGH WINDS/SNOW, MARINE TSTM WIND, NON-SEVERE WIND DAMAGE, NON TSTM WIND, STRONG WINDS, THUNDERSTORM WINDS, THUNDERSTORM WINDS 13, TSTM WIND (G40), TSTM WIND (G45), WIND, HURRICANE-GENERATED SWELLS, Hurricane Edouard, HURRICANE EMILY, TORNADO F2, TORNADO F3, WATERSPOUT TORNADO, WATERSPOUT/TORNADO, FOG AND COLD TEMPERATURES, FREEZING FOG, Dust Devil, EXTREME HEAT, Heat Wave, RECORD HEAT, UNSEASONABLY WARM, WARM WEATHER, COASTAL FLOODING/EROSION, FLOODIN, Coastal Storm, COASTAL STORM, EXCESSIVE RAINFALL, FREEZING DRIZZLE, FREEZING RAIN, MIXED PRECIP, THUNDERSTORM, THUNDERSTORMW, TIDAL FLOODING, Torrential Rainfall</code></pre>
<p>Now it is possible to create a more generic dataset:</p>
<pre class="r"><code>#Data frame with the number of fatalities depending on the type of event:
Money_damage2 <- as.data.frame(tapply(Money_damage$Cost, Money_damage$Event, sum))
Money_damage2[,1] <- as.numeric(Money_damage2[,1])
Money_damage2[,2] <- rownames(Money_damage2)
colnames(Money_damage2) <- c("Cost","Event")
rownames(Money_damage2) <- NULL
#Table
Money_damage2</code></pre>
<pre><code>## Cost Event
## 1 4610000 Cold
## 2 6780130 Dust
## 3 3838549570 Fire
## 4 2874000 Fog
## 5 1100000 Frost/Freeze
## 6 2383293200 Heat
## 7 170320500 Landslide
## 8 320786130 Lightning
## 9 232631700 Sea
## 10 12511673440 Snow
## 11 155537611254 Storm/Flood
## 12 55112899180 Tornado
## 13 8985942940 Wind</code></pre>
</div>
<div id="data-overview" class="section level3">
<h3>1.4. Data Overview</h3>
<p>The next step is having a look at the data. As this study evaluates the impact of the weather phenomena events to the human health and the economics, some statistics about number of injuries, fatalities and damage are provided.</p>
<pre class="r"><code>#Information about fatalities
number_of_fatalities = sum(Human_damage2$Deads, na.rm=T)
number_of_injuries = sum(Human_damage2$Injuries, na.rm=T)
total_damage = sum(Money_damage2$Cost, na.rm=T)</code></pre>
<p>Taking into account that the database currently contains data from <strong>January 1950</strong> to <strong>November 2011</strong>, the obtained results are:</p>
<ul>
<li>Fatalities: The number of registered fatalities is <strong>7582</strong>. ()</li>
<li>Injuries: The number of registered injuries is <strong>1.4052810^{5}</strong>.</li>
<li>Damage: . In this case, the total amount is of <strong>2.391090710^{11}</strong>.</li>
</ul>
</div>
</div>
<div id="results" class="section level2">
<h2>2. Results</h2>
<div id="harmful-events-for-population-health-1" class="section level3">
<h3>2.1. Harmful events for population health</h3>
<p>This part will focus on identifying which are the atmospheric phenomena that have most impact on the health of the population. The created datased <em>Human_damage2</em> will be used in order to create a graphics that illustrates the results.</p>
<p>The next two graphics represents the number of deads and the number of injuries depending on the type of event defined in the previous part.</p>
<pre class="r"><code> ggplot(Human_damage2,aes(x=Event, group=1))+
geom_bar(stat = "identity", aes(y=Deads))+
labs(x="Event type",y="Deads")+
ggtitle("Number of deads per event type")+
theme_bw()+
scale_y_continuous(lim=c(0,5280), breaks=round(seq(0,6000,by=1000),1))+
theme(panel.grid.minor=element_line(colour="lightgrey"),
panel.grid.major=element_line(colour="grey"),
axis.text.x = element_text(angle=45,hjust = 1,vjust = 1),
plot.title = element_text(face="bold"))</code></pre>
<p><img src="Project2_files/figure-html/unnamed-chunk-14-1.png" title="" alt="" width="672" /></p>
<pre class="r"><code> ggplot(Human_damage2,aes(x=Event, group=1))+
geom_bar(stat = "identity", aes(y=Injuries))+
labs(x="Event type",y="Deads")+
ggtitle("Number of injuries per event type")+
theme_bw()+
scale_y_continuous(lim=c(0,100000), breaks=round(seq(0,100000,by=10000),1))+
theme(panel.grid.minor=element_line(colour="lightgrey"),
panel.grid.major=element_line(colour="grey"),
axis.text.x = element_text(angle=45,hjust = 1,vjust = 1),
plot.title = element_text(face="bold"))</code></pre>
<p><img src="Project2_files/figure-html/unnamed-chunk-14-2.png" title="" alt="" width="672" /></p>
<pre class="r"><code> par(mfrow=c(1,1))</code></pre>
<p>The conclusion is that <strong>Tornado</strong> and <strong>Wind</strong> phenomena are the most dangerous for the population by far.</p>
<p>The next step is to find the concrete events that most affected to the population. The threshold is up to 200 deads and 6000 injuries.</p>
<pre class="r"><code>quantile(Human_damage$Deads, probs=c(0.9, 0.95, 0.975, 1))</code></pre>
<pre><code>## 90% 95% 97.5% 100%
## 38.3 74.8 173.1 5227.0</code></pre>
<pre class="r"><code>quantile(Human_damage$Injuries, probs=c(0.9, 0.95, 0.975, 1))</code></pre>
<pre><code>## 90% 95% 97.5% 100%
## 835.900 1531.350 5327.125 91346.000</code></pre>
<pre class="r"><code>more_deads <- which(Human_damage$Deads > 200)
more_inj <-which(Human_damage$Injuries > 5000)
Human_damage[more_deads, "Type_of_event"]</code></pre>
<pre><code>## [1] "EXCESSIVE HEAT" "LIGHTNING" "TORNADO"</code></pre>
<pre class="r"><code>Human_damage[more_inj, "Type_of_event"]</code></pre>
<pre><code>## [1] "EXCESSIVE HEAT" "FLOOD" "LIGHTNING" "TORNADO"
## [5] "TSTM WIND"</code></pre>
<p>And the event with more deads and injuies correspond to:</p>
<pre class="r"><code>most_dead <- which(Human_damage$Deads == 5227.0)
more_inj <-which(Human_damage$Injuries == 91346.000)
Human_damage[most_dead, "Type_of_event"]</code></pre>
<pre><code>## [1] "TORNADO"</code></pre>
<pre class="r"><code>Human_damage[most_dead, "Type_of_event"]</code></pre>
<pre><code>## [1] "TORNADO"</code></pre>
</div>
<div id="economic-consequences-due-to-atmospheric-phenomena-1" class="section level3">
<h3>2.2. Economic consequences due to atmospheric phenomena</h3>
<p>This part will focus on identifying which are the atmospheric phenomena that have most impact on the economic field. The created datased <em>Money_damage2</em> will be used in order to create a graphics that illustrates the results.</p>
<p>The next graphics represents the total cost depending on the type of event.</p>
<pre class="r"><code> ggplot(Money_damage2,aes(x=Event, group=1))+
geom_bar(stat = "identity", aes(y=Cost))+
labs(x="Event type",y="Cost [$]")+
ggtitle("Total cost per event type")+
theme_bw()+
scale_y_continuous(lim=c(0,1.56e+11), breaks=round(seq(0,1.56e+11,by=2e+10),1))+
theme(panel.grid.minor=element_line(colour="lightgrey"),
panel.grid.major=element_line(colour="grey"),
axis.text.x = element_text(angle=45,hjust = 1,vjust = 1),
plot.title = element_text(face="bold"))</code></pre>
<p><img src="Project2_files/figure-html/unnamed-chunk-17-1.png" title="" alt="" width="672" /></p>
<p>The conclusion is that <strong>Storm/Flood</strong> and <strong>Tornado</strong> phenomena are the most expensive for the Unitet States.</p>
<p>The next step is to find the concrete events that most affected to the economic consequences. The threshold is up to 200 deads and 6000 injuries.</p>
<pre class="r"><code>quantile(Money_damage$Deads, probs=c(0.9, 0.95, 0.975, 1))</code></pre>
<pre><code>## 90% 95% 97.5% 100%
## NA NA NA NA</code></pre>
<pre class="r"><code>more_cost <- which(Money_damage$Deads > 10000000000)
Money_damage[more_cost, "Type_of_event"]</code></pre>
<pre><code>## character(0)</code></pre>
<p>And the event with more deads and injuies correspond to:</p>
<pre class="r"><code>most_cost <- which(Money_damage$Deads == 138007444500)
Money_damage[most_cost, "Type_of_event"]</code></pre>
<pre><code>## character(0)</code></pre>
</div>
</div>
<div id="conclusion" class="section level2">
<h2>Conclusion</h2>
<p>Tornados are the phenomena that kill more people, whereas Floods are the events that cause more destruction and material losses.</p>
<div id="p.s." class="section level3">
<h3>P.S.</h3>
<p>Due to the lack of time, I could not do all the work I wish</p>
</div>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
$(document).ready(function () {
$('tr.header').parent('thead').parent('table').addClass('table table-condensed');
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>