library(tidyverse)
## -- Attaching packages -------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.3.0     v purrr   0.3.2
## v tibble  2.1.3     v dplyr   0.8.3
## v tidyr   1.0.0     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.4.0
## -- Conflicts ----------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(ggplot2)
library(readr)
library(maps)
## 
## Attaching package: 'maps'
## The following object is masked from 'package:purrr':
## 
##     map
library(viridis)
## Loading required package: viridisLite
library(naivebayes)
## naivebayes 0.9.6 loaded
library(caret)
## Loading required package: lattice
## 
## Attaching package: 'caret'
## The following object is masked from 'package:purrr':
## 
##     lift
library(e1071)
library(lattice)
chile<-read.csv2("covchile.csv")
chile
##                             FECHA INFECTADOS RECUPERADOR MUERTOS
## 1       lunes, 2 de marzo de 2020          0           0       0
## 2      martes, 3 de marzo de 2020          1           0       0
## 3   mi‚rcoles, 4 de marzo de 2020          1           0       0
## 4      jueves, 5 de marzo de 2020          4           0       0
## 5     viernes, 6 de marzo de 2020          4           0       0
## 6      s bado, 7 de marzo de 2020          4           0       0
## 7     domingo, 8 de marzo de 2020          8           0       0
## 8       lunes, 9 de marzo de 2020          8           0       0
## 9     martes, 10 de marzo de 2020         13           0       0
## 10 mi‚rcoles, 11 de marzo de 2020         23           0       0
## 11    jueves, 12 de marzo de 2020         23           0       0
## 12   viernes, 13 de marzo de 2020         43           0       0
## 13    s bado, 14 de marzo de 2020         61           0       0
## 14   domingo, 15 de marzo de 2020         74           0       0
## 15     lunes, 16 de marzo de 2020        155           0       0
boxplot(chile$INFECTADOS)

plot(chile$INFECTADOS)

summary(chile)
##                           FECHA     INFECTADOS      RECUPERADOR
##  domingo, 15 de marzo de 2020:1   Min.   :  0.00   Min.   :0   
##  domingo, 8 de marzo de 2020 :1   1st Qu.:  4.00   1st Qu.:0   
##  jueves, 12 de marzo de 2020 :1   Median :  8.00   Median :0   
##  jueves, 5 de marzo de 2020  :1   Mean   : 28.13   Mean   :0   
##  lunes, 16 de marzo de 2020  :1   3rd Qu.: 33.00   3rd Qu.:0   
##  lunes, 2 de marzo de 2020   :1   Max.   :155.00   Max.   :0   
##  (Other)                     :9                                
##     MUERTOS 
##  Min.   :0  
##  1st Qu.:0  
##  Median :0  
##  Mean   :0  
##  3rd Qu.:0  
##  Max.   :0  
## 
library(githubinstall)

