DengAI, Predicting the Spread of Desease

Libraries

library(neuralnet)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.6.2
library(ggfortify)
## Warning: package 'ggfortify' was built under R version 3.6.2
library(forecast)
## Warning: package 'forecast' was built under R version 3.6.2
## Registered S3 method overwritten by 'xts':
##   method     from
##   as.zoo.xts zoo
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## Registered S3 methods overwritten by 'forecast':
##   method                 from     
##   autoplot.Arima         ggfortify
##   autoplot.acf           ggfortify
##   autoplot.ar            ggfortify
##   autoplot.bats          ggfortify
##   autoplot.decomposed.ts ggfortify
##   autoplot.ets           ggfortify
##   autoplot.forecast      ggfortify
##   autoplot.stl           ggfortify
##   autoplot.ts            ggfortify
##   fitted.ar              ggfortify
##   fortify.ts             ggfortify
##   residuals.ar           ggfortify
library(psych)
## Warning: package 'psych' was built under R version 3.6.2
## 
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
library(stargazer)
## 
## Please cite as:
##  Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2.2. https://CRAN.R-project.org/package=stargazer
library(vars)
## Loading required package: MASS
## Warning: package 'MASS' was built under R version 3.6.2
## Loading required package: strucchange
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 3.6.2
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: sandwich
## Loading required package: urca
## Loading required package: lmtest
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:MASS':
## 
##     select
## The following object is masked from 'package:neuralnet':
## 
##     compute
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

Import Data

features.test = read.csv("/Users/nelsonwhite/Documents/ms applied economics/Predictive Analytics:Forecasting/final/data/dengue_features_test.csv")

features.train = read.csv("/Users/nelsonwhite/Documents/ms applied economics/Predictive Analytics:Forecasting/final/data/dengue_features_train.csv")

labels.train = read.csv("/Users/nelsonwhite/Documents/ms applied economics/Predictive Analytics:Forecasting/final/data/dengue_labels_train.csv")

Descriptive Statistics

head(features.test)
##   city year weekofyear week_start_date ndvi_ne     ndvi_nw    ndvi_se
## 1   sj 2008         18      2008-04-29 -0.0189 -0.01890000 0.10272860
## 2   sj 2008         19      2008-05-06 -0.0180 -0.01240000 0.08204286
## 3   sj 2008         20      2008-05-13 -0.0015          NA 0.15108330
## 4   sj 2008         21      2008-05-20      NA -0.01986667 0.12432860
## 5   sj 2008         22      2008-05-27  0.0568  0.03983333 0.06226667
## 6   sj 2008         23      2008-06-03 -0.0440 -0.03046667 0.13200000
##      ndvi_sw precipitation_amt_mm reanalysis_air_temp_k
## 1 0.09120000                78.60              298.4929
## 2 0.07231429                12.56              298.4757
## 3 0.09152857                 3.66              299.4557
## 4 0.12568570                 0.00              299.6900
## 5 0.07591429                 0.76              299.7800
## 6 0.08352857                71.17              299.7686
##   reanalysis_avg_temp_k reanalysis_dew_point_temp_k
## 1              298.5500                    294.5271
## 2              298.5571                    294.3957
## 3              299.3571                    295.3086
## 4              299.7286                    294.4029
## 5              299.6714                    294.7600
## 6              299.7286                    295.3143
##   reanalysis_max_air_temp_k reanalysis_min_air_temp_k
## 1                     301.1                     296.4
## 2                     300.8                     296.7
## 3                     302.2                     296.4
## 4                     303.0                     296.9
## 5                     302.3                     297.3
## 6                     301.9                     297.6
##   reanalysis_precip_amt_kg_per_m2 reanalysis_relative_humidity_percent
## 1                           25.37                             78.78143
## 2                           21.83                             78.23000
## 3                            4.12                             78.27000
## 4                            2.20                             73.01571
## 5                            4.36                             74.08429
## 6                           22.55                             76.55714
##   reanalysis_sat_precip_amt_mm reanalysis_specific_humidity_g_per_kg
## 1                        78.60                              15.91857
## 2                        12.56                              15.79143
## 3                         3.66                              16.67429
## 4                         0.00                              15.77571
## 5                         0.76                              16.13714
## 6                        71.17                              16.66714
##   reanalysis_tdtr_k station_avg_temp_c station_diur_temp_rng_c
## 1          3.128571           26.52857                7.057143
## 2          2.571429           26.07143                5.557143
## 3          4.428571           27.92857                7.785714
## 4          4.342857           28.05714                6.271429
## 5          3.542857           27.61429                7.085714
## 6          2.857143           28.00000                5.171429
##   station_max_temp_c station_min_temp_c station_precip_mm
## 1               33.3               21.7              75.2
## 2               30.0               22.2              34.3
## 3               32.8               22.8               3.0
## 4               33.3               24.4               0.3
## 5               33.3               23.3              84.1
## 6               32.8               25.0              27.7
summary(features.test)
##  city          year        weekofyear      week_start_date
##  iq:156   Min.   :2008   Min.   : 1.00   2010-07-02:  2   
##  sj:260   1st Qu.:2010   1st Qu.:13.75   2010-07-09:  2   
##           Median :2011   Median :26.00   2010-07-16:  2   
##           Mean   :2011   Mean   :26.44   2010-07-23:  2   
##           3rd Qu.:2012   3rd Qu.:39.00   2010-07-30:  2   
##           Max.   :2013   Max.   :53.00   2010-08-06:  2   
##                                          (Other)   :404   
##     ndvi_ne           ndvi_nw            ndvi_se          ndvi_sw        
##  Min.   :-0.4634   Min.   :-0.21180   Min.   :0.0062   Min.   :-0.01467  
##  1st Qu.:-0.0015   1st Qu.: 0.01597   1st Qu.:0.1487   1st Qu.: 0.13408  
##  Median : 0.1101   Median : 0.08870   Median :0.2042   Median : 0.18647  
##  Mean   : 0.1260   Mean   : 0.12680   Mean   :0.2077   Mean   : 0.20172  
##  3rd Qu.: 0.2633   3rd Qu.: 0.24240   3rd Qu.:0.2549   3rd Qu.: 0.25324  
##  Max.   : 0.5004   Max.   : 0.64900   Max.   :0.4530   Max.   : 0.52904  
##  NA's   :43        NA's   :11         NA's   :1        NA's   :1         
##  precipitation_amt_mm reanalysis_air_temp_k reanalysis_avg_temp_k
##  Min.   :  0.000      Min.   :294.6         Min.   :295.2        
##  1st Qu.:  8.175      1st Qu.:297.8         1st Qu.:298.3        
##  Median : 31.455      Median :298.5         Median :299.3        
##  Mean   : 38.354      Mean   :298.8         Mean   :299.4        
##  3rd Qu.: 57.773      3rd Qu.:300.2         3rd Qu.:300.5        
##  Max.   :169.340      Max.   :301.9         Max.   :303.3        
##  NA's   :2            NA's   :2             NA's   :2            
##  reanalysis_dew_point_temp_k reanalysis_max_air_temp_k
##  Min.   :290.8               Min.   :298.2            
##  1st Qu.:294.3               1st Qu.:301.4            
##  Median :295.8               Median :302.8            
##  Mean   :295.4               Mean   :303.6            
##  3rd Qu.:296.6               3rd Qu.:305.8            
##  Max.   :297.8               Max.   :314.1            
##  NA's   :2                   NA's   :2                
##  reanalysis_min_air_temp_k reanalysis_precip_amt_kg_per_m2
##  Min.   :286.2             Min.   :  0.00                 
##  1st Qu.:293.5             1st Qu.:  9.43                 
##  Median :296.3             Median : 25.85                 
##  Mean   :295.7             Mean   : 42.17                 
##  3rd Qu.:298.3             3rd Qu.: 56.48                 
##  Max.   :299.7             Max.   :301.40                 
##  NA's   :2                 NA's   :2                      
##  reanalysis_relative_humidity_percent reanalysis_sat_precip_amt_mm
##  Min.   :64.92                        Min.   :  0.000             
##  1st Qu.:77.40                        1st Qu.:  8.175             
##  Median :80.33                        Median : 31.455             
##  Mean   :82.50                        Mean   : 38.354             
##  3rd Qu.:88.33                        3rd Qu.: 57.773             
##  Max.   :97.98                        Max.   :169.340             
##  NA's   :2                            NA's   :2                   
##  reanalysis_specific_humidity_g_per_kg reanalysis_tdtr_k
##  Min.   :12.54                         Min.   : 1.486   
##  1st Qu.:15.79                         1st Qu.: 2.446   
##  Median :17.34                         Median : 2.914   
##  Mean   :16.93                         Mean   : 5.125   
##  3rd Qu.:18.17                         3rd Qu.: 8.171   
##  Max.   :19.60                         Max.   :14.486   
##  NA's   :2                             NA's   :2        
##  station_avg_temp_c station_diur_temp_rng_c station_max_temp_c
##  Min.   :24.16      Min.   : 4.043          Min.   :27.20     
##  1st Qu.:26.51      1st Qu.: 5.929          1st Qu.:31.10     
##  Median :27.48      Median : 6.643          Median :32.80     
##  Mean   :27.37      Mean   : 7.811          Mean   :32.53     
##  3rd Qu.:28.32      3rd Qu.: 9.812          3rd Qu.:33.90     
##  Max.   :30.27      Max.   :14.725          Max.   :38.40     
##  NA's   :12         NA's   :12              NA's   :3         
##  station_min_temp_c station_precip_mm
##  Min.   :14.20      Min.   :  0.00   
##  1st Qu.:21.20      1st Qu.:  9.10   
##  Median :22.20      Median : 23.60   
##  Mean   :22.37      Mean   : 34.28   
##  3rd Qu.:23.30      3rd Qu.: 47.75   
##  Max.   :26.70      Max.   :212.00   
##  NA's   :9          NA's   :5
head(features.train)
##   city year weekofyear week_start_date   ndvi_ne   ndvi_nw   ndvi_se
## 1   sj 1990         18      1990-04-30 0.1226000 0.1037250 0.1984833
## 2   sj 1990         19      1990-05-07 0.1699000 0.1421750 0.1623571
## 3   sj 1990         20      1990-05-14 0.0322500 0.1729667 0.1572000
## 4   sj 1990         21      1990-05-21 0.1286333 0.2450667 0.2275571
## 5   sj 1990         22      1990-05-28 0.1962000 0.2622000 0.2512000
## 6   sj 1990         23      1990-06-04        NA 0.1748500 0.2543143
##     ndvi_sw precipitation_amt_mm reanalysis_air_temp_k
## 1 0.1776167                12.42              297.5729
## 2 0.1554857                22.82              298.2114
## 3 0.1708429                34.54              298.7814
## 4 0.2358857                15.36              298.9871
## 5 0.2473400                 7.52              299.5186
## 6 0.1817429                 9.58              299.6300
##   reanalysis_avg_temp_k reanalysis_dew_point_temp_k
## 1              297.7429                    292.4143
## 2              298.4429                    293.9514
## 3              298.8786                    295.4343
## 4              299.2286                    295.3100
## 5              299.6643                    295.8214
## 6              299.7643                    295.8514
##   reanalysis_max_air_temp_k reanalysis_min_air_temp_k
## 1                     299.8                     295.9
## 2                     300.9                     296.4
## 3                     300.5                     297.3
## 4                     301.4                     297.0
## 5                     301.9                     297.5
## 6                     302.4                     298.1
##   reanalysis_precip_amt_kg_per_m2 reanalysis_relative_humidity_percent
## 1                           32.00                             73.36571
## 2                           17.94                             77.36857
## 3                           26.10                             82.05286
## 4                           13.90                             80.33714
## 5                           12.20                             80.46000
## 6                           26.49                             79.89143
##   reanalysis_sat_precip_amt_mm reanalysis_specific_humidity_g_per_kg
## 1                        12.42                              14.01286
## 2                        22.82                              15.37286
## 3                        34.54                              16.84857
## 4                        15.36                              16.67286
## 5                         7.52                              17.21000
## 6                         9.58                              17.21286
##   reanalysis_tdtr_k station_avg_temp_c station_diur_temp_rng_c
## 1          2.628571           25.44286                6.900000
## 2          2.371429           26.71429                6.371429
## 3          2.300000           26.71429                6.485714
## 4          2.428571           27.47143                6.771429
## 5          3.014286           28.94286                9.371429
## 6          2.100000           28.11429                6.942857
##   station_max_temp_c station_min_temp_c station_precip_mm
## 1               29.4               20.0              16.0
## 2               31.7               22.2               8.6
## 3               32.2               22.8              41.4
## 4               33.3               23.3               4.0
## 5               35.0               23.9               5.8
## 6               34.4               23.9              39.1
summary(features.train)
##  city          year        weekofyear      week_start_date
##  iq:520   Min.   :1990   Min.   : 1.00   2000-07-01:   2  
##  sj:936   1st Qu.:1997   1st Qu.:13.75   2000-07-08:   2  
##           Median :2002   Median :26.50   2000-07-15:   2  
##           Mean   :2001   Mean   :26.50   2000-07-22:   2  
##           3rd Qu.:2005   3rd Qu.:39.25   2000-07-29:   2  
##           Max.   :2010   Max.   :53.00   2000-08-05:   2  
##                                          (Other)   :1444  
##     ndvi_ne            ndvi_nw            ndvi_se        
##  Min.   :-0.40625   Min.   :-0.45610   Min.   :-0.01553  
##  1st Qu.: 0.04495   1st Qu.: 0.04922   1st Qu.: 0.15509  
##  Median : 0.12882   Median : 0.12143   Median : 0.19605  
##  Mean   : 0.14229   Mean   : 0.13055   Mean   : 0.20378  
##  3rd Qu.: 0.24848   3rd Qu.: 0.21660   3rd Qu.: 0.24885  
##  Max.   : 0.50836   Max.   : 0.45443   Max.   : 0.53831  
##  NA's   :194        NA's   :52         NA's   :22        
##     ndvi_sw         precipitation_amt_mm reanalysis_air_temp_k
##  Min.   :-0.06346   Min.   :  0.00       Min.   :294.6        
##  1st Qu.: 0.14421   1st Qu.:  9.80       1st Qu.:297.7        
##  Median : 0.18945   Median : 38.34       Median :298.6        
##  Mean   : 0.20231   Mean   : 45.76       Mean   :298.7        
##  3rd Qu.: 0.24698   3rd Qu.: 70.23       3rd Qu.:299.8        
##  Max.   : 0.54602   Max.   :390.60       Max.   :302.2        
##  NA's   :22         NA's   :13           NA's   :10           
##  reanalysis_avg_temp_k reanalysis_dew_point_temp_k
##  Min.   :294.9         Min.   :289.6              
##  1st Qu.:298.3         1st Qu.:294.1              
##  Median :299.3         Median :295.6              
##  Mean   :299.2         Mean   :295.2              
##  3rd Qu.:300.2         3rd Qu.:296.5              
##  Max.   :302.9         Max.   :298.4              
##  NA's   :10            NA's   :10                 
##  reanalysis_max_air_temp_k reanalysis_min_air_temp_k
##  Min.   :297.8             Min.   :286.9            
##  1st Qu.:301.0             1st Qu.:293.9            
##  Median :302.4             Median :296.2            
##  Mean   :303.4             Mean   :295.7            
##  3rd Qu.:305.5             3rd Qu.:297.9            
##  Max.   :314.0             Max.   :299.9            
##  NA's   :10                NA's   :10               
##  reanalysis_precip_amt_kg_per_m2 reanalysis_relative_humidity_percent
##  Min.   :  0.00                  Min.   :57.79                       
##  1st Qu.: 13.05                  1st Qu.:77.18                       
##  Median : 27.25                  Median :80.30                       
##  Mean   : 40.15                  Mean   :82.16                       
##  3rd Qu.: 52.20                  3rd Qu.:86.36                       
##  Max.   :570.50                  Max.   :98.61                       
##  NA's   :10                      NA's   :10                          
##  reanalysis_sat_precip_amt_mm reanalysis_specific_humidity_g_per_kg
##  Min.   :  0.00               Min.   :11.72                        
##  1st Qu.:  9.80               1st Qu.:15.56                        
##  Median : 38.34               Median :17.09                        
##  Mean   : 45.76               Mean   :16.75                        
##  3rd Qu.: 70.23               3rd Qu.:17.98                        
##  Max.   :390.60               Max.   :20.46                        
##  NA's   :13                   NA's   :10                           
##  reanalysis_tdtr_k station_avg_temp_c station_diur_temp_rng_c
##  Min.   : 1.357    Min.   :21.40      Min.   : 4.529         
##  1st Qu.: 2.329    1st Qu.:26.30      1st Qu.: 6.514         
##  Median : 2.857    Median :27.41      Median : 7.300         
##  Mean   : 4.904    Mean   :27.19      Mean   : 8.059         
##  3rd Qu.: 7.625    3rd Qu.:28.16      3rd Qu.: 9.567         
##  Max.   :16.029    Max.   :30.80      Max.   :15.800         
##  NA's   :10        NA's   :43         NA's   :43             
##  station_max_temp_c station_min_temp_c station_precip_mm
##  Min.   :26.70      Min.   :14.7       Min.   :  0.00   
##  1st Qu.:31.10      1st Qu.:21.1       1st Qu.:  8.70   
##  Median :32.80      Median :22.2       Median : 23.85   
##  Mean   :32.45      Mean   :22.1       Mean   : 39.33   
##  3rd Qu.:33.90      3rd Qu.:23.3       3rd Qu.: 53.90   
##  Max.   :42.20      Max.   :25.6       Max.   :543.30   
##  NA's   :20         NA's   :14         NA's   :22
head(labels.train)
##   city year weekofyear total_cases
## 1   sj 1990         18           4
## 2   sj 1990         19           5
## 3   sj 1990         20           4
## 4   sj 1990         21           3
## 5   sj 1990         22           6
## 6   sj 1990         23           2
summary(labels.train)
##  city          year        weekofyear     total_cases    
##  iq:520   Min.   :1990   Min.   : 1.00   Min.   :  0.00  
##  sj:936   1st Qu.:1997   1st Qu.:13.75   1st Qu.:  5.00  
##           Median :2002   Median :26.50   Median : 12.00  
##           Mean   :2001   Mean   :26.50   Mean   : 24.68  
##           3rd Qu.:2005   3rd Qu.:39.25   3rd Qu.: 28.00  
##           Max.   :2010   Max.   :53.00   Max.   :461.00

Combine the training datasets into one new data frame:

