Poultry Mortality Risk due to Avian Influenza

Integrating animal movement and historical disease occurence to improve disease risk models.

Contact:
John: jmh09r@my.fsu.edu

date() 
## [1] "Sun Aug 19 20:28:12 2018"
suppressMessages(library(INLA))
suppressMessages(library(rgdal))
suppressMessages(library(reshape2))
suppressMessages(library(raster))
suppressMessages(library(factoextra))
suppressMessages(library(corrplot))
suppressMessages(library(rasterVis))
suppressMessages(library(rgeos))
suppressMessages(library(maptools))
suppressMessages(library(mapproj))
suppressMessages(library(spdep))
suppressMessages(library(ggplot2))
suppressMessages(library(ggthemes))
suppressMessages(library(GISTools))
suppressMessages(library(lattice))
suppressMessages(library(gridExtra))
suppressMessages(library(dplyr))
suppressMessages(library(data.table))
suppressMessages(library(readr))
suppressMessages(library(stringr))
suppressMessages(library(lubridate))
suppressMessages(library(RcppRoll))
suppressMessages(library(changepoint))
suppressMessages(library(ecp))
suppressMessages(library(geosphere))
suppressMessages(library(moveHMM))
suppressMessages(library(adegenet))
suppressMessages(library(deldir))
suppressMessages(library(sp))
suppressMessages(library(spatstat))
suppressMessages(library(classInt))
suppressMessages(library(viridis))
suppressMessages(library(kableExtra))
source("RScripts.R")

Load and Prep Data

Removing “dead” locations.
Selecting “plausible” records from the DAF_Filter.
Formating date, adding local time (America/Chicago) and getting Hour, Day, Week, and season.

Argos_sp = read.csv("C:/Users/humph173/Documents/LabWork/Patuxent/Douglas_080218/BWTeal_2013-2017_Ramey_argos_tabular_diag_gis_filtered.csv",
                    stringsAsFactors=FALSE,
                    header = TRUE, sep=",")[,1:35] %>% 
                    filter(Fate == "alive",
                           DAF_Filter == 0) %>%
                    mutate(ID = Animal_ID,
                           ObsDate = as.POSIXct(Location_Datetime_GMT, 
                                                tz = "GMT", 
                                                format = "%Y/%m/%d %H:%M:%S"),
                           ObsDateD = as.Date(Location_Datetime_GMT),
                           LocT = ymd_hms(format(ObsDate, tz="America/Chicago", usetz=TRUE)),
                           LocHR = hour(LocT),
                           LocDY = day(LocT),
                           LocWK = week(LocT),
                           LocMN = month(LocT))

Argos_sp$Season = ifelse(Argos_sp$LocMN == 12 | Argos_sp$LocMN == 1, "Winter",
                      ifelse(Argos_sp$LocMN == 3, "Spring",
                             ifelse(Argos_sp$LocMN >= 4 & Argos_sp$LocMN <= 8, "Breeding",
                                    ifelse(Argos_sp$LocMN >= 9 & Argos_sp$LocMN <= 11, "Fall",
                                           ifelse(Argos_sp$LocMN == 2 & Argos_sp$Day <= 15, "Winter",
                                                  ifelse(Argos_sp$LocMN == 2 & Argos_sp$Day >= 16, "Spring",
                                                         NA))))))

Get Boundaries of North America

NAmer.reg = readOGR(dsn = "./Arc/NAmer/States", 
                  layer = "NA_regions", 
                  stringsAsFactors = FALSE)
## OGR data source with driver: ESRI Shapefile 
## Source: "C:\Users\humph173\Documents\LabWork\Patuxent\Patux_level1\Arc\NAmer\States", layer: "NA_regions"
## with 127 features
## It has 36 fields
## Integer64 fields read as strings:  FID_NA_reg FID_Cuba FID_ FID_NA_r_1 FID_0 MEXST0_ MEXST0_ID TOTPOP MALE FEMALE FID_NA_sta FID_Bahama OBJECTID TOTPOP_CY
LL84 = "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"

NAmer = gUnaryUnion(NAmer.reg)


tmp.ras = raster(res=0.5) #raster verion
extent(tmp.ras) = extent(NAmer)

Domain.r = rasterize(NAmer,
                     tmp.ras,
                     field = 0,
                     background = NA)

Grd.pnt = rasterToPoints(Domain.r, sp = TRUE)

Grd.pnt@data = Grd.pnt@data %>%
               mutate(Long = Grd.pnt@coords[,1],
                      Lat = Grd.pnt@coords[,2]) %>%
               select(-layer)

GLakes = readOGR(dsn = "./Arc/RedRast/GLake", 
                  layer = "GLakes", 
                  stringsAsFactors = FALSE)
## OGR data source with driver: ESRI Shapefile 
## Source: "C:\Users\humph173\Documents\LabWork\Patuxent\Patux_level1\Arc\RedRast\GLake", layer: "GLakes"
## with 5 features
## It has 6 fields
## Integer64 fields read as strings:  OBJECTID_1 ObjectID

Convert to Points

Locs = cbind(Argos_sp$Longitude, Argos_sp$Latitude)

Sp.pnts = SpatialPointsDataFrame(Locs, Argos_sp)
proj4string(Sp.pnts) = proj4string(NAmer.reg)

Grid Residence Time

Estimating duration of time (hours) spent in each grid cell. Individual birds are returned as layers in a raster stack. Birds are then combined to get the maximum duration any one bird spent in each cell. Time spent in grid cells lacking satellite fixes are interpolated assuming uniform movement between successful satellite captures. The custom function ResidenceRaster() is a wrapper combining the raster and trip packages.

Animal.IDs = levels(as.factor(Sp.pnts$Animal_ID))

for(i in 1:length(Animal.IDs)){
  
    Ani.tmp = subset(Sp.pnts, Animal_ID == Animal.IDs[i])
    
    tmp.res = ResidenceRaster(Ani.tmp, Domain.r)
    
    if(i == 1){Res.stk = tmp.res}
      else{Res.stk = stack(Res.stk, tmp.res)}
    
}

names(Res.stk) = Animal.IDs

Res.stk

ZZ = max(Res.stk)
ZZ

View Results

rng = seq(0, 105, 1)
mCols  = brewer.pal(9, "YlOrRd")[-c(1:2)]
cr0 = colorRampPalette(mCols)(n = 2000)
cr = colorRampPalette(c(cr0), 
         bias = 4)

#Removing background zeros for plotting
ZZ2 = ZZ
ZZ2[ZZ2 == 0] = NA

#Identifying areas where more than 1day was spent.
ZZ3 = ZZ2
ZZ3[ZZ3 < 1] = NA

REs.stkX = stack(ZZ2, ZZ3)
names(REs.stkX) = c("Duration", "Stopovers")

Plt.a = levelplot(REs.stkX, 
             margin = FALSE,
             layout = c(2,1),
             xlab =NULL, 
             ylab = NULL,
             main = "Residence Time (days)",
             maxpixels = 1e5,
             col.regions = cr, at =rng,
             colorkey = list(labels=list(at=c(0, 20, 40, 60, 80, 103),  
                             labels=c("0", "20", "40", "60", "80", "100 Days"), cex=1),
                             labels=list(cex=12),
                             space = "bottom"), 
                             par.strip.text = list(fontface='bold', cex=1),
             par.settings = list(axis.line = list(col = "black"),
                                 strip.background = list(col = 'transparent'), 
                                 strip.border = list(col = 'transparent')),
                                 scales = list(cex = 1)) + 
             latticeExtra::layer(sp.polygons(NAmer.reg, col = "darkgray", lwd = 0.5)) 

Plt.a

Construct Triangulated Mesh

NA.bf = gBuffer(NAmer, 
                width = 1, 
                byid = FALSE) 

