0.1 Working example

# Library ----
library(readxl)
## Warning: package 'readxl' was built under R version 4.2.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.2.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(lubridate)
## Warning: package 'lubridate' was built under R version 4.2.3
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.2.3
library(sf)
## Warning: package 'sf' was built under R version 4.2.3
## Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
setwd("C:/Users/alfredo.acosta/OneDrive - SVA/LORA/Draft/Scenario tree/")

0.2 DB WAHIS-INFUR —-

1 Number of Outbreaks —-

w <- read_xlsx("infur_20230407.xlsx")
# colnames(w)
# table(w$reporting_level)
# table(w$disease_eng)
# table(w$Species, w$is_wild == TRUE) #wild species
# table(w$Species[w$is_wild == FALSE]) #domestic species
# 
# View(w[w$disease_eng == "Rabies virus (Inf. with)" | w$disease_esp == "Cattle",])
# View(w[w$disease_eng == "Bluetongue virus (Inf. with)" | w$disease_esp == "Cattle",])
# View(w[w$disease_eng == "Classical swine fever virus (Inf. with)" | w$disease_esp == "Cattle",])

2 Modification in species category wahis (w) to match population FAOSTAT (p)

3 New variable species of functional groups

table(w$Species[w$is_wild == FALSE]) #domestic species TO MATCH
## 
##           Al indeterminatum       Aplodinotus grunniens 
##                           1                           2 
##   Austropotamobius pallipes                        Bees 
##                           1                        1099 
##                       Birds                   Buffaloes 
##                       24705                         302 
##             Camelidae (dom)           Carassius auratus 
##                          92                           3 
##                        Cats                      Cattle 
##                         291                       21493 
##              Cervidae (dom)      Channa aurantimaculata 
##                           8                           1 
##      Cherax quadricarinatus          Clarias gariepinus 
##                          27                           2 
##           Crassostrea gigas       Crassostrea virginica 
##                         103                           4 
##             Cyprinus carpio        Cyprinus rubrofuscus 
##                          98                           7 
##                        Dogs          Dorsoma cepedianum 
##                        1174                           1 
##               Equidae (dom)                 Esox lucius 
##                        3244                           1 
##            Esox masquinongy                       Goats 
##                           2                        3600 
##       Haliotis discushannai              Haliotis rubra 
##                           1                           1 
##          Inimicus japonicus               Labrus mixtus 
##                           1                           6 
##            Lates calcarifer         Lepomis macrochirus 
##                           1                           1 
##        Litopenaeus vannamei   Macrobrachium rosenbergii 
##                          17                           2 
##             Meretrix lyrata        Micropterus dolomieu 
##                           2                           2 
##       Micropterus salmoides          Mol indeterminatum 
##                           1                           1 
##             Morone chrysops          Moxostoma anisurum 
##                           1                           1 
##    Moxostoma macrolepidotum            Mustelidae (dom) 
##                           1                          66 
##              Mytilus edulis   Mytilus galloprovincialis 
##                           4                           5 
##      Neogobius melanostomus         Oncorhynchus mykiss 
##                           1                         137 
##       Oreochromis niloticus             Oreochromis spp 
##                          23                          61 
##               Ostrea angasi            Ostrea chilensis 
##                           5                           2 
##               Ostrea edulis               Other species 
##                           4                           1 
##             Penaeus indicus             Penaeus monodon 
##                           2                          18 
##        Penaeus stylirostris            Penaeus vannamei 
##                           4                          21 
##            Perca flavescens           Perna canaliculus 
##                           2                           1 
##          Pis indeterminatum      Pomoxis nigromaculatus 
##                           3                           1 
##          Procambarus alleni                     Rabbits 
##                           1                        1071 
## Rabbits/hares (mixed group)        Rachycentron canadum 
##                          27                           1 
##            Rana catesbeiana            Salmo marmoratus 
##                           4                           1 
##                 Salmo salar                Salmo trutta 
##                          37                           7 
##      Salmonidae (incognita)            Seriola dumerili 
##                           2                           1 
##                       Sheep    Sheep/goats (mixed herd) 
##                       15429                        1855 
##        Stizostedion vitreum                       Swine 
##                           1                       12484
table(w$Species[w$is_wild == FALSE]) %>% 
  as.data.frame() %>% 
  arrange(desc(Freq))