train <- left_join(x = labels.train, y = features.train, by = c("year", "weekofyear", "city"))
head(train)
##   city year weekofyear total_cases week_start_date   ndvi_ne   ndvi_nw
## 1   sj 1990         18           4      1990-04-30 0.1226000 0.1037250
## 2   sj 1990         19           5      1990-05-07 0.1699000 0.1421750
## 3   sj 1990         20           4      1990-05-14 0.0322500 0.1729667
## 4   sj 1990         21           3      1990-05-21 0.1286333 0.2450667
## 5   sj 1990         22           6      1990-05-28 0.1962000 0.2622000
## 6   sj 1990         23           2      1990-06-04        NA 0.1748500
##     ndvi_se   ndvi_sw precipitation_amt_mm reanalysis_air_temp_k
## 1 0.1984833 0.1776167                12.42              297.5729
## 2 0.1623571 0.1554857                22.82              298.2114
## 3 0.1572000 0.1708429                34.54              298.7814
## 4 0.2275571 0.2358857                15.36              298.9871
## 5 0.2512000 0.2473400                 7.52              299.5186
## 6 0.2543143 0.1817429                 9.58              299.6300
##   reanalysis_avg_temp_k reanalysis_dew_point_temp_k
## 1              297.7429                    292.4143
## 2              298.4429                    293.9514
## 3              298.8786                    295.4343
## 4              299.2286                    295.3100
## 5              299.6643                    295.8214
## 6              299.7643                    295.8514
##   reanalysis_max_air_temp_k reanalysis_min_air_temp_k
## 1                     299.8                     295.9
## 2                     300.9                     296.4
## 3                     300.5                     297.3
## 4                     301.4                     297.0
## 5                     301.9                     297.5
## 6                     302.4                     298.1
##   reanalysis_precip_amt_kg_per_m2 reanalysis_relative_humidity_percent
## 1                           32.00                             73.36571
## 2                           17.94                             77.36857
## 3                           26.10                             82.05286
## 4                           13.90                             80.33714
## 5                           12.20                             80.46000
## 6                           26.49                             79.89143
##   reanalysis_sat_precip_amt_mm reanalysis_specific_humidity_g_per_kg
## 1                        12.42                              14.01286
## 2                        22.82                              15.37286
## 3                        34.54                              16.84857
## 4                        15.36                              16.67286
## 5                         7.52                              17.21000
## 6                         9.58                              17.21286
##   reanalysis_tdtr_k station_avg_temp_c station_diur_temp_rng_c
## 1          2.628571           25.44286                6.900000
## 2          2.371429           26.71429                6.371429
## 3          2.300000           26.71429                6.485714
## 4          2.428571           27.47143                6.771429
## 5          3.014286           28.94286                9.371429
## 6          2.100000           28.11429                6.942857
##   station_max_temp_c station_min_temp_c station_precip_mm
## 1               29.4               20.0              16.0
## 2               31.7               22.2               8.6
## 3               32.2               22.8              41.4
## 4               33.3               23.3               4.0
## 5               35.0               23.9               5.8
## 6               34.4               23.9              39.1
summary(train)
##  city          year        weekofyear     total_cases    
##  iq:520   Min.   :1990   Min.   : 1.00   Min.   :  0.00  
##  sj:936   1st Qu.:1997   1st Qu.:13.75   1st Qu.:  5.00  
##           Median :2002   Median :26.50   Median : 12.00  
##           Mean   :2001   Mean   :26.50   Mean   : 24.68  
##           3rd Qu.:2005   3rd Qu.:39.25   3rd Qu.: 28.00  
##           Max.   :2010   Max.   :53.00   Max.   :461.00  
##                                                          
##    week_start_date    ndvi_ne            ndvi_nw        
##  2000-07-01:   2   Min.   :-0.40625   Min.   :-0.45610  
##  2000-07-08:   2   1st Qu.: 0.04495   1st Qu.: 0.04922  
##  2000-07-15:   2   Median : 0.12882   Median : 0.12143  
##  2000-07-22:   2   Mean   : 0.14229   Mean   : 0.13055  
##  2000-07-29:   2   3rd Qu.: 0.24848   3rd Qu.: 0.21660  
##  2000-08-05:   2   Max.   : 0.50836   Max.   : 0.45443  
##  (Other)   :1444   NA's   :194        NA's   :52        
##     ndvi_se            ndvi_sw         precipitation_amt_mm
##  Min.   :-0.01553   Min.   :-0.06346   Min.   :  0.00      
##  1st Qu.: 0.15509   1st Qu.: 0.14421   1st Qu.:  9.80      
##  Median : 0.19605   Median : 0.18945   Median : 38.34      
##  Mean   : 0.20378   Mean   : 0.20231   Mean   : 45.76      
##  3rd Qu.: 0.24885   3rd Qu.: 0.24698   3rd Qu.: 70.23      
##  Max.   : 0.53831   Max.   : 0.54602   Max.   :390.60      
##  NA's   :22         NA's   :22         NA's   :13          
##  reanalysis_air_temp_k reanalysis_avg_temp_k reanalysis_dew_point_temp_k
##  Min.   :294.6         Min.   :294.9         Min.   :289.6              
##  1st Qu.:297.7         1st Qu.:298.3         1st Qu.:294.1              
##  Median :298.6         Median :299.3         Median :295.6              
##  Mean   :298.7         Mean   :299.2         Mean   :295.2              
##  3rd Qu.:299.8         3rd Qu.:300.2         3rd Qu.:296.5              
##  Max.   :302.2         Max.   :302.9         Max.   :298.4              
##  NA's   :10            NA's   :10            NA's   :10                 
##  reanalysis_max_air_temp_k reanalysis_min_air_temp_k
##  Min.   :297.8             Min.   :286.9            
##  1st Qu.:301.0             1st Qu.:293.9            
##  Median :302.4             Median :296.2            
##  Mean   :303.4             Mean   :295.7            
##  3rd Qu.:305.5             3rd Qu.:297.9            
##  Max.   :314.0             Max.   :299.9            
##  NA's   :10                NA's   :10               
##  reanalysis_precip_amt_kg_per_m2 reanalysis_relative_humidity_percent
##  Min.   :  0.00                  Min.   :57.79                       
##  1st Qu.: 13.05                  1st Qu.:77.18                       
##  Median : 27.25                  Median :80.30                       
##  Mean   : 40.15                  Mean   :82.16                       
##  3rd Qu.: 52.20                  3rd Qu.:86.36                       
##  Max.   :570.50                  Max.   :98.61                       
##  NA's   :10                      NA's   :10                          
##  reanalysis_sat_precip_amt_mm reanalysis_specific_humidity_g_per_kg
##  Min.   :  0.00               Min.   :11.72                        
##  1st Qu.:  9.80               1st Qu.:15.56                        
##  Median : 38.34               Median :17.09                        
##  Mean   : 45.76               Mean   :16.75                        
##  3rd Qu.: 70.23               3rd Qu.:17.98                        
##  Max.   :390.60               Max.   :20.46                        
##  NA's   :13                   NA's   :10                           
##  reanalysis_tdtr_k station_avg_temp_c station_diur_temp_rng_c
##  Min.   : 1.357    Min.   :21.40      Min.   : 4.529         
##  1st Qu.: 2.329    1st Qu.:26.30      1st Qu.: 6.514         
##  Median : 2.857    Median :27.41      Median : 7.300         
##  Mean   : 4.904    Mean   :27.19      Mean   : 8.059         
##  3rd Qu.: 7.625    3rd Qu.:28.16      3rd Qu.: 9.567         
##  Max.   :16.029    Max.   :30.80      Max.   :15.800         
##  NA's   :10        NA's   :43         NA's   :43             
##  station_max_temp_c station_min_temp_c station_precip_mm
##  Min.   :26.70      Min.   :14.7       Min.   :  0.00   
##  1st Qu.:31.10      1st Qu.:21.1       1st Qu.:  8.70   
##  Median :32.80      Median :22.2       Median : 23.85   
##  Mean   :32.45      Mean   :22.1       Mean   : 39.33   
##  3rd Qu.:33.90      3rd Qu.:23.3       3rd Qu.: 53.90   
##  Max.   :42.20      Max.   :25.6       Max.   :543.30   
##  NA's   :20         NA's   :14         NA's   :22

Check and remove NA’s in the data:

anyNA(train)
## [1] TRUE
train = na.omit(train)

As with the previous project, we will re-format the date variables to make them easier to work with:

train$week_start_date <- as.Date(train$week_start_date, "%m/%d/%Y")
train$Month <- format(train$week_start_date, "%m")
train$Month <- as.numeric(train$Month)

Since we are predicting the cases per week in each location (San Juan and Iquitos), let us compare them side-by-side:

ggplot(data = train, aes(x=weekofyear, y=total_cases, fill = city)) + 
  geom_bar(stat = "identity",) + 
  facet_wrap(.~city) + 
  labs(x="Week of the Year", y="Total Cases", title = "Cases of Dengue per Week") +
  scale_fill_discrete(name = "City", labels = c("Iquitos (iq)", "San Juan (sj)")) +
  theme(legend.position="bottom") 

We can see from the data that the cities vary in cases and in yearly patterns considerably. In Iquitos, cases tend to be higher in the beginning and end of the year. In San Juan, cases spike around week 30, when that is the calmest part of the year in Iquitos.

Split up the data by city:

sj.train = train[1:936,]
iq.train = train[937:1456,]
head(sj.train)
##   city year weekofyear total_cases week_start_date   ndvi_ne   ndvi_nw
## 1   sj 1990         18           4            <NA> 0.1226000 0.1037250
## 2   sj 1990         19           5            <NA> 0.1699000 0.1421750
## 3   sj 1990         20           4            <NA> 0.0322500 0.1729667
## 4   sj 1990         21           3            <NA> 0.1286333 0.2450667
## 5   sj 1990         22           6            <NA> 0.1962000 0.2622000
## 7   sj 1990         24           4            <NA> 0.1129000 0.0928000
##     ndvi_se   ndvi_sw precipitation_amt_mm reanalysis_air_temp_k
## 1 0.1984833 0.1776167                12.42              297.5729
## 2 0.1623571 0.1554857                22.82              298.2114
## 3 0.1572000 0.1708429                34.54              298.7814
## 4 0.2275571 0.2358857                15.36              298.9871
## 5 0.2512000 0.2473400                 7.52              299.5186
## 7 0.2050714 0.2102714                 3.48              299.2071
##   reanalysis_avg_temp_k reanalysis_dew_point_temp_k
## 1              297.7429                    292.4143
## 2              298.4429                    293.9514
## 3              298.8786                    295.4343
## 4              299.2286                    295.3100
## 5              299.6643                    295.8214
## 7              299.2214                    295.8657
##   reanalysis_max_air_temp_k reanalysis_min_air_temp_k
## 1                     299.8                     295.9
## 2                     300.9                     296.4
## 3                     300.5                     297.3
## 4                     301.4                     297.0
## 5                     301.9                     297.5
## 7                     301.3                     297.7
##   reanalysis_precip_amt_kg_per_m2 reanalysis_relative_humidity_percent
## 1                           32.00                             73.36571
## 2                           17.94                             77.36857
## 3                           26.10                             82.05286
## 4                           13.90                             80.33714
## 5                           12.20                             80.46000
## 7                           38.60                             82.00000
##   reanalysis_sat_precip_amt_mm reanalysis_specific_humidity_g_per_kg
## 1                        12.42                              14.01286
## 2                        22.82                              15.37286
## 3                        34.54                              16.84857
## 4                        15.36                              16.67286
## 5                         7.52                              17.21000
## 7                         3.48                              17.23429
##   reanalysis_tdtr_k station_avg_temp_c station_diur_temp_rng_c
## 1          2.628571           25.44286                6.900000
## 2          2.371429           26.71429                6.371429
## 3          2.300000           26.71429                6.485714
## 4          2.428571           27.47143                6.771429
## 5          3.014286           28.94286                9.371429
## 7          2.042857           27.41429                6.771429
##   station_max_temp_c station_min_temp_c station_precip_mm Month
## 1               29.4               20.0              16.0    NA
## 2               31.7               22.2               8.6    NA
## 3               32.2               22.8              41.4    NA
## 4               33.3               23.3               4.0    NA
## 5               35.0               23.9               5.8    NA
## 7               32.2               23.3              29.7    NA
summary(sj.train)
##  city          year        weekofyear     total_cases     week_start_date
##  iq:209   Min.   :1990   Min.   : 1.00   Min.   :  0.00   Min.   :NA     
##  sj:727   1st Qu.:1996   1st Qu.:14.00   1st Qu.:  5.00   1st Qu.:NA     
##           Median :2001   Median :27.00   Median : 14.00   Median :NA     
##           Mean   :2000   Mean   :26.63   Mean   : 24.55   Mean   :NA     
##           3rd Qu.:2003   3rd Qu.:39.00   3rd Qu.: 30.00   3rd Qu.:NA     
##           Max.   :2008   Max.   :52.00   Max.   :329.00   Max.   :NA     
##                                                           NA's   :936    
##     ndvi_ne            ndvi_nw            ndvi_se        
##  Min.   :-0.40625   Min.   :-0.45610   Min.   :-0.01553  
##  1st Qu.: 0.02252   1st Qu.: 0.03360   1st Qu.: 0.14666  
##  Median : 0.08935   Median : 0.09045   Median : 0.18650  
##  Mean   : 0.10488   Mean   : 0.10436   Mean   : 0.19292  
##  3rd Qu.: 0.19296   3rd Qu.: 0.17539   3rd Qu.: 0.23171  
##  Max.   : 0.49340   Max.   : 0.43710   Max.   : 0.45538  
##                                                          
##     ndvi_sw         precipitation_amt_mm reanalysis_air_temp_k
##  Min.   :-0.06346   Min.   :  0.000      Min.   :294.6        
##  1st Qu.: 0.13496   1st Qu.:  6.763      1st Qu.:297.8        
##  Median : 0.17810   Median : 33.400      Median :298.9        
##  Mean   : 0.18841   Mean   : 41.794      Mean   :298.9        
##  3rd Qu.: 0.22735   3rd Qu.: 64.112      3rd Qu.:300.0        
##  Max.   : 0.54602   Max.   :390.600      Max.   :302.2        
##                                                               
##  reanalysis_avg_temp_k reanalysis_dew_point_temp_k
##  Min.   :294.9         Min.   :289.6              
##  1st Qu.:298.3         1st Qu.:294.0              
##  Median :299.4         Median :295.5              
##  Mean   :299.2         Mean   :295.1              
##  3rd Qu.:300.2         3rd Qu.:296.4              
##  Max.   :302.6         Max.   :297.8              
##                                                   
##  reanalysis_max_air_temp_k reanalysis_min_air_temp_k
##  Min.   :297.8             Min.   :287.3            
##  1st Qu.:300.8             1st Qu.:294.8            
##  Median :302.0             Median :296.9            
##  Mean   :302.7             Mean   :296.3            
##  3rd Qu.:303.3             3rd Qu.:298.1            
##  Max.   :313.2             Max.   :299.9            
##                                                     
##  reanalysis_precip_amt_kg_per_m2 reanalysis_relative_humidity_percent
##  Min.   :  0.00                  Min.   :57.79                       
##  1st Qu.: 11.59                  1st Qu.:76.73                       
##  Median : 23.93                  Median :79.48                       
##  Mean   : 35.69                  Mean   :80.59                       
##  3rd Qu.: 42.82                  3rd Qu.:82.61                       
##  Max.   :570.50                  Max.   :98.46                       
##                                                                      
##  reanalysis_sat_precip_amt_mm reanalysis_specific_humidity_g_per_kg
##  Min.   :  0.000              Min.   :11.72                        
##  1st Qu.:  6.763              1st Qu.:15.45                        
##  Median : 33.400              Median :16.87                        
##  Mean   : 41.794              Mean   :16.62                        
##  3rd Qu.: 64.112              3rd Qu.:17.89                        
##  Max.   :390.600              Max.   :19.44                        
##                                                                    
##  reanalysis_tdtr_k station_avg_temp_c station_diur_temp_rng_c
##  Min.   : 1.357    Min.   :22.84      Min.   : 4.529         
##  1st Qu.: 2.243    1st Qu.:26.18      1st Qu.: 6.414         
##  Median : 2.657    Median :27.37      Median : 7.029         
##  Mean   : 4.094    Mean   :27.14      Mean   : 7.641         
##  3rd Qu.: 3.604    3rd Qu.:28.16      3rd Qu.: 8.134         
##  Max.   :16.029    Max.   :30.80      Max.   :15.800         
##                                                              
##  station_max_temp_c station_min_temp_c station_precip_mm     Month    
##  Min.   :26.70      Min.   :14.70      Min.   :  0.000   Min.   : NA  
##  1st Qu.:31.10      1st Qu.:21.10      1st Qu.:  8.275   1st Qu.: NA  
##  Median :32.20      Median :22.20      Median : 21.100   Median : NA  
##  Mean   :32.16      Mean   :22.28      Mean   : 34.067   Mean   :NaN  
##  3rd Qu.:33.30      3rd Qu.:23.30      3rd Qu.: 45.525   3rd Qu.: NA  
##  Max.   :42.20      Max.   :25.60      Max.   :543.300   Max.   : NA  
##                                                          NA's   :936
head(iq.train)
##      city year weekofyear total_cases week_start_date   ndvi_ne   ndvi_nw
## 1163   iq 2004         45          22            <NA> 0.4148857 0.3245571
## 1164   iq 2004         46          37            <NA> 0.3466857 0.3154143
## 1165   iq 2004         47          33            <NA> 0.2278714 0.1945000
## 1166   iq 2004         48          18            <NA> 0.2153167 0.1672857
## 1167   iq 2004         49          83            <NA> 0.2019429 0.1593667
## 1169   iq 2004         51          32            <NA> 0.2611429 0.2033143
##        ndvi_se   ndvi_sw precipitation_amt_mm reanalysis_air_temp_k
## 1163 0.2727429 0.3656714                91.63              299.5043
## 1164 0.2708571 0.3742000                74.68              297.1686
## 1165 0.1909143 0.2095571                74.08              299.4186
## 1166 0.2026286 0.2191286                71.98              297.9586
## 1167 0.1590429 0.2410857                53.01              299.1771
## 1169 0.2437429 0.2363571                49.56              298.7014
##      reanalysis_avg_temp_k reanalysis_dew_point_temp_k
## 1163              300.7857                    296.1786
## 1164              297.7071                    296.4843
## 1165              301.2357                    296.0971
## 1166              299.2000                    297.0200
## 1167              300.3786                    296.4400
## 1169              300.0357                    296.3857
##      reanalysis_max_air_temp_k reanalysis_min_air_temp_k
## 1163                     309.2                     294.3
## 1164                     304.2                     292.4
## 1165                     309.3                     293.6
## 1166                     306.1                     293.6
## 1167                     309.5                     293.3
## 1169                     308.5                     293.8
##      reanalysis_precip_amt_kg_per_m2 reanalysis_relative_humidity_percent
## 1163                           67.00                             84.82714
## 1164                           53.90                             96.35429
## 1165                           26.80                             84.61143
## 1166                           56.80                             95.25143
## 1167                           36.83                             87.13000
## 1169                           38.00                             88.78000
##      reanalysis_sat_precip_amt_mm reanalysis_specific_humidity_g_per_kg
## 1163                        91.63                              17.80571
## 1164                        74.68                              18.12143
## 1165                        74.08                              17.73857
## 1166                        71.98                              18.71429
## 1167                        53.01                              18.11000
## 1169                        49.56                              18.04000
##      reanalysis_tdtr_k station_avg_temp_c station_diur_temp_rng_c
## 1163         10.657143             28.350                   12.35
## 1164          5.928571             27.200                    8.90
## 1165         11.642857             28.250                   11.00
## 1166          7.914286             28.000                   10.36
## 1167         10.957143             27.900                   11.00
## 1169         10.214286             28.375                    9.65
##      station_max_temp_c station_min_temp_c station_precip_mm Month
## 1163               34.9               21.8             101.4    NA
## 1164               33.7               22.4             184.2    NA
## 1165               35.8               22.5             107.4    NA
## 1166               35.3               22.6              77.0    NA
## 1167               34.1               22.4              64.0    NA
## 1169               34.0               22.6             128.3    NA
summary(iq.train)
##    city          year        weekofyear     total_cases    
##  iq  :263   Min.   :2004   Min.   : 1.00   Min.   : 0.000  
##  sj  :  0   1st Qu.:2006   1st Qu.:13.00   1st Qu.: 3.000  
##  NA's:257   Median :2007   Median :25.00   Median : 6.000  
##             Mean   :2007   Mean   :26.03   Mean   : 9.262  
##             3rd Qu.:2009   3rd Qu.:40.00   3rd Qu.:11.000  
##             Max.   :2010   Max.   :52.00   Max.   :83.000  
##             NA's   :257    NA's   :257     NA's   :257     
##  week_start_date    ndvi_ne           ndvi_nw           ndvi_se      
##  Min.   :NA      Min.   :0.06173   Min.   :0.05895   Min.   :0.0860  
##  1st Qu.:NA      1st Qu.:0.19586   1st Qu.:0.18614   1st Qu.:0.1923  
##  Median :NA      Median :0.26341   Median :0.23351   Median :0.2537  
##  Mean   :NA      Mean   :0.26369   Mean   :0.24113   Mean   :0.2505  
##  3rd Qu.:NA      3rd Qu.:0.32007   3rd Qu.:0.29122   3rd Qu.:0.2968  
##  Max.   :NA      Max.   :0.50836   Max.   :0.45443   Max.   :0.5383  
##  NA's   :520     NA's   :257       NA's   :257       NA's   :257     
##     ndvi_sw        precipitation_amt_mm reanalysis_air_temp_k
##  Min.   :0.06474   Min.   :  0.00       Min.   :294.9        
##  1st Qu.:0.20166   1st Qu.: 43.45       1st Qu.:297.3        
##  Median :0.26046   Median : 64.03       Median :297.9        
##  Mean   :0.26729   Mean   : 68.17       Mean   :298.0        
##  3rd Qu.:0.32245   3rd Qu.: 88.19       3rd Qu.:298.7        
##  Max.   :0.54573   Max.   :210.83       Max.   :300.7        
##  NA's   :257       NA's   :257          NA's   :257          
##  reanalysis_avg_temp_k reanalysis_dew_point_temp_k
##  Min.   :295.4         Min.   :290.1              
##  1st Qu.:298.4         1st Qu.:295.2              
##  Median :299.2         Median :296.2              
##  Mean   :299.2         Mean   :295.9              
##  3rd Qu.:300.2         3rd Qu.:296.8              
##  Max.   :302.2         Max.   :298.4              
##  NA's   :257           NA's   :257                
##  reanalysis_max_air_temp_k reanalysis_min_air_temp_k
##  Min.   :301.9             Min.   :286.9            
##  1st Qu.:305.2             1st Qu.:292.4            
##  Median :306.9             Median :293.5            
##  Mean   :306.9             Mean   :293.2            
##  3rd Qu.:308.4             3rd Qu.:294.4            
##  Max.   :313.2             Max.   :296.0            
##  NA's   :257               NA's   :257              
##  reanalysis_precip_amt_kg_per_m2 reanalysis_relative_humidity_percent
##  Min.   :  0.10                  Min.   :67.76                       
##  1st Qu.: 32.90                  1st Qu.:86.80                       
##  Median : 53.25                  Median :91.80                       
##  Mean   : 62.38                  Mean   :89.91                       
##  3rd Qu.: 72.00                  3rd Qu.:94.75                       
##  Max.   :288.40                  Max.   :98.61                       
##  NA's   :257                     NA's   :257                         
##  reanalysis_sat_precip_amt_mm reanalysis_specific_humidity_g_per_kg
##  Min.   :  0.00               Min.   :12.11                        
##  1st Qu.: 43.45               1st Qu.:16.72                        
##  Median : 64.03               Median :17.79                        
##  Mean   : 68.17               Mean   :17.50                        
##  3rd Qu.: 88.19               3rd Qu.:18.41                        
##  Max.   :210.83               Max.   :20.46                        
##  NA's   :257                  NA's   :257                          
##  reanalysis_tdtr_k station_avg_temp_c station_diur_temp_rng_c
##  Min.   : 3.714    Min.   :21.40      Min.   : 5.20          
##  1st Qu.: 7.279    1st Qu.:27.05      1st Qu.: 9.20          
##  Median : 8.600    Median :27.70      Median :10.42          
##  Mean   : 8.847    Mean   :27.56      Mean   :10.41          
##  3rd Qu.:10.657    3rd Qu.:28.22      3rd Qu.:11.50          
##  Max.   :13.800    Max.   :30.03      Max.   :14.90          
##  NA's   :257       NA's   :257        NA's   :257            
##  station_max_temp_c station_min_temp_c station_precip_mm     Month    
##  Min.   :31.00      Min.   :16.40      Min.   :  0.00    Min.   : NA  
##  1st Qu.:33.20      1st Qu.:21.00      1st Qu.: 16.40    1st Qu.: NA  
##  Median :33.90      Median :21.40      Median : 45.00    Median : NA  
##  Mean   :34.02      Mean   :21.34      Mean   : 65.29    Mean   :NaN  
##  3rd Qu.:35.00      3rd Qu.:22.10      3rd Qu.: 92.50    3rd Qu.: NA  
##  Max.   :38.60      Max.   :24.20      Max.   :350.90    Max.   : NA  
##  NA's   :257        NA's   :257        NA's   :257       NA's   :520