covid<-read.csv("../R STUDIO/03-16-2020.csv")
covid
##                   Province.State                   Country.Region
## 1                          Hubei                            China
## 2                                                           Italy
## 3                                                            Iran
## 4                                                           Spain
## 5                                                    Korea, South
## 6                                                         Germany
## 7                         France                           France
## 8                                                     Switzerland
## 9                 United Kingdom                   United Kingdom
## 10                   Netherlands                      Netherlands
## 11                     Guangdong                            China
## 12                                                         Norway
## 13                         Henan                            China
## 14                      Zhejiang                            China
## 15                                                         Sweden
## 16                                                        Belgium
## 17                                                        Austria
## 18                         Hunan                            China
## 19                         Anhui                            China
## 20                      New York                               US
## 21                       Jiangxi                            China
## 22                       Denmark                          Denmark
## 23                    Washington                               US
## 24                                                          Japan
## 25                      Shandong                            China
## 26              Diamond Princess                      Cruise Ship
## 27                       Jiangsu                            China
## 28                     Chongqing                            China
## 29                                                       Malaysia
## 30                    California                               US
## 31                       Sichuan                            China
## 32                  Heilongjiang                            China
## 33                       Beijing                            China
## 34                                                          Qatar
## 35                      Shanghai                            China
## 36                                                         Greece
## 37                                                       Portugal
## 38                         Hebei                            China
## 39                                                        Czechia
## 40                        Fujian                            China
## 41                                                        Finland
## 42                                                         Israel
## 43                                                       Slovenia
## 44                       Guangxi                            China
## 45                       Shaanxi                            China
## 46                                                      Singapore
## 47                                                        Bahrain
## 48                                                        Estonia
## 49                                                         Brazil
## 50                 Massachusetts                               US
## 51                                                        Iceland
## 52                    New Jersey                               US
## 53                       Ontario                           Canada
## 54                                                         Poland
## 55                        Yunnan                            China
## 56               New South Wales                        Australia
## 57                                                        Ireland
## 58                        Hainan                            China
## 59                      Colorado                               US
## 60                                                        Romania
## 61                                                          Chile
## 62                     Hong Kong                            China
## 63                       Florida                               US
## 64                                                          Egypt
## 65                                                       Thailand
## 66                       Guizhou                            China
## 67                                                    Philippines
## 68                       Tianjin                            China
## 69                                                       Pakistan
## 70                     Louisiana                               US
## 71                                                      Indonesia
## 72                         Gansu                            China
## 73                        Shanxi                            China
## 74                      Liaoning                            China
## 75                                                           Iraq
## 76                                                         Kuwait
## 77                       Georgia                               US
## 78                                                          India
## 79                                                   Saudi Arabia
## 80                                                     San Marino
## 81                      Illinois                               US
## 82              British Columbia                           Canada
## 83                                                        Lebanon
## 84                                           United Arab Emirates
## 85                         Jilin                            China
## 86                                                         Russia
## 87                                                           Peru
## 88                         Texas                               US
## 89                                                     Luxembourg
## 90                  Pennsylvania                               US
## 91                      Xinjiang                            China
## 92                Inner Mongolia                            China
## 93                       Ningxia                            China
## 94                      Victoria                        Australia
## 95                    Queensland                        Australia
## 96                                                        Taiwan*
## 97                                                       Slovakia
## 98                                                   South Africa
## 99                                                        Vietnam
## 100                                                       Croatia
## 101                                                     Argentina
## 102                      Alberta                           Canada
## 103                                                        Panama
## 104                                                        Serbia
## 105                                                       Algeria
## 106                                                        Brunei
## 107                                                      Colombia
## 108                    Minnesota                               US
## 109                                                        Mexico
## 110                     Michigan                               US
## 111                                                       Armenia
## 112                                                      Bulgaria
## 113                    Tennessee                               US
## 114                                                       Albania
## 115                       Quebec                           Canada
## 116                         Ohio                               US
## 117                     Virginia                               US
## 118             Diamond Princess                               US
## 119                    Wisconsin                               US
## 120                       Nevada                               US
## 121                     Maryland                               US
## 122                                                       Hungary
## 123                       Oregon                               US
## 124                         Utah                               US
## 125               North Carolina                               US
## 126                                                       Ecuador
## 127                                                       Belarus
## 128                                                    Costa Rica
## 129                                                        Latvia
## 130                                                        Cyprus
## 131                                                       Georgia
## 132               South Carolina                               US
## 133                                                         Malta
## 134                  Connecticut                               US
## 135              South Australia                        Australia
## 136                                                       Morocco
## 137                      Alabama                               US
## 138            Western Australia                        Australia
## 139                                                     Sri Lanka
## 140                                        Bosnia and Herzegovina
## 141                      Indiana                               US
## 142                                                       Senegal
## 143                                                       Moldova
## 144                         Iowa                               US
## 145                                                          Oman
## 146                     Arkansas                               US
## 147         District of Columbia                               US
## 148                                                   Afghanistan
## 149                     Kentucky                               US
## 150                 Rhode Island                               US
## 151                                                       Tunisia
## 152               Grand Princess                               US
## 153                      Qinghai                            China
## 154                Faroe Islands                          Denmark
## 155                                               North Macedonia
## 156                                                        Turkey
## 157                      Arizona                               US
## 158                     Nebraska                               US
## 159                                                        Jordan
## 160                                                     Lithuania
## 161                        Maine                               US
## 162                New Hampshire                               US
## 163                   New Mexico                               US
## 164                                                     Venezuela
## 165                                                    Azerbaijan
## 166                                                  Burkina Faso
## 167                                                    Martinique
## 168                                                      Maldives
## 169                  Mississippi                               US
## 170                      Vermont                               US
## 171                                                       Bolivia
## 172                        Macau                            China
## 173                                            Dominican Republic
## 174                                                 French Guiana
## 175                       Kansas                               US
## 176                                                       Jamaica
## 177                                                    Kazakhstan
## 178                     Oklahoma                               US
## 179                 South Dakota                               US
## 180                                                       Reunion
## 181                                                    Bangladesh
## 182                                                   New Zealand
## 183                                                      Paraguay
## 184                     Delaware                               US
## 185                                                       Uruguay
## 186                     Tasmania                        Australia
## 187                                                      Cambodia
## 188                     Manitoba                           Canada
## 189                 Saskatchewan                           Canada
## 190                                                        Monaco
## 191                       Hawaii                               US
## 192                      Montana                               US
## 193                                                       Ukraine
## 194                New Brunswick                           Canada
## 195                                                         Ghana
## 196                                                    Guadeloupe
## 197                                                      Honduras
## 198                     Missouri                               US
## 199              Channel Islands                   United Kingdom
## 200                                                    Uzbekistan
## 201                  Nova Scotia                           Canada
## 202                                                      Ethiopia
## 203                French Guiana                           France
## 204                                                        Rwanda
## 205                        Idaho                               US
## 206                  Puerto Rico                               US
## 207                                                      Cameroon
## 208                                                          Cuba
## 209                                                        Guyana
## 210                                                 Liechtenstein
## 211                                           Trinidad and Tobago
## 212             French Polynesia                           France
## 213                   Guadeloupe                           France
## 214             Saint Barthelemy                           France
## 215                                                          Guam
## 216                                                         Kenya
## 217                                                   Puerto Rico
## 218                                                    Seychelles
## 219                         Guam                               US
## 220                      Wyoming                               US
## 221                                                       Andorra
## 222                                                         Aruba
## 223 Australian Capital Territory                        Australia
## 224               Grand Princess                           Canada
## 225                                              Congo (Kinshasa)
## 226                    St Martin                           France
## 227                                                     Guatemala
## 228                                                        Jersey
## 229                                                        Kosovo
## 230                                                       Namibia
## 231                                                       Nigeria
## 232                                                   Saint Lucia
## 233                                           Antigua and Barbuda
## 234           Northern Territory                        Australia
## 235                                                         Benin
## 236                                                        Bhutan
## 237    Newfoundland and Labrador                           Canada
## 238         Prince Edward Island                           Canada
## 239                                      Central African Republic
## 240                        Tibet                            China
## 241                                           Congo (Brazzaville)
## 242                                                 Cote d'Ivoire
## 243                                             Equatorial Guinea
## 244                                                      Eswatini
## 245                      Mayotte                           France
## 246                                                         Gabon
## 247                                                     Greenland
## 248                                                      Guernsey
## 249                                                        Guinea
## 250                                                      Holy See
## 251                                                       Liberia
## 252                                                    Mauritania
## 253                                                       Mayotte
## 254                                                      Mongolia
## 255                                                         Nepal
## 256                      Curacao                      Netherlands
## 257                                         Republic of the Congo
## 258                              Saint Vincent and the Grenadines
## 259                                                       Somalia
## 260                                                         Sudan
## 261                                                      Suriname
## 262                                                      Tanzania
## 263                                                   The Bahamas
## 264                                                          Togo
## 265                       Alaska                               US
## 266                 North Dakota                               US
## 267               Virgin Islands                               US
## 268               Cayman Islands                   United Kingdom
## 269                    Gibraltar                   United Kingdom
## 270        From Diamond Princess                        Australia
## 271                West Virginia                               US
## 272                                occupied Palestinian territory
##             Last.Update Confirmed Deaths Recovered Latitude Longitude
## 1   2020-03-16T14:38:45     67798   3099     55142  30.9756  112.2707
## 2   2020-03-16T17:33:03     27980   2158      2749  41.8719   12.5674
## 3   2020-03-16T14:38:45     14991    853      4590  32.4279   53.6880
## 4   2020-03-16T20:13:11      9942    342       530  40.4637   -3.7492
## 5   2020-03-16T14:38:45      8236     75      1137  35.9078  127.7669
## 6   2020-03-16T20:13:11      7272     17        67  51.1657   10.4515
## 7   2020-03-16T20:13:11      6633    148        12  46.2276    2.2137
## 8   2020-03-15T18:20:18      2200     14         4  46.8182    8.2275
## 9   2020-03-16T19:13:13      1543     55        20  55.3781   -3.4360
## 10  2020-03-16T14:38:46      1413     24         2  52.1326    5.2913
## 11  2020-03-16T01:53:03      1361      8      1306  23.3417  113.4244
## 12  2020-03-16T21:13:12      1333      3         1  60.4720    8.4689
## 13  2020-03-14T09:53:08      1273     22      1250  33.8820  113.6140
## 14  2020-03-16T14:38:45      1231      1      1216  29.1832  120.0934
## 15  2020-03-16T14:38:45      1103      6         1  60.1282   18.6435
## 16  2020-03-16T14:38:45      1058      5         1  50.5039    4.4699
## 17  2020-03-16T15:13:09      1018      3         6  47.5162   14.5501
## 18  2020-03-14T08:33:03      1018      4      1014  27.6104  111.7088
## 19  2020-03-11T02:18:14       990      6       984  31.8257  117.2264
## 20  2020-03-16T21:53:03       967     10         0  42.1657  -74.9481
## 21  2020-03-12T02:13:04       935      1       934  27.6140  115.7221
## 22  2020-03-16T18:33:03       914      3         1  56.2639    9.5018
## 23  2020-03-16T23:53:03       904     48         1  47.4009 -121.4905
## 24  2020-03-16T14:38:45       825     27       144  36.2048  138.2529
## 25  2020-03-16T14:38:45       760      7       746  36.3427  118.1498
## 26  2020-03-13T14:13:25       696      7       325  35.4498  139.6649
## 27  2020-03-15T01:53:02       631      0       631  32.9711  119.4550
## 28  2020-03-15T03:53:04       576      6       570  30.0572  107.8740
## 29  2020-03-16T14:38:45       566      0        42   4.2105  101.9758
## 30  2020-03-16T23:53:03       557      7         6  36.1162 -119.6816
## 31  2020-03-15T18:20:18       539      3       516  30.6171  102.7103
## 32  2020-03-16T14:38:45       482     13       455  47.8620  127.7615
## 33  2020-03-16T14:38:45       452      8       360  40.1824  116.4142
## 34  2020-03-16T15:13:09       439      0         4  25.3548   51.1839
## 35  2020-03-16T14:38:45       355      3       325  31.2020  121.4491
## 36  2020-03-16T00:22:10       331      4         8  39.0742   21.8243
## 37  2020-03-16T14:38:45       331      0         3  39.3999   -8.2245
## 38  2020-03-13T11:09:03       318      6       310  38.0428  114.5149
## 39  2020-03-16T23:53:02       298      0         3  49.8175   15.4730
## 40  2020-03-11T02:18:14       296      1       295  26.0789  117.9874
## 41  2020-03-16T14:38:45       277      0        10  61.9241   25.7482
## 42  2020-03-16T14:38:45       255      0         4  31.0461   34.8516
## 43  2020-03-16T14:38:45       253      1         0  46.1512   14.9955
## 44  2020-03-16T14:38:45       252      2       248  23.8298  108.7881
## 45  2020-03-16T14:38:45       245      2       233  35.1917  108.8701
## 46  2020-03-16T14:38:45       243      0       109   1.3521  103.8198
## 47  2020-03-16T20:33:03       214      1        77  26.0667   50.5577
## 48  2020-03-16T14:38:45       205      0         1  58.5953   25.0136
## 49  2020-03-16T02:33:08       200      0         1 -14.2350  -51.9253
## 50  2020-03-16T21:53:03       197      0         1  42.2302  -71.5301
## 51  2020-03-16T02:13:15       180      0         0  64.9631  -19.0208
## 52  2020-03-16T22:13:21       178      2         1  40.2989  -74.5210
## 53  2020-03-16T16:13:26       177      0         5  51.2538  -85.3232
## 54  2020-03-16T21:13:17       177      4        13  51.9194   19.1451
## 55  2020-03-16T23:53:02       176      2       172  24.9740  101.4870
## 56  2020-03-16T14:38:46       171      2         4 -33.8688  151.2093
## 57  2020-03-16T14:38:45       169      2         0  53.1424   -7.6921
## 58  2020-03-16T14:38:45       168      6       161  19.1959  109.7453
## 59  2020-03-16T23:53:03       160      1         0  39.0598 -105.3111
## 60  2020-03-16T14:38:45       158      0         9  45.9432   24.9668
## 61  2020-03-16T14:38:45       155      0         0 -35.6751  -71.5430
## 62  2020-03-16T14:38:45       155      4        84  22.3000  114.2000
## 63  2020-03-16T22:13:21       155      5         0  27.7663  -81.6868
## 64  2020-03-16T15:53:45       150      2        27  26.8206   30.8025
## 65  2020-03-16T14:38:45       147      1        35  15.8700  100.9925
## 66  2020-03-16T14:38:45       146      2       144  26.8154  106.8748
## 67  2020-03-16T14:38:45       142     12         2  12.8797  121.7740
## 68  2020-03-15T18:20:18       136      3       133  39.3054  117.3230
## 69  2020-03-16T14:38:45       136      0         2  30.3753   69.3451
## 70  2020-03-16T22:13:21       136      3         0  31.1695  -91.8678
## 71  2020-03-16T14:38:45       134      5         8  -0.7893  113.9213
## 72  2020-03-15T18:20:18       133      2        91  36.0611  103.8343
## 73  2020-03-13T11:09:03       133      0       133  37.5777  112.2922
## 74  2020-03-16T14:38:45       125      1       115  41.2956  122.6085
## 75  2020-03-16T02:13:15       124     10        26  33.2232   43.6793
## 76  2020-03-16T14:38:45       123      0         9  29.3117   47.4818
## 77  2020-03-16T16:53:06       121      1         0  33.0406  -83.6431
## 78  2020-03-16T14:38:45       119      2        13  20.5937   78.9629
## 79  2020-03-16T01:13:12       118      0         2  23.8859   45.0792
## 80  2020-03-16T01:33:03       109      7         4  43.9424   12.4578
## 81  2020-03-16T22:13:21       105      0         2  40.3495  -88.9861
## 82  2020-03-16T19:13:13       103      4         4  53.7267 -127.6476
## 83  2020-03-16T00:22:11        99      3         1  33.8547   35.8623
## 84  2020-03-16T00:22:11        98      0        23  23.4241   53.8478
## 85  2020-03-16T00:22:10        93      1        92  43.6661  126.1923
## 86  2020-03-16T14:38:45        90      0         8  61.5240  105.3188
## 87  2020-03-16T14:38:45        86      0         0  -9.1900  -75.0152
## 88  2020-03-16T23:53:03        85      0         0  31.0545  -97.5635
## 89  2020-03-16T01:53:03        77      1         0  49.8153    6.1296
## 90  2020-03-16T20:13:20        77      0         0  40.5908  -77.2098
## 91  2020-03-11T02:18:14        76      3        73  41.1129   85.2401
## 92  2020-03-16T14:38:45        75      1        73  44.0935  113.9448
## 93  2020-03-16T14:38:45        75      0        75  37.2692  106.1655
## 94  2020-03-16T14:38:45        71      0         8 -37.8136  144.9631
## 95  2020-03-16T14:38:46        68      0         8 -28.0167  153.4000
## 96  2020-03-16T14:38:45        67      1        20  23.7000  121.0000
## 97  2020-03-16T14:38:45        63      0         0  48.6690   19.6990
## 98  2020-03-16T14:38:45        62      0         0 -30.5595   22.9375
## 99  2020-03-16T14:53:04        61      0        16  14.0583  108.2772
## 100 2020-03-16T14:38:45        57      0         2  45.1000   15.2000
## 101 2020-03-16T14:38:45        56      2         1 -38.4161  -63.6167
## 102 2020-03-16T02:33:09        56      0         0  53.9333 -116.5765
## 103 2020-03-16T14:38:45        55      1         0   8.5380  -80.7821
## 104 2020-03-16T14:38:45        55      0         1  44.0165   21.0059
## 105 2020-03-16T14:38:45        54      4        12  28.0339    1.6596
## 106 2020-03-16T14:38:45        54      0         0   4.5353  114.7277
## 107 2020-03-16T14:38:45        54      0         0   4.5709  -74.2973
## 108 2020-03-16T16:53:06        54      0         0  45.6945  -93.9002
## 109 2020-03-16T14:38:45        53      0         4  23.6345 -102.5528
## 110 2020-03-16T14:38:46        53      0         0  43.3266  -84.5361
## 111 2020-03-16T21:13:17        52      0         0  40.0691   45.0382
## 112 2020-03-16T14:38:45        52      2         0  42.7339   25.4858
## 113 2020-03-16T22:13:21        52      0         0  35.7478  -86.6923
## 114 2020-03-16T14:38:45        51      1         0  41.1533   20.1683
## 115 2020-03-16T20:13:20        50      0         0  52.9399  -73.5491
## 116 2020-03-16T20:13:21        50      0         0  40.3888  -82.7649
## 117 2020-03-16T22:13:21        49      1         0  37.7693  -78.1700
## 118 2020-03-16T16:53:06        47      0         0  35.4437  139.6380
## 119 2020-03-16T20:13:20        47      0         1  44.2685  -89.6165
## 120 2020-03-16T20:13:20        45      1         0  38.3135 -117.0554
## 121 2020-03-16T20:13:20        41      0         3  39.0639  -76.8021
## 122 2020-03-16T14:38:45        39      1         1  47.1625   19.5033
## 123 2020-03-16T02:33:09        39      1         0  44.5720 -122.0709
## 124 2020-03-16T22:33:03        39      0         0  40.1500 -111.8624
## 125 2020-03-16T23:53:03        38      0         0  35.6301  -79.8064
## 126 2020-03-16T02:33:08        37      2         0  -1.8312  -78.1834
## 127 2020-03-16T14:38:45        36      0         3  53.7098   27.9534
## 128 2020-03-16T02:33:08        35      0         0   9.7489  -83.7534
## 129 2020-03-16T14:38:45        34      0         1  56.8796   24.6032
## 130 2020-03-16T02:33:08        33      0         0  35.1264   33.4299
## 131 2020-03-16T02:13:16        33      0         1  42.3154   43.3569
## 132 2020-03-16T22:33:03        33      1         0  33.8569  -80.9450
## 133 2020-03-16T15:33:03        30      0         2  35.9375   14.3754
## 134 2020-03-16T20:13:20        30      0         0  41.5978  -72.7554
## 135 2020-03-16T14:38:46        29      0         3 -34.9285  138.6007
## 136 2020-03-16T14:38:45        29      1         1  31.7917   -7.0926
## 137 2020-03-16T22:33:03        29      0         0  32.3182  -86.9023
## 138 2020-03-16T14:38:46        28      1         0 -31.9505  115.8605
## 139 2020-03-16T15:53:45        28      0         1   7.8731   80.7718
## 140 2020-03-16T21:13:17        25      0         0  43.9159   17.6791
## 141 2020-03-16T22:33:03        25      1         0  39.8494  -86.2583
## 142 2020-03-16T01:13:13        24      0         2  14.4974  -14.4524
## 143 2020-03-16T00:22:11        23      0         0  47.4116   28.3699
## 144 2020-03-16T23:53:03        23      0         0  42.0115  -93.2105
## 145 2020-03-16T00:22:11        22      0         9  21.4735   55.9754
## 146 2020-03-16T17:13:23        22      0         0  34.9697  -92.3731
## 147 2020-03-16T23:53:03        22      0         0  38.8974  -77.0268
## 148 2020-03-16T14:38:45        21      0         1  33.9391   67.7100
## 149 2020-03-16T18:33:03        21      1         1  37.6681  -84.6701
## 150 2020-03-16T18:14:12        21      0         0  41.6809  -71.5118
## 151 2020-03-16T01:13:13        20      0         0  33.8869    9.5375
## 152 2020-03-16T17:13:23        20      0         0  37.6489 -122.6655
## 153 2020-03-11T02:18:14        18      0        18  35.7452   95.9956
## 154 2020-03-16T14:38:45        18      0         0  61.8926   -6.9118
## 155 2020-03-16T14:38:45        18      0         1  41.6086   21.7453
## 156 2020-03-16T01:13:13        18      0         0  38.9637   35.2433
## 157 2020-03-16T17:13:23        18      0         1  33.7298 -111.4312
## 158 2020-03-16T17:13:23        18      0         0  41.1254  -98.2681
## 159 2020-03-16T15:13:35        17      0         1  30.5852   36.2384
## 160 2020-03-16T14:38:45        17      0         1  55.1694   23.8813
## 161 2020-03-16T18:14:12        17      0         0  44.6939  -69.3819
## 162 2020-03-16T22:33:03        17      0         0  43.4525  -71.5639
## 163 2020-03-16T02:53:12        17      0         0  34.8405 -106.2485
## 164 2020-03-16T00:53:03        17      0         0   6.4238  -66.5897
## 165 2020-03-16T14:38:45        15      1         6  40.1431   47.5769
## 166 2020-03-16T14:38:45        15      0         0  12.2383   -1.5616
## 167 2020-03-16T14:38:45        15      1         0  14.6415  -61.0242
## 168 2020-03-15T18:20:18        13      0         0   3.2028   73.2207
## 169 2020-03-16T22:33:03        13      0         0  32.7416  -89.6787
## 170 2020-03-16T17:13:23        12      0         0  44.0459  -72.7107
## 171 2020-03-16T14:38:45        11      0         0 -16.2902  -63.5887
## 172 2020-03-16T00:22:10        11      0        10  22.1667  113.5500
## 173 2020-03-14T20:53:02        11      0         0  18.7357  -70.1627
## 174 2020-03-16T14:38:46        11      0         0   3.9339  -53.1258
## 175 2020-03-16T17:13:23        11      1         0  38.5266  -96.7265
## 176 2020-03-16T01:53:03        10      0         2  18.1096  -77.2975
## 177 2020-03-16T14:38:45        10      0         0  48.0196   66.9237
## 178 2020-03-16T18:14:12        10      0         0  35.5653  -96.9289
## 179 2020-03-16T20:13:20        10      1         0  44.2998  -99.4388
## 180 2020-03-16T14:38:45         9      0         0 -21.1151   55.5364
## 181 2020-03-16T14:38:45         8      0         2  23.6850   90.3563
## 182 2020-03-15T18:20:18         8      0         0 -40.9006  174.8860
## 183 2020-03-16T14:38:45         8      0         0 -23.4425  -58.4438
## 184 2020-03-16T20:13:20         8      0         0  39.3185  -75.5071
## 185 2020-03-16T14:38:45         8      0         0 -32.5228  -55.7658
## 186 2020-03-16T14:38:46         7      0         0 -41.4545  145.9707
## 187 2020-03-14T12:53:07         7      0         1  12.5657  104.9910
## 188 2020-03-16T02:53:12         7      0         0  53.7609  -98.8139
## 189 2020-03-16T20:13:20         7      0         0  52.9399 -106.4509
## 190 2020-03-16T14:38:45         7      0         0  43.7384    7.4246
## 191 2020-03-16T02:53:12         7      0         0  21.0943 -157.4983
## 192 2020-03-15T18:20:19         7      0         0  46.9219 -110.4544
## 193 2020-03-16T21:13:17         7      1         0  48.3794   31.1656
## 194 2020-03-16T02:53:12         6      0         0  46.5653  -66.4619
## 195 2020-03-15T18:20:18         6      0         0   7.9465   -1.0232
## 196 2020-03-16T14:38:45         6      0         0  16.2650  -61.5510
## 197 2020-03-16T14:38:45         6      0         0  15.2000  -86.2419
## 198 2020-03-16T17:13:23         6      0         0  38.4561  -92.2884
## 199 2020-03-16T14:38:45         6      0         0  49.3723   -2.3644
## 200 2020-03-16T14:38:45         6      0         0  41.3775   64.5853
## 201 2020-03-16T17:53:03         5      0         0  44.6820  -63.7443
## 202 2020-03-16T14:38:45         5      0         0   9.1450   40.4897
## 203 2020-03-16T14:38:45         5      0         0   4.0000  -53.0000
## 204 2020-03-16T01:33:03         5      0         0  -1.9403   29.8739
## 205 2020-03-15T18:20:19         5      0         0  44.2405 -114.4788
## 206 2020-03-16T00:22:11         5      0         0  18.2208  -66.5901
## 207 2020-03-16T02:33:08         4      0         0   3.8480   11.5021
## 208 2020-03-13T23:53:02         4      0         0  21.5218  -77.7812
## 209 2020-03-15T18:20:19         4      1         0   4.8604  -58.9302
## 210 2020-03-14T20:53:02         4      0         0  47.1660    9.5554
## 211 2020-03-16T14:38:45         4      0         0  10.6918  -61.2225
## 212 2020-03-15T18:20:19         3      0         0 -17.6797 -149.4068
## 213 2020-03-16T14:38:45         3      0         0  16.2500  -61.5833
## 214 2020-03-16T14:38:45         3      0         0  17.9000  -62.8333
## 215 2020-03-16T02:13:16         3      0         0  13.4443  144.7937
## 216 2020-03-16T00:22:11         3      0         0  -0.0236   37.9062
## 217 2020-03-16T14:38:45         3      0         0  18.2000  -66.5000
## 218 2020-03-16T01:13:13         3      0         0  -4.6796   55.4920
## 219 2020-03-15T18:20:19         3      0         0  13.4443  144.7937
## 220 2020-03-15T02:53:03         3      0         0  42.7560 -107.3025
## 221 2020-03-16T02:33:08         2      0         1  42.5063    1.5218
## 222 2020-03-13T23:53:03         2      0         0  12.5211  -69.9683
## 223 2020-03-16T14:38:46         2      0         0 -35.4735  149.0124
## 224 2020-03-16T00:22:11         2      0         0  37.6489 -122.6655
## 225 2020-03-13T22:22:02         2      0         0  -4.0383   21.7587
## 226 2020-03-14T16:33:03         2      0         0  18.0708  -63.0501
## 227 2020-03-16T14:38:45         2      1         0  15.7835  -90.2308
## 228 2020-03-14T16:33:03         2      0         0  49.1900   -2.1100
## 229 2020-03-15T18:20:19         2      0         0  42.6026   20.9030
## 230 2020-03-14T16:33:03         2      0         0 -22.9576   18.4904
## 231 2020-03-13T22:22:02         2      0         0   9.0820    8.6753
## 232 2020-03-16T00:22:11         2      0         0  13.9094  -60.9789
## 233 2020-03-15T18:20:19         1      0         0  17.0608  -61.7964
## 234 2020-03-14T01:53:03         1      0         0 -12.4634  130.8456
## 235 2020-03-16T14:38:46         1      0         0   9.3077    2.3158
## 236 2020-03-13T22:22:02         1      0         0  27.5142   90.4336
## 237 2020-03-15T02:13:21         1      0         0  53.1355  -57.6604
## 238 2020-03-15T02:13:21         1      0         0  46.5107  -63.4168
## 239 2020-03-16T03:33:03         1      0         0   6.6111   20.9394
## 240 2020-03-11T02:18:14         1      0         1  31.6927   88.0924
## 241 2020-03-16T14:38:45         1      0         0  -0.2280   15.8277
## 242 2020-03-13T22:22:02         1      0         0   7.5400   -5.5471
## 243 2020-03-15T06:41:54         1      0         0   1.5000   10.0000
## 244 2020-03-15T06:41:54         1      0         0 -26.5225   31.4659
## 245 2020-03-16T14:38:45         1      0         0 -12.8431   45.1383
## 246 2020-03-14T13:33:04         1      0         0  -0.8037   11.6094
## 247 2020-03-16T16:53:06         1      0         0  71.7069  -42.6043
## 248 2020-03-13T22:22:03         1      0         0  49.4500   -2.5800
## 249 2020-03-15T06:41:54         1      0         0   9.9456   -9.6966
## 250 2020-03-13T22:22:02         1      0         0  41.9029   12.4534
## 251 2020-03-16T14:38:46         1      0         0   6.4281   -9.4295
## 252 2020-03-15T18:20:19         1      0         0  21.0079  -10.9408
## 253 2020-03-16T14:38:45         1      0         0 -12.8275   45.1662
## 254 2020-03-13T22:22:02         1      0         0  46.8625  103.8467
## 255 2020-03-13T22:22:03         1      0         1  28.3949   84.1240
## 256 2020-03-16T00:22:11         1      0         0  12.1696  -68.9900
## 257 2020-03-16T03:33:03         1      0         0  -1.4400   15.5560
## 258 2020-03-14T16:33:03         1      0         0  12.9843  -61.2872
## 259 2020-03-16T14:38:46         1      0         0   5.1521   46.1996
## 260 2020-03-14T01:13:32         1      1         0  12.8628   30.2176
## 261 2020-03-14T16:33:03         1      0         0   3.9193  -56.0278
## 262 2020-03-16T14:38:45         1      0         0  -6.3690   34.8888
## 263 2020-03-16T03:33:03         1      0         0  24.2500  -76.0000
## 264 2020-03-13T22:22:02         1      0         0   8.6195    0.8248
## 265 2020-03-13T14:53:03         1      0         0  61.3707 -152.4044
## 266 2020-03-12T09:33:03         1      0         0  47.5289  -99.7840
## 267 2020-03-16T00:22:11         1      0         0  18.3358  -64.8963
## 268 2020-03-16T14:53:04         1      1         0  19.3133  -81.2546
## 269 2020-03-14T16:33:03         1      0         1  36.1408   -5.3536
## 270 2020-03-14T02:33:04         0      0         0  35.4437  139.6380
## 271 2020-03-10T02:33:04         0      0         0  38.4912  -80.9545
## 272 2020-03-11T20:53:02         0      0         0  31.9522   35.2332
library(ggplot2)  