##                           Var1  Freq
## 1                        Birds 24705
## 2                       Cattle 21493
## 3                        Sheep 15429
## 4                        Swine 12484
## 5                        Goats  3600
## 6                Equidae (dom)  3244
## 7     Sheep/goats (mixed herd)  1855
## 8                         Dogs  1174
## 9                         Bees  1099
## 10                     Rabbits  1071
## 11                   Buffaloes   302
## 12                        Cats   291
## 13         Oncorhynchus mykiss   137
## 14           Crassostrea gigas   103
## 15             Cyprinus carpio    98
## 16             Camelidae (dom)    92
## 17            Mustelidae (dom)    66
## 18             Oreochromis spp    61
## 19                 Salmo salar    37
## 20      Cherax quadricarinatus    27
## 21 Rabbits/hares (mixed group)    27
## 22       Oreochromis niloticus    23
## 23            Penaeus vannamei    21
## 24             Penaeus monodon    18
## 25        Litopenaeus vannamei    17
## 26              Cervidae (dom)     8
## 27        Cyprinus rubrofuscus     7
## 28                Salmo trutta     7
## 29               Labrus mixtus     6
## 30   Mytilus galloprovincialis     5
## 31               Ostrea angasi     5
## 32       Crassostrea virginica     4
## 33              Mytilus edulis     4
## 34               Ostrea edulis     4
## 35        Penaeus stylirostris     4
## 36            Rana catesbeiana     4
## 37           Carassius auratus     3
## 38          Pis indeterminatum     3
## 39       Aplodinotus grunniens     2
## 40          Clarias gariepinus     2
## 41            Esox masquinongy     2
## 42   Macrobrachium rosenbergii     2
## 43             Meretrix lyrata     2
## 44        Micropterus dolomieu     2
## 45            Ostrea chilensis     2
## 46             Penaeus indicus     2
## 47            Perca flavescens     2
## 48      Salmonidae (incognita)     2
## 49           Al indeterminatum     1
## 50   Austropotamobius pallipes     1
## 51      Channa aurantimaculata     1
## 52          Dorsoma cepedianum     1
## 53                 Esox lucius     1
## 54       Haliotis discushannai     1
## 55              Haliotis rubra     1
## 56          Inimicus japonicus     1
## 57            Lates calcarifer     1
## 58         Lepomis macrochirus     1
## 59       Micropterus salmoides     1
## 60          Mol indeterminatum     1
## 61             Morone chrysops     1
## 62          Moxostoma anisurum     1
## 63    Moxostoma macrolepidotum     1
## 64      Neogobius melanostomus     1
## 65               Other species     1
## 66           Perna canaliculus     1
## 67      Pomoxis nigromaculatus     1
## 68          Procambarus alleni     1
## 69        Rachycentron canadum     1
## 70            Salmo marmoratus     1
## 71            Seriola dumerili     1
## 72        Stizostedion vitreum     1
w$Species_fg <- w$Species
w$Species_fg <- gsub("Swine", "Swine / pigs", w$Species_fg) #swine
w$Species_fg <- gsub("Equidae (dom)", "Horses", w$Species_fg) #Horses
w$Species_fg <- gsub("Birds", "Chickens", w$Species_fg) #Birds

table(w$Species_fg[w$is_wild == FALSE]) %>% 
  as.data.frame() %>% 
  arrange(desc(Freq))