Adding variables for converting Celcius to Fahrenheit. This will come in handy later.

sj.train$avg_temp_f = sj.train$station_avg_temp_c * 2 + 30
sj.train$max_temp_f = sj.train$station_max_temp_c * 2 + 30

What kind of seasonality is present in the data?

sj.ts = ts(sj.train, start = c(1990, 04, 30), end = c(2004, 10, 28), frequency =  52)
iq.ts = ts(iq.train, start = c(2005, 11, 11), end = c(2010, 6, 25), frequency = 52)
autoplot(sj.ts[,4], main="Total Cases, San Juan", xlab = "Date", ylab="Number of Cases") 

There is clear seasonality in the San Juan data. The cases tend to spike in the middle of the year.

autoplot(iq.ts[,4], main="Total Cases, Iquitos", xlab = "Date", ylab="Number of Cases") 

There is some seasonality in the data although it is not uniform. Cases tend to spike in the spring and summer; however, in some years, they spike in the very beginning or stay relatively the same throughout. This is interesting to note because both cities have similar populations.

As mentioned in the introduction, cases of Dengue are related to environmental variables such as temperature, precipitation, and vegetation. Now we will investigate for patterns between cases of the virus and environmental variables.

autoplot(sj.ts[,10], main = "Precipitation vs Dengue Cases in San Juan", series = "Precipitation, Millimeters", xlab = "Date", ylab = "Precipitation & Cases") +
  autolayer(sj.ts[,04], series = "Dengue Cases")

autoplot(iq.ts[,10], main = "Precipitation vs Dengue Cases in Iquitos", series = "Precipitation, Millimeters", xlab = "Date", ylab = "Precipitation & Cases") +
  autolayer(iq.ts[,04], series = "Dengue Cases")

autoplot(sj.ts[,17], main = "Humidity vs Dengue Cases in San Juan", series = "Humidity, Percent", xlab = "Date", ylab = "Humidity & Cases") +
  autolayer(sj.ts[,04], series = "Dengue Cases")

autoplot(iq.ts[,17], main = "Humidity vs Dengue Cases in Iquitos", series = "Humidity, Percent", xlab = "Date", ylab = "Humidity & Cases") +
  autolayer(iq.ts[,04], series = "Dengue Cases")

autoplot(sj.ts[,21], main = "Average Temperature vs Dengue Cases in San Juan", series = "Temperature, Celcius", xlab = "Date", ylab = "Temperature & Cases") +
  autolayer(sj.ts[,04], series = "Dengue Cases")

Although I typically prefer to use metric in an academic context, the Farenheit scale is much dramatic and thus may be easier to interpret on a graph of this scale.

autoplot(sj.ts[,27], main = "Average Temperature vs Dengue Cases in San Juan", series = "Temperature, Fahrenheit", xlab = "Date", ylab = "Temperature & Cases") +
  autolayer(sj.ts[,04], series = "Dengue Cases")

autoplot(sj.ts[,28], main = "Maximum Temperature vs Dengue Cases in San Juan", series = "Temperature, Fahrenheit", xlab = "Date", ylab = "Temperature & Cases") +
  autolayer(sj.ts[,04], series = "Dengue Cases")

There does not appear to be any discernable correlation in the data, or the changes in temperature are too small to see in this format.

San Juan Models & Evaluation

ARIMA

sj.arima = auto.arima(sj.train[,4])
forecast(sj.arima)
##     Point Forecast     Lo 80    Hi 80     Lo 95    Hi 95
## 937       2.900022 -11.28639 17.08644 -18.79623 24.59627
## 938       2.607559 -18.26069 23.47581 -29.30768 34.52279
## 939       4.397989 -21.94048 30.73646 -35.88323 44.67921
## 940       2.634337 -27.53971 32.80838 -43.51288 48.78155
## 941       3.654582 -30.40089 37.71006 -48.42877 55.73793
## 942       3.411803 -33.92202 40.74562 -53.68535 60.50895
## 943       3.182942 -37.16859 43.53447 -58.52940 64.89529
## 944       3.542094 -39.69544 46.77963 -62.58401 69.66820
## 945       3.269543 -42.59224 49.13133 -66.87001 73.40909
## 946       3.387852 -45.00377 51.77948 -70.62075 77.39646
autoplot(forecast(sj.arima))

Auto.arima chose Arima(2,1,2). The forecast is quite broad, and obviously, anything below 0 is unreasonable.

checkresiduals(forecast(sj.arima))

## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(2,1,2)
## Q* = 12.739, df = 6, p-value = 0.04737
## 
## Model df: 4.   Total lags used: 10
summary(sj.arima)
## Series: sj.train[, 4] 
## ARIMA(2,1,2) 
## 
## Coefficients:
##           ar1      ar2     ma1     ma2
##       -1.0630  -0.4773  1.1418  0.6150
## s.e.   0.1499   0.1765  0.1356  0.1599
## 
## sigma^2 estimated as 122.5:  log likelihood=-3572.69
## AIC=7155.37   AICc=7155.44   BIC=7179.57
## 
## Training set error measures:
##                         ME     RMSE      MAE MPE MAPE     MASE        ACF1
## Training set -0.0006230492 11.04011 6.717139 NaN  Inf 1.014952 0.002718952

The residuals plot is mostly white noise with a light pattern; the ACF graph only breaks at Lag = 7, and the graph is normally distrubuted.

STL

sj.stl = stl(sj.ts[,4], s.window = "periodic", robust = TRUE)
forecast(sj.stl)
##          Point Forecast      Lo 80     Hi 80      Lo 95     Hi 95
## 2004.192   1.2762026053  -14.57110  17.12350  -22.96015  25.51256
## 2004.212  -0.2006205288  -22.61096  22.20972  -34.47428  34.07304
## 2004.231  -0.2657960059  -27.71229  27.18070  -42.24159  41.70999
## 2004.250  -0.2336949435  -31.92591  31.45852  -48.70276  48.23537
## 2004.269  -4.7129591314  -40.14576  30.71984  -58.90274  49.47683
## 2004.288  -1.2173991707  -40.03195  37.59715  -60.57914  58.14434
## 2004.308  -2.4110659839  -44.33548  39.51334  -66.52892  61.70679
## 2004.327  -3.5301549844  -48.34915  41.28884  -72.07490  65.01459
## 2004.346  -0.4338847010  -47.97155  47.10378  -73.13646  72.26869
## 2004.365  -0.5046762011  -50.61371  49.60436  -77.13984  76.13048
## 2004.385  -1.9023880714  -54.45714  50.65237  -82.27795  78.47317
## 2004.404   0.3359784418  -54.55563  55.22759  -83.61349  84.28545
## 2004.423   0.4146497294  -56.71831  57.54761  -86.96267  87.79197
## 2004.442  -1.6004500047  -60.89009  57.68919  -92.27613  89.07523
## 2004.462   0.3275070610  -61.04307  61.69809  -93.53070  94.18571
## 2004.481   0.6948279598  -62.68841  64.07807  -96.24147  97.63113
## 2004.500  -3.7185097955  -69.05243  61.61541 -103.63812  96.20110
## 2004.519  -2.7692705972  -69.99730  64.45876 -105.58567 100.04713
## 2004.538  -2.4696046833  -71.53982  66.60061 -108.10338 103.16417
## 2004.558  -4.4303130683  -75.29484  66.43421 -112.80825 103.94763
## 2004.577  -4.2301264714  -76.84464  68.38439 -115.28444 106.82419
## 2004.596  -2.2615543471  -76.58486  72.06175 -115.92924 111.40614
## 2004.615  -0.8065209425  -76.80021  75.18717 -117.02884 115.41579
## 2004.635  -0.5954715195  -78.22360  77.03266 -119.31746 118.12651
## 2004.654  -3.5589718858  -82.78784  75.66990 -124.72907 117.61113
## 2004.673  -3.3599021628  -84.15780  77.43799 -126.92962 120.20982
## 2004.692  -2.2206258420  -84.55766  80.11641 -128.14425 123.70300
## 2004.712  -2.5409825785  -86.38890  81.30693 -130.77531 125.69334
## 2004.731  -1.7810436592  -87.11310  83.55101 -132.28516 128.72307
## 2004.750  -2.1069049537  -88.89772  84.68391 -134.84201 130.62820
## 2004.769  -2.8570543495  -91.08252  85.36841 -137.78626 132.07215
## 2004.788  -0.7470195920  -90.38417  88.89013 -137.83522 136.34118
## 2004.808  -0.8450731830  -91.87202  90.18188 -140.05878 138.36864
## 2004.827  -0.5708222184  -92.96667  91.82502 -141.87807 140.73643
## 2004.846  -0.5133059099  -94.25806  93.23145 -143.88353 142.85692
## 2004.865  -1.4219724762  -96.49650  93.65255 -146.82591 143.98197
## 2004.885   1.6906079998  -94.69534  98.07656 -145.71899 149.10020
## 2004.904   2.1200256679  -95.55975  99.79980 -147.26830 151.50835
## 2004.923   1.3328724098  -97.62381 100.28955 -150.00831 152.67406
## 2004.942   2.1276703373  -98.08965 102.34499 -151.14150 155.39684
## 2004.962   2.2608111715  -99.20149 103.72311 -152.91238 157.43401
## 2004.981   3.0622541604  -99.62993 105.75444 -153.99189 160.11640
## 2005.000   6.3178635804  -97.58965 110.22538 -152.59496 165.23069
## 2005.019   7.2386172808  -97.87017 112.34741 -153.51140 167.98864
## 2005.038   5.6169647553 -100.67953 111.91346 -156.94949 168.18342
## 2005.058   6.8765650374 -100.59450 114.34763 -157.48625 171.23938
## 2005.077  10.3305155222  -98.30243 118.96346 -155.80924 176.47027
## 2005.096   6.8939789518 -102.88855 116.67651 -161.00391 174.79187
## 2005.115   5.2671491434 -105.65305 116.18735 -164.37065 174.90495
## 2005.135   3.1325162610 -108.91380 115.17883 -168.22754 174.49257
## 2005.154   3.2472015085 -109.91403 116.40843 -169.81796 176.31236
## 2005.173  -0.0003260588 -114.26559 114.26493 -174.75396 174.75331
## 2005.192   1.2762026053 -114.08253 116.63493 -175.14975 177.70215
## 2005.212  -0.2006205288 -116.64255 116.24131 -178.28318 177.88194
## 2005.231  -0.2657960059 -117.78094 117.24935 -179.98970 179.45811
## 2005.250  -0.2336949435 -118.81234 118.34495 -181.58409 181.11670
## 2005.269  -4.7129591314 -124.34566 114.91974 -187.67538 178.24946
## 2005.288  -1.2173991707 -121.89494 119.46014 -185.77777 183.34297
## 2005.308  -2.4110659839 -124.12448 119.30235 -188.55567 183.73354
## 2005.327  -3.5301549844 -126.27070 119.21039 -191.24562 184.18531
## 2005.346  -0.4338847010 -124.19304 123.32527 -189.70718 188.83941
## 2005.365  -0.5046762011 -125.27412 124.26477 -191.32308 190.31373
## 2005.385  -1.9023880714 -127.67401 123.86924 -194.25349 190.44871
## 2005.404   0.3359784418 -126.42990 127.10186 -193.53570 194.20766
## 2005.423   0.4146497294 -127.33775 128.16705 -194.96578 195.79508
## 2005.442  -1.6004500047 -130.33180 127.13090 -198.47806 195.27716
## 2005.462   0.3275070610 -129.37541 130.03043 -198.03599 198.69101
## 2005.481   0.6948279598 -129.97244 131.36209 -199.14351 200.53317
## 2005.500  -3.7185097955 -135.34305 127.90604 -205.02088 197.58386
## 2005.519  -2.7692705972 -135.34418 129.80564 -205.52510 199.98656
## 2005.538  -2.4696046833 -135.98812 131.04891 -206.66855 201.72934
## 2005.558  -4.4303130683 -138.88581 130.02518 -210.06225 201.20162
## 2005.577  -4.2301264714 -139.61612 131.15587 -211.28513 202.82488
## 2005.596  -2.2615543471 -138.57169 134.04858 -210.72992 206.20681
## 2005.615  -0.8065209425 -138.03458 136.42154 -210.67873 209.06568
## 2005.635  -0.5954715195 -138.73535 137.54441 -211.86219 210.67124
## 2005.654  -3.5589718858 -142.60469 135.48675 -216.21105 209.09311
## 2005.673  -3.3599021628 -143.30560 136.58580 -217.38838 210.66858
## 2005.692  -2.2206258420 -143.06056 138.61930 -217.61671 213.17546
## 2005.712  -2.5409825785 -144.26950 139.18753 -219.29604 214.21408
## 2005.731  -1.7810436592 -144.39261 140.83052 -219.88661 216.32453
## 2005.750  -2.1069049537 -145.59609 141.38228 -221.55467 217.34086
## 2005.769  -2.8570543495 -147.21852 141.50441 -223.63886 217.92475
## 2005.788  -0.7470195920 -145.97552 144.48149 -222.85485 221.36081
## 2005.808  -0.8450731830 -146.93547 145.24533 -224.27106 222.58091
## 2005.827  -0.5708222184 -147.51806 146.37642 -225.30723 224.16559
## 2005.846  -0.5133059099 -148.31242 147.28581 -226.55255 225.52593
## 2005.865  -1.4219724762 -150.06808 147.22413 -228.75657 225.91263
## 2005.885   1.6906079998 -147.79769 151.17891 -226.93202 230.31323
## 2005.904   2.1200256679 -148.20575 152.44580 -227.78340 232.02346
## 2005.923   1.3328724098 -149.82573 152.49148 -229.84427 232.51001
## 2005.942   2.1276703373 -149.85921 154.11455 -230.31620 234.57154
## 2005.962   2.2608111715 -150.54985 155.07147 -231.44292 235.96455
## 2005.981   3.0622541604 -150.56777 156.69228 -231.89459 238.01910
## 2006.000   6.3178635804 -148.12718 160.76290 -229.88544 242.52117
## 2006.019   7.2386172808 -148.01716 162.49440 -230.20461 244.68184
## 2006.038   5.6169647553 -150.44534 161.67927 -233.05974 244.29367
## 2006.058   6.8765650374 -149.98812 163.74125 -233.02727 246.78040
## 2006.077  10.3305155222 -147.33247 167.99350 -230.79421 251.45524
## 2006.096   6.8939789518 -151.56328 165.35124 -235.44549 249.23344
## 2006.115   5.2671491434 -153.98042 164.51472 -238.28100 248.81530
## 2006.135   3.1325162610 -156.90147 163.16650 -241.61834 247.88337
## 2006.154   3.2472015085 -157.56935 164.06375 -242.70049 249.19489
## 2006.173  -0.0003260588 -161.59565 161.59500 -247.13905 247.13840
autoplot(forecast(sj.stl))

autoplot(sj.stl)

The STL forecast seems to pick up on the off-season dengue pattern well enough, but does not predict any seasonal spikes. It also predicts negative Dengue cases which does not make sense for the data.

checkresiduals(forecast(sj.stl))
## Warning in checkresiduals(forecast(sj.stl)): The fitted degrees of freedom
## is based on the model used for the seasonally adjusted data.