NA.bnds = inla.sp2segment(NA.bf)

MaxEdge = 0.5

mesh0 = inla.mesh.2d(boundary = NA.bnds, 
                     cutoff = 1, 
                     max.edge = MaxEdge,
                     min.angle = 21) 

MeshLocs = cbind(mesh0$loc[,1], mesh0$loc[,2]) 

xyz = as.data.frame(                
          inla.mesh.map(MeshLocs, 
                        projection = "longlat", 
                        inverse = TRUE))

true.radius.of.earth = 6371 #km
radius.of.earth = 1

mesh.dom = inla.mesh.create(loc = xyz,
                     cutoff = 35/true.radius.of.earth, 
                     refine=list(max.edge = 1000/true.radius.of.earth, 
                                 min.angle = 26))

Click, drag, and zoom to view mesh

mesh.dom$n 
## [1] 9555
plot(mesh.dom, rgl = TRUE, main = " ")

You must enable Javascript to view this page properly.

Areal Exposure

Tessellation around mesh nodes.

dd = as.data.frame(cbind(mesh.dom$loc[,1], 
                         mesh.dom$loc[,2],
                         mesh.dom$loc[,3]))

dd = as.data.frame(
          inla.mesh.map(dd, 
                        projection = "longlat", 
                        inverse = FALSE))

names(dd) = c("Long", "Lat")

nProj = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0
         +x_0=0 +y_0=0 +k=1 +units=km +nadgrids=@null +no_defs"

dd.pnt = spTransform(
              SpatialPointsDataFrame(dd[,c("Long","Lat")], dd,
              proj4string = CRS(proj4string(NAmer))),
              nProj)

NA.unP = spTransform(NAmer, nProj)

Poly.msh = Mesh_tessellation(dd.pnt)

Poly.msh$Area = gArea(Poly.msh, byid=TRUE)
proj4string(Poly.msh) = proj4string(dd.pnt)

dd.pnt$Area = extract(Poly.msh, dd.pnt, 
                      method="simple")[,"Area"]

dd.pnt$Domain = is.na(over(dd.pnt, NA.unP))

dd.pnt$Exp = ifelse(dd.pnt$Domain == TRUE, 0, dd.pnt$Area)

Poly.in = spTransform(Poly.msh, proj4string(NAmer))
Poly.in = crop(Poly.in, NAmer)

Poly.msh$Zones = 1:nrow(Poly.msh@data)

Aggregate to Zones

Zones delineate each node’s area of influence. Here we record the longest duration in each zone.

#Poly.in$Dur = extract(ZZ, 
#                      spTransform(Poly.in, CRS(proj4string(ZZ))), 
#                      fun=max, sp=FALSE) 

#dd.pnt$Dur = as.numeric(extract(
#                          Poly.in, 
#                          spTransform(dd.pnt, proj4string(Poly.in)), 
#                          method = "simple")[,"Dur"])

Poly.in$IDx = 1:nrow(Poly.in@data)
Poly.in$IDx = Poly.in$IDx - 1

tmp.cov = read.csv("./Arc/RedRast/Dur_tab/Duration.csv",
                     stringsAsFactors=FALSE,
                     header = TRUE, sep=",")
  
Poly.in$Dur = as.numeric(with(tmp.cov ,
                            MAX[match(Poly.in$IDx, 
                                                 FID)]))

Poly.in$Dur[is.na(Poly.in$Dur)] = 0

Add Additional Variables

Pre-processed as above.

GetFiles = list.files(path = "./Arc/RedRast/CSV2", full.names = TRUE)

CovLabels = substr(GetFiles, 20, 24)

for(i in 1:length(CovLabels)){
  
  tmp.cov = read.csv(GetFiles[[i]],
                     stringsAsFactors=FALSE,
                     header = TRUE, sep=",")
  
  tmp.vec = as.numeric(with(tmp.cov ,
                              MEAN[match(Poly.in$IDx, 
                                                   FID)]))
  
  tmp.vec[is.na(tmp.vec)] = mean(tmp.vec, na.rm=T)
  
  
  if(i == 1){OutCov = tmp.vec}
      else{OutCov = as.data.frame(cbind(OutCov, tmp.vec))}
  
}
  
names(OutCov) = CovLabels

tmp.cov = read.csv("./Arc/RedRast/CSV2/WaterArea.csv",
                     stringsAsFactors=FALSE,
                     header = TRUE, sep=",")
  
OutCov$Water = as.numeric(with(tmp.cov ,
                            COUNT[match(Poly.in$IDx, 
                                                 FID)]))

OutCov$Water[is.na(OutCov$Water)] = median(OutCov$Water, na.rm=T)


##Chicken
tmp.cov = read.csv("./Arc/RedRast/CSV2/GChick.csv",
                     stringsAsFactors=FALSE,
                     header = TRUE, sep=",")
  
OutCov$GChic = as.numeric(with(tmp.cov ,
                            SUM[match(Poly.in$IDx, 
                                                 FID)]))

OutCov$GChic[is.na(OutCov$GChic)] = median(OutCov$GChic, na.rm=T)


##Ducks
tmp.cov = read.csv("./Arc/RedRast/CSV2/GDucks.csv",
                     stringsAsFactors=FALSE,
                     header = TRUE, sep=",")
  
OutCov$GDuck = as.numeric(with(tmp.cov ,
                            SUM[match(Poly.in$IDx, 
                                                 FID)]))

OutCov$GDuck[is.na(OutCov$GDuck)] = median(OutCov$GDuck, na.rm=T)

Cov.df = OutCov

for(i in 1:ncol(Cov.df)){
      Cov.df[,i] = as.numeric(scale(Cov.df[,i], scale = T, center = T))
}
  

names(Cov.df) = paste(names(OutCov), "_s", sep="")
  
Cov.df = cbind(OutCov, Cov.df)                     
             

ScCov.df = names(Cov.df)

Poly.in@data = cbind(Poly.in@data, Cov.df)

Poly.inP = spTransform(Poly.in, proj4string(dd.pnt))

TTTT = over(dd.pnt, Poly.inP)
TTTT[is.na(TTTT)] = 0

dd.pnt@data = cbind(dd.pnt@data, TTTT)

Avian Influenza Outbreaks

Load EMPRES Data

Loading global data then selecting years 2004-2017, domestic livestock outbreaks, and records for North America.

CleanEMPRES("C:/Users/humph173/Documents/LabWork/Patuxent/EMPRES", "EMPRES.cln")
EMPRES.cln = as.data.frame(EMPRES.cln)

#Observations
dim(EMPRES.cln)[1]
## [1] 7937
str(EMPRES.cln)
## 'data.frame':    7937 obs. of  13 variables:
##  $ Id       : int  234352 234350 234330 234310 234302 234301 234300 234299 234298 234295 ...
##  $ Spp      : Factor w/ 495 levels "","captive, amur tiger",..: 30 183 183 183 183 183 30 30 140 183 ...
##  $ Long     : num  120.22 25.45 6.33 19.4 44.21 ...
##  $ Lat      : num  23.8 42.2 53.2 -34.3 33.5 ...
##  $ AI       : chr  "H5N2 HPAI" "H5N8 HPAI" "H5N6 HPAI" "H5N8 HPAI" ...
##  $ ObsDate  : Date, format: "2018-02-15" "2017-11-20" ...
##  $ Year     : int  2018 2017 2018 2018 2018 2018 2018 2018 2018 2018 ...
##  $ Month    : int  2 11 2 1 2 2 2 2 2 2 ...
##  $ Week     : int  7 47 8 5 7 7 7 7 7 6 ...
##  $ Day      : int  15 20 24 29 14 13 12 12 12 11 ...
##  $ Cntry    : chr  "Taiwan (Province of China)" "Bulgaria" "Netherlands" "South Africa" ...
##  $ sumAtRisk: int  28451 2981 37866 14 130500 39500 15767 12807 1985 2058 ...
##  $ sumDeaths: int  250 19 230 4 77850 13500 482 800 29 10 ...
EMPRES.cln %>% 
   group_by(Year) %>%
   summarise(no_rows = length(Year))