muerteCOVID<-covid[, 4:5]     


ggplot(muerteCOVID, aes(x=Confirmed, y=Deaths)) + geom_point()

library(neuralnet)     
## 
## Attaching package: 'neuralnet'
## The following object is masked from 'package:dplyr':
## 
##     compute
maxs <- apply(muerteCOVID, 2, max) # Máximo valor de las variables
mins <- apply(muerteCOVID, 2, min) # Mínimo valor de las variables
scaled <- as.data.frame(scale(muerteCOVID, center=mins, scale=maxs-mins))

head(cbind(muerteCOVID, scaled))
##   Confirmed Deaths Confirmed      Deaths
## 1     67798   3099 1.0000000 1.000000000
## 2     27980   2158 0.4126965 0.696353662
## 3     14991    853 0.2211127 0.275250081
## 4      9942    342 0.1466415 0.110358180
## 5      8236     75 0.1214785 0.024201355
## 6      7272     17 0.1072598 0.005485641
library(gridExtra)
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
plot1 <- ggplot(muerteCOVID, aes(x=Confirmed, y=Deaths)) + geom_point()
plot2 <- ggplot(scaled, aes(x=Confirmed, y=Deaths)) + geom_point()
grid.arrange(plot1, plot2, ncol=2)

library(neuralnet)
mod1 <- neuralnet(Deaths ~ Confirmed, data=scaled, hidden=c(3), threshold=0.01)