## 
##  Ljung-Box test
## 
## data:  Residuals from STL +  ETS(A,N,N)
## Q* = 109.92, df = 102, p-value = 0.2786
## 
## Model df: 2.   Total lags used: 104
summary(sj.stl)
##  Call:
##  stl(x = sj.ts[, 4], s.window = "periodic", robust = TRUE)
## 
##  Time.series components:
##     seasonal             trend            remainder        
##  Min.   :-4.900388   Min.   :-1.09067   Min.   :-25.82910  
##  1st Qu.:-2.408055   1st Qu.:13.47346   1st Qu.: -6.54055  
##  Median :-0.692105   Median :17.52147   Median : -0.07309  
##  Mean   : 0.046851   Mean   :19.66993   Mean   : 10.16894  
##  3rd Qu.: 1.932597   3rd Qu.:25.30298   3rd Qu.: 12.79968  
##  Max.   :10.143086   Max.   :45.66268   Max.   :289.49539  
##  IQR:
##      STL.seasonal STL.trend STL.remainder data  
##       4.341       11.830    19.340        26.500
##    %  16.4         44.6      73.0         100.0 
## 
##  Weights:
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.0000  0.7868  0.9452  0.7982  0.9876  1.0000 
## 
##  Other components: List of 5
##  $ win  : Named num [1:3] 7351 79 53
##  $ deg  : Named int [1:3] 0 1 1
##  $ jump : Named num [1:3] 736 8 6
##  $ inner: int 1
##  $ outer: int 15

There is a light pattern in the residual graph, and the ACF breaks at a few more lags than the previous model. However the residuals are still normally distrubuted with a slight left skew.

VAR

Some factors that may affect mosquito population include precipitation, temperature, dew point, and humidity.

Thus the linear model:

Total cases = Average temperature(k) + Dew point(k) + Precipitation + Humidity(%)

sj.tslm = tslm(sj.ts[,4]~sj.ts[,10]+sj.ts[,12]+sj.ts[,13]+sj.ts[,17])

summary(sj.tslm)
## 
## Call:
## tslm(formula = sj.ts[, 4] ~ sj.ts[, 10] + sj.ts[, 12] + sj.ts[, 
##     13] + sj.ts[, 17])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -37.930 -20.534  -7.808   7.785 288.368 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.474e+03  3.471e+02  -4.246 2.46e-05 ***
## sj.ts[, 10] -5.930e-03  3.308e-02  -0.179  0.85778    
## sj.ts[, 12] -1.549e+01  6.673e+00  -2.321  0.02054 *  
## sj.ts[, 13]  2.163e+01  6.562e+00   3.296  0.00103 ** 
## sj.ts[, 17] -3.089e+00  1.355e+00  -2.281  0.02286 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 34.64 on 730 degrees of freedom
## Multiple R-squared:  0.08285,    Adjusted R-squared:  0.07783 
## F-statistic: 16.49 on 4 and 730 DF,  p-value: 6.091e-13

The linear model shows us that the Dew point, Precipitation, and Humidity are all significant variables for predicting the number of cases.

sj.tsint = ts.intersect(sj.ts[,12], sj.ts[,13], sj.ts[,17])

VARselect(sj.tsint)
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##     10      4      1     10 
## 
## $criteria
##                  1           2           3           4           5
## AIC(n) -3.02200595 -3.07309439 -3.11107032 -3.14427779 -3.14793248
## HQ(n)  -2.99271032 -3.02182703 -3.03783123 -3.04906699 -3.03074995
## SC(n)  -2.94609690 -2.94025355 -2.92129770 -2.89757339 -2.84429629
## FPE(n)  0.04870344  0.04627782  0.04455348  0.04309854  0.04294174
##                  6          7          8           9          10
## AIC(n) -3.17093374 -3.2030264 -3.1931879 -3.21343239 -3.21581363
## HQ(n)  -3.03177948 -3.0419004 -3.0100902 -3.00836296 -2.98877247
## SC(n)  -2.81036576 -2.7855267 -2.7187563 -2.68206905 -2.62751851
## FPE(n)  0.04196591  0.0406413  0.0410442  0.04022297  0.04012896

The following models will be named according to the number of lags used.

VARselect suggests a wide range of lags. Therefore multiple will be tested, starting with 10 because it has the most support.

sj.var10 = VAR(sj.tsint, p = 10)

summary(sj.var10)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: sj.ts...12., sj.ts...13., sj.ts...17. 
## Deterministic variables: const 
## Sample size: 725 
## Log Likelihood: -1827.459 
## Roots of the characteristic polynomial:
## 0.9788 0.9788 0.926 0.926 0.9245 0.8608 0.8608 0.813 0.813 0.8099 0.8099 0.8093 0.8093 0.8046 0.8046 0.7958 0.7958 0.7926 0.7926 0.7708 0.7708 0.7574 0.7574 0.7559 0.7559 0.7316 0.7316 0.7243 0.7243 0.4138
## Call:
## VAR(y = sj.tsint, p = 10)
## 
## 
## Estimation results for equation sj.ts...12.: 
## ============================================ 
## sj.ts...12. = sj.ts...12..l1 + sj.ts...13..l1 + sj.ts...17..l1 + sj.ts...12..l2 + sj.ts...13..l2 + sj.ts...17..l2 + sj.ts...12..l3 + sj.ts...13..l3 + sj.ts...17..l3 + sj.ts...12..l4 + sj.ts...13..l4 + sj.ts...17..l4 + sj.ts...12..l5 + sj.ts...13..l5 + sj.ts...17..l5 + sj.ts...12..l6 + sj.ts...13..l6 + sj.ts...17..l6 + sj.ts...12..l7 + sj.ts...13..l7 + sj.ts...17..l7 + sj.ts...12..l8 + sj.ts...13..l8 + sj.ts...17..l8 + sj.ts...12..l9 + sj.ts...13..l9 + sj.ts...17..l9 + sj.ts...12..l10 + sj.ts...13..l10 + sj.ts...17..l10 + const 
## 
##                  Estimate Std. Error t value Pr(>|t|)    
## sj.ts...12..l1   0.455696   0.156746   2.907  0.00376 ** 
## sj.ts...13..l1   0.171377   0.164831   1.040  0.29884    
## sj.ts...17..l1  -0.036273   0.034227  -1.060  0.28962    
## sj.ts...12..l2  -0.333581   0.181847  -1.834  0.06702 .  
## sj.ts...13..l2   0.496525   0.193441   2.567  0.01047 *  
## sj.ts...17..l2  -0.104186   0.040390  -2.579  0.01010 *  
## sj.ts...12..l3   0.134258   0.182732   0.735  0.46276    
## sj.ts...13..l3  -0.042968   0.194740  -0.221  0.82544    
## sj.ts...17..l3   0.002479   0.040599   0.061  0.95133    
## sj.ts...12..l4   0.504420   0.185646   2.717  0.00675 ** 
## sj.ts...13..l4  -0.453594   0.197819  -2.293  0.02215 *  
## sj.ts...17..l4   0.107496   0.041285   2.604  0.00942 ** 
## sj.ts...12..l5   0.180015   0.186656   0.964  0.33517    
## sj.ts...13..l5  -0.110613   0.198659  -0.557  0.57785    
## sj.ts...17..l5   0.034489   0.041521   0.831  0.40647    
## sj.ts...12..l6   0.036953   0.187549   0.197  0.84386    
## sj.ts...13..l6   0.016123   0.199779   0.081  0.93570    
## sj.ts...17..l6  -0.005526   0.041746  -0.132  0.89473    
## sj.ts...12..l7   0.145489   0.197729   0.736  0.46210    
## sj.ts...13..l7  -0.255344   0.210249  -1.214  0.22498    
## sj.ts...17..l7   0.037539   0.044132   0.851  0.39528    
## sj.ts...12..l8  -0.328971   0.243696  -1.350  0.17748    
## sj.ts...13..l8   0.373316   0.258828   1.442  0.14966    
## sj.ts...17..l8  -0.077416   0.055070  -1.406  0.16024    
## sj.ts...12..l9   0.514957   0.244438   2.107  0.03550 *  
## sj.ts...13..l9  -0.606062   0.260154  -2.330  0.02011 *  
## sj.ts...17..l9   0.127927   0.055339   2.312  0.02109 *  
## sj.ts...12..l10  0.065753   0.240674   0.273  0.78478    
## sj.ts...13..l10 -0.167580   0.250283  -0.670  0.50336    
## sj.ts...17..l10  0.024457   0.053757   0.455  0.64928    
## const           49.876953  10.516259   4.743 2.56e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.5362 on 694 degrees of freedom
## Multiple R-Squared: 0.8178,  Adjusted R-squared: 0.8099 
## F-statistic: 103.8 on 30 and 694 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation sj.ts...13.: 
## ============================================ 
## sj.ts...13. = sj.ts...12..l1 + sj.ts...13..l1 + sj.ts...17..l1 + sj.ts...12..l2 + sj.ts...13..l2 + sj.ts...17..l2 + sj.ts...12..l3 + sj.ts...13..l3 + sj.ts...17..l3 + sj.ts...12..l4 + sj.ts...13..l4 + sj.ts...17..l4 + sj.ts...12..l5 + sj.ts...13..l5 + sj.ts...17..l5 + sj.ts...12..l6 + sj.ts...13..l6 + sj.ts...17..l6 + sj.ts...12..l7 + sj.ts...13..l7 + sj.ts...17..l7 + sj.ts...12..l8 + sj.ts...13..l8 + sj.ts...17..l8 + sj.ts...12..l9 + sj.ts...13..l9 + sj.ts...17..l9 + sj.ts...12..l10 + sj.ts...13..l10 + sj.ts...17..l10 + const 
## 
##                 Estimate Std. Error t value Pr(>|t|)    
## sj.ts...12..l1   0.37146    0.21587   1.721 0.085738 .  
## sj.ts...13..l1   0.31595    0.22700   1.392 0.164422    
## sj.ts...17..l1   0.01039    0.04714   0.221 0.825545    
## sj.ts...12..l2  -0.15790    0.25044  -0.630 0.528583    
## sj.ts...13..l2   0.37650    0.26640   1.413 0.158028    
## sj.ts...17..l2  -0.05828    0.05562  -1.048 0.295138    
## sj.ts...12..l3  -0.16786    0.25166  -0.667 0.504971    
## sj.ts...13..l3   0.31745    0.26819   1.184 0.236944    
## sj.ts...17..l3  -0.07598    0.05591  -1.359 0.174587    
## sj.ts...12..l4   0.44225    0.25567   1.730 0.084115 .  
## sj.ts...13..l4  -0.45009    0.27243  -1.652 0.098963 .  
## sj.ts...17..l4   0.12883    0.05686   2.266 0.023768 *  
## sj.ts...12..l5  -0.36886    0.25706  -1.435 0.151762    
## sj.ts...13..l5   0.50685    0.27359   1.853 0.064367 .  
## sj.ts...17..l5  -0.09269    0.05718  -1.621 0.105487    
## sj.ts...12..l6   0.12155    0.25829   0.471 0.638084    
## sj.ts...13..l6  -0.14291    0.27513  -0.519 0.603629    
## sj.ts...17..l6   0.02357    0.05749   0.410 0.681980    
## sj.ts...12..l7   0.08636    0.27231   0.317 0.751236    
## sj.ts...13..l7  -0.19479    0.28955  -0.673 0.501336    
## sj.ts...17..l7   0.02781    0.06078   0.458 0.647407    
## sj.ts...12..l8   0.11357    0.33561   0.338 0.735169    
## sj.ts...13..l8  -0.10379    0.35645  -0.291 0.771011    
## sj.ts...17..l8   0.03432    0.07584   0.453 0.651028    
## sj.ts...12..l9  -0.21146    0.33664  -0.628 0.530114    
## sj.ts...13..l9   0.15963    0.35828   0.446 0.656057    
## sj.ts...17..l9  -0.03491    0.07621  -0.458 0.647012    
## sj.ts...12..l10  0.08717    0.33145   0.263 0.792638    
## sj.ts...13..l10 -0.28116    0.34469  -0.816 0.414945    
## sj.ts...17..l10  0.05984    0.07403   0.808 0.419238    
## const           50.03539   14.48282   3.455 0.000584 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.7384 on 694 degrees of freedom
## Multiple R-Squared: 0.7868,  Adjusted R-squared: 0.7776 
## F-statistic: 85.36 on 30 and 694 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation sj.ts...17.: 
## ============================================ 
## sj.ts...17. = sj.ts...12..l1 + sj.ts...13..l1 + sj.ts...17..l1 + sj.ts...12..l2 + sj.ts...13..l2 + sj.ts...17..l2 + sj.ts...12..l3 + sj.ts...13..l3 + sj.ts...17..l3 + sj.ts...12..l4 + sj.ts...13..l4 + sj.ts...17..l4 + sj.ts...12..l5 + sj.ts...13..l5 + sj.ts...17..l5 + sj.ts...12..l6 + sj.ts...13..l6 + sj.ts...17..l6 + sj.ts...12..l7 + sj.ts...13..l7 + sj.ts...17..l7 + sj.ts...12..l8 + sj.ts...13..l8 + sj.ts...17..l8 + sj.ts...12..l9 + sj.ts...13..l9 + sj.ts...17..l9 + sj.ts...12..l10 + sj.ts...13..l10 + sj.ts...17..l10 + const 
## 
##                 Estimate Std. Error t value Pr(>|t|)    
## sj.ts...12..l1   2.30894    0.83614   2.761  0.00591 ** 
## sj.ts...13..l1  -2.12943    0.87927  -2.422  0.01570 *  
## sj.ts...17..l1   0.81320    0.18258   4.454 9.82e-06 ***
## sj.ts...12..l2   1.05060    0.97004   1.083  0.27916    
## sj.ts...13..l2  -0.71676    1.03189  -0.695  0.48753    
## sj.ts...17..l2   0.25083    0.21546   1.164  0.24475    
## sj.ts...12..l3  -0.57766    0.97476  -0.593  0.55363    
## sj.ts...13..l3   0.81071    1.03881   0.780  0.43541    
## sj.ts...17..l3  -0.18146    0.21657  -0.838  0.40238    
## sj.ts...12..l4   0.06258    0.99030   0.063  0.94963    
## sj.ts...13..l4  -0.36834    1.05524  -0.349  0.72715    
## sj.ts...17..l4   0.18080    0.22023   0.821  0.41194    
## sj.ts...12..l5  -2.37393    0.99569  -2.384  0.01738 *  
## sj.ts...13..l5   2.74776    1.05972   2.593  0.00972 ** 
## sj.ts...17..l5  -0.55347    0.22149  -2.499  0.01269 *  
## sj.ts...12..l6   0.85025    1.00046   0.850  0.39570    
## sj.ts...13..l6  -1.18724    1.06569  -1.114  0.26564    
## sj.ts...17..l6   0.22176    0.22269   0.996  0.31969    
## sj.ts...12..l7  -0.24353    1.05476  -0.231  0.81747    
## sj.ts...13..l7   0.25205    1.12155   0.225  0.82225    
## sj.ts...17..l7  -0.03443    0.23542  -0.146  0.88375    
## sj.ts...12..l8   2.01637    1.29996   1.551  0.12133    
## sj.ts...13..l8  -2.15170    1.38068  -1.558  0.11959    
## sj.ts...17..l8   0.50692    0.29377   1.726  0.08487 .  
## sj.ts...12..l9  -3.75014    1.30392  -2.876  0.00415 ** 
## sj.ts...13..l9   3.92979    1.38776   2.832  0.00476 ** 
## sj.ts...17..l9  -0.84066    0.29520  -2.848  0.00453 ** 
## sj.ts...12..l10 -0.28368    1.28384  -0.221  0.82519    
## sj.ts...13..l10 -0.19986    1.33510  -0.150  0.88105    
## sj.ts...17..l10  0.08310    0.28676   0.290  0.77206    
## const           33.61516   56.09758   0.599  0.54922    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 2.86 on 694 degrees of freedom
## Multiple R-Squared: 0.3671,  Adjusted R-squared: 0.3398 
## F-statistic: 13.42 on 30 and 694 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##             sj.ts...12. sj.ts...13. sj.ts...17.
## sj.ts...12.      0.2875      0.2370     -0.1391
## sj.ts...13.      0.2370      0.5452      1.5330
## sj.ts...17.     -0.1391      1.5330      8.1803
## 
## Correlation matrix of residuals:
##             sj.ts...12. sj.ts...13. sj.ts...17.
## sj.ts...12.     1.00000      0.5987    -0.09073
## sj.ts...13.     0.59867      1.0000     0.72588
## sj.ts...17.    -0.09073      0.7259     1.00000
autoplot(forecast(sj.var10))

sj.var4 = VAR(sj.tsint, p = 4)

summary(sj.var4)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: sj.ts...12., sj.ts...13., sj.ts...17. 
## Deterministic variables: const 
## Sample size: 731 
## Log Likelihood: -1917.909 
## Roots of the characteristic polynomial:
## 0.9554 0.9554 0.7746 0.547 0.547 0.5168 0.5168 0.4555 0.4555 0.2992 0.2992 0.2783
## Call:
## VAR(y = sj.tsint, p = 4)
## 
## 
## Estimation results for equation sj.ts...12.: 
## ============================================ 
## sj.ts...12. = sj.ts...12..l1 + sj.ts...13..l1 + sj.ts...17..l1 + sj.ts...12..l2 + sj.ts...13..l2 + sj.ts...17..l2 + sj.ts...12..l3 + sj.ts...13..l3 + sj.ts...17..l3 + sj.ts...12..l4 + sj.ts...13..l4 + sj.ts...17..l4 + const 
## 
##                Estimate Std. Error t value Pr(>|t|)    
## sj.ts...12..l1  0.48874    0.16167   3.023 0.002591 ** 
## sj.ts...13..l1  0.24755    0.16973   1.459 0.145126    
## sj.ts...17..l1 -0.04208    0.03538  -1.189 0.234676    
## sj.ts...12..l2 -0.29989    0.18770  -1.598 0.110547    
## sj.ts...13..l2  0.46985    0.19943   2.356 0.018744 *  
## sj.ts...17..l2 -0.09632    0.04167  -2.311 0.021104 *  
## sj.ts...12..l3  0.20800    0.18853   1.103 0.270279    
## sj.ts...13..l3 -0.15199    0.20069  -0.757 0.449082    
## sj.ts...17..l3  0.02553    0.04190   0.609 0.542550    
## sj.ts...12..l4  0.68232    0.17830   3.827 0.000141 ***
## sj.ts...13..l4 -0.75952    0.18561  -4.092 4.76e-05 ***
## sj.ts...17..l4  0.16731    0.03888   4.303 1.92e-05 ***
## const          29.31439    6.90339   4.246 2.46e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.563 on 718 degrees of freedom
## Multiple R-Squared: 0.7923,  Adjusted R-squared: 0.7888 
## F-statistic: 228.2 on 12 and 718 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation sj.ts...13.: 
## ============================================ 
## sj.ts...13. = sj.ts...12..l1 + sj.ts...13..l1 + sj.ts...17..l1 + sj.ts...12..l2 + sj.ts...13..l2 + sj.ts...17..l2 + sj.ts...12..l3 + sj.ts...13..l3 + sj.ts...17..l3 + sj.ts...12..l4 + sj.ts...13..l4 + sj.ts...17..l4 + const 
## 
##                Estimate Std. Error t value Pr(>|t|)   
## sj.ts...12..l1  0.30784    0.22150   1.390  0.16503   
## sj.ts...13..l1  0.51593    0.23255   2.219  0.02682 * 
## sj.ts...17..l1 -0.01591    0.04847  -0.328  0.74289   
## sj.ts...12..l2 -0.21502    0.25717  -0.836  0.40338   
## sj.ts...13..l2  0.43967    0.27325   1.609  0.10805   
## sj.ts...17..l2 -0.06428    0.05710  -1.126  0.26063   
## sj.ts...12..l3 -0.09691    0.25831  -0.375  0.70765   
## sj.ts...13..l3  0.21061    0.27497   0.766  0.44395   
## sj.ts...17..l3 -0.05154    0.05741  -0.898  0.36963   
## sj.ts...12..l4  0.42154    0.24429   1.726  0.08486 . 
## sj.ts...13..l4 -0.62451    0.25431  -2.456  0.01429 * 
## sj.ts...17..l4  0.15938    0.05327   2.992  0.00287 **
## const           8.14222    9.45847   0.861  0.38961   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.7714 on 718 degrees of freedom
## Multiple R-Squared: 0.7602,  Adjusted R-squared: 0.7562 
## F-statistic: 189.7 on 12 and 718 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation sj.ts...17.: 
## ============================================ 
## sj.ts...17. = sj.ts...12..l1 + sj.ts...13..l1 + sj.ts...17..l1 + sj.ts...12..l2 + sj.ts...13..l2 + sj.ts...17..l2 + sj.ts...12..l3 + sj.ts...13..l3 + sj.ts...17..l3 + sj.ts...12..l4 + sj.ts...13..l4 + sj.ts...17..l4 + const 
## 
##                 Estimate Std. Error t value Pr(>|t|)    
## sj.ts...12..l1   1.96372    0.82840   2.370   0.0180 *  
## sj.ts...13..l1  -1.63197    0.86969  -1.876   0.0610 .  
## sj.ts...17..l1   0.73402    0.18129   4.049 5.71e-05 ***
## sj.ts...12..l2   0.69695    0.96179   0.725   0.4689    
## sj.ts...13..l2  -0.34996    1.02192  -0.342   0.7321    
## sj.ts...17..l2   0.19524    0.21354   0.914   0.3609    
## sj.ts...12..l3  -0.51119    0.96604  -0.529   0.5969    
## sj.ts...13..l3   0.74261    1.02835   0.722   0.4704    
## sj.ts...17..l3  -0.15594    0.21469  -0.726   0.4679    
## sj.ts...12..l4  -0.69098    0.91363  -0.756   0.4497    
## sj.ts...13..l4   0.06979    0.95107   0.073   0.9415    
## sj.ts...17..l4   0.08562    0.19924   0.430   0.6675    
## const          -80.25238   35.37362  -2.269   0.0236 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 2.885 on 718 degrees of freedom
## Multiple R-Squared: 0.3392,  Adjusted R-squared: 0.3282 
## F-statistic: 30.72 on 12 and 718 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##             sj.ts...12. sj.ts...13. sj.ts...17.
## sj.ts...12.      0.3170       0.273     -0.1045
## sj.ts...13.      0.2730       0.595      1.6001
## sj.ts...17.     -0.1045       1.600      8.3226
## 
## Correlation matrix of residuals:
##             sj.ts...12. sj.ts...13. sj.ts...17.
## sj.ts...12.     1.00000      0.6286    -0.06432
## sj.ts...13.     0.62855      1.0000     0.71903
## sj.ts...17.    -0.06432      0.7190     1.00000
autoplot(forecast(sj.var4))