## # A tibble: 15 x 2
##     Year no_rows
##    <int>   <int>
##  1  2004     981
##  2  2005     369
##  3  2006     757
##  4  2007     378
##  5  2008     509
##  6  2009     115
##  7  2010     109
##  8  2011     419
##  9  2012     210
## 10  2013     248
## 11  2014     193
## 12  2015     911
## 13  2016    1239
## 14  2017    1401
## 15  2018      98
EMPRES.cln$Dom = grepl("domestic", EMPRES.cln$Spp)

EMPRES.cln %>% 
   group_by(Dom) %>%
   summarise(no_rows = length(Dom))
## # A tibble: 2 x 2
##   Dom   no_rows
##   <lgl>   <int>
## 1 FALSE     374
## 2 TRUE     7563
E.df = EMPRES.cln %>%
          mutate(OBS = 1) %>%
          filter(Year >= 2004 & Year <= 2017,
                 Dom == "TRUE") %>%
          select(Long, Lat, OBS, AI, Spp, ObsDate, Year, Month, sumAtRisk, sumDeaths)


O.pnts = SpatialPointsDataFrame(E.df[,c("Long","Lat")], E.df)
proj4string(O.pnts) = proj4string(NAmer)

O.pnts$Domain = is.na(over(O.pnts, NAmer))
O.pnts = subset(O.pnts, Domain == "FALSE")

Median Global Incidence Rate (IR)

Indirect Standardization

Inc.df = as.data.frame(
            O.pnts@data %>%
                  group_by(Year) %>%
                  summarise(Mortality = sum(sumDeaths),
                            atRisk = sum(sumAtRisk))) %>%
         mutate(IR = Mortality/atRisk) 

Global.IR = mean(Inc.df$IR)

Global.IR
## [1] 0.02302809
Inc.df$Expected = Global.IR*Inc.df$atRisk

Compare Estimate

Inc.plt = Inc.df %>% filter(Mortality > 0)


lds.plt = ggplot(Inc.plt, aes(factor(Year), IR)) +
                 geom_bar(fill="gray", 
                          stat="identity") +
                 geom_hline(aes(yintercept=Global.IR), 
                            lwd=1.5, col="black", lty="dashed" ) +
                 geom_text(aes(x=3, y=Global.IR+0.005, label= "Mean Global IR"), size=6) +
                 ylab(" ") +
                 ylab("Incidence Rate (IR)") +
                 theme_classic() +
                 theme(axis.title.x=element_blank(),
                        axis.text.x=element_text(size=16, face="bold"),
                        axis.text.y=element_text(size=16, face="bold"),
                        axis.ticks.x=element_blank(),
                        panel.border = element_rect(color = "black", fill = NA, size = 1),
                        strip.text.x = element_text(size=16, face="bold"),
                        axis.title.y = element_text(size=16, face="bold"),
                        legend.title = element_text(size=16, face="bold"),
                        legend.position="bottom")

lds.plt

Expected Mortality for All Locations

Assuming an outbreak.

Poly.in$Expected = Global.IR*Poly.in$GChic #Chicken only

Poly.in$Exp_CD = Global.IR*(Poly.in$GChic+Poly.in$GDuck) #chicken and ducks

Get Additional Outbreak Data (2015)

F1.df = read.csv("./US_AI_2015/ai_022718A.csv",
                    stringsAsFactors=FALSE,
                    header = TRUE, sep=",") %>%
                mutate(ObsDate = as.POSIXct(Collection_Date, 
                                    tz = "America/Chicago", 
                                    format = "%m/%d/%Y %H:%M:%S"),
                       Year = year(ObsDate),
                       Month = month(ObsDate)) %>%
                select(Long, Lat, ObsDate, Year, Month)

F2.df = read.csv("./US_AI_2015/ai_022718B.csv",
                    stringsAsFactors=FALSE,
                    header = TRUE, sep=",") %>%
                mutate(ObsDate = as.POSIXct(Confirmation_Date, 
                                    tz = "America/Chicago", 
                                    format = "%m/%d/%Y %H:%M:%S"),
                       Year = year(ObsDate),
                       Month = month(ObsDate)) %>%
                select(Long, Lat, ObsDate, Year, Month)


AI_1415.pnt = rbind(F1.df, F2.df)


AI_1415.pnt = AI_1415.pnt %>%
                        mutate(IDs = 1:nrow(AI_1415.pnt),
                               Source = "US")

AI_1415.pnt = SpatialPointsDataFrame(AI_1415.pnt[,c("Long","Lat")], AI_1415.pnt)
proj4string(AI_1415.pnt) = proj4string(NAmer)

Combine with EMPRES

Also, removing duplicates.

All.ai = rbind(
          O.pnts@data %>%
              mutate(Source = "EMPRES",
                     IDs = 1:nrow(O.pnts@data)) %>%
              select(Long, Lat, ObsDate, Year, Month, IDs, Source),
          AI_1415.pnt@data[, c("Long", "Lat", "ObsDate", "Year", "Month", "IDs", "Source")])

All.ai$dups = duplicated(All.ai[, c("Long","Lat")])

All.ai %>%
  group_by(dups) %>%
  summarise(Cnt = length(dups))
## # A tibble: 2 x 2
##   dups    Cnt
##   <lgl> <int>
## 1 FALSE   395
## 2 TRUE     42
All.ai = All.ai %>% filter(dups == "FALSE")

All.ai.pnt = SpatialPointsDataFrame(All.ai[,c("Long","Lat")], All.ai)
proj4string(All.ai.pnt) = proj4string(NAmer)

View Outbreak Locations

wmap_df = fortify(NAmer.reg)
## Regions defined for each Polygons
tmp.df = All.ai.pnt@data %>% 
            select(Long, Lat)

ggplot(wmap_df, aes(long,lat, group=group)) + 
        geom_polygon(fill = "tan", col="black") + 
        geom_point(data=tmp.df, 
                   aes(Long, Lat, 
                       group=NULL, fill=NULL),
                       col = "red", size=1) +
        xlab("Longitude") +
        ylab("Latitude") +
        ggtitle("A.I. Outbreaks (2004-2017)") +
        guides(color=guide_legend(title = "Year")) +
        scale_x_longitude(xmin=-130, xmax=80, step=10) +
        scale_y_latitude(ymin=10, ymax=80, step=10) +
        coord_equal() + 
        theme(panel.grid.minor = element_blank(),
              panel.grid.major = element_blank(),
              panel.background = element_blank(),
              plot.background = element_blank(),
              panel.border = element_blank(),
              legend.title = element_blank(),
              axis.title.x = element_text(size=16, face="bold"),
              axis.title.y = element_text(size=16, face="bold"),
              plot.title = element_text(size=20, face="bold", hjust = 0.5))

Outbreak Counts

Counting number of outbreaks in each zone.

n.events = poly.counts(spTransform(All.ai.pnt, 
                       proj4string(Poly.msh)), Poly.msh)

Poly.msh$n.events = n.events

Events.df = over(dd.pnt, Poly.msh)

dd.pnt@data = cbind(dd.pnt@data, Events.df[,c("Zones", "n.events")])

dd.pnt$Expected = over(dd.pnt, 
                       spTransform(Poly.in,
                       proj4string(dd.pnt)))[,"Expected"]

dd.pnt$Expected[is.na(dd.pnt$Expected)] = 0

dd.pnt$Exp_CD = over(dd.pnt, 
                       spTransform(Poly.in,
                       proj4string(dd.pnt)))[,"Exp_CD"]