##                           Var1  Freq
## 1                     Chickens 24705
## 2                       Cattle 21493
## 3                        Sheep 15429
## 4                 Swine / pigs 12484
## 5                        Goats  3600
## 6                Equidae (dom)  3244
## 7     Sheep/goats (mixed herd)  1855
## 8                         Dogs  1174
## 9                         Bees  1099
## 10                     Rabbits  1071
## 11                   Buffaloes   302
## 12                        Cats   291
## 13         Oncorhynchus mykiss   137
## 14           Crassostrea gigas   103
## 15             Cyprinus carpio    98
## 16             Camelidae (dom)    92
## 17            Mustelidae (dom)    66
## 18             Oreochromis spp    61
## 19                 Salmo salar    37
## 20      Cherax quadricarinatus    27
## 21 Rabbits/hares (mixed group)    27
## 22       Oreochromis niloticus    23
## 23            Penaeus vannamei    21
## 24             Penaeus monodon    18
## 25        Litopenaeus vannamei    17
## 26              Cervidae (dom)     8
## 27        Cyprinus rubrofuscus     7
## 28                Salmo trutta     7
## 29               Labrus mixtus     6
## 30   Mytilus galloprovincialis     5
## 31               Ostrea angasi     5
## 32       Crassostrea virginica     4
## 33              Mytilus edulis     4
## 34               Ostrea edulis     4
## 35        Penaeus stylirostris     4
## 36            Rana catesbeiana     4
## 37           Carassius auratus     3
## 38          Pis indeterminatum     3
## 39       Aplodinotus grunniens     2
## 40          Clarias gariepinus     2
## 41            Esox masquinongy     2
## 42   Macrobrachium rosenbergii     2
## 43             Meretrix lyrata     2
## 44        Micropterus dolomieu     2
## 45            Ostrea chilensis     2
## 46             Penaeus indicus     2
## 47            Perca flavescens     2
## 48      Salmonidae (incognita)     2
## 49           Al indeterminatum     1
## 50   Austropotamobius pallipes     1
## 51      Channa aurantimaculata     1
## 52          Dorsoma cepedianum     1
## 53                 Esox lucius     1
## 54       Haliotis discushannai     1
## 55              Haliotis rubra     1
## 56          Inimicus japonicus     1
## 57            Lates calcarifer     1
## 58         Lepomis macrochirus     1
## 59       Micropterus salmoides     1
## 60          Mol indeterminatum     1
## 61             Morone chrysops     1
## 62          Moxostoma anisurum     1
## 63    Moxostoma macrolepidotum     1
## 64      Neogobius melanostomus     1
## 65               Other species     1
## 66           Perna canaliculus     1
## 67      Pomoxis nigromaculatus     1
## 68          Procambarus alleni     1
## 69        Rachycentron canadum     1
## 70            Salmo marmoratus     1
## 71            Seriola dumerili     1
## 72        Stizostedion vitreum     1

4 Read the world map —-

wm <- st_read("TM_WORLD_BORDERS_SIMPL-0.3.shp")
## Reading layer `TM_WORLD_BORDERS_SIMPL-0.3' from data source 
##   `C:\Users\alfredo.acosta\OneDrive - SVA\LORA\Draft\Scenario tree\TM_WORLD_BORDERS_SIMPL-0.3.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 246 features and 11 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -180 ymin: -90 xmax: 180 ymax: 83.57027
## Geodetic CRS:  WGS 84

4.1 Selecting month and disease to analyse —-