plot(mod1, rep="best")

names(mod1) # Elementos que tiene al interior mod1
##  [1] "call"                "response"            "covariate"          
##  [4] "model.list"          "err.fct"             "act.fct"            
##  [7] "linear.output"       "data"                "exclude"            
## [10] "net.result"          "weights"             "generalized.weights"
## [13] "startweights"        "result.matrix"

Predicción

test <- data.frame(Deaths = scaled$Deaths)
myprediction <- compute(x=mod1, covariate=test)

myprediction$net.result[1:5]  # Esto esta como escalar, se vuelve a su forma original
## [1] 1.009606624 1.014730640 0.378897628 0.044255734 0.003893118
#confirmados
yhat_red <- myprediction$net.result * (max(muerteCOVID$Confirmed)-min(muerteCOVID$Confirmed))+min(muerteCOVID$Confirmed)
muerteCOVID$yhat_red <- yhat_red
yhat_red[1:5] 
## [1] 68449.3099 68796.7079 25688.5014  3000.4503   263.9456
#muertos
yhat_red <- myprediction$net.result * (max(muerteCOVID$Deaths)-min(muerteCOVID$Deaths))+min(muerteCOVID$Deaths)
muerteCOVID$yhat_red <- yhat_red
yhat_red[1:5] 
## [1] 3128.77093 3144.65025 1174.20375  137.14852   12.06477

H0: NO ES PANDEMIA YA QUE POSEE DISTRIBUCIÓN GAUSSIANA

RECHAZO DE H0, CLARAMENTE EL MODELO NO ES FACTIBLE, YA QUE ESTAMOS TRATANDO CON UNA DISTRIBUCIÓN EXPONENCIAL O SIMILAR *** ESTO DEMUESTRA EL EFECTO DE PANDEMIA ***

ggplot(muerteCOVID, aes(x=Confirmed, y=yhat_red)) + geom_point() +
  geom_abline(intercept=0, slope=1, color="blue", linetype="dashed", size=1.5)