dd.pnt$Exp_CD[is.na(dd.pnt$Exp_CD)] = 0

Sum Poultry Mortatlity

Adding-up documented killed poultry by zone.

O.pnts$Zone = over(spTransform(O.pnts, 
                   proj4string(Poly.msh)), 
                   Poly.msh)[,"Zones"]

Poly.in$Zone = over(spTransform(Poly.in, 
                   proj4string(dd.pnt)), 
                   dd.pnt)[,"Zones"]

SDeath.df = as.data.frame(
                    O.pnts@data %>%
                           group_by(Zone) %>%
                           summarise(SDth = sum(sumDeaths)))


Poly.in$nMort = as.numeric(with(SDeath.df,
                              SDth[match(Poly.in$Zone, 
                                                   Zone)]))

Poly.in$nMort[is.na(Poly.in$nMort)] = 0




dd.pnt$nMort = as.numeric(with(SDeath.df,
                              SDth[match(dd.pnt$Zones, 
                                                   Zone)]))

dd.pnt$nMort[is.na(dd.pnt$nMort)] = 0




Poly.msh$nMort = as.numeric(with(SDeath.df,
                              SDth[match(Poly.msh$Zones, 
                                                   Zone)]))

Poly.msh$nMort[is.na(Poly.msh$nMort)] = 0

Outbreak Temporal Trend

Examening outbreak vs. migration timing.

Time.df = All.ai.pnt@data %>%
          mutate(OB = 1) %>%
          select(OB, Year, Month)

Yr.lvs = levels(factor(Time.df$Year))

Time.bg = rbind(Time.df, Time.df, Time.df, Time.df) 

Time.bg = Time.bg %>%
            mutate(OB = 0,
                   Month = sample(1:12, 
                           nrow(Time.bg), 
                           replace=T),
                   Year = sample(Yr.lvs,
                           nrow(Time.bg), 
                           replace=T))

Time.df = rbind(Time.df, Time.bg)


Trnd.frm = OB ~ -1 +  f(Month, 
                        model="rw1", 
                        constr=F)

Trend.mod = inla(Trnd.frm, 
                 data = Time.df, 
                 family = "binomial",
                 verbose = FALSE,
                 control.fixed = list(prec = 0.001, 
                                      prec.intercept = 0.0001), 
                 control.predictor = list(compute = TRUE, 
                                        link = 1), 
                 control.inla = list(strategy="gaussian", 
                                     int.strategy = "eb"),
                 control.results = list(return.marginals.random = TRUE,
                                        return.marginals.predictor = TRUE),
                 control.compute=list(dic = TRUE, cpo = TRUE, waic = TRUE)) 
T.df = as.data.frame(Trend.mod$summary.random$Month)[,c(1:2,4,6)]
names(T.df) = c("IDo", "Meano", "Q025o", "Q975o")

BWTE Latitudinal Movement

Lat.df =Argos_sp %>%
          select(Longitude, Latitude, ObsDate, LocT, LocHR, LocDY, LocWK, LocMN, Season)

Lat.df$DOY = strftime(Lat.df$LocT, format = "%j")

Dy.lvs = levels(factor(Lat.df$DOY))


Lat.mx = as.data.frame(
            Lat.df %>%
              group_by(LocMN) %>%
              summarize((mL = max(Latitude))))

names(Lat.mx) = c("DOY", "mL")

Lat.df$mL = as.numeric(with(Lat.mx,
                              mL[match(Lat.df$LocMN, 
                                              DOY)])) 



LatM.frm = mL ~ -1 +  f(DOY, 
                        model="rw1", 
                        constr=F)

Lat.mod = inla(LatM.frm, 
                 data = Lat.mx, 
                 family = "gaussian",
                 verbose = FALSE,
                 control.fixed = list(prec = 0.001, 
                                      prec.intercept = 0.0001), 
                 control.predictor = list(compute = TRUE, 
                                        link = 1), 
                 control.inla = list(strategy="gaussian", 
                                     int.strategy = "eb"),
                 control.results = list(return.marginals.random = TRUE,
                                        return.marginals.predictor = TRUE),
                 control.compute=list(dic = TRUE, cpo = TRUE, waic = TRUE)) 
L.df = as.data.frame(Lat.mod$summary.random$DOY)[,c(1:2,4,6)]
names(L.df) = c("IDl", "Meanl", "Q025l", "Q975l")

Compare Migration Vs. Outbreak Time

Complex plotting…

comb.df = cbind(T.df, L.df)
comb.df$pMeano = plogis(comb.df$Meano)
comb.df$Ole = plogis(comb.df$Q025o)
comb.df$Olue = plogis(comb.df$Q975o)

o1 = ggplot(comb.df) + 
  stat_smooth(aes(x = IDo, y = Ole), span = 1, method = "loess", se = FALSE) +
  stat_smooth(aes(x = IDo, y = Olue), span = 1, method = "loess", se = FALSE)

oo1 = ggplot_build(o1)

df2 = data.frame(x = oo1$data[[1]]$x,
                  ymin = oo1$data[[1]]$y,
                  ymax = oo1$data[[2]]$y) 


comb.df$Lat = L.df$Meanl
comb.df$SLat = Scale(comb.df$Lat)*max(comb.df$pMeano)
comb.df$Sue = Scale(comb.df$Q975l)*max(comb.df$pMeano)
comb.df$Sle = Scale(comb.df$Q025l)*max(comb.df$pMeano)
mxLp = max(L.df$Meanl)/max(comb.df$SLat)

l1 = ggplot(comb.df) + 
  stat_smooth(aes(x = IDo, y = Sle), span = 0.85, method = "loess", se = FALSE) +
  stat_smooth(aes(x = IDo, y = Sue), span = 0.85, method = "loess", se = FALSE)

ll1 = ggplot_build(l1)

df3 = data.frame(x = ll1$data[[1]]$x,
                  ymin = ll1$data[[1]]$y,
                  ymax = ll1$data[[2]]$y) 


p = ggplot() +
    geom_smooth(data =comb.df, aes(IDo, pMeano), 
                col = "black", linetype= "solid",
                method = "loess", span = 1,
                se = FALSE, lwd = 1) +
    geom_smooth(data=comb.df, aes(x=IDo, y=SLat),
                            col = "red", 
                            linetype= "dashed",
                            method = "loess",
                            span = 0.85,
                            se = FALSE,
                            lwd = 1)
       
p = p + geom_ribbon(data = df2, aes(x = x, ymin = ymin, ymax = ymax), alpha=0.2) 
                  
p = p + geom_ribbon(data = df3, aes(x = x, ymin = ymin, ymax = ymax), alpha=0.9)

p = p + scale_y_continuous(sec.axis = sec_axis(~.*mxLp, name = expression("Movement   ("~degree~"Latitude)")),
                            breaks = seq(0, 0.5, 0.1), limits = c(0, 0.5)) 

p = p + scale_x_continuous(breaks = c(1:12),
                           labels = month.abb) +
        geom_text(aes(x=7.5, y=0.15, label= "Outbreaks"), size=6) +
        geom_text(aes(x=10.65, y=0.4, label= "BWTE Movement"), size=6) +
        xlab(" ") +
        ylab("OutBreak Month Probability") +  
        theme_classic() +
        theme(axis.text=element_text(size=16),
              strip.text = element_text(size = 20),
              axis.title = element_text(size = 20, vjust=2))
              #axis.title.y.right = element_text(face="bold", size = 20, vjust=2),
              #axis.title.x = element_text(face="bold", size = 20, vjust=2))

p

Spatial Modeling

Project Zones to Mesh

dd.pntll = spTransform(dd.pnt, proj4string(NAmer))

locs = cbind(dd.pntll@coords[,1], dd.pntll@coords[,2])