sj.var1 = VAR(sj.tsint, p = 1)

summary(sj.var1)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: sj.ts...12., sj.ts...13., sj.ts...17. 
## Deterministic variables: const 
## Sample size: 734 
## Log Likelihood: -1996.246 
## Roots of the characteristic polynomial:
## 0.9075 0.7662 0.4411
## Call:
## VAR(y = sj.tsint, p = 1)
## 
## 
## Estimation results for equation sj.ts...12.: 
## ============================================ 
## sj.ts...12. = sj.ts...12..l1 + sj.ts...13..l1 + sj.ts...17..l1 + const 
## 
##                Estimate Std. Error t value Pr(>|t|)    
## sj.ts...12..l1  0.60110    0.11881   5.059 5.32e-07 ***
## sj.ts...13..l1  0.26898    0.11691   2.301   0.0217 *  
## sj.ts...17..l1 -0.04096    0.02418  -1.694   0.0906 .  
## const          43.22769    5.81719   7.431 3.02e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.5766 on 730 degrees of freedom
## Multiple R-Squared: 0.7787,  Adjusted R-squared: 0.7778 
## F-statistic: 856.1 on 3 and 730 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation sj.ts...13.: 
## ============================================ 
## sj.ts...13. = sj.ts...12..l1 + sj.ts...13..l1 + sj.ts...17..l1 + const 
## 
##                Estimate Std. Error t value Pr(>|t|)    
## sj.ts...12..l1  0.32133    0.16327   1.968   0.0494 *  
## sj.ts...13..l1  0.65760    0.16067   4.093 4.74e-05 ***
## sj.ts...17..l1 -0.02529    0.03323  -0.761   0.4468    
## const           6.87335    7.99440   0.860   0.3902    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.7924 on 730 degrees of freedom
## Multiple R-Squared: 0.7429,  Adjusted R-squared: 0.7419 
## F-statistic: 703.2 on 3 and 730 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation sj.ts...17.: 
## ============================================ 
## sj.ts...17. = sj.ts...12..l1 + sj.ts...13..l1 + sj.ts...17..l1 + const 
## 
##                 Estimate Std. Error t value Pr(>|t|)    
## sj.ts...12..l1    2.2882     0.6047   3.784 0.000167 ***
## sj.ts...13..l1   -1.8403     0.5951  -3.093 0.002059 ** 
## sj.ts...17..l1    0.8562     0.1231   6.958 7.70e-12 ***
## const          -130.3805    29.6075  -4.404 1.22e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 2.935 on 730 degrees of freedom
## Multiple R-Squared: 0.306,   Adjusted R-squared: 0.3032 
## F-statistic: 107.3 on 3 and 730 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##             sj.ts...12. sj.ts...13. sj.ts...17.
## sj.ts...12.     0.33246      0.2906    -0.07931
## sj.ts...13.     0.29060      0.6279     1.68328
## sj.ts...17.    -0.07931      1.6833     8.61235
## 
## Correlation matrix of residuals:
##             sj.ts...12. sj.ts...13. sj.ts...17.
## sj.ts...12.     1.00000      0.6360    -0.04687
## sj.ts...13.     0.63604      1.0000     0.72385
## sj.ts...17.    -0.04687      0.7239     1.00000
autoplot(forecast(sj.var1))

Neural Network

sj.n1 = nnetar(sj.ts[,4], size = 1)
sj.n2 = nnetar(sj.ts[,4], size = 2)
sj.n3 = nnetar(sj.ts[,4], size = 3)
sj.n4 = nnetar(sj.ts[,4], size = 4)
sj.n1.fcast = forecast(sj.n1)
sj.n2.fcast = forecast(sj.n2)
sj.n3.fcast = forecast(sj.n3)
sj.n4.fcast = forecast(sj.n4)
autoplot(sj.ts[,4]) + 
  autolayer(sj.n1.fcast,series="Size 1") + 
  autolayer(sj.n2.fcast,series="Size 2") + 
  autolayer(sj.n3.fcast,series="Size 3") + 
  autolayer(sj.n4.fcast,series="Size 4") +
  ylab("Cases") + 
  xlab("Time") + 
  ggtitle("San Juan Neural Net")

The forecasts all share a similar pattern. Neural nets with Sizes 2-4 all capture a downward trend after a significant spike; all Sizes capture a bump in the beginning of the forecast followed by a spike.

checkresiduals(sj.n1.fcast)
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.

accuracy(sj.n1.fcast)
##                       ME     RMSE     MAE  MPE MAPE      MASE        ACF1
## Training set -0.02968979 11.80618 7.66867 -Inf  Inf 0.2234228 0.003317925
sj.n1.fcast
##          Point Forecast
## 2004.192       2.863876
## 2004.212       6.016093
## 2004.231       9.296859
## 2004.250      12.027797
## 2004.269      15.063115
## 2004.288      17.882773
## 2004.308      20.282907
## 2004.327      22.328893
## 2004.346      24.040261
## 2004.365      25.549038
## 2004.385      26.625867
## 2004.404      27.409386
## 2004.423      27.701037
## 2004.442      28.027705
## 2004.462      28.009507
## 2004.481      27.776507
## 2004.500      27.362731
## 2004.519      27.068701
## 2004.538      25.965649
## 2004.558      24.735829
## 2004.577      23.118423
## 2004.596      21.305390
## 2004.615      19.557448
## 2004.635      16.486784
## 2004.654      14.223476
## 2004.673      12.719799
## 2004.692      12.820097
## 2004.712      13.002250
## 2004.731      13.956421
## 2004.750      14.970629
## 2004.769      16.605367
## 2004.788      18.074083
## 2004.808      19.626185
## 2004.827      21.135140
## 2004.846      22.788810
## 2004.865      24.200654
## 2004.885      25.448726
## 2004.904      26.681186
## 2004.923      27.796988
## 2004.942      28.746251
## 2004.962      29.534346
## 2004.981      30.238212
## 2005.000      30.882098
## 2005.019      31.346146
## 2005.038      31.824597
## 2005.058      32.233635
## 2005.077      32.596909
## 2005.096      32.888011
## 2005.115      33.145132
## 2005.135      33.358591
## 2005.154      33.539376
## 2005.173      33.685286
## 2005.192      33.744268
## 2005.212      33.706720
## 2005.231      33.570605
## 2005.250      33.353770
## 2005.269      33.049238
## 2005.288      32.667896
## 2005.308      32.224789
## 2005.327      31.739079
## 2005.346      31.224906
## 2005.365      30.695285
## 2005.385      30.167072
## 2005.404      29.653995
## 2005.423      29.172178
## 2005.442      28.724769
## 2005.462      28.321908
## 2005.481      27.968846
## 2005.500      27.670356
## 2005.519      27.421354
## 2005.538      27.236827
## 2005.558      27.116646
## 2005.577      27.066685
## 2005.596      27.085251
## 2005.615      27.168395
## 2005.635      27.338486
## 2005.654      27.574925
## 2005.673      27.855823
## 2005.692      28.136562
## 2005.712      28.410355
## 2005.731      28.651471
## 2005.750      28.853666
## 2005.769      28.995169
## 2005.788      29.079621
## 2005.808      29.103235
## 2005.827      29.070849
## 2005.846      28.980257
## 2005.865      28.842192
## 2005.885      28.664503
## 2005.904      28.454016
## 2005.923      28.217374
## 2005.942      27.963826
## 2005.962      27.701670
## 2005.981      27.436922
## 2006.000      27.174084
## 2006.019      26.919806
## 2006.038      26.676001
## 2006.058      26.445451
## 2006.077      26.229433
## 2006.096      26.029983
## 2006.115      25.847257
## 2006.135      25.681580
## 2006.154      25.532529
## 2006.173      25.399818
checkresiduals(sj.n2.fcast)
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.

accuracy(sj.n2.fcast)
##                       ME     RMSE      MAE  MPE MAPE      MASE        ACF1
## Training set -0.06673523 10.76818 6.983735 -Inf  Inf 0.2034676 0.003897812
sj.n2.fcast
##          Point Forecast
## 2004.192       2.153358
## 2004.212       4.180864
## 2004.231       6.383274
## 2004.250       7.793618
## 2004.269       9.979473
## 2004.288      11.977475
## 2004.308      13.272749
## 2004.327      14.559217
## 2004.346      15.546916
## 2004.365      16.591889
## 2004.385      17.067913
## 2004.404      17.519546
## 2004.423      17.574159
## 2004.442      17.887912
## 2004.462      17.821878
## 2004.481      17.772338
## 2004.500      17.638068
## 2004.519      17.620342
## 2004.538      17.257477
## 2004.558      17.012082
## 2004.577      16.712228
## 2004.596      16.460517
## 2004.615      16.216269
## 2004.635      15.710000
## 2004.654      15.631709
## 2004.673      15.520677
## 2004.692      15.410622
## 2004.712      15.299120
## 2004.731      15.508691
## 2004.750      15.552825
## 2004.769      16.174794
## 2004.788      16.452044
## 2004.808      16.938425
## 2004.827      17.550969
## 2004.846      18.641195
## 2004.865      19.319786
## 2004.885      20.007910
## 2004.904      21.107823
## 2004.923      22.090781
## 2004.942      22.961569
## 2004.962      23.790662
## 2004.981      24.738030
## 2005.000      25.770888
## 2005.019      26.500019
## 2005.038      27.677659
## 2005.058      28.790379
## 2005.077      29.982846
## 2005.096      31.184303
## 2005.115      32.530023
## 2005.135      33.923765
## 2005.154      35.441749
## 2005.173      37.089371
## 2005.192      38.546059
## 2005.212      39.879287
## 2005.231      41.034702
## 2005.250      42.088584
## 2005.269      42.900599
## 2005.288      43.532393
## 2005.308      44.017909
## 2005.327      44.367835
## 2005.346      44.585893
## 2005.365      44.681933
## 2005.385      44.707821
## 2005.404      44.663986
## 2005.423      44.588161
## 2005.442      44.461009
## 2005.462      44.327506
## 2005.481      44.181663
## 2005.500      44.040828
## 2005.519      43.892096
## 2005.538      43.772482
## 2005.558      43.667061
## 2005.577      43.587263
## 2005.596      43.525760
## 2005.615      43.489616
## 2005.635      43.494821
## 2005.654      43.509113
## 2005.673      43.538980
## 2005.692      43.582541
## 2005.712      43.642084
## 2005.731      43.686898
## 2005.750      43.734479
## 2005.769      43.735534
## 2005.788      43.723039
## 2005.808      43.668407
## 2005.827      43.570038
## 2005.846      43.383568
## 2005.865      43.151496
## 2005.885      42.861048
## 2005.904      42.488141
## 2005.923      42.040780
## 2005.942      41.534928
## 2005.962      40.973025
## 2005.981      40.348743
## 2006.000      39.664821
## 2006.019      38.947964
## 2006.038      38.172085
## 2006.058      37.352654
## 2006.077      36.489182
## 2006.096      35.593125
## 2006.115      34.658815
## 2006.135      33.696495
## 2006.154      32.707153
## 2006.173      31.696422
checkresiduals(sj.n3.fcast)
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.

accuracy(sj.n3.fcast)
##                      ME     RMSE      MAE  MPE MAPE      MASE         ACF1
## Training set 0.02416489 9.892929 6.631209 -Inf  Inf 0.1931969 -0.003795321
sj.n3.fcast
##          Point Forecast
## 2004.192       1.623465
## 2004.212       2.803540
## 2004.231       4.365614
## 2004.250       5.485757
## 2004.269       7.187762
## 2004.288       8.673815
## 2004.308       9.799751
## 2004.327      11.034191
## 2004.346      12.002567
## 2004.365      13.052858
## 2004.385      13.677144
## 2004.404      14.304278
## 2004.423      14.524470
## 2004.442      15.018683
## 2004.462      15.105125
## 2004.481      15.185897
## 2004.500      15.172882
## 2004.519      15.279234
## 2004.538      14.942068
## 2004.558      14.759483
## 2004.577      14.513230
## 2004.596      14.333202
## 2004.615      14.125699
## 2004.635      15.140561
## 2004.654      15.228469
## 2004.673      14.821148
## 2004.692      14.902273
## 2004.712      14.868542
## 2004.731      15.090183
## 2004.750      15.126058
## 2004.769      15.823993
## 2004.788      16.108605
## 2004.808      16.659374
## 2004.827      17.347842
## 2004.846      18.509569
## 2004.865      19.278525
## 2004.885      20.151803
## 2004.904      21.487248
## 2004.923      22.704645
## 2004.942      23.909871
## 2004.962      25.154054
## 2004.981      26.585024
## 2005.000      28.187926
## 2005.019      29.542641
## 2005.038      31.504023
## 2005.058      33.500871
## 2005.077      35.702509
## 2005.096      38.052973
## 2005.115      40.704455
## 2005.135      43.559569
## 2005.154      46.692424
## 2005.173      50.105232
## 2005.192      53.608400
## 2005.212      57.262511
## 2005.231      60.999981
## 2005.250      64.897592
## 2005.269      68.812610
## 2005.288      72.785999
## 2005.308      76.775796
## 2005.327      80.565833
## 2005.346      84.250104
## 2005.365      87.792640
## 2005.385      91.231910
## 2005.404      94.468546
## 2005.423      97.566826
## 2005.442     100.394143
## 2005.462     103.081510
## 2005.481     107.857213
## 2005.500     112.787922
## 2005.519     117.488335
## 2005.538     121.393289
## 2005.558     124.645113
## 2005.577     127.046898
## 2005.596     128.680907
## 2005.615     129.565079
## 2005.635     129.446170
## 2005.654     128.674221
## 2005.673     127.637648
## 2005.692     126.418829
## 2005.712     125.142145
## 2005.731     123.870395
## 2005.750     122.815920
## 2005.769     121.770842
## 2005.788     120.890939
## 2005.808     120.051789
## 2005.827     119.224442
## 2005.846     118.136073
## 2005.865     116.942194
## 2005.885     115.610754
## 2005.904     114.033010
## 2005.923     112.234945
## 2005.942     110.319261
## 2005.962     106.907323
## 2005.981     102.397580
## 2006.000      97.889699
## 2006.019      93.735276
## 2006.038      89.584637
## 2006.058      85.473511
## 2006.077      81.522031
## 2006.096      77.743423
## 2006.115      74.004491
## 2006.135      70.264644
## 2006.154      66.505317
## 2006.173      62.785162
checkresiduals(sj.n4.fcast)
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.

accuracy(sj.n4.fcast)
##                       ME     RMSE      MAE  MPE MAPE      MASE        ACF1
## Training set -0.01262545 9.361571 6.421832 -Inf  Inf 0.1870968 -0.01516512
sj.n4.fcast
##          Point Forecast
## 2004.192       1.713198
## 2004.212       3.037005
## 2004.231       4.629786
## 2004.250       5.597591
## 2004.269       7.330493
## 2004.288       8.888608
## 2004.308       9.788867
## 2004.327      10.949356
## 2004.346      11.767011
## 2004.365      12.706200
## 2004.385      13.218102
## 2004.404      13.761281
## 2004.423      13.694947
## 2004.442      14.176138
## 2004.462      14.031144
## 2004.481      13.830394
## 2004.500      13.574832
## 2004.519      13.561185
## 2004.538      12.716193
## 2004.558      12.200309
## 2004.577      11.588408
## 2004.596      11.176546
## 2004.615      10.671486
## 2004.635      11.623065
## 2004.654      11.189595
## 2004.673      10.772242
## 2004.692      10.694182
## 2004.712      10.562266
## 2004.731      10.963337
## 2004.750      11.094119
## 2004.769      11.808791
## 2004.788      12.211616
## 2004.808      12.790973
## 2004.827      13.513925
## 2004.846      14.755184
## 2004.865      15.512001
## 2004.885      16.310806
## 2004.904      17.665346
## 2004.923      18.806399
## 2004.942      19.887469
## 2004.962      20.973768
## 2004.981      22.218895
## 2005.000      23.600133
## 2005.019      24.640751
## 2005.038      26.326756
## 2005.058      27.985626
## 2005.077      29.813577
## 2005.096      31.785748
## 2005.115      34.050230
## 2005.135      36.525331
## 2005.154      39.308346
## 2005.173      42.427615
## 2005.192      45.722235
## 2005.212      49.276962
## 2005.231      53.055190
## 2005.250      57.162822
## 2005.269      61.485566
## 2005.288      66.143923
## 2005.308      71.258004
## 2005.327      76.912263
## 2005.346      83.408739
## 2005.365      91.129063
## 2005.385     100.548372
## 2005.404     111.423268
## 2005.423     123.052597
## 2005.442     133.884284
## 2005.462     141.935510
## 2005.481     145.627199
## 2005.500     145.911122
## 2005.519     143.848342
## 2005.538     140.898765
## 2005.558     137.225313
## 2005.577     133.208249
## 2005.596     129.141494
## 2005.615     125.645605
## 2005.635     122.519354
## 2005.654     120.211622
## 2005.673     118.697484
## 2005.692     118.060528
## 2005.712     118.131082
## 2005.731     118.833339
## 2005.750     120.046445
## 2005.769     121.519650
## 2005.788     123.109148
## 2005.808     124.598891
## 2005.827     125.809272
## 2005.846     126.461648
## 2005.865     126.607760
## 2005.885     126.215699
## 2005.904     125.211302
## 2005.923     123.679960
## 2005.942     121.782032
## 2005.962     119.647934
## 2005.981     117.335759
## 2006.000     114.918307
## 2006.019     112.555360
## 2006.038     110.160840
## 2006.058     107.753394
## 2006.077     105.267907
## 2006.096     102.664576
## 2006.115      99.784272
## 2006.135      96.514269
## 2006.154      92.711368
## 2006.173      88.321871