date_to_analyse <- ymd("2021-08-01") #ASF HPAI 
disease_to_analyse <- "African swine fever virus (Inf. with)"
{
  
  w$date <- floor_date(w$event_confirmation_date, unit="month")
  
  # Number of outbreaks
  outb <- w %>% 
    filter(date == date_to_analyse) %>% 
    filter(disease_eng == disease_to_analyse) %>% 
    group_by(Species, iso_code, country, reporting_level, date) %>% 
    summarize(outbreak=n())
  
  outb
  
  # Number of Cases ----
  # Species is for domestic and have the same ID as in faostats
  cases <- w %>% 
    filter(date == date_to_analyse) %>% 
    filter(disease_eng == disease_to_analyse) %>% 
    group_by(Species_fg, iso_code, country, reporting_level, date) %>% 
    summarize(cases=sum(cases, na.rm = TRUE))
  cases
  # DB FAOSTATS ----
  # p=population of animals
  p <- read.csv(file="FAOSTAT_data_en_10-25-2023.csv")
  colnames(p)
  head(p)
  
  # Species
  table(p$Item)
  cases$Species_fg
  colnames(p)
  
  pop <- p %>% 
    filter(Item %in% cases$Species_fg) %>% 
    filter(Area.Code..ISO3. %in% cases$iso_code) %>% 
    filter(Year %in% year(date_to_analyse))
  
  # WORLD MAP ----
  
  # Update the number of outbreaks on the map
  wm$outbreak <- outb$outbreak[match(wm$ISO3, outb$iso_code)]
  
    # Update the number of cases on the map
  wm$cases <- cases$cases[match(wm$ISO3, outb$iso_code)]
  
  # Update the population on the map
  wm$pop <- pop$Value[match(wm$ISO3, pop$Area.Code..ISO3.)]
  
  # Prevalence ----
  wm$prev <- wm$cases/wm$pop
 
  # Maps of outbreaks
  pal <- colorNumeric(
    palette = "Spectral",
    domain = wm$outbreak, 
    na.color = "white"
  )
  
  map <- leaflet(wm) %>%
    addProviderTiles(providers$Esri.WorldStreetMap)
  
  mo <- map %>%
    setView(lng = 25, lat = 10, zoom = 2) %>%
    addPolygons(weight = 0.5, 
                color = ~pal(outbreak),
                popup = ~paste(NAME, outbreak)) %>% 
    addLegend("bottomright", pal = pal, values = ~outbreak,
              title = paste("Outbreaks", "<br>", date_to_analyse, "<br>", disease_to_analyse),
              opacity = 1)

# Maps of cases ----
library(leaflet)
pal <- colorNumeric(
  palette = "Spectral",
  domain = wm$cases, 
  na.color = "white")

map <- leaflet(wm) %>%
  addProviderTiles(providers$Esri.WorldStreetMap)

mc <- map %>%
  setView(lng = 25, lat = 10, zoom = 2) %>%
  addPolygons(weight = 0.5, 
              color = ~pal(cases),
              popup = ~paste(NAME, cases)) %>% 
  addLegend("bottomright", pal = pal, values = ~cases,
            title = paste("Cases",
                          "<br>",
                          date_to_analyse, 
                          "<br>", 
                          disease_to_analyse),
            opacity = 1)

# Map of prevalence ----
pal <- colorNumeric(
  palette = "Spectral",
  domain = wm$prev, 
  na.color = "white")

map <- leaflet(wm) %>%
  addProviderTiles(providers$Esri.WorldStreetMap)

mp <- map %>%
  setView(lng = 25, lat = 10, zoom = 2) %>%
  addPolygons(weight = 0.5, 
              color = ~pal(prev),
              popup = ~paste(NAME, prev)) %>% 
  addLegend("bottomright", pal = pal, values = ~prev,
            title = paste("prev",
                          "<br>",
                          date_to_analyse, 
                          "<br>", 
                          disease_to_analyse),
            opacity = 1)
head(wm %>% 
       as.data.frame() %>% 
       arrange(desc(prev)) %>% 
       select(NAME, pop, cases, prev))

}
## `summarise()` has grouped output by 'Species', 'iso_code', 'country',
## 'reporting_level'. You can override using the `.groups` argument.
## `summarise()` has grouped output by 'Species_fg', 'iso_code', 'country',
## 'reporting_level'. You can override using the `.groups` argument.
##                  NAME      pop cases         prev
## 1            Bulgaria   694660   100 1.439553e-04
## 2             Hungary  2725900    42 1.540776e-05
## 3 Republic of Moldova   339500     1 2.945508e-06
## 4             Ukraine  5876200     3 5.105340e-07
## 5              Russia 25850147    13 5.028985e-07
## 6 Antigua and Barbuda       NA    NA           NA
mo
mc
mp

5

Acosta, Alfredo PhD1. SVA1: FMVZ http://www.sva.se/.