locs = inla.mesh.map(locs, 
                     projection = "longlat", 
                     inverse = TRUE)

A.1 = inla.spde.make.A(mesh.dom, 
                          loc=locs) 

A.3 = A.2 = A.1 #extra copies

SPDE and Spatial Indices

spde1 = inla.spde2.pcmatern(mesh.dom, alpha = 2,
                            prior.range=c(3, 0.01),  
                            prior.sigma=c(1, 0.01),
                            constr = T)

Spatial Indicies

The “Xs” are extra copies for joint models (shared components).

field1 = inla.spde.make.index("field1", 
                               spde1$n.spde)

field1x = inla.spde.make.index("field1x", 
                               spde1$n.spde)

field1xx = inla.spde.make.index("field1xx", 
                               spde1$n.spde)

field2 = inla.spde.make.index("field2", 
                               spde1$n.spde)

field2x = inla.spde.make.index("field2x", 
                               spde1$n.spde)

field3 = inla.spde.make.index("field3", 
                               spde1$n.spde)

Construct Data Stacks

Organizing data for model fitting.

FE.df = dd.pntll@data

FE.lst.1 = list(c(field1,
                list(intercept1 = 1)),
                list(DurX = FE.df[,"Dur"]))

FE.df$Outbrk.OBS = ifelse(FE.df$n.events > 0, 1, 0)

Base.one = inla.stack(data = list(Y = FE.df$Outbrk.OBS),
                                  A = list(A.1, 1), 
                            effects = FE.lst.1,   
                                tag = "base.1")

Base.stk = inla.stack(data = list(Y = cbind(FE.df$Outbrk.OBS, NA), 
                               link = 1),
                                  A = list(A.1, 1), 
                            effects = FE.lst.1,   
                                tag = "base.1s")

FE.lst.1b = list(c(field2, field1x,
                list(intercept2 = 1)),
                list(DurX = FE.df[,"Dur"]))

TRI_OB.stk = inla.stack(data = list(Y = cbind(NA, FE.df$Outbrk.OBS, NA), 
                                 link = 1),
                                    A = list(A.1, 1), 
                              effects = FE.lst.1b,   
                                  tag = "ob.1t")


##BWTE Telemetry
##Stack forjoint models 
FE.df$DurOBS = ifelse(FE.df$Dur > 0.5, 1, 0)
Base.stkBinom = inla.stack(data = list(Y = cbind(FE.df$DurOBS, NA), 
                           link = 1,
                            nTr = rep(1, dim(FE.df)[1])),
                              A = list(A.1, 1), 
                        effects = FE.lst.1,   
                            tag = "base.1b")

FE.lst.1c = list(c(field1,
                list(intercept1 = 1)),
                list(DurX = FE.df[,"Dur"]))

TRI_bwtw.stk = inla.stack(data = list(Y = cbind(FE.df$DurOBS, NA, NA), 
                           link = 1,
                            nTr = rep(1, dim(FE.df)[1])),
                              A = list(A.2, 1), 
                        effects = FE.lst.1c,   
                            tag = "bwte.1t")


##Risk Stacks
FE.df$Glob_poul =(FE.df[,"GChic"]+FE.df[,"GDuck"])/10^4

FE.lst.2 = list(c(field2, field1x,
                list(intercept2 = 1)),
                list(Dur = FE.df[,"Dur"],
                     DEM = FE.df[,"DEMms_s"],
                     GChk = FE.df[,"GChic"],
                     Glob_poul = FE.df[,"Glob_poul"],
                     GDk = FE.df[,"GDuck"],
                     hPop = FE.df[,"hPopu_s"],
                     Slope = FE.df[,"Slope_s"],
                     Soil = FE.df[,"Soils_s"],
                     WaterA = FE.df[,"Water_s"],
                     WaterD = FE.df[,"Distw_s"],
                     Zone = FE.df[,"Zones"]))

range(FE.df$nMort)
FE.df$nMortS = ceiling(FE.df$nMort/10^4)

FE.df$ExpectedS = FE.df$Exp_CD/10^4 #All poultry
FE.df$ExpectedS[FE.df$ExpectedS == 0] = 10^-12


Risk.one = inla.stack(data = list(Y = FE.df$nMortS, 
                               link = 2,
                                  e = FE.df$ExpectedS),
                                  A = list(A.2, 1), 
                            effects = FE.lst.2,   
                                tag = "risk.1")

Risk.stk = inla.stack(data = list(Y = cbind(NA, FE.df$nMortS), 
                               link = 2,
                                  e = FE.df$ExpectedS),
                                  A = list(A.2, 1), 
                            effects = FE.lst.2,   
                                tag = "risk.1s")

Risk.stkCnt = inla.stack(data = list(Y = cbind(NA, FE.df$nMortS), 
                               link = 2,
                                  e = log(FE.df$ExpectedS)),
                                  A = list(A.2, 1), 
                            effects = FE.lst.2,   
                                tag = "risk.1sc")

FE.lst.2b = list(c(field3, 
                   field1xx, #shared fields
                   field2x,
                list(intercept3 = 1)),
                list(Dur = FE.df[,"Dur"],
                     DEM = FE.df[,"DEMms_s"],
                     GChk = FE.df[,"GChic"],
                     Glob_poul = FE.df[,"Glob_poul"],
                     GDk = FE.df[,"GDuck"],
                     hPop = FE.df[,"hPopu_s"],
                     Slope = FE.df[,"Slope_s"],
                     Soil = FE.df[,"Soils_s"],
                     WaterA = FE.df[,"Water_s"],
                     WaterD = FE.df[,"Distw_s"],
                     Zone = FE.df[,"Zones"]))

TRI_rsk.stk = inla.stack(data = list(Y = cbind(NA, NA, FE.df$nMortS), 
                               link = 2,
                                  e = FE.df$ExpectedS),
                                  A = list(A.3, 1), 
                            effects = FE.lst.2b,   
                                tag = "risk.1t")


# Binomial 
FE.df$n.Trials = ceiling(FE.df$Glob_poul)

Risk.bi = inla.stack(data = list(Y = FE.df$nMortS, 
                           link = 2,
                            nTr = FE.df$n.Trials),
                              A = list(A.2, 1), 
                        effects = FE.lst.2,   
                            tag = "risk.1b")

Risk.stkBinom = inla.stack(data = list(Y = cbind(NA, FE.df$nMortS), 
                           link = 2,
                            nTr = FE.df$n.Trials),
                              A = list(A.2, 1), 
                        effects = FE.lst.2,   
                            tag = "risk.1b")

Combine Data Stacks

Joint models require multiple datasets.

J.Stack = inla.stack(Base.stk, Risk.stk)

J.Stack1B = inla.stack(Base.stkBinom, Risk.stk)

J.Stack1C = inla.stack(Base.stk, Risk.stkCnt)

J.Stack2 = inla.stack(Base.stkBinom, Risk.stkBinom)

J.Stack.tri = inla.stack(TRI_bwtw.stk, TRI_OB.stk, TRI_rsk.stk)

Poisson Risk Models

Notes are added within the chunk to highlight model components.

Non-spatial Risk Model

A non-spatial model for later comparison.

lgam.prior = list(
                prec=list(
                  prior="loggamma",
                  param=c(1,0.00001))) #this is a prior specification.


Frm.Kns = Y ~ -1 + Glob_poul + #the "Y" is the past actual/observed/reported deaths. Including population. 
                   f(Zone,     #Using a "random intercept"" for each location
                     model="iid", 
                     hyper=lgam.prior)