Evaluating all of the Neural Net models as a whole, they paint a more comprehensive picture than the previous models that we have examined. Considering the patterns in the forecasts, we observe a small bump followed by a significant spike with is in-line with pervious patterns that we have seen in the data.

Iquitos Models & Evaluation

ARIMA

iq.arima = auto.arima(iq.ts[,4])
forecast(iq.arima)
##          Point Forecast     Lo 80    Hi 80     Lo 95    Hi 95
## 2010.115       4.254836 -5.735669 14.24534 -11.02432 19.53399
## 2010.135       4.293675 -6.744911 15.33226 -12.58839 21.17574
## 2010.154       5.431608 -6.705463 17.56868 -13.13044 23.99366
## 2010.173       6.066634 -6.763518 18.89679 -13.55539 25.68866
## 2010.192       6.639917 -6.640693 19.92053 -13.67102 26.95086
## 2010.212       6.488786 -7.089484 20.06706 -14.27739 27.25496
## 2010.231       6.761419 -7.015504 20.53834 -14.30857 27.83141
## 2010.250       7.157613 -6.752719 21.06795 -14.11640 28.43163
## 2010.269       7.599464 -6.400823 21.59975 -13.81213 29.01105
## 2010.288       7.853893 -6.207208 21.91500 -13.65071 29.35849
## 2010.308       7.735849 -6.366439 21.83814 -13.83174 29.30344
## 2010.327       7.751150 -6.379066 21.88137 -13.85915 29.36145
## 2010.346       8.012669 -6.136498 22.16184 -13.62661 29.65195
## 2010.365       7.913764 -6.248270 22.07580 -13.74520 29.57273
## 2010.385       8.057284 -6.113489 22.22806 -13.61504 29.72961
## 2010.404       8.288199 -5.888511 22.46491 -13.39321 29.96961
## 2010.423       8.513911 -5.666833 22.69466 -13.17367 30.20149
## 2010.442       8.796442 -5.387043 22.97993 -12.89533 30.48821
## 2010.462       8.739003 -5.446346 22.92435 -12.95562 30.43362
## 2010.481       8.460781 -5.725834 22.64740 -13.23577 30.15734
## 2010.500       8.554104 -5.633371 22.74158 -13.14377 30.25198
## 2010.519       8.550173 -5.637887 22.73823 -13.14859 30.24894
## 2010.538       8.383847 -5.804611 22.57230 -13.31553 30.08322
## 2010.558       8.691491 -5.497237 22.88022 -13.00830 30.39128
## 2010.577       8.884298 -5.304614 23.07321 -12.81577 30.58437
## 2010.596       8.902554 -5.286483 23.09159 -12.79771 30.60281
## 2010.615       9.260113 -4.929008 23.44923 -12.44028 30.96050
## 2010.635       9.498243 -4.690936 23.68742 -12.20223 31.19872
## 2010.654      10.461064 -3.728154 24.65028 -11.23947 32.16160
## 2010.673      10.353381 -3.835864 24.54263 -11.34720 32.05396
## 2010.692      10.266841 -3.922423 24.45610 -11.43376 31.96745
## 2010.712       9.754020 -4.435255 23.94330 -11.94660 31.45464
## 2010.731       9.148432 -5.040851 23.33772 -12.55220 30.84907
## 2010.750       9.163653 -5.025636 23.35294 -12.53699 30.86430
## 2010.769       8.821410 -5.367884 23.01070 -12.87924 30.52206
## 2010.788       8.573644 -5.615652 22.76294 -13.12701 30.27430
## 2010.808       9.548251 -4.641047 23.73755 -12.15241 31.24891
## 2010.827       9.910978 -4.278321 24.10028 -11.78968 31.61164
## 2010.846       9.651044 -4.538256 23.84034 -12.04962 31.35171
## 2010.865       9.531057 -4.658243 23.72036 -12.16960 31.23172
## 2010.885       9.716234 -4.473067 23.90554 -11.98443 31.41690
## 2010.904      10.839924 -3.349377 25.02922 -10.86074 32.54059
## 2010.923      10.617735 -3.571566 24.80704 -11.08293 32.31840
## 2010.942      10.221644 -3.967657 24.41095 -11.47902 31.92231
## 2010.962       9.982895 -4.206406 24.17220 -11.71777 31.68356
## 2010.981      10.478238 -3.711064 24.66754 -11.22243 32.17890
## 2011.000       9.742020 -4.447281 23.93132 -11.95864 31.44268
## 2011.019       9.212091 -4.977211 23.40139 -12.48857 30.91275
## 2011.038       9.202163 -4.987139 23.39146 -12.49850 30.90283
## 2011.058       9.882128 -4.307173 24.07143 -11.81854 31.58279
## 2011.077       9.050359 -5.138942 23.23966 -12.65030 30.75102
## 2011.096       9.238143 -4.951158 23.42744 -12.46252 30.93881
## 2011.115       9.174743 -5.037563 23.38705 -12.56110 30.91059
## 2011.135       9.049447 -5.167937 23.26683 -12.69417 30.79306
## 2011.154       9.229590 -4.993655 23.45284 -12.52299 30.98217
## 2011.173       9.240333 -4.986895 23.46756 -12.51833 30.99900
## 2011.192       9.271795 -4.958137 23.50173 -12.49101 31.03460
## 2011.212       9.014234 -5.217537 23.24601 -12.75138 30.77985
## 2011.231       8.982427 -5.250594 23.21545 -12.78510 30.74996
## 2011.250       9.034114 -5.199758 23.26798 -12.73471 30.80294
## 2011.269       9.129088 -5.105361 23.36354 -12.64062 30.89880
## 2011.288       9.157462 -5.077380 23.39230 -12.61285 30.92777
## 2011.308       9.031869 -5.203239 23.26698 -12.73885 30.80259
## 2011.327       8.979509 -5.255780 23.21480 -12.79149 30.75051
## 2011.346       9.049466 -5.185946 23.28488 -12.72172 30.82065
## 2011.365       8.964198 -5.271298 23.19969 -12.80711 30.73551
## 2011.385       8.996188 -5.239365 23.23174 -12.77521 30.76759
## 2011.404       9.073733 -5.161859 23.30933 -12.69773 30.84519
## 2011.423       9.153724 -5.081894 23.38934 -12.61778 30.92522
## 2011.442       9.263505 -4.972131 23.49914 -12.50802 31.03503
## 2011.462       9.222043 -5.013605 23.45769 -12.54950 30.99359
## 2011.481       9.082933 -5.152724 23.31859 -12.68863 30.85449
## 2011.500       9.114909 -5.120753 23.35057 -12.65666 30.88648
## 2011.519       9.104517 -5.131149 23.34018 -12.66706 30.87609
## 2011.538       9.021828 -5.213841 23.25750 -12.74975 30.79340
## 2011.558       9.155800 -5.079871 23.39147 -12.61578 30.92738
## 2011.577       9.238606 -4.997066 23.47428 -12.53298 31.01019
## 2011.596       9.242927 -4.992746 23.47860 -12.52866 31.01451
## 2011.615       9.402157 -4.833516 23.63783 -12.36943 31.17374
## 2011.635       9.507682 -4.727992 23.74336 -12.26390 31.27927
## 2011.654       9.943047 -4.292627 24.17872 -11.82854 31.71463
## 2011.673       9.892269 -4.343405 24.12794 -11.87932 31.66385
## 2011.692       9.851422 -4.384252 24.08710 -11.92016 31.62301
## 2011.712       9.617102 -4.618572 23.85278 -12.15448 31.38869
## 2011.731       9.340838 -4.894836 23.57651 -12.43075 31.11242
## 2011.750       9.346907 -4.888767 23.58258 -12.42468 31.11849
## 2011.769       9.190661 -5.045013 23.42634 -12.58092 30.96225
## 2011.788       9.077477 -5.158197 23.31315 -12.69411 30.84906
## 2011.808       9.519951 -4.715723 23.75563 -12.25163 31.29154
## 2011.827       9.684415 -4.551259 23.92009 -12.08717 31.45600
## 2011.846       9.565954 -4.669720 23.80163 -12.20563 31.33754
## 2011.865       9.511155 -4.724519 23.74683 -12.26043 31.28274
## 2011.885       9.595096 -4.640578 23.83077 -12.17649 31.36668
## 2011.904      10.105622 -4.130053 24.34130 -11.66596 31.87721
## 2011.923      10.004489 -4.231185 24.24016 -11.76710 31.77607
## 2011.942       9.824347 -4.411327 24.06002 -11.94724 31.59593
## 2011.962       9.715736 -4.519938 23.95141 -12.05585 31.48732
## 2011.981       9.940781 -4.294893 24.17646 -11.83080 31.71237
## 2012.000       9.606108 -4.629566 23.84178 -12.16548 31.37769
## 2012.019       9.365203 -4.870471 23.60088 -12.40638 31.13679
## 2012.038       9.360644 -4.875030 23.59632 -12.41094 31.13223
## 2012.058       9.669643 -4.566031 23.90532 -12.10194 31.44123
## 2012.077       9.291580 -4.944094 23.52725 -12.48000 31.06317
## 2012.096       9.376900 -4.858774 23.61257 -12.39468 31.14848
autoplot(forecast(iq.arima))

Auto.arima chose Arima(1,0,2). The forecast is quite broad, and obviously, anything below 0 is unreasonable.

checkresiduals(forecast(iq.arima))

## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(1,0,2)(1,0,1)[52] with non-zero mean
## Q* = 25.177, df = 45, p-value = 0.9926
## 
## Model df: 6.   Total lags used: 51
summary(iq.arima)
## Series: iq.ts[, 4] 
## ARIMA(1,0,2)(1,0,1)[52] with non-zero mean 
## 
## Coefficients:
##          ar1      ma1     ma2    sar1     sma1    mean
##       0.8244  -0.3545  0.1176  0.4545  -0.3736  9.4923
## s.e.  0.0509   0.0776  0.0740  0.5889   0.6057  2.2616
## 
## sigma^2 estimated as 60.77:  log likelihood=-886.57
## AIC=1787.14   AICc=1787.59   BIC=1811.96
## 
## Training set error measures:
##                      ME     RMSE     MAE  MPE MAPE      MASE       ACF1
## Training set -0.1017739 7.703724 4.53396 -Inf  Inf 0.4654896 0.01575443

The residuals plot is mostly white noise with a couple of spikes; the ACF performs well; the graph is normally distrubuted but with a slight right skew.

STL

iq.stl = stl(iq.ts[,4], s.window = "periodic", robust = TRUE)
forecast(iq.stl)
##          Point Forecast      Lo 80    Hi 80      Lo 95     Hi 95
## 2010.115     3.08905850  -7.538237 13.71635 -13.163988  19.34210
## 2010.135     2.44055722  -9.765479 14.64659 -16.226964  21.10808
## 2010.154     1.84153902 -11.761226 15.44430 -18.962095  22.64517
## 2010.173     4.52704113 -10.341823 19.39590 -18.212924  27.26701
## 2010.192    14.59314538  -1.442160 30.62845  -9.930738  39.11703
## 2010.212     1.72720125 -15.395267 18.84967 -24.459354  27.91376
## 2010.231     3.85994505 -14.284663 22.00455 -23.889839  31.60973
## 2010.250     1.78117903 -17.330982 20.89334 -27.448349  31.01071
## 2010.269     0.71607639 -19.316962 20.74911 -29.921811  31.35396
## 2010.288     1.13643125 -19.776974 22.04984 -30.847862  33.12072
## 2010.308     0.89940369 -20.858777 22.65758 -32.376861  34.17567
## 2010.327     0.92676759 -21.644593 23.49813 -33.593149  35.44668
## 2010.346     1.12921405 -22.227031 24.48546 -34.591081  36.84951
## 2010.365    -1.10255924 -25.218158 23.01304 -37.984185  35.77907
## 2010.385     0.93314495 -23.918616 25.78491 -37.074343  38.94063
## 2010.404     0.48959287 -25.077141 26.05633 -38.611353  39.59054
## 2010.423     1.30687164 -24.955379 27.56912 -38.857775  41.47152
## 2010.442     2.05500086 -24.884815 28.99482 -39.145893  43.25589
## 2010.462     1.82607889 -25.774675 29.42683 -40.385631  44.03779
## 2010.481     0.62460765 -27.621622 28.87084 -42.574273  43.82349
## 2010.500     2.12801530 -26.749266 31.00530 -42.035976  46.29201
## 2010.519     0.46903019 -29.025805 29.96387 -44.639427  45.57749
## 2010.538    -0.07235503 -30.172076 30.02737 -46.105906  45.96120
## 2010.558     1.55706899 -29.135619 32.24976 -45.383347  48.49748
## 2010.577     1.35515328 -29.919261 32.62957 -46.474936  49.18524
## 2010.596    -1.87774114 -33.723257 29.96777 -50.581255  46.82577
## 2010.615     0.94472800 -31.461827 33.35128 -48.616821  50.50628
## 2010.635    -1.27953958 -34.237584 31.67850 -51.684519  49.12544
## 2010.654     1.12740680 -32.373050 34.62786 -50.107120  52.36193
## 2010.673     1.18021393 -32.854011 35.21444 -50.870642  53.23107
## 2010.692     0.79342852 -33.766323 35.35318 -52.061150  53.64801
## 2010.712     0.10016324 -34.977241 35.17757 -53.546097  53.74642
## 2010.731     0.46550210 -35.122026 36.05303 -53.960926  54.89193
## 2010.750     1.06709961 -35.023344 37.15754 -54.128470  56.26267
## 2010.769     1.18311443 -35.403331 37.76956 -54.771025  57.13725
## 2010.788    -0.40580671 -37.481619 36.67001 -57.108369  56.29676
## 2010.808     3.73673694 -33.822067 41.29554 -53.704497  61.17797
## 2010.827     2.71097595 -35.324687 40.74664 -55.459551  60.88150
## 2010.846     0.50266127 -38.003956 39.00928 -58.388128  59.39345
## 2010.865     3.23243526 -35.739445 42.20432 -56.369913  62.83478
## 2010.885     4.74016806 -34.691487 44.17182 -55.565344  65.04568
## 2010.904     6.65960820 -33.226521 46.54574 -54.340962  67.66018
## 2010.923     1.12980395 -39.205679 41.46529 -60.557994  62.81760
## 2010.942     1.88417994 -38.895706 42.66407 -60.483273  64.25163
## 2010.962     5.35324931 -35.866248 46.57275 -57.686532  68.39303
## 2010.981    16.38619391 -25.268276 58.04066 -47.318821  80.09121
## 2011.000     5.99715768 -36.087790 48.08210 -58.366215  70.36053
## 2011.019     2.70720288 -39.803862 45.21827 -62.307861  67.72227
## 2011.038     3.04444748 -39.888507 45.97740 -62.615840  68.70474
## 2011.058     4.51669832 -38.834040 47.86744 -61.782534  70.81593
## 2011.077    -0.75408721 -44.518621 43.01045 -67.686165  66.17799
## 2011.096     5.10620321 -39.068250 49.28066 -62.452792  72.66520
## 2011.115     3.08905850 -41.491545 47.66966 -65.091090  71.26921
## 2011.135     2.44055722 -42.542529 47.42364 -66.355137  71.23625
## 2011.154     1.84153902 -43.540462 47.22354 -67.564241  71.24732
## 2011.173     4.52704113 -41.250397 50.30448 -65.483509  74.53759
## 2011.192    14.59314538 -31.576344 60.76263 -56.016996  85.20329
## 2011.212     1.72720125 -44.831038 48.28544 -69.477482  72.93188
## 2011.231     3.85994505 -43.083825 50.80372 -67.934356  75.65425
## 2011.250     1.78117903 -45.544981 49.10734 -70.597938  74.16030
## 2011.269     0.71607639 -46.989409 48.42156 -72.243168  73.67532
## 2011.288     1.13643125 -46.945387 49.21825 -72.398364  74.67123
## 2011.308     0.89940369 -47.555825 49.35463 -73.206473  75.00528
## 2011.327     0.92676759 -47.899015 49.75255 -73.745823  75.59936
## 2011.346     1.12921405 -48.064332 50.32276 -74.105822  76.36425
## 2011.365    -1.10255924 -50.661139 48.45602 -76.895867  74.69075
## 2011.385     0.93314495 -48.987800 50.85409 -75.414352  77.28064
## 2011.404     0.48959287 -49.791106 50.77029 -76.408100  77.38729
## 2011.423     1.30687164 -49.331025 51.94477 -76.137108  78.75085
## 2011.442     2.05500086 -48.937591 53.04759 -75.931439  80.04144
## 2011.462     1.82607889 -49.518759 53.17092 -76.699074  80.35123
## 2011.481     0.62460765 -51.070075 52.31929 -78.435588  79.68480
## 2011.500     2.12801530 -49.914161 54.17019 -77.463626  81.71966
## 2011.519     0.46903019 -51.918335 52.85640 -79.650531  80.58859
## 2011.538    -0.07235503 -52.802650 52.65794 -80.716381  80.57167
## 2011.558     1.55706899 -51.513939 54.62808 -79.608033  82.72217
## 2011.577     1.35515328 -52.054394 54.76470 -80.327701  83.03801
## 2011.596    -1.87774114 -55.623696 51.86821 -84.075086  80.31960
## 2011.615     0.94472800 -53.135542 55.02500 -81.763907  83.65336
## 2011.635    -1.27953958 -55.692070 53.13299 -84.496323  81.93724
## 2011.654     1.12740680 -53.615368 55.87018 -82.594442  84.84926
## 2011.673     1.18021393 -53.890824 56.25125 -83.043671  85.40410
## 2011.692     0.79342852 -54.603928 56.19079 -83.929518  85.51637
## 2011.712     0.10016324 -55.621601 55.82193 -85.118922  85.31925
## 2011.731     0.46550210 -55.578792 56.50980 -85.246850  86.17785
## 2011.750     1.06709961 -55.297879 57.43208 -85.135697  87.26990
## 2011.769     1.18311443 -55.500735 57.86696 -85.507352  87.87358
## 2011.788    -0.40580671 -57.406742 56.59513 -87.581215  86.76960
## 2011.808     3.73673694 -53.579531 61.05300 -83.920930  91.39440
## 2011.827     2.71097595 -54.918899 60.34085 -85.426311  90.84826
## 2011.846     0.50266127 -57.439123 58.44445 -88.111651  89.11697
## 2011.865     3.23243526 -55.019588 61.48446 -85.856347  92.32122
## 2011.885     4.74016806 -53.820451 63.30079 -84.820571  94.30091
## 2011.904     6.65960820 -52.207989 65.52721 -83.370613  96.68983
## 2011.923     1.12980395 -58.043179 60.30279 -89.367464  91.62707
## 2011.942     1.88417994 -57.592621 61.36098 -89.077737  92.84610
## 2011.962     5.35324931 -54.425825 65.13232 -86.070956  96.77745
## 2011.981    16.38619391 -43.693633 76.46602 -75.497973 108.27036
## 2012.000     5.99715768 -54.381924 66.37624 -86.344680  98.33899
## 2012.019     2.70720288 -57.969658 63.38406 -90.090048  95.50445
## 2012.038     3.04444748 -57.928738 64.01763 -90.205993  96.29489
## 2012.058     4.51669832 -56.751378 65.78478 -89.184739  98.21814
## 2012.077    -0.75408721 -62.315643 60.80747 -94.904362  93.39619
## 2012.096     5.10620321 -56.747439 66.95985 -89.490779  99.70319
autoplot(forecast(iq.stl)) +
  ylab("Dengue Cases") + 
  ggtitle("Iquitos STL + ETS(A,N,N") +
  xlab("Date")

autoplot(iq.stl)

The STL forecast seems to pick up on the off-season and peak-season well. Visiaully, this model performs significantly better for Iquitos than San Juan. However, as with the San Juan model, this one also predicts negative cases in some years.

