#Removing all the objects in the memory
rm(list = ls())
#Loading the libraries 
library(fpp2)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## -- Attaching packages ---------------------------------------------- fpp2 2.4 --
## v ggplot2   3.3.3     v fma       2.4  
## v forecast  8.14      v expsmooth 2.3
## 
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v tibble  3.1.1     v dplyr   1.0.6
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## v purrr   0.3.4
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(dplyr)
library(readr)
library(psych)
## 
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
library(caret)
## Loading required package: lattice
## 
## Attaching package: 'caret'
## The following object is masked from 'package:purrr':
## 
##     lift
library(neuralnet)
## 
## Attaching package: 'neuralnet'
## The following object is masked from 'package:dplyr':
## 
##     compute
library(neuralnet)
library(knitr)
#Importing the test and train dataset
dengue_features_test <- read_csv("C:/Users/HP/Desktop/dengue_features_test.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   .default = col_double(),
##   city = col_character(),
##   week_start_date = col_date(format = "")
## )
## i Use `spec()` for the full column specifications.
View(dengue_features_test)
attach(dengue_features_test)
dim(dengue_features_test)
## [1] 416  24
#Selecting only important variables 
dengue_features_test <- select(dengue_features_test,
                               city, year, week_start_date, precipitation_amt_mm, 
                               reanalysis_air_temp_k ,reanalysis_avg_temp_k,
                               reanalysis_relative_humidity_percent, 
                               reanalysis_sat_precip_amt_mm)

view(dengue_features_test)
attach(dengue_features_test)
## The following objects are masked from dengue_features_test (pos = 3):
## 
##     city, precipitation_amt_mm, reanalysis_air_temp_k,
##     reanalysis_avg_temp_k, reanalysis_relative_humidity_percent,
##     reanalysis_sat_precip_amt_mm, week_start_date, year
#Checking for missing values and removing them 
sum(is.na(dengue_features_test))
## [1] 10
#Removing missing observation 
dengue_features_test <- na.omit(dengue_features_test)
dengue_features_test
## # A tibble: 414 x 8
##    city   year week_start_date precipitation_amt_mm reanalysis_air_temp_k
##    <chr> <dbl> <date>                         <dbl>                 <dbl>
##  1 sj     2008 2008-04-29                     78.6                   298.
##  2 sj     2008 2008-05-06                     12.6                   298.
##  3 sj     2008 2008-05-13                      3.66                  299.
##  4 sj     2008 2008-05-20                      0                     300.
##  5 sj     2008 2008-05-27                      0.76                  300.
##  6 sj     2008 2008-06-03                     71.2                   300.
##  7 sj     2008 2008-06-10                     49.0                   300.
##  8 sj     2008 2008-06-17                     30.8                   300.
##  9 sj     2008 2008-06-24                      8.02                  301.
## 10 sj     2008 2008-07-01                     17.5                   300.
## # ... with 404 more rows, and 3 more variables: reanalysis_avg_temp_k <dbl>,
## #   reanalysis_relative_humidity_percent <dbl>,
## #   reanalysis_sat_precip_amt_mm <dbl>
#Train dataset
dengue_features_train <- read_csv("C:/Users/HP/Desktop/dengue_features_train.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   .default = col_double(),
##   city = col_character(),
##   week_start_date = col_date(format = "")
## )
## i Use `spec()` for the full column specifications.
View(dengue_features_train)
attach(dengue_features_train) #Attaching the variables in the dataset
## The following objects are masked from dengue_features_test (pos = 3):
## 
##     city, precipitation_amt_mm, reanalysis_air_temp_k,
##     reanalysis_avg_temp_k, reanalysis_relative_humidity_percent,
##     reanalysis_sat_precip_amt_mm, week_start_date, year
## The following objects are masked from dengue_features_test (pos = 4):
## 
##     city, ndvi_ne, ndvi_nw, ndvi_se, ndvi_sw, precipitation_amt_mm,
##     reanalysis_air_temp_k, reanalysis_avg_temp_k,
##     reanalysis_dew_point_temp_k, reanalysis_max_air_temp_k,
##     reanalysis_min_air_temp_k, reanalysis_precip_amt_kg_per_m2,
##     reanalysis_relative_humidity_percent, reanalysis_sat_precip_amt_mm,
##     reanalysis_specific_humidity_g_per_kg, reanalysis_tdtr_k,
##     station_avg_temp_c, station_diur_temp_rng_c, station_max_temp_c,
##     station_min_temp_c, station_precip_mm, week_start_date, weekofyear,
##     year
#Selecting only important variables 
dengue_features_train <- select(dengue_features_train, city,
                                year, week_start_date,precipitation_amt_mm,
                                reanalysis_air_temp_k,reanalysis_avg_temp_k,
                                reanalysis_relative_humidity_percent,reanalysis_sat_precip_amt_mm
                                )
dengue_features_train <- as_tibble(dengue_features_train)
view(dengue_features_train)
attach(dengue_features_train)
## The following objects are masked from dengue_features_train (pos = 3):
## 
##     city, precipitation_amt_mm, reanalysis_air_temp_k,
##     reanalysis_avg_temp_k, reanalysis_relative_humidity_percent,
##     reanalysis_sat_precip_amt_mm, week_start_date, year
## The following objects are masked from dengue_features_test (pos = 4):
## 
##     city, precipitation_amt_mm, reanalysis_air_temp_k,
##     reanalysis_avg_temp_k, reanalysis_relative_humidity_percent,
##     reanalysis_sat_precip_amt_mm, week_start_date, year
## The following objects are masked from dengue_features_test (pos = 5):
## 
##     city, precipitation_amt_mm, reanalysis_air_temp_k,
##     reanalysis_avg_temp_k, reanalysis_relative_humidity_percent,
##     reanalysis_sat_precip_amt_mm, week_start_date, year
#Checking for missing values and removing them 
sum(is.na(dengue_features_train))
## [1] 56
#Removing missing observation 
dengue_features_train <- na.omit(dengue_features_train)
dengue_features_train
## # A tibble: 1,443 x 8
##    city   year week_start_date precipitation_amt_mm reanalysis_air_temp_k
##    <chr> <dbl> <date>                         <dbl>                 <dbl>
##  1 sj     1990 1990-04-30                     12.4                   298.
##  2 sj     1990 1990-05-07                     22.8                   298.
##  3 sj     1990 1990-05-14                     34.5                   299.
##  4 sj     1990 1990-05-21                     15.4                   299.
##  5 sj     1990 1990-05-28                      7.52                  300.
##  6 sj     1990 1990-06-04                      9.58                  300.
##  7 sj     1990 1990-06-11                      3.48                  299.
##  8 sj     1990 1990-06-18                    151.                    300.
##  9 sj     1990 1990-06-25                     19.3                   300.
## 10 sj     1990 1990-07-02                     14.4                   300.
## # ... with 1,433 more rows, and 3 more variables: reanalysis_avg_temp_k <dbl>,
## #   reanalysis_relative_humidity_percent <dbl>,
## #   reanalysis_sat_precip_amt_mm <dbl>
sum(is.na(dengue_features_train)) #There are no missing observation
## [1] 0
#Data Description 
describe(dengue_features_train[-c(1:4)])
##                                      vars    n   mean    sd median trimmed
## reanalysis_air_temp_k                   1 1443 298.70  1.36 298.65  298.72
## reanalysis_avg_temp_k                   2 1443 299.23  1.26 299.29  299.26
## reanalysis_relative_humidity_percent    3 1443  82.17  7.16  80.30   81.70
## reanalysis_sat_precip_amt_mm            4 1443  45.76 43.72  38.34   40.16
##                                        mad    min    max  range  skew kurtosis
## reanalysis_air_temp_k                 1.57 294.64 302.20   7.56 -0.08    -0.69
## reanalysis_avg_temp_k                 1.43 294.89 302.93   8.04 -0.19    -0.53
## reanalysis_relative_humidity_percent  5.68  57.79  98.61  40.82  0.57    -0.40
## reanalysis_sat_precip_amt_mm         44.23   0.00 390.60 390.60  1.73     6.74
##                                        se
## reanalysis_air_temp_k                0.04
## reanalysis_avg_temp_k                0.03
## reanalysis_relative_humidity_percent 0.19
## reanalysis_sat_precip_amt_mm         1.15
knitr::kable(describe(dengue_features_train[-c(1:4)]))
vars n mean sd median trimmed mad min max range skew kurtosis se
reanalysis_air_temp_k 1 1443 298.70389 1.363079 298.64857 298.71992 1.573674 294.63571 302.2000 7.564286 -0.0845621 -0.6865367 0.0358829
reanalysis_avg_temp_k 2 1443 299.22823 1.261648 299.29286 299.25639 1.429650 294.89286 302.9286 8.035714 -0.1935768 -0.5309318 0.0332128
reanalysis_relative_humidity_percent 3 1443 82.16908 7.158343 80.30286 81.70087 5.682594 57.78714 98.6100 40.822857 0.5705195 -0.4022083 0.1884427
reanalysis_sat_precip_amt_mm 4 1443 45.76039 43.715537 38.34000 40.15939 44.225958 0.00000 390.6000 390.600000 1.7338384 6.7388910 1.1508074
#Data description in San Juan
San_Juan_dengue_train <- filter(dengue_features_train,
                                city == "sj")
view(San_Juan_dengue_train)
knitr::kable(describe(San_Juan_dengue_train[-c(1:4)]))
vars n mean sd median trimmed mad min max range skew kurtosis se
reanalysis_air_temp_k 1 927 299.16831 1.235662 299.27000 299.20093 1.459302 295.93857 302.20000 6.261429 -0.2241410 -0.8722457 0.0405845
reanalysis_avg_temp_k 2 927 299.28122 1.218206 299.38571 299.31410 1.408470 296.11429 302.16429 6.050000 -0.2307338 -0.8159498 0.0400111
reanalysis_relative_humidity_percent 3 927 78.56764 3.390744 78.66857 78.62003 3.486228 66.73571 87.57571 20.840000 -0.1930726 -0.0833090 0.1113666
reanalysis_sat_precip_amt_mm 4 927 35.47081 44.606137 20.80000 27.51576 30.838080 0.00000 390.60000 390.600000 2.6102012 11.6922106 1.4650578
#San Juan test data
San_Juan_dengue_test <- filter(dengue_features_test,
                                city == "sj")
view(San_Juan_dengue_test)
#converting the dataset into a timeseries data 
#Precipitation
San_Juan_dengue_train_precipitation.ts <- ts(San_Juan_dengue_train$precipitation_amt_mm, start = 1990, frequency = 52)
view(San_Juan_dengue_train_precipitation.ts)
#Datavisualization
autoplot(San_Juan_dengue_train_precipitation.ts)+
  ggtitle("San Juan Precipitation amount (mm)")+
  ylab("Precipitation amount (mm)")+
  xlab("Time") +
  theme_light()

#Humidity
San_Juan_dengue_train_humidity.ts <- ts(San_Juan_dengue_train$reanalysis_relative_humidity_percent, start = 1990, frequency = 52)
view(San_Juan_dengue_train_humidity.ts)
#Datavisualization
autoplot(San_Juan_dengue_train_humidity.ts)+
  ggtitle("San Juan Relative Humidity percent")+
  ylab("Relative Humidity")+
  xlab("Time") +
  theme_light()

#Temperature
San_Juan_dengue_train_temp.ts <- ts(San_Juan_dengue_train$reanalysis_air_temp_k, start = 1990, frequency = 52)
view(San_Juan_dengue_train_temp.ts)
#Datavisualization
autoplot(San_Juan_dengue_train_temp.ts)+
  ggtitle("San Juan Air Temperature (k)")+
  ylab("Air Temperature")+
  xlab("Time") +
  theme_grey()

#Data description in Iquitos
iquitos_dengue_train <- filter(dengue_features_train,
                                city == "iq")
view(iquitos_dengue_train)
knitr::kable(describe(iquitos_dengue_train[-c(1:4)]))
vars n mean sd median trimmed mad min max range skew kurtosis se
reanalysis_air_temp_k 1 516 297.86954 1.170997 297.82286 297.86236 1.131012 294.63571 301.6371 7.001429 0.1056252 -0.0381419 0.0515503
reanalysis_avg_temp_k 2 516 299.13304 1.332073 299.12143 299.15093 1.408470 294.89286 302.9286 8.035714 -0.1077805 -0.2133632 0.0586412
reanalysis_relative_humidity_percent 3 516 88.63912 7.583889 90.91714 89.58349 6.321171 57.78714 98.6100 40.822857 -1.0992274 0.7842504 0.3338621
reanalysis_sat_precip_amt_mm 4 516 64.24574 35.218995 60.47000 62.24196 33.944127 0.00000 210.8300 210.830000 0.5973640 0.3969977 1.5504298
#Iquitos test data data
iquitos_dengue_test <- filter(dengue_features_test,
                                city == "sj")
view(iquitos_dengue_test)
#converting the dataset into a timeseries data 
#Precipitation
iquitos_dengue_train_precipitation.ts <- ts(iquitos_dengue_train $precipitation_amt_mm, start = 1990, frequency = 52)
view(iquitos_dengue_train_precipitation.ts)
#Datavisualization
autoplot(iquitos_dengue_train_precipitation.ts)+
  ggtitle("Iquitos Precipitation amount (mm)")+
  ylab("Precipitation amount (mm)")+
  xlab("Time") +
  theme_gray()

#Humidity
iquitos_dengue_train_humidity.ts <- ts(iquitos_dengue_train$reanalysis_relative_humidity_percent, start = 1990, frequency = 52)
view(iquitos_dengue_train_humidity.ts)
#Datavisualization
autoplot(iquitos_dengue_train_humidity.ts)+
  ggtitle("Iquitos Relative Humidity percent")+
  ylab("Relative Humidity")+
  xlab("Time") +
  theme_light()

#Temperature
iquitos_train_temp.ts <- ts(iquitos_dengue_train$reanalysis_air_temp_k, start = 1990, frequency = 52)
view(iquitos_train_temp.ts)
#Datavisualization
autoplot(iquitos_train_temp.ts)+
  ggtitle("Iquitos Air Temperature (k)")+
  ylab("Air Temperature")+
  xlab("Time") +
  theme_grey()

#total dengue cases 
#importing the dataset
dengue_labels_train <- read_csv("C:/Users/HP/Desktop/dengue_labels_train.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   city = col_character(),
##   year = col_double(),
##   weekofyear = col_double(),
##   total_cases = col_double()
## )
View(dengue_labels_train)
attach(dengue_labels_train)
## The following objects are masked from dengue_features_train (pos = 3):
## 
##     city, year
## The following objects are masked from dengue_features_train (pos = 4):
## 
##     city, weekofyear, year
## The following objects are masked from dengue_features_test (pos = 5):
## 
##     city, year
## The following objects are masked from dengue_features_test (pos = 6):
## 
##     city, weekofyear, year
#data description 
aggregate((total_cases) ~ city, data = dengue_labels_train, FUN = sum)
##   city (total_cases)
## 1   iq          3934
## 2   sj         31993
san.juan.cases <- filter(dengue_labels_train, city == "sj")
san.juan.cases
## # A tibble: 936 x 4
##    city   year weekofyear total_cases
##    <chr> <dbl>      <dbl>       <dbl>
##  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
##  7 sj     1990         24           4
##  8 sj     1990         25           5
##  9 sj     1990         26          10
## 10 sj     1990         27           6
## # ... with 926 more rows
San_Juan.cases.ts <- ts(san.juan.cases$total_cases, start = 1990, frequency = 52)
view(San_Juan.cases.ts)
#Datavisualization
autoplot(San_Juan.cases.ts)+
  ggtitle("San Juan total dengue cases")+
  ylab("dengue cases")+
  xlab("Time") +
  theme_light()

iquitos.cases <- filter(dengue_labels_train, city == "iq")
iquitos.cases
## # A tibble: 520 x 4
##    city   year weekofyear total_cases
##    <chr> <dbl>      <dbl>       <dbl>
##  1 iq     2000         26           0
##  2 iq     2000         27           0
##  3 iq     2000         28           0
##  4 iq     2000         29           0
##  5 iq     2000         30           0
##  6 iq     2000         31           0
##  7 iq     2000         32           0
##  8 iq     2000         33           0
##  9 iq     2000         34           0
## 10 iq     2000         35           0
## # ... with 510 more rows
attach(iquitos.cases)
## The following objects are masked from dengue_labels_train:
## 
##     city, total_cases, weekofyear, year
## The following objects are masked from dengue_features_train (pos = 4):
## 
##     city, year
## The following objects are masked from dengue_features_train (pos = 5):
## 
##     city, weekofyear, year
## The following objects are masked from dengue_features_test (pos = 6):
## 
##     city, year
## The following objects are masked from dengue_features_test (pos = 7):
## 
##     city, weekofyear, year
iquitos.ts <- ts(iquitos.cases$total_cases, start = 1990, frequency = 52)
iquitos.ts
## Time Series:
## Start = c(1990, 1) 
## End = c(1999, 52) 
## Frequency = 52 
##   [1]   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0   1   1   0
##  [19]   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0
##  [37]   0   0   0   0   0   1   0   0   0   0   1   1   0   0   1   0   0   0
##  [55]   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
##  [73]   1   1   1   2   4   1   4  11  16  23  12  14  18   8   7  10   7  10
##  [91]   5  11   8  18  13   9  22  10   5  13   2  11  11   3   7   7   4   5
## [109]   6   7   7   4   9  17   8  22  18  21  16  31  25  28  26  18  27  11
## [127]  38  29  21  11  10   5   6   2   1   2   2   3   5   1   4   2   4   0
## [145]   0   0   0   1   1   1   1   1   2   3   4   6   2   2   5   1   1   0
## [163]   0   0   0   2   0   3   0   0   0   2   2   3   3   3   1   2   3   6
## [181]   5   1   4   5   8   5   2   3   3   1   6   4   1   2   3   1   8   4
## [199]   6   7   5   8   6   5   6   6  13   2  10   3  12   7   6   5   6   6
## [217]   6   8   6   9  12  19   8  16  21   6  22  37  33  18  83 116  32   7
## [235]   9  10   5   8   7   8  11   6   7   7  14   7   9  13  16   7   9   2
## [253]  13   8   3   5   4   8   2   3   5   7   3   5   6   5   5   4   0   0
## [271]   0   0   0   2   4   4   3   3   5   6  14   3   7  11   2   6   8  25
## [289]  21  10  28  39  20  24  28  26   8   9  12  18   9   9   6   6   8   5
## [307]   7   6   5   3   1   0   1   2   3   2   2   2   2   2   4   0   6   3
## [325]   2   6   2   7   4   6   6   2  13  10   5   2   0   1   0  14   6  10
## [343]   5  12   9   5  11   2   6   7   6   5   9   5   8   3   4  11   5   8
## [361]   4   3   1   2   3   4   1   8   5   3   2   7   1   6   7   5   2   6
## [379]  11   6   3  11  11   5   4   9  23  28  26   7  29  58  26  38  35  37
## [397]  20  29  25  23   9   3   6   6   3   1   3   1   1   0   2   1   1   0
## [415]   0   1   0   3   3   1   5   2   5   5   5   9  17  19  25  45  34  63
## [433]  44  50  35  16  16  13   9  15   4   0   1  10  11  29  35  30  20  21
## [451]  12   9  11   9   5  11   3   5   5   4   4   1   0   2   3   3   5   2
## [469]   1   2   0   0   3   5   5   7   5   2   2   2   0   2   1   1   2   2
## [487]   3   9   5   5   4   4   1   0   0  10   9  17  16  11  12  19  15  12
## [505]  12  16   9   4   9   6   8   4   2   7   6   5   8   1   1   4
autoplot(iquitos.ts)+
  ggtitle("iquitos total dengue cases")+
  ylab("Iquitos cases")+
  xlab("Time") +
  theme_light()

#ETS model
Ets_San.Juan_train.model <- ets(San_Juan.cases.ts)
Ets_San.Juan_train.model
## ETS(A,Ad,N) 
## 
## Call:
##  ets(y = San_Juan.cases.ts) 
## 
##   Smoothing parameters:
##     alpha = 0.9999 
##     beta  = 0.1355 
##     phi   = 0.8 
## 
##   Initial states:
##     l = 3.0767 
##     b = 0.2624 
## 
##   sigma:  13.4753
## 
##      AIC     AICc      BIC 
## 11279.55 11279.64 11308.60
summary(Ets_San.Juan_train.model)
## ETS(A,Ad,N) 
## 
## Call:
##  ets(y = San_Juan.cases.ts) 
## 
##   Smoothing parameters:
##     alpha = 0.9999 
##     beta  = 0.1355 
##     phi   = 0.8 
## 
##   Initial states:
##     l = 3.0767 
##     b = 0.2624 
## 
##   sigma:  13.4753
## 
##      AIC     AICc      BIC 
## 11279.55 11279.64 11308.60 
## 
## Training set error measures:
##                      ME     RMSE      MAE MPE MAPE      MASE       ACF1
## Training set 0.00139911 13.43929 8.026055 NaN  Inf 0.2196945 0.01271293
#forecasting for the total cases using ETS Model
forecast_ets.san.juan <- forecast(Ets_San.Juan_train.model)
forecast_ets.san.juan
##          Point Forecast      Lo 80     Hi 80      Lo 95     Hi 95
## 2008.000       5.228984  -12.04034  22.49831  -21.18217  31.64014
## 2008.019       5.412350  -20.36663  31.19133  -34.01320  44.83790
## 2008.038       5.559044  -27.46309  38.58118  -44.94396  56.06204
## 2008.058       5.676398  -33.91225  45.26505  -54.86921  66.22201
## 2008.077       5.770282  -39.91170  51.45226  -64.09428  75.63484
## 2008.096       5.845390  -45.55476  57.24554  -72.76435  84.45513
## 2008.115       5.905476  -50.89588  62.70683  -80.96470  92.77565
## 2008.135       5.953544  -55.97209  67.87917  -88.75353 100.66062
## 2008.154       5.992000  -60.81143  72.79542  -96.17502 108.15902
## 2008.173       6.022764  -65.43668  77.48221 -103.26503 115.31056
## 2008.192       6.047375  -69.86720  81.96195 -110.05395 122.14870
## 2008.212       6.067064  -74.11982  86.25395 -116.56819 128.70232
## 2008.231       6.082816  -78.20943  90.37506 -122.83105 134.99668
## 2008.250       6.095417  -82.14931  94.34014 -128.86325 141.05408
## 2008.269       6.105498  -85.95137  98.16237 -134.68334 146.89433
## 2008.288       6.113562  -89.62634 101.85346 -140.30798 152.53510
## 2008.308       6.120014  -93.18385 105.42388 -145.75214 157.99217
## 2008.327       6.125176  -96.63264 108.88299 -151.02935 163.27970
## 2008.346       6.129305  -99.98059 112.23920 -156.15178 168.41039
## 2008.365       6.132608 -103.23483 115.50005 -161.13046 173.39568
## 2008.385       6.135251 -106.40183 118.67233 -165.97536 178.24587
## 2008.404       6.137365 -109.48745 121.76218 -170.69553 182.97026
## 2008.423       6.139056 -112.49702 124.77513 -175.29916 187.57727
## 2008.442       6.140409 -115.43538 127.71620 -179.79371 192.07453
## 2008.462       6.141492 -118.30695 130.58993 -184.18597 196.46895
## 2008.481       6.142358 -121.11575 133.40046 -188.48212 200.76684
## 2008.500       6.143051 -123.86546 136.15156 -192.68781 204.97391
## 2008.519       6.143605 -126.55946 138.84667 -196.80822 209.09543
## 2008.538       6.144048 -129.20082 141.48891 -200.84806 213.13616
## 2008.558       6.144403 -131.79238 144.08118 -204.81170 217.10051
## 2008.577       6.144687 -134.33675 146.62612 -208.70312 220.99250
## 2008.596       6.144914 -136.83632 149.12615 -212.52601 224.81584
## 2008.615       6.145095 -139.29332 151.58351 -216.28377 228.57396
## 2008.635       6.145241 -141.70979 154.00027 -219.97952 232.27000
## 2008.654       6.145357 -144.08764 156.37835 -223.61618 235.90689
## 2008.673       6.145450 -146.42861 158.71951 -227.19644 239.48734
## 2008.692       6.145524 -148.73435 161.02540 -230.72281 243.01386
## 2008.712       6.145584 -151.00639 163.29755 -234.19761 246.48878
## 2008.731       6.145631 -153.24613 165.53739 -237.62302 249.91429
## 2008.750       6.145669 -155.45490 167.74624 -241.00107 253.29241
## 2008.769       6.145700 -157.63394 169.92534 -244.33365 256.62505
## 2008.788       6.145724 -159.78442 172.07587 -247.62253 259.91398
## 2008.808       6.145744 -161.90742 174.19890 -250.86938 263.16087
## 2008.827       6.145759 -164.00395 176.29547 -254.07577 266.36729
## 2008.846       6.145772 -166.07499 178.36654 -257.24316 269.53470
## 2008.865       6.145782 -168.12144 180.41300 -260.37293 272.66450
## 2008.885       6.145790 -170.14415 182.43572 -263.46640 275.75798
## 2008.904       6.145796 -172.14392 184.43551 -266.52479 278.81638
## 2008.923       6.145801 -174.12151 186.41312 -269.54926 281.84087
## 2008.942       6.145805 -176.07766 188.36927 -272.54093 284.83254
## 2008.962       6.145809 -178.01303 190.30464 -275.50083 287.79244
## 2008.981       6.145811 -179.92827 192.21990 -278.42995 290.72157
## 2009.000       6.145813 -181.82401 194.11564 -281.32923 293.62085
## 2009.019       6.145815 -183.70082 195.99245 -284.19956 296.49119
## 2009.038       6.145816 -185.55926 197.85089 -287.04180 299.33343
## 2009.058       6.145817 -187.39986 199.69149 -289.85675 302.14839
## 2009.077       6.145818 -189.22312 201.51475 -292.64519 304.93682
## 2009.096       6.145819 -191.02952 203.32116 -295.40784 307.69948
## 2009.115       6.145820 -192.81952 205.11116 -298.14541 310.43705
## 2009.135       6.145820 -194.59356 206.88520 -300.85857 313.15021
## 2009.154       6.145820 -196.35207 208.64371 -303.54797 315.83961
## 2009.173       6.145821 -198.09543 210.38707 -306.21421 318.50585
## 2009.192       6.145821 -199.82403 212.11568 -308.85789 321.14953
## 2009.212       6.145821 -201.53825 213.82990 -311.47956 323.77120
## 2009.231       6.145821 -203.23844 215.53008 -314.07977 326.37141
## 2009.250       6.145821 -204.92493 217.21657 -316.65904 328.95068
## 2009.269       6.145821 -206.59805 218.88970 -319.21786 331.50950
## 2009.288       6.145821 -208.25812 220.54976 -321.75671 334.04836
## 2009.308       6.145821 -209.90543 222.19708 -324.27606 336.56770
## 2009.327       6.145822 -211.54028 223.83192 -326.77634 339.06798
## 2009.346       6.145822 -213.16294 225.45458 -329.25799 341.54963
## 2009.365       6.145822 -214.77368 227.06533 -331.72140 344.01305
## 2009.385       6.145822 -216.37276 228.66441 -334.16699 346.45863
## 2009.404       6.145822 -217.96044 230.25208 -336.59513 348.88677
## 2009.423       6.145822 -219.53694 231.82859 -339.00618 351.29782
## 2009.442       6.145822 -221.10251 233.39415 -341.40051 353.69215
## 2009.462       6.145822 -222.65736 234.94901 -343.77846 356.07010
## 2009.481       6.145822 -224.20173 236.49337 -346.14035 358.43199
## 2009.500       6.145822 -225.73580 238.02744 -348.48652 360.77816
## 2009.519       6.145822 -227.25979 239.55144 -350.81726 363.10890
## 2009.538       6.145822 -228.77390 241.06554 -353.13289 365.42453
## 2009.558       6.145822 -230.27831 242.56995 -355.43368 367.72533
## 2009.577       6.145822 -231.77321 244.06485 -357.71993 370.01157
## 2009.596       6.145822 -233.25877 245.55041 -359.99190 372.28355
## 2009.615       6.145822 -234.73517 247.02681 -362.24986 374.54151
## 2009.635       6.145822 -236.20258 248.49422 -364.49407 376.78571
## 2009.654       6.145822 -237.66115 249.95279 -366.72477 379.01641
## 2009.673       6.145822 -239.11105 251.40270 -368.94220 381.23384
## 2009.692       6.145822 -240.55243 252.84408 -371.14660 383.43824
## 2009.712       6.145822 -241.98544 254.27708 -373.33819 385.62984
## 2009.731       6.145822 -243.41022 255.70186 -375.51721 387.80885
## 2009.750       6.145822 -244.82691 257.11855 -377.68385 389.97549
## 2009.769       6.145822 -246.23565 258.52729 -379.83833 392.12997
## 2009.788       6.145822 -247.63656 259.92821 -381.98084 394.27249
## 2009.808       6.145822 -249.02979 261.32144 -384.11160 396.40325
## 2009.827       6.145822 -250.41545 262.70710 -386.23079 398.52243
## 2009.846       6.145822 -251.79367 264.08532 -388.33859 400.63023
## 2009.865       6.145822 -253.16456 265.45621 -390.43519 402.72683
## 2009.885       6.145822 -254.52825 266.81989 -392.52077 404.81241
## 2009.904       6.145822 -255.88483 268.17648 -394.59549 406.88713
## 2009.923       6.145822 -257.23443 269.52608 -396.65952 408.95116
## 2009.942       6.145822 -258.57715 270.86880 -398.71303 411.00467
## 2009.962       6.145822 -259.91310 272.20474 -400.75618 413.04782
## 2009.981       6.145822 -261.24236 273.53401 -402.78912 415.08076
#Visualizing
autoplot(forecast_ets.san.juan, 
         main = "San Juan Total Dengue Fever Cases",
         ylab = " Total cases")

#modellin ETS in Iquitos
Ets_iquitos_train.model <- ets(iquitos.ts)
## Warning in ets(iquitos.ts): I can't handle data with frequency greater than 24.
## Seasonality will be ignored. Try stlf() if you need seasonal forecasts.
Ets_iquitos_train.model
## ETS(A,N,N) 
## 
## Call:
##  ets(y = iquitos.ts) 
## 
##   Smoothing parameters:
##     alpha = 0.6543 
## 
##   Initial states:
##     l = 0.0744 
## 
##   sigma:  7.4063
## 
##      AIC     AICc      BIC 
## 5338.417 5338.463 5351.178
summary(Ets_iquitos_train.model)
## ETS(A,N,N) 
## 
## Call:
##  ets(y = iquitos.ts) 
## 
##   Smoothing parameters:
##     alpha = 0.6543 
## 
##   Initial states:
##     l = 0.0744 
## 
##   sigma:  7.4063
## 
##      AIC     AICc      BIC 
## 5338.417 5338.463 5351.178 
## 
## Training set error measures:
##                       ME     RMSE      MAE  MPE MAPE      MASE      ACF1
## Training set 0.009226816 7.392083 3.699635 -Inf  Inf 0.3919034 0.0713476
#forecasting for the total cases using ETS Model
forecast_ets.iquitos <- forecast(Ets_iquitos_train.model)
forecast_ets.iquitos
##          Point Forecast      Lo 80    Hi 80     Lo 95     Hi 95
## 2000.000       3.213589  -6.278017 12.70520 -11.30257  17.72975
## 2000.019       3.213589  -8.129126 14.55630 -14.13360  20.56078
## 2000.038       3.213589  -9.717915 16.14509 -16.56344  22.99062
## 2000.058       3.213589 -11.131807 17.55899 -18.72580  25.15298
## 2000.077       3.213589 -12.418334 18.84551 -20.69337  27.12055
## 2000.096       3.213589 -13.606744 20.03392 -22.51089  28.93807
## 2000.115       3.213589 -14.716559 21.14374 -24.20821  30.63539
## 2000.135       3.213589 -15.761575 22.18875 -25.80642  32.23360
## 2000.154       3.213589 -16.751967 23.17915 -27.32109  33.74827
## 2000.173       3.213589 -17.695501 24.12268 -28.76411  35.19128
## 2000.192       3.213589 -18.598258 25.02544 -30.14475  36.57193
## 2000.212       3.213589 -19.465107 25.89229 -31.47048  37.89766
## 2000.231       3.213589 -20.300021 26.72720 -32.74738  39.17455
## 2000.250       3.213589 -21.106289 27.53347 -33.98046  40.40763
## 2000.269       3.213589 -21.886672 28.31385 -35.17395  41.60113
## 2000.288       3.213589 -22.643513 29.07069 -36.33144  42.75861
## 2000.308       3.213589 -23.378822 29.80600 -37.45599  43.88317
## 2000.327       3.213589 -24.094339 30.52152 -38.55028  44.97746
## 2000.346       3.213589 -24.791581 31.21876 -39.61662  46.04380
## 2000.365       3.213589 -25.471880 31.89906 -40.65705  47.08423
## 2000.385       3.213589 -26.136415 32.56359 -41.67337  48.10055
## 2000.404       3.213589 -26.786234 33.21341 -42.66718  49.09436
## 2000.423       3.213589 -27.422272 33.84945 -43.63992  50.06710
## 2000.442       3.213589 -28.045371 34.47255 -44.59286  51.02004
## 2000.462       3.213589 -28.656290 35.08347 -45.52718  51.95436
## 2000.481       3.213589 -29.255716 35.68290 -46.44393  52.87111
## 2000.500       3.213589 -29.844275 36.27145 -47.34405  53.77123
## 2000.519       3.213589 -30.422537 36.84972 -48.22843  54.65561
## 2000.538       3.213589 -30.991025 37.41820 -49.09785  55.52503
## 2000.558       3.213589 -31.550217 37.97740 -49.95306  56.38024
## 2000.577       3.213589 -32.100556 38.52773 -50.79474  57.22191
## 2000.596       3.213589 -32.642449 39.06963 -51.62349  58.05067
## 2000.615       3.213589 -33.176273 39.60345 -52.43990  58.86708
## 2000.635       3.213589 -33.702378 40.12956 -53.24451  59.67169
## 2000.654       3.213589 -34.221091 40.64827 -54.03781  60.46499
## 2000.673       3.213589 -34.732714 41.15989 -54.82027  61.24745
## 2000.692       3.213589 -35.237529 41.66471 -55.59232  62.01950
## 2000.712       3.213589 -35.735802 42.16298 -56.35437  62.78154
## 2000.731       3.213589 -36.227781 42.65496 -57.10678  63.53396
## 2000.750       3.213589 -36.713699 43.14088 -57.84993  64.27711
## 2000.769       3.213589 -37.193773 43.62095 -58.58414  65.01132
## 2000.788       3.213589 -37.668210 44.09539 -59.30973  65.73691
## 2000.808       3.213589 -38.137205 44.56438 -60.02699  66.45417
## 2000.827       3.213589 -38.600939 45.02812 -60.73621  67.16339
## 2000.846       3.213589 -39.059586 45.48677 -61.43765  67.86483
## 2000.865       3.213589 -39.513311 45.94049 -62.13157  68.55874
## 2000.885       3.213589 -39.962267 46.38945 -62.81819  69.24536
## 2000.904       3.213589 -40.406603 46.83378 -63.49774  69.92492
## 2000.923       3.213589 -40.846459 47.27364 -64.17044  70.59762
## 2000.942       3.213589 -41.281966 47.70914 -64.83649  71.26367
## 2000.962       3.213589 -41.713252 48.14043 -65.49608  71.92326
## 2000.981       3.213589 -42.140436 48.56762 -66.14941  72.57659
## 2001.000       3.213589 -42.563635 48.99081 -66.79663  73.22381
## 2001.019       3.213589 -42.982957 49.41014 -67.43793  73.86511
## 2001.038       3.213589 -43.398506 49.82569 -68.07346  74.50064
## 2001.058       3.213589 -43.810384 50.23756 -68.70337  75.13055
## 2001.077       3.213589 -44.218685 50.64586 -69.32782  75.75499
## 2001.096       3.213589 -44.623502 51.05068 -69.94693  76.37411
## 2001.115       3.213589 -45.024921 51.45210 -70.56085  76.98803
## 2001.135       3.213589 -45.423028 51.85021 -71.16970  77.59688
## 2001.154       3.213589 -45.817902 52.24508 -71.77361  78.20078
## 2001.173       3.213589 -46.209621 52.63680 -72.37269  78.79987
## 2001.192       3.213589 -46.598260 53.02544 -72.96706  79.39424
## 2001.212       3.213589 -46.983890 53.41107 -73.55683  79.98401
## 2001.231       3.213589 -47.366580 53.79376 -74.14210  80.56928
## 2001.250       3.213589 -47.746397 54.17358 -74.72298  81.15016
## 2001.269       3.213589 -48.123403 54.55058 -75.29957  81.72674
## 2001.288       3.213589 -48.497661 54.92484 -75.87194  82.29912
## 2001.308       3.213589 -48.869229 55.29641 -76.44021  82.86739
## 2001.327       3.213589 -49.238166 55.66534 -77.00445  83.43163
## 2001.346       3.213589 -49.604525 56.03170 -77.56475  83.99193
## 2001.365       3.213589 -49.968361 56.39554 -78.12118  84.54836
## 2001.385       3.213589 -50.329724 56.75690 -78.67384  85.10102
## 2001.404       3.213589 -50.688665 57.11584 -79.22280  85.64997
## 2001.423       3.213589 -51.045232 57.47241 -79.76812  86.19530
## 2001.442       3.213589 -51.399470 57.82665 -80.30988  86.73706
## 2001.462       3.213589 -51.751426 58.17860 -80.84815  87.27533
## 2001.481       3.213589 -52.101142 58.52832 -81.38299  87.81017
## 2001.500       3.213589 -52.448661 58.87584 -81.91448  88.34166
## 2001.519       3.213589 -52.794024 59.22120 -82.44266  88.86984
## 2001.538       3.213589 -53.137270 59.56445 -82.96761  89.39479
## 2001.558       3.213589 -53.478438 59.90562 -83.48938  89.91656
## 2001.577       3.213589 -53.817565 60.24474 -84.00803  90.43521
## 2001.596       3.213589 -54.154687 60.58187 -84.52362  90.95080
## 2001.615       3.213589 -54.489840 60.91702 -85.03619  91.46337
## 2001.635       3.213589 -54.823057 61.25024 -85.54580  91.97298
## 2001.654       3.213589 -55.154372 61.58155 -86.05251  92.47968
## 2001.673       3.213589 -55.483818 61.91100 -86.55635  92.98353
## 2001.692       3.213589 -55.811424 62.23860 -87.05738  93.48456
## 2001.712       3.213589 -56.137222 62.56440 -87.55564  93.98282
## 2001.731       3.213589 -56.461241 62.88842 -88.05119  94.47837
## 2001.750       3.213589 -56.783511 63.21069 -88.54406  94.97124
## 2001.769       3.213589 -57.104058 63.53124 -89.03429  95.46147
## 2001.788       3.213589 -57.422911 63.85009 -89.52194  95.94912
## 2001.808       3.213589 -57.740097 64.16728 -90.00703  96.43421
## 2001.827       3.213589 -58.055640 64.48282 -90.48961  96.91679
## 2001.846       3.213589 -58.369566 64.79675 -90.96972  97.39690
## 2001.865       3.213589 -58.681901 65.10908 -91.44739  97.87457
## 2001.885       3.213589 -58.992667 65.41985 -91.92267  98.34985
## 2001.904       3.213589 -59.301888 65.72907 -92.39558  98.82276
## 2001.923       3.213589 -59.609587 66.03677 -92.86617  99.29335
## 2001.942       3.213589 -59.915787 66.34297 -93.33446  99.76164
## 2001.962       3.213589 -60.220508 66.64769 -93.80049 100.22767
## 2001.981       3.213589 -60.523773 66.95095 -94.26429 100.69147
#Visualizing
autoplot(forecast_ets.iquitos, 
         main = "Iquitos Total Dengue Fever Cases",
         ylab = " Total cases")

#ARIMA Model
arima_iquitos_model <- auto.arima(iquitos.ts)
arima_iquitos_model
## Series: iquitos.ts 
## ARIMA(0,1,2)(0,0,1)[52] 
## 
## Coefficients:
##           ma1      ma2    sma1
##       -0.2508  -0.2322  0.0568
## s.e.   0.0430   0.0449  0.0375
## 
## sigma^2 estimated as 52.12:  log likelihood=-1761.09
## AIC=3530.18   AICc=3530.26   BIC=3547.19
forecast.iquitos <- forecast(arima_iquitos_model)
autoplot(forecast.iquitos,
          main = "Iquitos Total Dengue Fever Cases",
         ylab = " Total cases")

#ARIMA Model
arima_san.juan_model <- auto.arima(San_Juan.cases.ts)
arima_san.juan_model
## Series: San_Juan.cases.ts 
## ARIMA(1,1,1) 
## 
## Coefficients:
##          ar1      ma1
##       0.7116  -0.5929
## s.e.  0.0948   0.1078
## 
## sigma^2 estimated as 180.9:  log likelihood=-3755.85
## AIC=7517.71   AICc=7517.73   BIC=7532.23
forecast.san.juan.model <- forecast(arima_san.juan_model)
autoplot(forecast.san.juan.model,
          main = "San Juan Total Dengue Fever Cases",
         ylab = " Total cases")

#data transformation
library(MASS)
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
## The following objects are masked from 'package:fma':
## 
##     cement, housing, petrol
lambda_san.juan <- BoxCox.lambda(San_Juan.cases.ts)
## Warning in guerrero(x, lower, upper): Guerrero's method for selecting a Box-Cox
## parameter (lambda) is given for strictly positive data.
lambda_san.juan
## [1] 4.102259e-05
transformed_san.juan <- BoxCox(San_Juan.cases.ts, lambda = lambda_san.juan)
transformed_san.juan
## Time Series:
## Start = c(1990, 1) 
## End = c(2007, 52) 
## Frequency = 52 
##   [1]      1.386334      1.609491      1.386334      1.098637      1.791825
##   [6]      0.693157      1.386334      1.609491      2.302694      1.791825
##  [11]      2.079530      0.693157      1.791825      2.833378      3.135696
##  [16]      2.565084      3.044713      3.332432      3.178261      2.995916
##  [21]      3.689159      3.296060      3.737956      3.496758      3.761490
##  [26]      3.611185      4.043387      4.263053      3.784483      4.025684
##  [31]      3.970615      3.951564      3.850452      3.258314      3.296060
##  [36]      3.044713      3.044713      3.258314      3.526616      3.611185
##  [41]      2.833378      2.944617      3.219088      2.890543      3.044713
##  [46]      2.833378      2.833378      2.772746      2.772746      2.708201
##  [51]      3.135696      2.772746      2.833378      2.485033      2.833378
##  [56]      2.302694      2.708201      2.944617      3.044713      2.639200
##  [61]      2.890543      2.565084      2.639200      2.890543      3.135696
##  [66]      3.219088      4.127484      4.094688      4.331118      4.190015
##  [71]      4.159238      4.219873      4.489050      4.522208      4.942143
##  [76]      4.754054      4.956331      4.860297      4.942143      4.942143
##  [81]      4.844668      4.860297      5.130439      4.949262      4.682581
##  [86]      4.357098      4.248865      4.394845      4.644833      4.500225
##  [91]      4.443056      4.007663      3.970615      4.174745      3.496758
##  [96]      3.637858      4.077878      3.689159      3.611185      3.367528
## [101]      3.401435      3.401435      3.332432      3.135696      3.178261
## [106]      3.367528      3.258314      3.135696      2.995916      2.944617
## [111]      2.995916      3.258314      3.367528      3.434229      3.332432
## [116]      3.258314      3.465982      3.555607      3.496758      3.401435
## [121]      3.951564      4.077878      4.205055      4.174745      4.304445
## [126]      4.248865      4.111221      3.970615      4.331118      4.111221
## [131]      4.043387      3.784483      3.526616      3.850452      4.094688
## [136]      4.094688      3.970615      3.583782      3.434229      3.401435
## [141]      3.465982      3.332432      3.496758      3.496758      3.555607
## [146]      3.091238      2.565084      2.565084      3.044713      2.833378
## [151]      2.398013      2.079530      2.079530      1.791825      1.791825
## [156]      1.945988      2.485033      2.833378      2.302694      2.302694
## [161]      2.890543      2.944617      2.485033      3.091238      2.485033
## [166]      3.044713      2.890543      2.772746      2.772746      3.091238
## [171]      2.833378      3.219088      3.135696      2.485033      3.219088
## [176]      3.332432      3.296060      2.890543      3.135696      3.135696
## [181]      3.367528      3.637858      3.583782      3.761490      3.828942
## [186]      3.434229      3.219088      3.689159      3.434229      3.637858
## [191]      3.401435      3.091238      3.434229      3.258314      3.555607
## [196]      3.583782      3.663837      3.219088      3.434229      3.611185
## [201]      3.496758      3.219088      3.178261      2.890543      3.135696
## [206]      2.565084      2.890543      2.639200      2.833378      3.091238
## [211]      2.565084      3.178261      3.434229      3.526616      3.434229
## [216]      3.434229      3.637858      3.892131      3.737956      3.892131
## [221]      4.007663      4.382421      4.431220      4.277041      4.489050
## [226]      4.745394      5.187938      5.308846      5.606447      5.711096
## [231]      5.979619      6.055191      6.134170      5.943524      5.808834
## [236]      5.867174      6.016900      5.897867      5.884032      5.663618
## [241]      5.398760      5.004460      4.718956      5.037473      4.511277
## [246]      4.277041      4.025684      3.828942      3.611185      3.258314
## [251]      2.833378      2.833378      2.995916      2.398013      1.945988
## [256]      2.772746      2.639200      2.772746      1.609491      0.693157
## [261]      1.791825      1.609491      1.386334      1.098637      1.386334
## [266]      2.772746      2.079530      1.945988      2.302694      2.639200
## [271]      1.945988      2.197324      2.398013      3.135696      2.833378
## [276]      2.944617      3.178261      2.833378      3.332432      3.689159
## [281]      3.496758      3.434229      3.496758      3.367528      3.401435
## [286]      3.583782      3.871508      3.689159      3.332432      3.583782
## [291]      2.944617      3.526616      3.135696      2.833378      2.833378
## [296]      3.135696      2.639200      2.995916      2.565084      3.135696
## [301]      2.995916      2.772746      2.772746      3.135696      2.639200
## [306]      2.708201      1.386334      1.609491      1.609491      2.398013
## [311]      2.398013      1.945988      1.386334      1.791825      1.609491
## [316]      0.693157      1.386334      0.693157      1.386334      1.791825
## [321]      1.791825      1.386334      1.791825      2.398013      2.772746
## [326]      2.197324      2.485033      2.565084      3.296060      3.044713
## [331]      2.944617      2.833378      3.178261      3.296060      3.401435
## [336]      3.367528      3.219088      3.555607      3.496758      3.401435
## [341]      3.367528      3.434229      3.367528      3.091238      3.296060
## [346]      3.178261      3.258314      3.367528      3.091238      3.496758
## [351]      3.178261      3.401435      2.995916      2.833378      3.178261
## [356]      3.332432      2.890543      2.565084      2.197324      2.639200
## [361]      2.398013      2.398013      2.944617      2.302694      2.079530
## [366]      2.079530      2.197324      1.098637      1.945988      2.639200
## [371]      1.386334      2.197324      2.639200      1.945988      2.197324
## [376]      1.098637      1.098637      2.639200      2.485033      2.302694
## [381]      3.044713      3.258314      3.850452      3.737956      3.434229
## [386]      3.526616      3.496758      3.951564      4.025684      4.248865
## [391]      4.718956      4.248865      3.850452      3.871508      3.892131
## [396]      4.190015      4.025684      4.111221      4.205055      4.159238
## [401]      4.219873      3.892131      3.912337      4.025684      4.317870
## [406]      4.143487      4.127484      3.713855      3.912337      3.526616
## [411]      3.434229      3.637858      3.401435      3.465982      3.258314
## [416]      3.401435      3.583782      3.555607      3.828942      3.871508
## [421]      3.784483      3.932143      4.077878      4.263053      4.625412
## [426]      4.852513      4.844668      5.011150      5.252839      5.545808
## [431]      5.796747      5.572791      5.394224      5.318700      5.199051
## [436]      4.595553      3.989310      4.382421      4.625412      4.844668
## [441]      4.290837      4.219873      4.159238      4.007663      4.205055
## [446]      4.431220      4.443056      4.205055      4.290837      4.489050
## [451]      4.219873      4.077878      4.025684      4.344192      4.317870
## [456]      3.850452      3.912337      3.737956      3.332432      3.611185
## [461]      3.611185      3.296060      2.485033      2.708201      3.091238
## [466]      2.079530      2.708201      2.833378      2.302694      2.197324
## [471]      2.398013      2.995916      2.565084      2.398013      2.772746
## [476]      2.398013      1.945988      2.833378      2.639200      2.565084
## [481]      2.708201      3.401435      3.219088      3.689159      3.784483
## [486]      3.219088      3.044713      3.871508      4.025684      4.094688
## [491]      3.806960      4.007663      3.465982      3.828942      4.111221
## [496]      3.737956      3.611185      3.761490      3.526616      3.689159
## [501]      3.219088      2.772746      2.833378      2.833378      2.772746
## [506]      3.135696      2.890543      2.890543      2.197324      1.945988
## [511]      1.945988      1.386334      1.098637      0.693157      2.079530
## [516]      1.098637      0.000000      0.000000      0.693157      1.098637
## [521]      1.098637      0.693157 -24376.811309 -24376.811309      0.693157
## [526]      0.693157 -24376.811309      1.791825      1.098637      1.791825
## [531]      0.693157      1.098637      0.693157      1.386334      1.609491
## [536]      0.693157      2.197324      0.693157      1.386334      2.079530
## [541]      1.791825      1.098637      2.398013      2.639200      2.708201
## [546]      2.995916      2.197324      2.995916      3.332432      3.637858
## [551]      3.401435      3.401435      3.135696      2.772746      3.091238
## [556]      3.332432      2.639200      2.833378      2.995916      2.833378
## [561]      2.302694      2.565084      2.995916      2.197324      2.890543
## [566]      2.197324      2.079530      2.944617      2.398013      1.386334
## [571]      1.791825      1.791825      2.079530      2.565084      2.079530
## [576]      2.079530      1.609491      2.772746      2.485033      2.398013
## [581]      2.890543      2.302694      3.091238      2.639200      2.772746
## [586]      2.890543      3.296060      3.637858      3.555607      3.713855
## [591]      3.932143      4.174745      4.007663      3.989310      4.127484
## [596]      4.159238      4.025684      4.174745      4.263053      4.317870
## [601]      4.263053      4.277041      3.850452      3.296060      3.555607
## [606]      3.219088      2.944617      3.611185      3.637858      3.526616
## [611]      3.258314      2.944617      2.890543      3.091238      2.772746
## [616]      2.890543      1.791825      2.485033      1.791825      1.791825
## [621]      1.098637      1.945988      1.791825      0.000000      1.098637
## [626]      0.693157      0.693157      0.000000      2.302694      1.098637
## [631]      1.098637      0.000000      0.000000      0.693157      1.791825
## [636]      1.098637      1.098637      1.609491      1.386334      1.945988
## [641]      1.791825      1.609491      1.945988      1.791825      1.386334
## [646]      1.386334      1.945988      2.197324      1.609491      1.609491
## [651]      2.302694      1.791825      2.565084      1.791825      1.609491
## [656]      1.609491      2.197324      1.098637      1.791825      2.398013
## [661]      1.945988      1.945988      2.708201      2.197324      1.791825
## [666]      1.791825      1.791825      1.945988      2.302694      2.079530
## [671]      1.945988      2.485033      1.098637      0.693157      1.945988
## [676]      1.609491      1.609491      1.945988      1.945988      1.945988
## [681]      1.945988      2.302694      2.565084      2.302694      2.639200
## [686]      2.398013      2.995916      3.219088      2.833378      2.890543
## [691]      3.219088      3.044713      3.434229      3.465982      3.258314
## [696]      3.555607      3.332432      3.611185      3.713855      3.526616
## [701]      3.401435      3.663837      3.663837      3.663837      3.526616
## [706]      3.401435      3.611185      3.367528      3.258314      2.708201
## [711]      3.091238      2.708201      2.995916      2.639200      2.302694
## [716]      3.044713      2.639200      2.639200      2.197324      2.398013
## [721]      1.609491      1.791825      1.945988      2.398013      1.386334
## [726]      1.098637      0.693157      1.791825      2.302694      1.945988
## [731]      1.609491      1.098637      2.485033      2.565084      2.302694
## [736]      2.565084      2.565084      2.079530      3.044713      2.890543
## [741]      2.079530      1.945988      2.995916      2.639200      2.639200
## [746]      1.945988      2.639200      2.302694      2.565084      3.296060
## [751]      2.565084      2.890543      2.772746      2.772746      2.995916
## [756]      2.833378      1.386334      2.708201      2.079530      1.791825
## [761]      2.485033      2.708201      2.398013      2.302694      2.708201
## [766]      2.833378      1.945988      1.945988      2.079530      2.197324
## [771]      2.485033      2.485033      1.609491      1.386334      2.398013
## [776]      1.386334      1.609491      1.945988      0.000000      0.000000
## [781]      1.386334      0.693157      1.791825      1.098637      1.386334
## [786]      2.302694      2.485033      3.044713      3.258314      3.044713
## [791]      3.401435      3.806960      4.025684      4.317870      4.419241
## [796]      4.407118      4.836762      4.779592      4.920477      4.875685
## [801]      4.718956      4.407118      4.290837      3.761490      4.007663
## [806]      4.007663      3.970615      3.828942      3.761490      3.367528
## [811]      3.091238      3.258314      2.565084      2.833378      2.079530
## [816]      2.565084      2.302694      2.833378      2.944617      2.197324
## [821]      2.197324      2.197324      1.098637      1.945988      1.945988
## [826] -24376.811309      0.693157      1.098637      1.098637      0.000000
## [831]      1.098637      1.098637      1.098637      1.945988      1.098637
## [836]      1.609491      2.398013      1.609491      1.609491      1.791825
## [841]      1.791825      1.386334      1.386334      2.079530      2.639200
## [846]      2.485033      2.772746      2.302694      2.772746      2.890543
## [851]      2.708201      3.135696      2.833378      3.496758      2.708201
## [856]      2.565084      2.398013      2.639200      2.833378      2.944617
## [861]      2.995916      2.485033      3.044713      1.945988      2.944617
## [866]      2.302694      2.565084      2.302694      2.079530      3.044713
## [871]      2.398013      2.197324      2.639200      2.639200      2.708201
## [876]      2.890543      2.772746      2.485033      2.995916      2.079530
## [881]      1.098637      2.565084      1.386334      0.000000      2.302694
## [886]      2.079530      2.565084      2.302694      3.044713      2.890543
## [891]      3.044713      3.526616      3.219088      3.526616      3.496758
## [896]      3.689159      3.737956      3.583782      4.277041      4.317870
## [901]      4.331118      4.522208      4.263053      4.718956      4.663885
## [906]      4.615557      5.136339      4.905768      4.663885      4.219873
## [911]      3.871508      3.871508      3.258314      3.496758      3.367528
## [916]      2.833378      2.485033      2.565084      2.833378      2.708201
## [921]      2.639200      2.708201      2.302694      2.197324      0.693157
## [926]      1.791825      2.079530      1.609491      0.000000      0.693157
## [931]      1.098637      1.386334      1.098637      0.000000      1.098637
## [936]      1.609491
## attr(,"lambda")
## [1] 4.102259e-05
#San Juan ANN
san.juan_Neural_nets <- nnetar(transformed_san.juan)
san.juan_Neural_nets
## Series: transformed_san.juan 
## Model:  NNAR(7,1,4)[52] 
## Call:   nnetar(y = transformed_san.juan)
## 
## Average of 20 networks, each of which is
## a 8-4-1 network with 41 weights
## options were - linear output units 
## 
## sigma^2 estimated as 1699311
summary(san.juan_Neural_nets)
##           Length Class        Mode     
## x         936    ts           numeric  
## m           1    -none-       numeric  
## p           1    -none-       numeric  
## P           1    -none-       numeric  
## scalex      2    -none-       list     
## size        1    -none-       numeric  
## subset    936    -none-       numeric  
## model      20    nnetarmodels list     
## nnetargs    0    -none-       list     
## fitted    936    ts           numeric  
## residuals 936    ts           numeric  
## lags        8    -none-       numeric  
## series      1    -none-       character
## method      1    -none-       character
## call        2    -none-       call
#Forecasting the dengue cases in San Juan City
forecast_San_Juan <- forecast(san.juan_Neural_nets, h = 12)
forecast_San_Juan
##          Point Forecast
## 2008.000      -130.3336
## 2008.019     -1580.9993
## 2008.038     -6708.5229
## 2008.058     -7223.5498
## 2008.077     -3535.4338
## 2008.096     -5109.8738
## 2008.115    -10535.4935
## 2008.135     -6090.3269
## 2008.154     -6415.0276
## 2008.173     -5538.9186
## 2008.192     -8073.9457
## 2008.212     -7038.2443
autoplot(forecast_San_Juan)+
  ggtitle("Total Dengue Cases in the Next Six Weeks In San Juan City")+
  ylab("Dengue Fever Cases")+
  xlab("Time") +
  theme_gray()

#Checking the RMSE
accuracy_San.juan <- accuracy(forecast_San_Juan, h = 12)
print(accuracy_San.juan)
##                   ME     RMSE      MAE MPE MAPE      MASE        ACF1
## Training set 1.22496 1303.576 153.5642 Inf  Inf 0.6927443 0.000144969
#ANN in Iquitos 
iquitos_Neural_nets <- nnetar(iquitos.ts)
iquitos_Neural_nets
## Series: iquitos.ts 
## Model:  NNAR(5,1,4)[52] 
## Call:   nnetar(y = iquitos.ts)
## 
## Average of 20 networks, each of which is
## a 6-4-1 network with 33 weights
## options were - linear output units 
## 
## sigma^2 estimated as 23.3
summary(san.juan_Neural_nets)
##           Length Class        Mode     
## x         936    ts           numeric  
## m           1    -none-       numeric  
## p           1    -none-       numeric  
## P           1    -none-       numeric  
## scalex      2    -none-       list     
## size        1    -none-       numeric  
## subset    936    -none-       numeric  
## model      20    nnetarmodels list     
## nnetargs    0    -none-       list     
## fitted    936    ts           numeric  
## residuals 936    ts           numeric  
## lags        8    -none-       numeric  
## series      1    -none-       character
## method      1    -none-       character
## call        2    -none-       call
#RMSE
forecast_iquitos_city <- forecast(iquitos_Neural_nets, h = 12)
forecast_iquitos_city
##          Point Forecast
## 2000.000       3.880639
## 2000.019       4.719079
## 2000.038       4.705055
## 2000.058       4.682420
## 2000.077       4.611933
## 2000.096       4.495722
## 2000.115       4.408870
## 2000.135       4.267140
## 2000.154       4.251814
## 2000.173       4.382139
## 2000.192       4.427632
## 2000.212       4.466648
autoplot(forecast_iquitos_city)+
  ggtitle("Total Dengue Cases in the Next Six Weeks In Iquitos City")+
  ylab("Dengue Fever Cases")+
  xlab("Time") +
  theme_gray()

#RMSE
accuracy_model.equitos <- accuracy(forecast_iquitos_city, h = 12)
print(accuracy_model.equitos)
##                       ME     RMSE      MAE  MPE MAPE     MASE        ACF1
## Training set -0.09081555 4.826704 3.256718 -Inf  Inf 0.344985 -0.02161592