Model.Kns = inla(Frm.Kns, #formula
                 data = inla.stack.data(Risk.one, spde=spde1), #the data
                 family = "poisson", #likelihood
                 verbose = FALSE,
                 E = inla.stack.data(Risk.one)$e, #Expected mortality/IR
                 control.fixed = list(prec = 0.001, #prior for linear effects
                                      prec.intercept = 0.0001), 
                 control.predictor = list(
                                        A = inla.stack.A(Risk.one), #report fitted values on natural scale
                                        compute = TRUE, 
                                        link = 1), 
                 control.inla = list(strategy="gaussian", 
                                     int.strategy = "eb"), #speeding-up the process bu using a mode
                 control.results = list(return.marginals.random = TRUE,
                                        return.marginals.predictor = TRUE),
                 control.compute=list(dic = TRUE, cpo = TRUE, waic = TRUE)) #evaluation stats to calculate
GetMets(Model.Kns)
##   Metric   Tier.1
## 1    DIC 2295.393
## 2   WAIC 2600.919
## 3   lCPO    1.585

Base Spatial Risk Model

Building on the previous model, geography is added to the model.

Frm.sp = Y ~ -1 +  intercept2 +
                    Glob_poul +
                  f(field2, # Location information
                    model = spde1) +
                  f(Zone, 
                    model="iid", 
                    hyper = lgam.prior)

theta.sp = c(0.04838131, 1.11166713, -1.92674712) 

Model.sp = inla(Frm.sp, 
                 data = inla.stack.data(Risk.one, 
                                        spde=spde1), 
                 family = "poisson",
                 verbose = FALSE,
                 E = inla.stack.data(Risk.one)$e,
                 control.fixed = list(prec = 0.001, 
                                      prec.intercept = 0.0001), 
                 control.predictor = list(
                                        A = inla.stack.A(Risk.one), 
                                        compute = TRUE, 
                                        link = 1), 
                 control.mode = list(restart = TRUE, theta = theta.sp),
                 control.inla = list(strategy="gaussian", 
                                     int.strategy = "eb"),
                 control.results = list(return.marginals.random = TRUE,
                                        return.marginals.predictor = TRUE),
                 control.compute=list(dic = TRUE, cpo = TRUE, waic = TRUE)) 
GetMets(Model.sp)[1,2]
## [1] 1801.457

Joint Spatial Risk Model (Risk + Outbreak)

Two models combined. The first evaluates outbreak geography, the second uses that information (and error) to inform risk assessment.

Frm.J = Y ~ -1 + intercept1 + 
                 intercept2 + 
                 Glob_poul +
              f(field1, 
                model = spde1) +
              f(field1x,        #shared component
                copy = "field1",  
                fixed = FALSE) + 
              f(field2, 
                model = spde1) +
              f(Zone, 
                model="iid", 
                hyper = lgam.prior)



thetaJ = c(4.46449696, 0.59065970, -0.06708619, 0.22549147, 0.94051323, -1.80026797, 1.52569363) 

ModelJ = inla(Frm.J, 
               data = inla.stack.data(J.Stack, 
                                      spde1=spde1), 
               family = c("gaussian", "poisson"), 
               verbose = FALSE,
               E = inla.stack.data(J.Stack)$e,
               control.fixed = list(prec = 0.001, 
                                    prec.intercept = 0.0001), 
               control.predictor = list(
                                      A = inla.stack.A(J.Stack), 
                                      compute = TRUE, 
                                      link = 1), 
               control.mode = list(restart = TRUE, theta = thetaJ),
               control.inla = list(strategy="gaussian", 
                                   int.strategy = "eb"),
               control.results = list(return.marginals.random = TRUE,
                                      return.marginals.predictor = TRUE),
               control.compute=list(dic = TRUE, cpo = TRUE, waic = TRUE)) 
GetMets(ModelJ)[1,3]
## [1] 1494.169

Joint Spatial Risk Model (BWTE Residence Time)

Combined model using BWTE to improve risk estimates.

Frm.J2 = Y ~ -1 + intercept1 + 
                  intercept2 + 
                  Glob_poul +
                f(field1, 
                  model = spde1) +
                f(field1x, 
                  copy = "field1",  
                  fixed = FALSE) + 
                f(field2, 
                  model = spde1) +
                f(Zone, 
                  model="iid", 
                  hyper = lgam.prior)


thetaJ2 = c(-0.71162907, 1.84564916, 0.01065652, 1.20662303, -1.80211150, 0.35373520) 

ModelJ2 = inla(Frm.J2, 
               data = inla.stack.data(J.Stack1B, 
                                      spde1=spde1), 
               family = c("binomial", "poisson"), 
               verbose = FALSE,
               E = inla.stack.data(J.Stack1B)$e,
               control.fixed = list(prec = 0.001, 
                                    prec.intercept = 0.0001), 
               control.predictor = list(
                                      A = inla.stack.A(J.Stack1B), 
                                      compute = TRUE, 
                                      link = 1), 
               control.mode = list(restart = TRUE, theta = thetaJ2),
               control.inla = list(strategy="gaussian", 
                                   int.strategy = "eb"),
               control.results = list(return.marginals.random = TRUE,
                                      return.marginals.predictor = TRUE),
               control.compute=list(dic = TRUE, cpo = TRUE, waic = TRUE)) 
GetMets(ModelJ2)[1,3]
## [1] 1638.494

Joint Spatial Risk Model (Coregion: Risk + Outbreaks + Residence Time)

A three part model combining using BWTE and outbreak geography to inform risk modeling.

Frm.J3 = Y ~ -1 + intercept1 + 
                  intercept2 + 
                  intercept3 + 
                  Glob_poul +
                f(field1, 
                  model = spde1) +
                f(field1x, 
                  copy = "field1",  
                  fixed = FALSE) + 
                f(field1xx, 
                  copy = "field1",  
                  fixed = FALSE) + 
                f(field2, 
                  model = spde1) +
                f(field2x, 
                  copy = "field2",  
                  fixed = FALSE) + 
                f(field3, 
                  model = spde1) +
                f(Zone, 
                  model="iid", 
                  hyper = lgam.prior)


thetaJ3 = c(4.46112801, -0.69415733, 1.72425359, 0.71776090, -0.07067129, -0.08180539, 1.33184966,
            -1.26110173, 0.01720369, 0.83479079, 1.25481985) 

Model.J4 = inla(Frm.J3, 
               data = inla.stack.data(J.Stack.tri, 
                                      spde1=spde1), 
               family = c("binomial", "gaussian", "poisson"), 
               verbose = FALSE,
               E = inla.stack.data(J.Stack.tri)$e,
               control.fixed = list(prec = 0.001, 
                                    prec.intercept = 0.0001), 
               control.predictor = list(
                                      A = inla.stack.A(J.Stack.tri), 
                                      compute = TRUE, 
                                      link = 1), 
               control.mode = list(restart = TRUE, theta = thetaJ3),
               control.inla = list(strategy="gaussian", 
                                   int.strategy = "eb"),
               control.results = list(return.marginals.random = TRUE,
                                      return.marginals.predictor = TRUE),
               control.compute=list(dic = TRUE, cpo = TRUE, waic = TRUE)) 
GetMets(Model.J4)[1,4]
## [1] 1065.73

Estimated Poultry Mortality (counts)

Using best model to estimate poultry mortality.

ModelC = inla(Frm.J3, 
               data = inla.stack.data(J.Stack.tri, 
                                      spde1=spde1), 
               family = c("binomial", "gaussian", "poisson"), 
               verbose = FALSE,
               offset = inla.stack.data(J.Stack1C)$e, #log(e) as population offset
               control.fixed = list(prec = 0.001, 
                                    prec.intercept = 0.0001), 
               control.predictor = list(
                                      A = inla.stack.A(J.Stack.tri), 
                                      compute = TRUE, 
                                      link = 1), 
               control.mode = list(restart = TRUE, theta = thetaJ3),
               control.inla = list(strategy="gaussian", 
                                   int.strategy = "eb"),
               control.results = list(return.marginals.random = TRUE,
                                      return.marginals.predictor = TRUE),
               control.compute=list(dic = TRUE, cpo = TRUE, waic = TRUE))