checkresiduals(forecast(iq.stl))
## Warning in checkresiduals(forecast(iq.stl)): The fitted degrees of freedom
## is based on the model used for the seasonally adjusted data.

## 
##  Ljung-Box test
## 
## data:  Residuals from STL +  ETS(A,N,N)
## Q* = 43.087, df = 49, p-value = 0.7106
## 
## Model df: 2.   Total lags used: 51
summary(forecast(iq.stl))
## 
## Forecast method: STL +  ETS(A,N,N)
## 
## Model Information:
## ETS(A,N,N) 
## 
## Call:
##  ets(y = na.interp(x), model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend) 
## 
##   Smoothing parameters:
##     alpha = 0.565 
## 
##   Initial states:
##     l = 21.0606 
## 
##   sigma:  8.2925
## 
##      AIC     AICc      BIC 
## 2506.619 2506.714 2517.254 
## 
## Error measures:
##                      ME     RMSE      MAE MPE MAPE     MASE        ACF1
## Training set -0.1295968 8.260067 4.757433 NaN  Inf 0.488433 0.002786997
## 
## Forecasts:
##          Point Forecast      Lo 80    Hi 80      Lo 95     Hi 95
## 2010.115     3.08905850  -7.538237 13.71635 -13.163988  19.34210
## 2010.135     2.44055722  -9.765479 14.64659 -16.226964  21.10808
## 2010.154     1.84153902 -11.761226 15.44430 -18.962095  22.64517
## 2010.173     4.52704113 -10.341823 19.39590 -18.212924  27.26701
## 2010.192    14.59314538  -1.442160 30.62845  -9.930738  39.11703
## 2010.212     1.72720125 -15.395267 18.84967 -24.459354  27.91376
## 2010.231     3.85994505 -14.284663 22.00455 -23.889839  31.60973
## 2010.250     1.78117903 -17.330982 20.89334 -27.448349  31.01071
## 2010.269     0.71607639 -19.316962 20.74911 -29.921811  31.35396
## 2010.288     1.13643125 -19.776974 22.04984 -30.847862  33.12072
## 2010.308     0.89940369 -20.858777 22.65758 -32.376861  34.17567
## 2010.327     0.92676759 -21.644593 23.49813 -33.593149  35.44668
## 2010.346     1.12921405 -22.227031 24.48546 -34.591081  36.84951
## 2010.365    -1.10255924 -25.218158 23.01304 -37.984185  35.77907
## 2010.385     0.93314495 -23.918616 25.78491 -37.074343  38.94063
## 2010.404     0.48959287 -25.077141 26.05633 -38.611353  39.59054
## 2010.423     1.30687164 -24.955379 27.56912 -38.857775  41.47152
## 2010.442     2.05500086 -24.884815 28.99482 -39.145893  43.25589
## 2010.462     1.82607889 -25.774675 29.42683 -40.385631  44.03779
## 2010.481     0.62460765 -27.621622 28.87084 -42.574273  43.82349
## 2010.500     2.12801530 -26.749266 31.00530 -42.035976  46.29201
## 2010.519     0.46903019 -29.025805 29.96387 -44.639427  45.57749
## 2010.538    -0.07235503 -30.172076 30.02737 -46.105906  45.96120
## 2010.558     1.55706899 -29.135619 32.24976 -45.383347  48.49748
## 2010.577     1.35515328 -29.919261 32.62957 -46.474936  49.18524
## 2010.596    -1.87774114 -33.723257 29.96777 -50.581255  46.82577
## 2010.615     0.94472800 -31.461827 33.35128 -48.616821  50.50628
## 2010.635    -1.27953958 -34.237584 31.67850 -51.684519  49.12544
## 2010.654     1.12740680 -32.373050 34.62786 -50.107120  52.36193
## 2010.673     1.18021393 -32.854011 35.21444 -50.870642  53.23107
## 2010.692     0.79342852 -33.766323 35.35318 -52.061150  53.64801
## 2010.712     0.10016324 -34.977241 35.17757 -53.546097  53.74642
## 2010.731     0.46550210 -35.122026 36.05303 -53.960926  54.89193
## 2010.750     1.06709961 -35.023344 37.15754 -54.128470  56.26267
## 2010.769     1.18311443 -35.403331 37.76956 -54.771025  57.13725
## 2010.788    -0.40580671 -37.481619 36.67001 -57.108369  56.29676
## 2010.808     3.73673694 -33.822067 41.29554 -53.704497  61.17797
## 2010.827     2.71097595 -35.324687 40.74664 -55.459551  60.88150
## 2010.846     0.50266127 -38.003956 39.00928 -58.388128  59.39345
## 2010.865     3.23243526 -35.739445 42.20432 -56.369913  62.83478
## 2010.885     4.74016806 -34.691487 44.17182 -55.565344  65.04568
## 2010.904     6.65960820 -33.226521 46.54574 -54.340962  67.66018
## 2010.923     1.12980395 -39.205679 41.46529 -60.557994  62.81760
## 2010.942     1.88417994 -38.895706 42.66407 -60.483273  64.25163
## 2010.962     5.35324931 -35.866248 46.57275 -57.686532  68.39303
## 2010.981    16.38619391 -25.268276 58.04066 -47.318821  80.09121
## 2011.000     5.99715768 -36.087790 48.08210 -58.366215  70.36053
## 2011.019     2.70720288 -39.803862 45.21827 -62.307861  67.72227
## 2011.038     3.04444748 -39.888507 45.97740 -62.615840  68.70474
## 2011.058     4.51669832 -38.834040 47.86744 -61.782534  70.81593
## 2011.077    -0.75408721 -44.518621 43.01045 -67.686165  66.17799
## 2011.096     5.10620321 -39.068250 49.28066 -62.452792  72.66520
## 2011.115     3.08905850 -41.491545 47.66966 -65.091090  71.26921
## 2011.135     2.44055722 -42.542529 47.42364 -66.355137  71.23625
## 2011.154     1.84153902 -43.540462 47.22354 -67.564241  71.24732
## 2011.173     4.52704113 -41.250397 50.30448 -65.483509  74.53759
## 2011.192    14.59314538 -31.576344 60.76263 -56.016996  85.20329
## 2011.212     1.72720125 -44.831038 48.28544 -69.477482  72.93188
## 2011.231     3.85994505 -43.083825 50.80372 -67.934356  75.65425
## 2011.250     1.78117903 -45.544981 49.10734 -70.597938  74.16030
## 2011.269     0.71607639 -46.989409 48.42156 -72.243168  73.67532
## 2011.288     1.13643125 -46.945387 49.21825 -72.398364  74.67123
## 2011.308     0.89940369 -47.555825 49.35463 -73.206473  75.00528
## 2011.327     0.92676759 -47.899015 49.75255 -73.745823  75.59936
## 2011.346     1.12921405 -48.064332 50.32276 -74.105822  76.36425
## 2011.365    -1.10255924 -50.661139 48.45602 -76.895867  74.69075
## 2011.385     0.93314495 -48.987800 50.85409 -75.414352  77.28064
## 2011.404     0.48959287 -49.791106 50.77029 -76.408100  77.38729
## 2011.423     1.30687164 -49.331025 51.94477 -76.137108  78.75085
## 2011.442     2.05500086 -48.937591 53.04759 -75.931439  80.04144
## 2011.462     1.82607889 -49.518759 53.17092 -76.699074  80.35123
## 2011.481     0.62460765 -51.070075 52.31929 -78.435588  79.68480
## 2011.500     2.12801530 -49.914161 54.17019 -77.463626  81.71966
## 2011.519     0.46903019 -51.918335 52.85640 -79.650531  80.58859
## 2011.538    -0.07235503 -52.802650 52.65794 -80.716381  80.57167
## 2011.558     1.55706899 -51.513939 54.62808 -79.608033  82.72217
## 2011.577     1.35515328 -52.054394 54.76470 -80.327701  83.03801
## 2011.596    -1.87774114 -55.623696 51.86821 -84.075086  80.31960
## 2011.615     0.94472800 -53.135542 55.02500 -81.763907  83.65336
## 2011.635    -1.27953958 -55.692070 53.13299 -84.496323  81.93724
## 2011.654     1.12740680 -53.615368 55.87018 -82.594442  84.84926
## 2011.673     1.18021393 -53.890824 56.25125 -83.043671  85.40410
## 2011.692     0.79342852 -54.603928 56.19079 -83.929518  85.51637
## 2011.712     0.10016324 -55.621601 55.82193 -85.118922  85.31925
## 2011.731     0.46550210 -55.578792 56.50980 -85.246850  86.17785
## 2011.750     1.06709961 -55.297879 57.43208 -85.135697  87.26990
## 2011.769     1.18311443 -55.500735 57.86696 -85.507352  87.87358
## 2011.788    -0.40580671 -57.406742 56.59513 -87.581215  86.76960
## 2011.808     3.73673694 -53.579531 61.05300 -83.920930  91.39440
## 2011.827     2.71097595 -54.918899 60.34085 -85.426311  90.84826
## 2011.846     0.50266127 -57.439123 58.44445 -88.111651  89.11697
## 2011.865     3.23243526 -55.019588 61.48446 -85.856347  92.32122
## 2011.885     4.74016806 -53.820451 63.30079 -84.820571  94.30091
## 2011.904     6.65960820 -52.207989 65.52721 -83.370613  96.68983
## 2011.923     1.12980395 -58.043179 60.30279 -89.367464  91.62707
## 2011.942     1.88417994 -57.592621 61.36098 -89.077737  92.84610
## 2011.962     5.35324931 -54.425825 65.13232 -86.070956  96.77745
## 2011.981    16.38619391 -43.693633 76.46602 -75.497973 108.27036
## 2012.000     5.99715768 -54.381924 66.37624 -86.344680  98.33899
## 2012.019     2.70720288 -57.969658 63.38406 -90.090048  95.50445
## 2012.038     3.04444748 -57.928738 64.01763 -90.205993  96.29489
## 2012.058     4.51669832 -56.751378 65.78478 -89.184739  98.21814
## 2012.077    -0.75408721 -62.315643 60.80747 -94.904362  93.39619
## 2012.096     5.10620321 -56.747439 66.95985 -89.490779  99.70319

There is a light pattern in the residual graph, and the ACF breaks at Lags = 3 & 4. However the residuals are still normally distrubuted with a slight right skew.

VAR

Some factors that may affect mosquito population include precipitation, temperature, dew point, and humidity.

Thus the linear model:

Total cases = Average temperature(k) + Dew point(k) + Precipitation + Humidity(%)

iq.tslm = tslm(iq.ts[,4]~iq.ts[,10]+iq.ts[,12]+iq.ts[,13]+iq.ts[,17])

summary(iq.tslm)
## 
## Call:
## tslm(formula = iq.ts[, 4] ~ iq.ts[, 10] + iq.ts[, 12] + iq.ts[, 
##     13] + iq.ts[, 17])
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -11.330  -5.943  -3.275   1.383  72.257 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)   
## (Intercept) -588.27881  223.52810  -2.632  0.00902 **
## iq.ts[, 10]    0.02178    0.02086   1.044  0.29727   
## iq.ts[, 12]   -1.57977    2.39838  -0.659  0.51070   
## iq.ts[, 13]    3.76451    2.86641   1.313  0.19028   
## iq.ts[, 17]   -0.49990    0.62757  -0.797  0.42646   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 10.73 on 251 degrees of freedom
## Multiple R-squared:  0.0504, Adjusted R-squared:  0.03527 
## F-statistic:  3.33 on 4 and 251 DF,  p-value: 0.01112

The linear model shows us that none of the variables chosen are necessarily significant, unlike the linear model for San Juan. However I have decided to proceed in a similar manner, since the purpose of this project is to use these environmental variables to try to predict the spread of Dengue.

iq.tsint = ts.intersect(iq.ts[,12], iq.ts[,13], iq.ts[,17])

VARselect(iq.tsint)
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      4      1      1      4 
## 
## $criteria
##                  1            2           3           4          5
## AIC(n) -0.08909472 -0.128363752 -0.13421663 -0.17714232 -0.1673213
## HQ(n)  -0.02024428 -0.007875485  0.03790947  0.04662161  0.1080805
## SC(n)   0.08189706  0.170871867  0.29326282  0.37858097  0.5166459
## FPE(n)  0.91476679  0.879573939  0.87451822  0.83790826  0.8463946
##                 6          7           8           9          10
## AIC(n) -0.1436316 -0.1120790 -0.07229027 -0.04660093 -0.01304136
## HQ(n)   0.1834080  0.2665984  0.35802496  0.43535214  0.52054953
## SC(n)   0.6685794  0.8283758  0.99640836  1.15034155  1.31214495
## FPE(n)  0.8670082  0.8952596  0.93222786  0.95730941  0.99103989

The following models will be named according to the number of lags used.

VARselect suggests lags = 4 & 1.

iq.var4 = VAR(iq.tsint, p = 4)

summary(iq.var4)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: iq.ts...12., iq.ts...13., iq.ts...17. 
## Deterministic variables: const 
## Sample size: 252 
## Log Likelihood: -1011.659 
## Roots of the characteristic polynomial:
## 0.898 0.898 0.712 0.6682 0.6682 0.6173 0.6173 0.602 0.5705 0.4916 0.4916 0.0489
## Call:
## VAR(y = iq.tsint, p = 4)
## 
## 
## Estimation results for equation iq.ts...12.: 
## ============================================ 
## iq.ts...12. = iq.ts...12..l1 + iq.ts...13..l1 + iq.ts...17..l1 + iq.ts...12..l2 + iq.ts...13..l2 + iq.ts...17..l2 + iq.ts...12..l3 + iq.ts...13..l3 + iq.ts...17..l3 + iq.ts...12..l4 + iq.ts...13..l4 + iq.ts...17..l4 + const 
## 
##                Estimate Std. Error t value Pr(>|t|)    
## iq.ts...12..l1  0.08523    0.22255   0.383    0.702    
## iq.ts...13..l1  0.32082    0.28284   1.134    0.258    
## iq.ts...17..l1 -0.09114    0.05864  -1.554    0.121    
## iq.ts...12..l2 -0.17029    0.22150  -0.769    0.443    
## iq.ts...13..l2  0.44348    0.28574   1.552    0.122    
## iq.ts...17..l2 -0.07151    0.05904  -1.211    0.227    
## iq.ts...12..l3  0.06110    0.21997   0.278    0.781    
## iq.ts...13..l3 -0.07036    0.28557  -0.246    0.806    
## iq.ts...17..l3  0.01173    0.05901   0.199    0.843    
## iq.ts...12..l4  0.15451    0.21738   0.711    0.478    
## iq.ts...13..l4 -0.10040    0.27684  -0.363    0.717    
## iq.ts...17..l4 -0.01700    0.05828  -0.292    0.771    
## const          99.65304   23.94749   4.161 4.42e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.9549 on 239 degrees of freedom
## Multiple R-Squared: 0.4068,  Adjusted R-squared: 0.377 
## F-statistic: 13.66 on 12 and 239 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation iq.ts...13.: 
## ============================================ 
## iq.ts...13. = iq.ts...12..l1 + iq.ts...13..l1 + iq.ts...17..l1 + iq.ts...12..l2 + iq.ts...13..l2 + iq.ts...17..l2 + iq.ts...12..l3 + iq.ts...13..l3 + iq.ts...17..l3 + iq.ts...12..l4 + iq.ts...13..l4 + iq.ts...17..l4 + const 
## 
##                  Estimate Std. Error t value Pr(>|t|)   
## iq.ts...12..l1 -0.1354917  0.2027256  -0.668  0.50456   
## iq.ts...13..l1  0.6867163  0.2576476   2.665  0.00822 **
## iq.ts...17..l1 -0.0635551  0.0534210  -1.190  0.23534   
## iq.ts...12..l2  0.0410781  0.2017685   0.204  0.83885   
## iq.ts...13..l2  0.1498824  0.2602886   0.576  0.56527   
## iq.ts...17..l2 -0.0006325  0.0537848  -0.012  0.99063   
## iq.ts...12..l3 -0.1829216  0.2003791  -0.913  0.36223   
## iq.ts...13..l3  0.4450298  0.2601391   1.711  0.08843 . 
## iq.ts...17..l3 -0.0701198  0.0537543  -1.304  0.19333   
## iq.ts...12..l4  0.1629231  0.1980236   0.823  0.41147   
## iq.ts...13..l4 -0.1358648  0.2521826  -0.539  0.59056   
## iq.ts...17..l4  0.0420633  0.0530910   0.792  0.42898   
## const          -0.5985053 21.8146679  -0.027  0.97813   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.8699 on 239 degrees of freedom
## Multiple R-Squared: 0.5373,  Adjusted R-squared: 0.514 
## F-statistic: 23.13 on 12 and 239 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation iq.ts...17.: 
## ============================================ 
## iq.ts...17. = iq.ts...12..l1 + iq.ts...13..l1 + iq.ts...17..l1 + iq.ts...12..l2 + iq.ts...13..l2 + iq.ts...17..l2 + iq.ts...12..l3 + iq.ts...13..l3 + iq.ts...17..l3 + iq.ts...12..l4 + iq.ts...13..l4 + iq.ts...17..l4 + const 
## 
##                  Estimate Std. Error t value Pr(>|t|)    
## iq.ts...12..l1   -0.97830    1.17675  -0.831 0.406605    
## iq.ts...13..l1    1.80845    1.49556   1.209 0.227776    
## iq.ts...17..l1    0.04605    0.31009   0.149 0.882073    
## iq.ts...12..l2    0.83842    1.17120   0.716 0.474775    
## iq.ts...13..l2   -1.04386    1.51089  -0.691 0.490304    
## iq.ts...17..l2    0.27574    0.31220   0.883 0.378008    
## iq.ts...12..l3   -1.16228    1.16313  -0.999 0.318676    
## iq.ts...13..l3    2.25587    1.51002   1.494 0.136513    
## iq.ts...17..l3   -0.37865    0.31203  -1.214 0.226123    
## iq.ts...12..l4    0.61069    1.14946   0.531 0.595715    
## iq.ts...13..l4   -0.66484    1.46383  -0.454 0.650115    
## iq.ts...17..l4    0.38325    0.30818   1.244 0.214859    
## const          -429.48801  126.62675  -3.392 0.000813 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 5.049 on 239 degrees of freedom
## Multiple R-Squared: 0.3942,  Adjusted R-squared: 0.3637 
## F-statistic: 12.96 on 12 and 239 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##             iq.ts...12. iq.ts...13. iq.ts...17.
## iq.ts...12.      0.9118      0.1103      -2.769
## iq.ts...13.      0.1103      0.7567       3.116
## iq.ts...17.     -2.7687      3.1162      25.495
## 
## Correlation matrix of residuals:
##             iq.ts...12. iq.ts...13. iq.ts...17.
## iq.ts...12.      1.0000      0.1328     -0.5742
## iq.ts...13.      0.1328      1.0000      0.7095
## iq.ts...17.     -0.5742      0.7095      1.0000
autoplot(forecast(iq.var4))

iq.var1 = VAR(iq.tsint, p = 1)