Compare Models

Models = c("Model1", "Model2",
           "Model3", "Model4",
           "Model5")

Type = c("Non-spatial",
         "Spatial (Base)",
         "Risk-Outbreak (Joint)",
         "Risk-BWTE (Joint)",
         "Risk-Outbreak-BWTE (Joint)")

#Deviance information criteria
DICs = c(Model.Kns$dic$dic, Model.sp$dic$dic, 
         tapply(ModelJ$dic$local.dic, ModelJ$dic$family, sum)[2],
         GetMets(ModelJ2)[1,3],
         GetMets(Model.J4)[1,4])

#Watanabe-Akaike information criteria
WAICs = c(Model.Kns$waic$waic, Model.sp$waic$waic, 
         tapply(ModelJ$waic$local.waic, ModelJ$dic$family, sum)[1],
         GetMets(Model.J4)[1,3])

Model_mets = as.data.frame(cbind(Model = Models,
                                 DIC = round(DICs, 2),
                                 Type = Type))
rownames(Model_mets) = 1:nrow(Model_mets)

kable(Model_mets) %>%
      kable_styling("striped", full_width = F) %>%
      row_spec(0, font_size = 20) 
Model DIC Type
Model1 2295.39 Non-spatial
Model2 1801.46 Spatial (Base)
Model3 1494.17 Risk-Outbreak (Joint)
Model4 1638.49 Risk-BWTE (Joint)
Model5 1065.73 Risk-Outbreak-BWTE (Joint)
library(xtable)
## 
## Attaching package: 'xtable'
## The following object is masked from 'package:maptools':
## 
##     label
Table2 = xtable(Model_mets)
print(Table2, include.rownames = FALSE)
## % latex table generated in R 3.5.1 by xtable 1.8-2 package
## % Sun Aug 19 20:29:35 2018
## \begin{table}[ht]
## \centering
## \begin{tabular}{lll}
##   \hline
## Model & DIC & Type \\ 
##   \hline
## Model1 & 2295.39 & Non-spatial \\ 
##   Model2 & 1801.46 & Spatial (Base) \\ 
##   Model3 & 1494.17 & Risk-Outbreak (Joint) \\ 
##   Model4 & 1638.49 & Risk-BWTE (Joint) \\ 
##   Model5 & 1065.73 & Risk-Outbreak-BWTE (Joint) \\ 
##    \hline
## \end{tabular}
## \end{table}

Extract Results (Best Model)

Poly.plot = Poly.in

idat = inla.stack.index(J.Stack.tri, "risk.1t")$data
Poly.msh$Fit.r = Model.J4$summary.fitted.values$mean[idat]
Poly.plot$Fit.r = as.numeric(with(Poly.msh@data,
                              Fit.r[match(Poly.plot$Zone, 
                                                    Zones)]))

idat = inla.stack.index(Risk.one, "risk.1")$data
Poly.msh$Fit.ns = Model.Kns$summary.fitted.values$mean[idat]
Poly.plot$Fit.ns = as.numeric(with(Poly.msh@data,
                              Fit.ns[match(Poly.plot$Zone, 
                                                    Zones)]))

idat = inla.stack.index(J.Stack1C, "risk.1sc")$data
Poly.msh$MortCnt = ModelC$summary.fitted.values$mean[idat]
Poly.plot$MortCnt = as.numeric(with(Poly.msh@data,
                              MortCnt[match(Poly.plot$Zone, 
                                                    Zones)]))


Poly.plot = subset(Poly.plot, is.na(Fit.r) ==  FALSE)

Prepare Map and Calibrate Unstable Ratios

NA_proj_df = fortify(NAmer.reg)
## Regions defined for each Polygons
GLakes_df = fortify(GLakes)
## Regions defined for each Polygons
Out.df = All.ai.pnt@data %>%
          select(Long, Lat)

Poly.plot@data$id = rownames(Poly.plot@data)
wmap_df = fortify(Poly.plot, region = "id")
wmap_df = left_join(wmap_df, Poly.plot@data, by = "id")

wmap_df$GlobPoultry = wmap_df$GChic+wmap_df$GDuck

wmap_df$Fit.r2 = ifelse(wmap_df$GlobPoultry < 10^4, 
                        min(wmap_df$Fit.r), wmap_df$Fit.r)

quantiles = quantile(wmap_df$Fit.r2, probs = c(.01, .999))

wmap_df$Fit.r3 = ifelse(wmap_df$Fit.r2 > quantiles[2], 
                        round(quantiles[2],2), wmap_df$Fit.r2)


ns.quant = quantile(wmap_df$Fit.ns, probs = 0.99)

wmap_df$Fit.ns2 = ifelse(wmap_df$GlobPoultry < 10^4, 
                         min(wmap_df$Fit.ns),wmap_df$Fit.ns)
wmap_df$Fit.ns3 = ifelse(wmap_df$Fit.ns2 > ns.quant, 
                         round(ns.quant,2),wmap_df$Fit.ns2)

Plot Risk

#wmap_df$brks = cut(wmap_df$Fit.r3, 
#               breaks= c(-1, 0.20, 0.50, 0.8, 1, 1.3, 1.65))


ggplot(wmap_df, 
        aes(long,lat, group=group, fill = Fit.r3)) + 
        geom_polygon(col="#2b2b2b") + 
        geom_polygon(data=NA_proj_df, 
                   aes(long, lat, 
                       group=group), fill="transparent", 
                       col = "white", size=0.25) +
        geom_polygon(data=GLakes_df, 
                   aes(long, lat), fill="white", 
                       col = "white", size=1) +
        #geom_point(data=Out.df, 
        #           aes(Long, Lat, 
        #               group=NULL, fill=NULL), 
        #               col = "red", size=1.5) +
        scale_fill_viridis(name="Risk", discrete=F, direction = -1) + 
        xlab("Longitude") +
        ylab("Latitude") +
        scale_x_longitude(xmin=-140, xmax=-50, step=10) +
        scale_y_latitude(ymin=-10, ymax=90, step=10) +
        coord_equal() + 
        theme(panel.grid.minor = element_blank(),
              panel.grid.major = element_blank(),
              panel.background = element_blank(),
              plot.background = element_blank(),
              panel.border = element_blank(),
              legend.title = element_text(size=12, face="bold"),
              axis.title.x = element_text(size=16, face="bold"),
              axis.title.y = element_text(size=16, face="bold"),
              plot.title = element_blank())

Exceedance Probability

ggplot(wmap_df, 
            aes(long,lat, group=group, fill = pExc)) + 
            geom_polygon(col="#2b2b2b") + 
            geom_polygon(data=NA_proj_df, 
                       aes(long, lat, 
                           group=group), fill="transparent", 
                           col = "white", size=1) +
            scale_fill_viridis(name="Exceedance", 
                               discrete=F, direction = -1,
                               option = "B") + 
            xlab("Longitude") +
            ylab("Latitude") +
            scale_x_longitude(xmin=-140, xmax=-50, step=10) +
            scale_y_latitude(ymin=-10, ymax=90, step=10) +
            coord_equal() + 
            theme(panel.grid.minor = element_blank(),
                  panel.grid.major = element_blank(),
                  panel.background = element_blank(),
                  plot.background = element_blank(),
                  panel.border = element_blank(),
                  legend.title = element_text(size=12, face="bold"),
                  axis.title.x = element_text(size=16, face="bold"),
                  axis.title.y = element_text(size=16, face="bold"),
                  plot.title = element_blank())

Plot Poultry Mortality (counts)

Exceed.cuts = round(quantile(wmap_df$MortCnt*10^4, probs = c(0, 0.25, 0.5, 0.75, 0.99, 1)), 2)

wmap_df$brksC = ifelse(wmap_df$GlobPoultry < 10, 0.01, wmap_df$MortCnt*10^4)
  
wmap_df$brksC  = cut(wmap_df$brksC, 
                    breaks= c(0, 100, 1000, 10000, 100000, 1000000))


ggplot(wmap_df, 
        aes(long,lat, group=group, fill = brksC)) + 
        geom_polygon(col= "#2b2b2b", size=0.05) + 
        geom_polygon(data=NA_proj_df, 
                   aes(long, lat, 
                       group=group), fill="transparent", 
                       col = "black", size=0.5) +
        geom_polygon(data=GLakes_df, 
                   aes(long, lat), fill="white", 
                       col = "black", size=1) +
        #geom_point(data=Out.df, 
        #           aes(Long, Lat, 
        #               group=NULL, fill=NULL), 
        #               col = "red", size=1.5) +
        scale_fill_viridis(name="Mortality", discrete=T, direction = -1, option = "A") + 
        xlab("Longitude") +
        ylab("Latitude") +
        scale_x_longitude(xmin=-140, xmax=-50, step=10) +
        scale_y_latitude(ymin=-10, ymax=90, step=10) +
        coord_equal() + 
        theme(panel.grid.minor = element_blank(),
              panel.grid.major = element_blank(),
              panel.background = element_blank(),
              plot.background = element_blank(),
              panel.border = element_blank(),
              legend.title = element_text(size=12, face="bold"),
              axis.title.x = element_text(size=16, face="bold"),
              axis.title.y = element_text(size=16, face="bold"),
              plot.title = element_blank())

Plot Non-Spatial Model

For comparsion.

wmap_df$brks4 = cut(wmap_df$Fit.ns3, 
               breaks= seq(0, 2.2, 0.2))


ggplot(wmap_df, 
        aes(long,lat, group=group, fill = brks4)) + 
        geom_polygon(col="#2b2b2b") + 
        geom_polygon(data=NA_proj_df, 
                   aes(long, lat, 
                       group=group), fill="transparent", 
                       col = "white", size=0.25) +
        geom_polygon(data=GLakes_df, 
                   aes(long, lat), fill="white", 
                       col = "white", size=1) +
        #geom_point(data=Out.df, 
        #           aes(Long, Lat, 
        #               group=NULL, fill=NULL), 
        #               col = "red", size=1.5) +
        scale_fill_viridis(name="Risk", discrete=T, direction = -1) + 
        xlab("Longitude") +
        ylab("Latitude") +
        scale_x_longitude(xmin=-140, xmax=-50, step=10) +
        scale_y_latitude(ymin=-10, ymax=90, step=10) +
        coord_equal() + 
        theme(panel.grid.minor = element_blank(),
              panel.grid.major = element_blank(),
              panel.background = element_blank(),
              plot.background = element_blank(),
              panel.border = element_blank(),
              legend.title = element_text(size=12, face="bold"),
              axis.title.x = element_text(size=16, face="bold"),
              axis.title.y = element_text(size=16, face="bold"),
              plot.title = element_blank())

sessionInfo()
## R version 3.5.1 (2018-07-02)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 17134)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=English_United States.1252 
## [2] LC_CTYPE=English_United States.1252   
## [3] LC_MONETARY=English_United States.1252
## [4] LC_NUMERIC=C                          
## [5] LC_TIME=English_United States.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] xtable_1.8-2        bindrcpp_0.2.2      trip_1.5.0         
##  [4] kableExtra_0.9.0    viridis_0.5.1       viridisLite_0.3.0  
##  [7] classInt_0.2-3      spatstat_1.56-0     rpart_4.1-13       
## [10] nlme_3.1-137        spatstat.data_1.3-1 deldir_0.1-15      
## [13] adegenet_2.1.1      ade4_1.7-11         moveHMM_1.6        
## [16] CircStats_0.2-6     boot_1.3-20         geosphere_1.5-7    
## [19] ecp_3.1.0           Rcpp_0.12.17        changepoint_2.2.2  
## [22] zoo_1.8-3           RcppRoll_0.3.0      lubridate_1.7.4    
## [25] stringr_1.3.1       readr_1.1.1         data.table_1.11.4  
## [28] dplyr_0.7.6         gridExtra_2.3       GISTools_0.7-4     
## [31] MASS_7.3-50         ggthemes_4.0.0      spdep_0.7-7        
## [34] spData_0.2.9.3      mapproj_1.2.6       maps_3.3.0         
## [37] maptools_0.9-2      rgeos_0.3-28        rasterVis_0.45     
## [40] latticeExtra_0.6-28 RColorBrewer_1.1-2  lattice_0.20-35    
## [43] corrplot_0.84       factoextra_1.0.5    ggplot2_3.0.0      
## [46] raster_2.6-7        reshape2_1.4.3      rgdal_1.3-3        
## [49] INLA_18.07.12       sp_1.3-1            Matrix_1.2-14      
## [52] rgl_0.99.16         knitr_1.20         
## 
## loaded via a namespace (and not attached):
##  [1] colorspace_1.3-2        seqinr_3.4-5           
##  [3] rjson_0.2.20            class_7.3-14           
##  [5] rprojroot_1.3-2         markdown_0.8           
##  [7] rstudioapi_0.7          hexbin_1.27.2          
##  [9] ggrepel_0.8.0           fansi_0.2.3            
## [11] xml2_1.2.0              splines_3.5.1          
## [13] polyclip_1.9-0          jsonlite_1.5           
## [15] cluster_2.0.7-1         png_0.1-7              
## [17] shiny_1.1.0             httr_1.3.1             
## [19] compiler_3.5.1          backports_1.1.2        
## [21] assertthat_0.2.0        lazyeval_0.2.1         
## [23] cli_1.0.0               later_0.7.3            
## [25] htmltools_0.3.6         tools_3.5.1            
## [27] ggmap_2.6.1             igraph_1.2.1           
## [29] coda_0.19-1             gtable_0.2.0           
## [31] glue_1.3.0              gmodels_2.18.1         
## [33] gdata_2.18.0            ape_5.1                
## [35] crosstalk_1.0.0         proto_1.0.0            
## [37] rvest_0.3.2             mime_0.5               
## [39] miniUI_0.1.1.1          gtools_3.8.1           
## [41] goftest_1.1-1           LearnBayes_2.15.1      
## [43] scales_0.5.0            hms_0.4.2              
## [45] promises_1.0.1          spatstat.utils_1.8-2   
## [47] parallel_3.5.1          expm_0.999-2           
## [49] stringi_1.1.7           highr_0.7              
## [51] e1071_1.6-8             permute_0.9-4          
## [53] manipulateWidget_0.10.0 RgoogleMaps_1.4.2      
## [55] rlang_0.2.1             pkgconfig_2.0.1        
## [57] evaluate_0.11           tensor_1.5             
## [59] purrr_0.2.5             bindr_0.1.1            
## [61] labeling_0.3            htmlwidgets_1.2        
## [63] tidyselect_0.2.4        plyr_1.8.4             
## [65] magrittr_1.5            R6_2.2.2               
## [67] pillar_1.3.0            foreign_0.8-71         
## [69] withr_2.1.2             mgcv_1.8-24            
## [71] abind_1.4-5             tibble_1.4.2           
## [73] crayon_1.3.4            utf8_1.1.4             
## [75] rmarkdown_1.10          jpeg_0.1-8             
## [77] grid_3.5.1              vegan_2.5-2            
## [79] digest_0.6.15           webshot_0.5.0          
## [81] httpuv_1.4.5            numDeriv_2016.8-1      
## [83] munsell_0.5.0