summary(iq.var4)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: iq.ts...12., iq.ts...13., iq.ts...17. 
## Deterministic variables: const 
## Sample size: 252 
## Log Likelihood: -1011.659 
## Roots of the characteristic polynomial:
## 0.898 0.898 0.712 0.6682 0.6682 0.6173 0.6173 0.602 0.5705 0.4916 0.4916 0.0489
## Call:
## VAR(y = iq.tsint, p = 4)
## 
## 
## Estimation results for equation iq.ts...12.: 
## ============================================ 
## iq.ts...12. = iq.ts...12..l1 + iq.ts...13..l1 + iq.ts...17..l1 + iq.ts...12..l2 + iq.ts...13..l2 + iq.ts...17..l2 + iq.ts...12..l3 + iq.ts...13..l3 + iq.ts...17..l3 + iq.ts...12..l4 + iq.ts...13..l4 + iq.ts...17..l4 + const 
## 
##                Estimate Std. Error t value Pr(>|t|)    
## iq.ts...12..l1  0.08523    0.22255   0.383    0.702    
## iq.ts...13..l1  0.32082    0.28284   1.134    0.258    
## iq.ts...17..l1 -0.09114    0.05864  -1.554    0.121    
## iq.ts...12..l2 -0.17029    0.22150  -0.769    0.443    
## iq.ts...13..l2  0.44348    0.28574   1.552    0.122    
## iq.ts...17..l2 -0.07151    0.05904  -1.211    0.227    
## iq.ts...12..l3  0.06110    0.21997   0.278    0.781    
## iq.ts...13..l3 -0.07036    0.28557  -0.246    0.806    
## iq.ts...17..l3  0.01173    0.05901   0.199    0.843    
## iq.ts...12..l4  0.15451    0.21738   0.711    0.478    
## iq.ts...13..l4 -0.10040    0.27684  -0.363    0.717    
## iq.ts...17..l4 -0.01700    0.05828  -0.292    0.771    
## const          99.65304   23.94749   4.161 4.42e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.9549 on 239 degrees of freedom
## Multiple R-Squared: 0.4068,  Adjusted R-squared: 0.377 
## F-statistic: 13.66 on 12 and 239 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation iq.ts...13.: 
## ============================================ 
## iq.ts...13. = iq.ts...12..l1 + iq.ts...13..l1 + iq.ts...17..l1 + iq.ts...12..l2 + iq.ts...13..l2 + iq.ts...17..l2 + iq.ts...12..l3 + iq.ts...13..l3 + iq.ts...17..l3 + iq.ts...12..l4 + iq.ts...13..l4 + iq.ts...17..l4 + const 
## 
##                  Estimate Std. Error t value Pr(>|t|)   
## iq.ts...12..l1 -0.1354917  0.2027256  -0.668  0.50456   
## iq.ts...13..l1  0.6867163  0.2576476   2.665  0.00822 **
## iq.ts...17..l1 -0.0635551  0.0534210  -1.190  0.23534   
## iq.ts...12..l2  0.0410781  0.2017685   0.204  0.83885   
## iq.ts...13..l2  0.1498824  0.2602886   0.576  0.56527   
## iq.ts...17..l2 -0.0006325  0.0537848  -0.012  0.99063   
## iq.ts...12..l3 -0.1829216  0.2003791  -0.913  0.36223   
## iq.ts...13..l3  0.4450298  0.2601391   1.711  0.08843 . 
## iq.ts...17..l3 -0.0701198  0.0537543  -1.304  0.19333   
## iq.ts...12..l4  0.1629231  0.1980236   0.823  0.41147   
## iq.ts...13..l4 -0.1358648  0.2521826  -0.539  0.59056   
## iq.ts...17..l4  0.0420633  0.0530910   0.792  0.42898   
## const          -0.5985053 21.8146679  -0.027  0.97813   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.8699 on 239 degrees of freedom
## Multiple R-Squared: 0.5373,  Adjusted R-squared: 0.514 
## F-statistic: 23.13 on 12 and 239 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation iq.ts...17.: 
## ============================================ 
## iq.ts...17. = iq.ts...12..l1 + iq.ts...13..l1 + iq.ts...17..l1 + iq.ts...12..l2 + iq.ts...13..l2 + iq.ts...17..l2 + iq.ts...12..l3 + iq.ts...13..l3 + iq.ts...17..l3 + iq.ts...12..l4 + iq.ts...13..l4 + iq.ts...17..l4 + const 
## 
##                  Estimate Std. Error t value Pr(>|t|)    
## iq.ts...12..l1   -0.97830    1.17675  -0.831 0.406605    
## iq.ts...13..l1    1.80845    1.49556   1.209 0.227776    
## iq.ts...17..l1    0.04605    0.31009   0.149 0.882073    
## iq.ts...12..l2    0.83842    1.17120   0.716 0.474775    
## iq.ts...13..l2   -1.04386    1.51089  -0.691 0.490304    
## iq.ts...17..l2    0.27574    0.31220   0.883 0.378008    
## iq.ts...12..l3   -1.16228    1.16313  -0.999 0.318676    
## iq.ts...13..l3    2.25587    1.51002   1.494 0.136513    
## iq.ts...17..l3   -0.37865    0.31203  -1.214 0.226123    
## iq.ts...12..l4    0.61069    1.14946   0.531 0.595715    
## iq.ts...13..l4   -0.66484    1.46383  -0.454 0.650115    
## iq.ts...17..l4    0.38325    0.30818   1.244 0.214859    
## const          -429.48801  126.62675  -3.392 0.000813 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 5.049 on 239 degrees of freedom
## Multiple R-Squared: 0.3942,  Adjusted R-squared: 0.3637 
## F-statistic: 12.96 on 12 and 239 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##             iq.ts...12. iq.ts...13. iq.ts...17.
## iq.ts...12.      0.9118      0.1103      -2.769
## iq.ts...13.      0.1103      0.7567       3.116
## iq.ts...17.     -2.7687      3.1162      25.495
## 
## Correlation matrix of residuals:
##             iq.ts...12. iq.ts...13. iq.ts...17.
## iq.ts...12.      1.0000      0.1328     -0.5742
## iq.ts...13.      0.1328      1.0000      0.7095
## iq.ts...17.     -0.5742      0.7095      1.0000
autoplot(forecast(iq.var4))

Neural Network

iq.n1 = nnetar(iq.ts[,4], size = 1)
iq.n2 = nnetar(iq.ts[,4], size = 2)
iq.n3 = nnetar(iq.ts[,4], size = 3)
iq.n4 = nnetar(iq.ts[,4], size = 4)
iq.n1.fcast = forecast(iq.n1)
iq.n2.fcast = forecast(iq.n2)
iq.n3.fcast = forecast(iq.n3)
iq.n4.fcast = forecast(iq.n4)
autoplot(iq.ts[,4]) + 
  autolayer(iq.n1.fcast,series="Size 1") + 
  autolayer(iq.n2.fcast,series="Size 2") + 
  autolayer(iq.n3.fcast,series="Size 3") + 
  autolayer(iq.n4.fcast,series="Size 4") +
  ylab("Cases") + 
  xlab("Time") + 
  ggtitle("Iquitos Neural Net")

I am not sure why the Neural net models perform so differently for San Juan and Iquitos. For San Juan, the model picked up nuance in the data, whereas with Iquitos, the models produce white noise or flat predictions at every Size. Perhaps the number of observations or time frame has a significant impact. Needless to say the performance here is sub-par.

checkresiduals(iq.n1.fcast)
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.

accuracy(iq.n1.fcast)
##                        ME    RMSE      MAE  MPE MAPE      MASE
## Training set -0.002789042 6.46119 4.071806 -Inf  Inf 0.4180415
##                      ACF1
## Training set -0.006693787
iq.n1.fcast
##          Point Forecast
## 2010.115       3.791414
## 2010.135       3.812863
## 2010.154       4.729203
## 2010.173       5.623150
## 2010.192       6.168889
## 2010.212       6.778439
## 2010.231       7.215695
## 2010.250       7.561193
## 2010.269       7.851504
## 2010.288       8.068321
## 2010.308       8.232043
## 2010.327       8.357674
## 2010.346       8.453944
## 2010.365       8.521798
## 2010.385       8.574285
## 2010.404       8.620262
## 2010.423       8.658044
## 2010.442       8.692066
## 2010.462       8.713620
## 2010.481       8.724756
## 2010.500       8.734280
## 2010.519       8.739733
## 2010.538       8.738673
## 2010.558       8.743355
## 2010.577       8.742492
## 2010.596       8.742519
## 2010.615       8.745065
## 2010.635       8.745916
## 2010.654       8.749645
## 2010.673       8.766645
## 2010.692       8.767866
## 2010.712       8.773467
## 2010.731       8.775160
## 2010.750       8.775560
## 2010.769       8.769251
## 2010.788       8.762627
## 2010.808       8.778252
## 2010.827       8.804496
## 2010.846       8.822525
## 2010.865       8.830303
## 2010.885       8.841757
## 2010.904       8.865086
## 2010.923       8.870562
## 2010.942       8.872756
## 2010.962       8.875352
## 2010.981       8.884345
## 2011.000       8.872964
## 2011.019       8.856579
## 2011.038       8.848609
## 2011.058       8.842271
## 2011.077       8.827269
## 2011.096       8.813536
## 2011.115       8.806165
## 2011.135       8.798003
## 2011.154       8.794525
## 2011.173       8.793728
## 2011.192       8.794120
## 2011.212       8.796483
## 2011.231       8.799463
## 2011.250       8.802852
## 2011.269       8.806475
## 2011.288       8.809949
## 2011.308       8.813212
## 2011.327       8.816176
## 2011.346       8.818793
## 2011.365       8.821060
## 2011.385       8.822997
## 2011.404       8.824645
## 2011.423       8.826036
## 2011.442       8.827211
## 2011.462       8.828185
## 2011.481       8.828978
## 2011.500       8.829626
## 2011.519       8.830143
## 2011.538       8.830544
## 2011.558       8.830869
## 2011.577       8.831116
## 2011.596       8.831306
## 2011.615       8.831460
## 2011.635       8.831577
## 2011.654       8.831676
## 2011.673       8.831792
## 2011.692       8.831878
## 2011.712       8.831964
## 2011.731       8.832037
## 2011.750       8.832095
## 2011.769       8.832128
## 2011.788       8.832141
## 2011.808       8.832189
## 2011.827       8.832278
## 2011.846       8.832384
## 2011.865       8.832491
## 2011.885       8.832611
## 2011.904       8.832762
## 2011.923       8.832891
## 2011.942       8.833007
## 2011.962       8.833111
## 2011.981       8.833214
## 2012.000       8.833266
## 2012.019       8.833277
## 2012.038       8.833271
## 2012.058       8.833244
## 2012.077       8.833184
## 2012.096       8.833106
checkresiduals(iq.n2.fcast)
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.

accuracy(iq.n2.fcast)
##                        ME     RMSE      MAE  MPE MAPE     MASE        ACF1
## Training set 0.0008275682 5.676093 3.624278 -Inf  Inf 0.372095 -0.03051129
iq.n2.fcast
##          Point Forecast
## 2010.115       4.256890
## 2010.135       4.369391
## 2010.154       4.215238
## 2010.173       4.372372
## 2010.192       4.276714
## 2010.212       4.249860
## 2010.231       4.248447
## 2010.250       4.231633
## 2010.269       4.225171
## 2010.288       4.226491
## 2010.308       4.219201
## 2010.327       4.217488
## 2010.346       4.215579
## 2010.365       4.217427
## 2010.385       4.217617
## 2010.404       4.215353
## 2010.423       4.220189
## 2010.442       4.230865
## 2010.462       4.224984
## 2010.481       4.218757
## 2010.500       4.217064
## 2010.519       4.215202
## 2010.538       4.217220
## 2010.558       4.214293
## 2010.577       4.214145
## 2010.596       4.213968
## 2010.615       4.212955
## 2010.635       4.212647
## 2010.654       4.213238
## 2010.673       4.241571
## 2010.692       4.227296
## 2010.712       4.226530
## 2010.731       4.223650
## 2010.750       4.220768
## 2010.769       4.217800
## 2010.788       4.218862
## 2010.808       4.244100
## 2010.827       4.339208
## 2010.846       4.359020
## 2010.865       4.323269
## 2010.885       4.330972
## 2010.904       4.411550
## 2010.923       4.378236
## 2010.942       4.349504
## 2010.962       4.341765
## 2010.981       4.372099
## 2011.000       4.310236
## 2011.019       4.272010
## 2011.038       4.262110
## 2011.058       4.257956
## 2011.077       4.237738
## 2011.096       4.228775
## 2011.115       4.226473
## 2011.135       4.223374
## 2011.154       4.221471
## 2011.173       4.221010
## 2011.192       4.220152
## 2011.212       4.219676
## 2011.231       4.219434
## 2011.250       4.219192
## 2011.269       4.219053
## 2011.288       4.218977
## 2011.308       4.218901
## 2011.327       4.218859
## 2011.346       4.218828
## 2011.365       4.218815
## 2011.385       4.218806
## 2011.404       4.218793
## 2011.423       4.218802
## 2011.442       4.218834
## 2011.462       4.218827
## 2011.481       4.218811
## 2011.500       4.218803
## 2011.519       4.218792
## 2011.538       4.218793
## 2011.558       4.218783
## 2011.577       4.218778
## 2011.596       4.218776
## 2011.615       4.218771
## 2011.635       4.218768
## 2011.654       4.218768
## 2011.673       4.218850
## 2011.692       4.218833
## 2011.712       4.218835
## 2011.731       4.218833
## 2011.750       4.218820
## 2011.769       4.218808
## 2011.788       4.218806
## 2011.808       4.218876
## 2011.827       4.219180
## 2011.846       4.219341
## 2011.865       4.219325
## 2011.885       4.219387
## 2011.904       4.219656
## 2011.923       4.219637
## 2011.942       4.219582
## 2011.962       4.219560
## 2011.981       4.219631
## 2012.000       4.219458
## 2012.019       4.219299
## 2012.038       4.219208
## 2012.058       4.219132
## 2012.077       4.219030
## 2012.096       4.218960
checkresiduals(iq.n3.fcast)
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.

accuracy(iq.n3.fcast)
##                       ME     RMSE      MAE  MPE MAPE      MASE        ACF1
## Training set -0.02248599 4.956641 3.334689 -Inf  Inf 0.3423636 -0.01034411
iq.n3.fcast
##          Point Forecast
## 2010.115       4.459031
## 2010.135       4.411400
## 2010.154       4.166678
## 2010.173       4.349768
## 2010.192       4.234116
## 2010.212       4.216010
## 2010.231       4.224030
## 2010.250       4.212775
## 2010.269       4.209912
## 2010.288       4.191694
## 2010.308       4.207935
## 2010.327       4.206508
## 2010.346       4.208825
## 2010.365       4.202230
## 2010.385       4.200741
## 2010.404       4.205362
## 2010.423       4.187510
## 2010.442       4.165007
## 2010.462       4.178335
## 2010.481       4.198567
## 2010.500       4.202122
## 2010.519       4.207130
## 2010.538       4.200821
## 2010.558       4.209137
## 2010.577       4.207650
## 2010.596       4.207340
## 2010.615       4.211108
## 2010.635       4.211355
## 2010.654       4.208272
## 2010.673       4.116350
## 2010.692       4.171122
## 2010.712       4.171081
## 2010.731       4.178596
## 2010.750       4.189065
## 2010.769       4.198788
## 2010.788       4.196077
## 2010.808       4.111580
## 2010.827       4.066749
## 2010.846       4.047235
## 2010.865       4.042918
## 2010.885       4.035541
## 2010.904       4.028065
## 2010.923       4.025248
## 2010.942       4.029959
## 2010.962       4.030324
## 2010.981       4.023854
## 2011.000       4.048344
## 2011.019       4.135520
## 2011.038       4.135498
## 2011.058       4.377710
## 2011.077       4.225397
## 2011.096       4.227245
## 2011.115       4.220944
## 2011.135       4.195384
## 2011.154       4.197969
## 2011.173       4.193018
## 2011.192       4.191173
## 2011.212       4.191657
## 2011.231       4.190871
## 2011.250       4.190890
## 2011.269       4.190951
## 2011.288       4.191044
## 2011.308       4.190946
## 2011.327       4.190956
## 2011.346       4.190931
## 2011.365       4.190978
## 2011.385       4.191003
## 2011.404       4.190967
## 2011.423       4.191139
## 2011.442       4.191386
## 2011.462       4.191324
## 2011.481       4.191165
## 2011.500       4.191109
## 2011.519       4.191015
## 2011.538       4.191036
## 2011.558       4.190951
## 2011.577       4.190943
## 2011.596       4.190940
## 2011.615       4.190893
## 2011.635       4.190884
## 2011.654       4.190906
## 2011.673       4.191783
## 2011.692       4.191442
## 2011.712       4.191479
## 2011.731       4.191460
## 2011.750       4.191292
## 2011.769       4.191179
## 2011.788       4.191160
## 2011.808       4.191933
## 2011.827       4.192506
## 2011.846       4.192898
## 2011.865       4.193161
## 2011.885       4.193355
## 2011.904       4.193511
## 2011.923       4.193603
## 2011.942       4.193604
## 2011.962       4.193620
## 2011.981       4.193686
## 2012.000       4.193469
## 2012.019       4.192611
## 2012.038       4.192418
## 2012.058       4.189910
## 2012.077       4.190787
## 2012.096       4.190669
checkresiduals(iq.n4.fcast)
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.

accuracy(iq.n4.fcast)
##                      ME     RMSE      MAE  MPE MAPE      MASE       ACF1
## Training set 0.01159781 4.306568 3.058338 -Inf  Inf 0.3139914 0.03443965
iq.n4.fcast
##          Point Forecast
## 2010.115       4.437469
## 2010.135       5.330118
## 2010.154       4.217758
## 2010.173       4.260243
## 2010.192       4.274966
## 2010.212       4.158213
## 2010.231       4.193563
## 2010.250       4.153089
## 2010.269       4.121580
## 2010.288       4.097215
## 2010.308       4.121448
## 2010.327       4.136242
## 2010.346       4.122950
## 2010.365       4.160987
## 2010.385       4.167289
## 2010.404       4.120351
## 2010.423       4.095742
## 2010.442       4.069891
## 2010.462       4.075322
## 2010.481       4.108340
## 2010.500       4.111704
## 2010.519       4.116616
## 2010.538       4.156649
## 2010.558       4.127774
## 2010.577       4.143113
## 2010.596       4.147614
## 2010.615       4.129454
## 2010.635       4.129507
## 2010.654       4.114142
## 2010.673       4.054087
## 2010.692       4.077098
## 2010.712       4.072669
## 2010.731       4.078471
## 2010.750       4.083302
## 2010.769       4.124461
## 2010.788       4.151844
## 2010.808       4.056642
## 2010.827       3.715693
## 2010.846       3.678489
## 2010.865       3.889232
## 2010.885       3.838082
## 2010.904       3.613445
## 2010.923       3.723145
## 2010.942       3.845778
## 2010.962       3.855737
## 2010.981       3.690542
## 2011.000       3.955064
## 2011.019       4.009403
## 2011.038       4.007558
## 2011.058       4.032273
## 2011.077       4.065452
## 2011.096       4.096042
## 2011.115       4.076825
## 2011.135       4.071234
## 2011.154       4.082057
## 2011.173       4.079558
## 2011.192       4.080037
## 2011.212       4.082518
## 2011.231       4.081944
## 2011.250       4.082671
## 2011.269       4.083336
## 2011.288       4.083636
## 2011.308       4.083578
## 2011.327       4.083490
## 2011.346       4.083631
## 2011.365       4.083211
## 2011.385       4.083085
## 2011.404       4.083559
## 2011.423       4.083836
## 2011.442       4.084208
## 2011.462       4.084288
## 2011.481       4.083989
## 2011.500       4.083949
## 2011.519       4.083858
## 2011.538       4.083364
## 2011.558       4.083603
## 2011.577       4.083413
## 2011.596       4.083305
## 2011.615       4.083512
## 2011.635       4.083503
## 2011.654       4.083684
## 2011.673       4.084401
## 2011.692       4.084263
## 2011.712       4.084382
## 2011.731       4.084398
## 2011.750       4.084322
## 2011.769       4.083876
## 2011.788       4.083500
## 2011.808       4.084441
## 2011.827       4.088369
## 2011.846       4.089455
## 2011.865       4.087689
## 2011.885       4.088531
## 2011.904       4.091106
## 2011.923       4.090059
## 2011.942       4.088883
## 2011.962       4.088760
## 2011.981       4.090342
## 2012.000       4.087428
## 2012.019       4.086555
## 2012.038       4.086345
## 2012.058       4.085575
## 2012.077       4.085058
## 2012.096       4.084569