Loading the required libraries

library(mapSpain)
library(randomForest)
library(ggplot2)
library(ggpubr)
library(mgcViz)
library(forecast)
library(DHARMa)

We first prepare the database for the communities and, afterwards, assemble them together to prepare the national database.

comunidad<-read.table("comunidad.txt", header = TRUE, sep = "\t",stringsAsFactors = T)
comunidad<- comunidad[names(comunidad[c(1,2,3)])]# eliminating unnecessary columns

Eliminating asturias, Cantabria,Asturias and Murcia (because of insufficient data - see main text)

comunidad<- comunidad[comunidad$community!="Asturias"&comunidad$community!="Cantabria"&comunidad$community!="R.deMurcia"&comunidad$community!="Canarias",]
comunidad$community<- factor(comunidad$community)

Creating one dataframe for each community

for (i in levels(comunidad$community)) {
  command <- paste0(i, "<-subset(comunidad, community=='", i, "')")
  eval(parse(text=command)) 
}

For each community, we replace missing values with the estimated ones from random forest techniques.

This is to identify and replace outliers in the time series of each community

for (i in levels(comunidad$community)) {
  command <- paste0(i,"$N[tsoutliers(",i,"$N)$index]<- tsoutliers(",i,"$N)$replacements") 
  eval(parse(text=command))
}

Joining the datasets together again

comunidad<- rbind(Andalucia,Aragon,Baleares,C.Valenciana,CastillalaMancha,CastillayLeon,Cataluna,Extremadura,Galicia,LaRioja,Madrid,Navarra,PaisVasco)
comunidad$RHD<- as.factor(ifelse(comunidad$year<1988,"no RHD",ifelse(comunidad$year<2011,"GI.1","GI.2")))

Creating a new national dataset made of the sums of annual Ns from each community (excluding Cantabria, Asturias and Murcia)

nacionalnew<- aggregate(comunidad$N, list(comunidad$year), FUN=mean)
names(nacionalnew)<- c("year","N")

National data - GAM analysis

We use GAM analyses on all years of collected data to evaluate the temporal pattern at the national level in the number of hunted rabbits.

gam1 <- gam(N ~ s(year, k=20) , data=nacionalnew, select=T, method="REML")# select=T means that we are using the double penalty approach to do selection. When select=T the p-value refers to the probability that actually there is no effect at all of the predictor on the response variable (flat line).
summary(gam1)# summary of results
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## N ~ s(year, k = 20)
## 
## Parametric coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   455500       8649   52.67   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Approximate significance of smooth terms:
##           edf Ref.df     F p-value    
## s(year) 10.21     19 10.94  <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## R-sq.(adj) =  0.845   Deviance explained = 88.7%
## -REML = 488.63  Scale est. = 2.9173e+09  n = 39
simgam2<- simulateResiduals(gam1,plot=T)# OK

gam.check(gam1)# OK

## 
## Method: REML   Optimizer: outer newton
## full convergence after 6 iterations.
## Gradient range [-3.013763e-06,-6.044938e-07]
## (score 488.6339 & scale 2917332364).
## Hessian positive definite, eigenvalue range [3.000395e-06,20.55868].
## Model rank =  20 / 20 
## 
## Basis dimension (k) checking results. Low p-value (k-index<1) may
## indicate that k is too low, especially if edf is close to k'.
## 
##           k'  edf k-index p-value
## s(year) 19.0 10.2    1.49       1

Creating a new, toy dataframe to make predictions from the model and use them to visualize them. Note there is no data for 2004, because it was not available (see main text).

newdata<- data.frame(year=1980:2018,N=nacionalnew$N)
predizioni<- predict(gam1,newdata = newdata, type="terms",se=T)
newdata$predsgam1<- as.numeric(predizioni$fit)+gam1$coefficients[1]
newdata$predsgam1se<- as.numeric(predizioni$se.fit)
newdata$RHD<- factor(c(rep("no RHD",8),rep("GI.1",23),rep("GI.2",8)))
newdata$RHD<- relevel(newdata$RHD,"no RHD")

National yearly numbers of hunted rabbits

This figure (Figure 2 in main text) represents the GAM curve depicting the variation in the number of hunted rabbits between 1980 and 2018 before and after GI.1 and GI.2. outbreaks

# png("Figure2.png",width=480*1.5)
ggplot(newdata, aes(x = year, y = N, fill=RHD))+
  geom_smooth(aes(ymin=predsgam1-1.96*predsgam1se,ymax=predsgam1+1.96*predsgam1se,fill= RHD),stat="identity",linetype=0,size=5)+
  scale_fill_brewer(palette = "BuPu")+
  geom_point()+
  scale_x_continuous(breaks = seq(min(newdata$year), max(newdata$year), by = 1))+ 
  theme(axis.text.x = element_text(angle = 45,size=13,vjust = 0.2))+#vjust align the labels under the tick (in the center)+
  theme(axis.text.y = element_text(size = rel(1.5), angle = 45, margin = margin(t = 0, r = 10, b = 0, l = 0)))+
  theme(axis.text.x = element_text(size = rel(1.5), angle = 45, margin = margin(t = 5, r = 0, b = 0, l = 0)))+
  labs(x="year", y="# hunted rabbits",title="Spain")+
  theme(axis.title.y = element_text(size = rel(1.8), angle = 90))+ 
  theme(axis.title.x = element_text(size = rel(1.8), angle = 0))+
  theme(plot.title = element_text(size = rel(1.8), angle = 00))+
  theme(legend.position = c(0.9,0.9),legend.text = element_text(size = 12),legend.title=element_blank())+
  theme(plot.margin = margin(t = 1, r = 1, b = 1, l = 1, unit = "cm"))

# dev.off()

Communities data - GAM analysis

We use GAM analyses on all years of collected data to evaluate the temporal pattern at level of each community in the number of hunted rabbits.

Andalusia

Andalucia<- comunidad[comunidad$community=="Andalucia",]

gam1and <- gam(N ~ s(year, k=20) , data=Andalucia, select=T, method="REML")
summary(gam1and)# summary of results
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## N ~ s(year, k = 20)
## 
## Parametric coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2023011      70096   28.86   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Approximate significance of smooth terms:
##           edf Ref.df     F p-value    
## s(year) 9.451     19 11.69  <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## R-sq.(adj) =  0.854   Deviance explained =   89%
## -REML = 566.46  Scale est. = 1.9163e+11  n = 39
simgam2and<- simulateResiduals(gam1and,plot=T)# OK

gam.check(gam1and)# OK

## 
## Method: REML   Optimizer: outer newton
## full convergence after 7 iterations.
## Gradient range [-5.364598e-13,2.599589e-06]
## (score 566.4607 & scale 191626541004).
## eigenvalue range [-2.599205e-06,20.323].
## Model rank =  20 / 20 
## 
## Basis dimension (k) checking results. Low p-value (k-index<1) may
## indicate that k is too low, especially if edf is close to k'.
## 
##            k'   edf k-index p-value
## s(year) 19.00  9.45    1.48       1

Creating a new, toy dataframe to make predictions from the model and use them to visualize them.

newdataAnd<- data.frame(year=sort(unique(Andalucia$year)),N=Andalucia[order(Andalucia$year),]$N)
predizioniAnd<- predict(gam1and,newdataAnd = newdataAnd, type="terms",se=T)
newdataAnd$predsgam1and<- as.numeric(predizioniAnd$fit)+gam1and$coefficients[1]
newdataAnd$predsgam1andse<- as.numeric(predizioniAnd$se.fit)
newdataAnd$RHD<- Andalucia$RHD
newdataAnd$RHD<- relevel(newdataAnd$RHD,"no RHD")

Andalusia yearly numbers of hunted rabbits

This figure represents the GAM curve depicting the variation in the number of hunted rabbits between 1980 and 2018 before and after GI.1 and GI.2 outbreaks in Andalusia.

# png("Figure1and.png",width=480*1.5)
p1<- ggplot(newdataAnd, aes(x = year, y = N, fill=RHD))+
  geom_smooth(aes(ymin=predsgam1and-1.96*predsgam1andse,ymax=predsgam1and+1.96*predsgam1andse,fill= RHD),stat="identity",linetype=0,size=5)+
  scale_fill_brewer(palette = "BuGn")+
  geom_point()+
  scale_x_continuous(breaks = seq(min(newdataAnd$year), max(newdataAnd$year), by = 1))+ 
  theme(axis.title.y = element_text(size = rel(1.8), angle = 90))+ 
  theme(axis.title.x = element_text(size = rel(1.8), angle = 0))+
  theme(axis.text.x = element_text(angle = 45,size=13,vjust = 0.2))+#vjust align the labels under the tick (in the center)+
  theme(axis.text.y = element_text(size = rel(1.5), angle = 45, margin = margin(t = 0, r = 10, b = 0, l = 0)))+
  theme(axis.text.x = element_text(size = rel(1.5), angle = 45, margin = margin(t = 5, r = 0, b = 0, l = 0)))+
  labs(y="# hunted rabbits",title="Andalusia")+
  theme(legend.position = c(0.9,0.9),legend.text = element_text(size = 12),legend.title=element_blank())+
  theme(plot.margin = margin(t = 1, r = 1, b = 1, l = 1, unit = "cm"))
p1

# dev.off()

Aragon

Aragon<- comunidad[comunidad$community=="Aragon",]

gam1ara <- gam(N ~ s(year, k=20) , data=Aragon, select=T, method="REML")
summary(gam1ara)# summary of results
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## N ~ s(year, k = 20)
## 
## Parametric coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   182752       5710      32   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Approximate significance of smooth terms:
##           edf Ref.df     F p-value    
## s(year) 7.416     19 50.81  <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## R-sq.(adj) =  0.962   Deviance explained =   97%
## -REML = 467.58  Scale est. = 1.2718e+09  n = 39
simgam2and<- simulateResiduals(gam1ara,plot=T)# OK

gam.check(gam1ara)#OK

## 
## Method: REML   Optimizer: outer newton
## full convergence after 11 iterations.
## Gradient range [-3.776319e-08,1.247419e-08]
## (score 467.5842 & scale 1271752878).
## Hessian positive definite, eigenvalue range [0.4193064,19.61939].
## Model rank =  20 / 20 
## 
## Basis dimension (k) checking results. Low p-value (k-index<1) may
## indicate that k is too low, especially if edf is close to k'.
## 
##            k'   edf k-index p-value
## s(year) 19.00  7.42    1.16    0.81

Creating a new, toy dataframe to make predictions from the model and use them to visualize them.

newdataAra<- data.frame(year=sort(unique(Aragon$year)),N=Aragon[order(Aragon$year),]$N)
predizioniAra<- predict(gam1ara,newdataAra = newdataAra, type="terms",se=T)
newdataAra$predsgam1ara<- as.numeric(predizioniAra$fit)+gam1ara$coefficients[1]
newdataAra$predsgam1arase<- as.numeric(predizioniAra$se.fit)
newdataAra$RHD<- Aragon$RHD
#str(newdataAra$RHD)
newdataAra$RHD<- relevel(newdataAra$RHD,"no RHD")

Aragon yearly numbers of hunted rabbits

This figure represents the GAM curve depicting the variation in the number of hunted rabbits between 1980 and 2018 before and after GI.1 and GI.2 outbreaks in Aragon.

# png("Figure1ara.png",width=480*1.5)
p2<- ggplot(newdataAra, aes(x = year, y = N, fill=RHD))+
  geom_smooth(aes(ymin=predsgam1ara-1.96*predsgam1arase,ymax=predsgam1ara+1.96*predsgam1arase,fill= RHD),stat="identity",linetype=0)+
  scale_fill_brewer(palette = "BuGn")+
  geom_point()+
  scale_x_continuous(breaks = seq(min(newdataAra$year), max(newdataAra$year), by = 1))+ 
  theme(axis.title.y = element_text(size = rel(1.8), angle = 90))+ 
  theme(axis.title.x = element_text(size = rel(1.8), angle = 0))+
  theme(axis.text.x = element_text(angle = 45,size=13,vjust = 0.2))+#vjust align the labels under the tick (in the center)+
  theme(axis.text.y = element_text(size = rel(1.5), angle = 45, margin = margin(t = 0, r = 10, b = 0, l = 0)))+
  theme(axis.text.x = element_text(size = rel(1.5), angle = 45, margin = margin(t = 5, r = 0, b = 0, l = 0)))+
  labs(y="# hunted rabbits",title="Aragon")+
  theme(legend.position = c(0.9,0.9),legend.text = element_text(size = 12),legend.title=element_blank())+
  theme(plot.margin = margin(t = 1, r = 1, b = 1, l = 1, unit = "cm"))
p2

# dev.off()

Balearic Islands

Baleares<- comunidad[comunidad$community=="Baleares",]

gam1bal <- gam(N ~ s(year, k=20) , data=Baleares, select=T, method="REML")
summary(gam1bal)# summary of results
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## N ~ s(year, k = 20)
## 
## Parametric coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   415756      11530   36.06   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Approximate significance of smooth terms:
##           edf Ref.df     F p-value    
## s(year) 15.53     19 47.34  <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## R-sq.(adj) =  0.959   Deviance explained = 97.6%
## -REML =  515.4  Scale est. = 5.1843e+09  n = 39
simgam2and<- simulateResiduals(gam1bal,plot=T)# OK

gam.check(gam1bal)# OK

## 
## Method: REML   Optimizer: outer newton
## full convergence after 7 iterations.
## Gradient range [-4.750783e-05,-6.061421e-06]
## (score 515.4009 & scale 5184330900).
## Hessian positive definite, eigenvalue range [4.751164e-05,22.6113].
## Model rank =  20 / 20 
## 
## Basis dimension (k) checking results. Low p-value (k-index<1) may
## indicate that k is too low, especially if edf is close to k'.
## 
##           k'  edf k-index p-value
## s(year) 19.0 15.5    1.42    0.98

Creating a new, toy dataframe to make predictions from the model and use them to visualize them.

newdataBal<- data.frame(year=sort(unique(Baleares$year)),N=Baleares[order(Baleares$year),]$N)
predizioniBal<- predict(gam1bal,newdataBal = newdataBal, type="terms",se=T)
newdataBal$predsgam1bal<- as.numeric(predizioniBal$fit)+gam1bal$coefficients[1]
newdataBal$predsgam1balse<- as.numeric(predizioniBal$se.fit)
newdataBal$RHD<- Baleares$RHD
newdataBal$RHD<- relevel(newdataBal$RHD,"no RHD")

Balearic Islands’ yearly numbers of hunted rabbits

This figure represents the GAM curve depicting the variation in the number of hunted rabbits between 1980 and 2018 before and after GI.1 and GI.2 outbreaks in Balearic Islands.

# png("Figure1bal.png",width=480*1.5)
p3<- ggplot(newdataBal, aes(x = year, y = N, fill=RHD))+
  geom_smooth(aes(ymin=predsgam1bal-1.96*predsgam1balse,ymax=predsgam1bal+1.96*predsgam1balse,fill= RHD),stat="identity",linetype=0)+
  scale_fill_brewer(palette = "BuGn")+
  geom_point()+
  scale_x_continuous(breaks = seq(min(newdataBal$year), max(newdataBal$year), by = 1))+ 
  theme(axis.title.y = element_text(size = rel(1.8), angle = 90))+ 
  theme(axis.title.x = element_text(size = rel(1.8), angle = 0))+
  theme(axis.text.x = element_text(angle = 45,size=13,vjust = 0.2))+#vjust align the labels under the tick (in the center)+
  theme(axis.text.y = element_text(size = rel(1.5), angle = 45, margin = margin(t = 0, r = 10, b = 0, l = 0)))+
  theme(axis.text.x = element_text(size = rel(1.5), angle = 45, margin = margin(t = 5, r = 0, b = 0, l = 0)))+
  labs(y="# hunted rabbits",title="Balearic Islands")+
  theme(legend.position = c(0.9,0.9),legend.text = element_text(size = 12),legend.title=element_blank())+
  theme(plot.margin = margin(t = 1, r = 1, b = 1, l = 1, unit = "cm"))
p3

# dev.off()

Basque Country

PaisVasco<- comunidad[comunidad$community=="PaisVasco",]
gam1pai <- gam(N ~ s(year, k=20) , data=PaisVasco, select=T, method="REML") 
summary(gam1pai)# summary of results
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## N ~ s(year, k = 20)
## 
## Parametric coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   4102.5      142.9   28.71   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Approximate significance of smooth terms:
##           edf Ref.df     F p-value    
## s(year) 8.172     19 6.837  <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## R-sq.(adj) =  0.774   Deviance explained = 82.2%
## -REML = 328.64  Scale est. = 7.9621e+05  n = 39
simgam2pai<- simulateResiduals(gam1pai,plot=T)# OK

gam.check(gam1pai)# OK

## 
## Method: REML   Optimizer: outer newton
## full convergence after 11 iterations.
## Gradient range [-8.361913e-05,4.423263e-05]
## (score 328.6437 & scale 796211.1).
## Hessian positive definite, eigenvalue range [0.3252916,19.76446].
## Model rank =  20 / 20 
## 
## Basis dimension (k) checking results. Low p-value (k-index<1) may
## indicate that k is too low, especially if edf is close to k'.
## 
##            k'   edf k-index p-value
## s(year) 19.00  8.17    1.07    0.66

Creating a new, toy dataframe to make predictions from the model and use them to visualize them.

newdataPai<- data.frame(year=sort(unique(PaisVasco$year)),N=PaisVasco[order(PaisVasco$year),]$N)
predizioniPai<- predict(gam1pai,newdataPai = newdataPai, type="terms",se=T)
newdataPai$predsgam1pai<- as.numeric(predizioniPai$fit)+gam1pai$coefficients[1]
newdataPai$predsgam1paise<- as.numeric(predizioniPai$se.fit)
newdataPai$RHD<- PaisVasco$RHD
newdataPai$RHD<- relevel(newdataPai$RHD,"no RHD")

Basque Country yearly numbers of hunted rabbits

This figure represents the GAM curve depicting the variation in the number of hunted rabbits between 1980 and 2018 before and after GI.1 and GI.2 outbreaks in Basque Country.

# png("Figure1pai.png",width=480*1.5)
p13<- ggplot(newdataPai, aes(x = year, y = N, fill=RHD))+
  geom_smooth(aes(ymin=predsgam1pai-1.96*predsgam1paise,ymax=predsgam1pai+1.96*predsgam1paise,fill= RHD),stat="identity",linetype=0)+
  scale_fill_brewer(palette = "BuGn")+
  geom_point()+
  scale_x_continuous(breaks = seq(min(newdataPai$year), max(newdataPai$year), by = 1))+ 
  theme(axis.title.y = element_text(size = rel(1.8), angle = 90))+ 
  theme(axis.title.x = element_text(size = rel(1.8), angle = 0))+
  theme(axis.text.x = element_text(angle = 45,size=13,vjust = 0.2))+#vjust align the labels under the tick (in the center)+
  theme(axis.text.y = element_text(size = rel(1.5), angle = 45, margin = margin(t = 0, r = 10, b = 0, l = 0)))+
  theme(axis.text.x = element_text(size = rel(1.5), angle = 45, margin = margin(t = 5, r = 0, b = 0, l = 0)))+
  labs(y="# hunted rabbits",title="Basque Country")+
  theme(legend.position = c(0.9,0.9),legend.text = element_text(size = 12),legend.title=element_blank())+
  theme(plot.margin = margin(t = 1, r = 1, b = 1, l = 1, unit = "cm"))
p13

# dev.off()

Castille La Mancha

CastillalaMancha<- comunidad[comunidad$community=="CastillalaMancha",]
CastillalaMancha<- CastillalaMancha[order(CastillalaMancha$year),]

gam1clm <- gam(N ~ s(year, k=20) , data=CastillalaMancha, select=T, method="REML")
summary(gam1clm)# summary of results
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## N ~ s(year, k = 20)
## 
## Parametric coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1484833      45925   32.33   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Approximate significance of smooth terms:
##           edf Ref.df     F p-value    
## s(year) 6.636     19 7.187  <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## R-sq.(adj) =  0.782   Deviance explained =   82%
## -REML =  544.5  Scale est. = 8.2254e+10  n = 39
simgam2and<- simulateResiduals(gam1clm,plot=T)# OK

gam.check(gam1clm)# OK

## 
## Method: REML   Optimizer: outer newton
## full convergence after 4 iterations.
## Gradient range [-1.045278e-05,5.132807e-05]
## (score 544.5039 & scale 82254084987).
## Hessian positive definite, eigenvalue range [8.165634e-06,19.59717].
## Model rank =  20 / 20 
## 
## Basis dimension (k) checking results. Low p-value (k-index<1) may
## indicate that k is too low, especially if edf is close to k'.
## 
##            k'   edf k-index p-value
## s(year) 19.00  6.64    0.85    0.16

Creating a new, toy dataframe to make predictions from the model and use them to visualize them.

newdataClm<- data.frame(year=sort(unique(CastillalaMancha$year)),N=CastillalaMancha[order(CastillalaMancha$year),]$N)
predizioniClm<- predict(gam1clm,newdataClm = newdataClm, type="terms",se=T)
newdataClm$predsgam1clm<- as.numeric(predizioniClm$fit)+gam1clm$coefficients[1]
newdataClm$predsgam1clmse<- as.numeric(predizioniClm$se.fit)
newdataClm$RHD<- CastillalaMancha$RHD
newdataClm$RHD<- relevel(newdataClm$RHD,"no RHD")

Castille La Mancha yearly numbers of hunted rabbits

This figure represents the GAM curve depicting the variation in the number of hunted rabbits between 1980 and 2018 before and after GI.1 and GI.2 outbreaks in Castille La Mancha.

# png("Figure1clm.png",width=480*1.5)
p4<- ggplot(newdataClm, aes(x = year, y = N, fill=RHD))+
  geom_smooth(aes(ymin=predsgam1clm-1.96*predsgam1clmse,ymax=predsgam1clm+1.96*predsgam1clmse,fill= RHD),stat="identity",linetype=0)+
  scale_fill_brewer(palette = "BuGn")+
  geom_point()+
  scale_x_continuous(breaks = seq(min(newdataClm$year), max(newdataClm$year), by = 1))+ 
  theme(axis.title.y = element_text(size = rel(1.8), angle = 90))+ 
  theme(axis.title.x = element_text(size = rel(1.8), angle = 0))+
  theme(axis.text.x = element_text(angle = 45,size=13,vjust = 0.2))+#vjust align the labels under the tick (in the center)+
  theme(axis.text.y = element_text(size = rel(1.5), angle = 45, margin = margin(t = 0, r = 10, b = 0, l = 0)))+
  theme(axis.text.x = element_text(size = rel(1.5), angle = 45, margin = margin(t = 5, r = 0, b = 0, l = 0)))+
  labs(y="# hunted rabbits",title="Castille La Mancha")+
  theme(legend.position = c(0.9,0.9),legend.text = element_text(size = 12),legend.title=element_blank())+
  theme(plot.margin = margin(t = 1, r = 1, b = 1, l = 1, unit = "cm"))
p4

# dev.off()

Castille and Leon

CastillayLeon<- comunidad[comunidad$community=="CastillayLeon",]
CastillayLeon<- CastillayLeon[order(CastillayLeon$year),]
gam1cyl <- gam(N ~ s(year, k=20) , data=CastillayLeon, select=T, method="REML")
summary(gam1cyl)# summary of results
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## N ~ s(year, k = 20)
## 
## Parametric coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   276847      10156   27.26   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Approximate significance of smooth terms:
##           edf Ref.df     F p-value    
## s(year) 5.694     19 11.14  <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## R-sq.(adj) =  0.848   Deviance explained = 87.1%
## -REML = 485.37  Scale est. = 4.0227e+09  n = 39
simgam2and<- simulateResiduals(gam1cyl,plot=T)# OK

gam.check(gam1cyl)# OK

## 
## Method: REML   Optimizer: outer newton
## full convergence after 9 iterations.
## Gradient range [-6.364965e-06,4.789114e-06]
## (score 485.3667 & scale 4022744860).
## Hessian positive definite, eigenvalue range [0.1925016,19.3626].
## Model rank =  20 / 20 
## 
## Basis dimension (k) checking results. Low p-value (k-index<1) may
## indicate that k is too low, especially if edf is close to k'.
## 
##            k'   edf k-index p-value
## s(year) 19.00  5.69    1.02    0.44

Creating a new, toy dataframe to make predictions from the model and use them to visualize them.

newdataCyl<- data.frame(year=sort(unique(CastillayLeon$year)),N=CastillayLeon[order(CastillayLeon$year),]$N)
predizioniCyl<- predict(gam1cyl,newdataCyl = newdataCyl, type="terms",se=T)
newdataCyl$predsgam1cyl<- as.numeric(predizioniCyl$fit)+gam1cyl$coefficients[1]
newdataCyl$predsgam1cylse<- as.numeric(predizioniCyl$se.fit)
newdataCyl$RHD<- CastillayLeon$RHD
newdataCyl$RHD<- relevel(newdataCyl$RHD,"no RHD")

Castille and Leon yearly numbers of hunted rabbits

This figure represents the GAM curve depicting the variation in the number of hunted rabbits between 1980 and 2018 before and after GI.1 and GI.2 outbreaks in Castille and Leon.

# png("Figure1cyl.png",width=480*1.5)
p5<- ggplot(newdataCyl, aes(x = year, y = N, fill=RHD))+
  geom_smooth(aes(ymin=predsgam1cyl-1.96*predsgam1cylse,ymax=predsgam1cyl+1.96*predsgam1cylse,fill= RHD),stat="identity",linetype=0)+
  scale_fill_brewer(palette = "BuGn")+
  geom_point()+
  scale_x_continuous(breaks = seq(min(newdataCyl$year), max(newdataCyl$year), by = 1))+ 
  theme(axis.title.y = element_text(size = rel(1.8), angle = 90))+ 
  theme(axis.title.x = element_text(size = rel(1.8), angle = 0))+
  theme(axis.text.x = element_text(angle = 45,size=13,vjust = 0.2))+#vjust align the labels under the tick (in the center)+
  theme(axis.text.y = element_text(size = rel(1.5), angle = 45, margin = margin(t = 0, r = 10, b = 0, l = 0)))+
  theme(axis.text.x = element_text(size = rel(1.5), angle = 45, margin = margin(t = 5, r = 0, b = 0, l = 0)))+
  labs(y="# hunted rabbits",title="Castille and Leon")+
  theme(legend.position = c(0.9,0.9),legend.text = element_text(size = 12),legend.title=element_blank())+
  theme(plot.margin = margin(t = 1, r = 1, b = 1, l = 1, unit = "cm"))
p5

# dev.off()

Catalonia

Temporal pattern of ynHR in Cataluna.

Cataluna<- comunidad[comunidad$community=="Cataluna",]
gam1cat <- gam(N ~ s(year, k=20) , data=Cataluna, select=T, method="REML")
summary(gam1cat)# summary of results
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## N ~ s(year, k = 20)
## 
## Parametric coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   189551       3214   58.98   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Approximate significance of smooth terms:
##           edf Ref.df     F p-value    
## s(year) 3.923     19 3.652  <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## R-sq.(adj) =  0.646   Deviance explained = 68.3%
## -REML = 438.14  Scale est. = 4.028e+08  n = 39
simgam2and<- simulateResiduals(gam1cat,plot=T)# OK

gam.check(gam1cat)# OK

## 
## Method: REML   Optimizer: outer newton
## full convergence after 4 iterations.
## Gradient range [-0.0001422475,0.0001665832]
## (score 438.1402 & scale 402797146).
## Hessian positive definite, eigenvalue range [0.0001279724,19.21014].
## Model rank =  20 / 20 
## 
## Basis dimension (k) checking results. Low p-value (k-index<1) may
## indicate that k is too low, especially if edf is close to k'.
## 
##            k'   edf k-index p-value
## s(year) 19.00  3.92    0.92    0.22

Creating a new, toy dataframe to make predictions from the model and use them to visualize them.

newdataCat<- data.frame(year=sort(unique(Cataluna$year)),N=Cataluna[order(Cataluna$year),]$N)
predizioniCat<- predict(gam1cat,newdataCat = newdataCat, type="terms",se=T)
newdataCat$predsgam1cat<- as.numeric(predizioniCat$fit)+gam1cat$coefficients[1]
newdataCat$predsgam1catse<- as.numeric(predizioniCat$se.fit)
newdataCat$RHD<- Cataluna$RHD
newdataCat$RHD<- relevel(newdataCat$RHD,"no RHD")

Catalonia yearly numbers of hunted rabbits

This figure represents the GAM curve depicting the variation in the number of hunted rabbits between 1980 and 2018 before and after GI.1 and GI.2 outbreaks in Catalonia.

# png("Figure1cat.png",width=480*1.5)
p6<- ggplot(newdataCat, aes(x = year, y = N, fill=RHD))+
  geom_smooth(aes(ymin=predsgam1cat-1.96*predsgam1catse,ymax=predsgam1cat+1.96*predsgam1catse,fill= RHD),stat="identity",linetype=0)+
  scale_fill_brewer(palette = "BuGn")+
  geom_point()+
  scale_x_continuous(breaks = seq(min(newdataCat$year), max(newdataCat$year), by = 1))+ 
  theme(axis.title.y = element_text(size = rel(1.8), angle = 90))+ 
  theme(axis.title.x = element_text(size = rel(1.8), angle = 0))+
  theme(axis.text.x = element_text(angle = 45,size=13,vjust = 0.2))+#vjust align the labels under the tick (in the center)+
  theme(axis.text.y = element_text(size = rel(1.5), angle = 45, margin = margin(t = 0, r = 10, b = 0, l = 0)))+
  theme(axis.text.x = element_text(size = rel(1.5), angle = 45, margin = margin(t = 5, r = 0, b = 0, l = 0)))+
  labs(y="# hunted rabbits",title="Catalonia")+
  theme(legend.position = c(0.9,0.9),legend.text = element_text(size = 12),legend.title=element_blank())+
  theme(plot.margin = margin(t = 1, r = 1, b = 1, l = 1, unit = "cm"))
p6

# dev.off()

Extremadura

Extremadura<- comunidad[comunidad$community=="Extremadura",]
gam1ext <- gam(N ~ s(year, k=20) , data=Extremadura, select=T, method="REML") 
summary(gam1ext)# summary of results
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## N ~ s(year, k = 20)
## 
## Parametric coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   416371      24435   17.04   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Approximate significance of smooth terms:
##           edf Ref.df     F p-value    
## s(year) 4.496     19 4.595  <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## R-sq.(adj) =  0.697   Deviance explained = 73.3%
## -REML = 516.32  Scale est. = 2.3286e+10  n = 39
simgam2and<- simulateResiduals(gam1ext,plot=T)# OK

gam.check(gam1ext)# OK

## 
## Method: REML   Optimizer: outer newton
## full convergence after 4 iterations.
## Gradient range [-0.0001309699,8.130931e-05]
## (score 516.3195 & scale 23286293815).
## Hessian positive definite, eigenvalue range [0.0001309406,19.27776].
## Model rank =  20 / 20 
## 
## Basis dimension (k) checking results. Low p-value (k-index<1) may
## indicate that k is too low, especially if edf is close to k'.
## 
##           k'  edf k-index p-value
## s(year) 19.0  4.5    1.06    0.61

Creating a new, toy dataframe to make predictions from the model and use them to visualize them.

newdataExt<- data.frame(year=sort(unique(Extremadura$year)),N=Extremadura[order(Extremadura$year),]$N)
predizioniExt<- predict(gam1ext,newdataExt = newdataExt, type="terms",se=T)
newdataExt$predsgam1ext<- as.numeric(predizioniExt$fit)+gam1ext$coefficients[1]
newdataExt$predsgam1extse<- as.numeric(predizioniExt$se.fit)
newdataExt$RHD<- Extremadura$RHD
newdataExt$RHD<- relevel(newdataExt$RHD,"no RHD")

Extremadura yearly numbers of hunted rabbits

This figure represents the GAM curve depicting the variation in the number of hunted rabbits between 1980 and 2018 before and after GI.1 and GI.2 outbreaks in Extremadura.

# png("Figure1ext.png",width=480*1.5)
p9<- ggplot(newdataExt, aes(x = year, y = N, fill=RHD))+
  geom_smooth(aes(ymin=predsgam1ext-1.96*predsgam1extse,ymax=predsgam1ext+1.96*predsgam1extse,fill= RHD),stat="identity",linetype=0)+
  scale_fill_brewer(palette = "BuGn")+
  geom_point()+
  scale_x_continuous(breaks = seq(min(newdataExt$year), max(newdataExt$year), by = 1))+ 
  theme(axis.title.y = element_text(size = rel(1.8), angle = 90))+ 
  theme(axis.title.x = element_text(size = rel(1.8), angle = 0))+
  theme(axis.text.x = element_text(angle = 45,size=13,vjust = 0.2))+#vjust align the labels under the tick (in the center)+
  theme(axis.text.y = element_text(size = rel(1.5), angle = 45, margin = margin(t = 0, r = 10, b = 0, l = 0)))+
  theme(axis.text.x = element_text(size = rel(1.5), angle = 45, margin = margin(t = 5, r = 0, b = 0, l = 0)))+
  labs(y="# hunted rabbits",title="Extremadura")+
  theme(legend.position = c(0.9,0.9),legend.text = element_text(size = 12),legend.title=element_blank())+
  theme(plot.margin = margin(t = 1, r = 1, b = 1, l = 1, unit = "cm"))
p9

Galicia

Galicia<- comunidad[comunidad$community=="Galicia",]

gam1gal <- gam(N ~ s(year, k=20) , data=Galicia, select=T, method="REML") 
summary(gam1gal)# summary of results
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## N ~ s(year, k = 20)
## 
## Parametric coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   144480       5240   27.57   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Approximate significance of smooth terms:
##           edf Ref.df     F p-value    
## s(year) 2.863     19 5.892  <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## R-sq.(adj) =  0.747   Deviance explained = 76.6%
## -REML = 454.73  Scale est. = 1.0708e+09  n = 39
simgam2and<- simulateResiduals(gam1gal,plot=T)# OK

gam.check(gam1gal)# OK

## 
## Method: REML   Optimizer: outer newton
## full convergence after 4 iterations.
## Gradient range [-0.0003050271,0.0002228541]
## (score 454.7262 & scale 1070779005).
## Hessian positive definite, eigenvalue range [2.951103e-05,19.1133].
## Model rank =  20 / 20 
## 
## Basis dimension (k) checking results. Low p-value (k-index<1) may
## indicate that k is too low, especially if edf is close to k'.
## 
##            k'   edf k-index p-value
## s(year) 19.00  2.86    1.13    0.73

Creating a new, toy dataframe to make predictions from the model and use them to visualize them.

newdataGal<- data.frame(year=sort(unique(Galicia$year)),N=Galicia[order(Galicia$year),]$N)
predizioniGal<- predict(gam1gal,newdataGal = newdataGal, type="terms",se=T)
newdataGal$predsgam1gal<- as.numeric(predizioniGal$fit)+gam1gal$coefficients[1]
newdataGal$predsgam1galse<- as.numeric(predizioniGal$se.fit)
newdataGal$RHD<- Galicia$RHD
newdataGal$RHD<- relevel(newdataGal$RHD,"no RHD")

Galicia yearly numbers of hunted rabbits

This figure represents the GAM curve depicting the variation in the number of hunted rabbits between 1980 and 2018 before and after GI.1 and GI.2 outbreaks in Galicia.

# png("Figure1gal.png",width=480*1.5)
p10<- ggplot(newdataGal, aes(x = year, y = N, fill=RHD))+
  geom_smooth(aes(ymin=predsgam1gal-1.96*predsgam1galse,ymax=predsgam1gal+1.96*predsgam1galse,fill= RHD),stat="identity",linetype=0,size=15)+
  scale_fill_brewer(palette = "BuGn")+
  geom_point()+
  scale_x_continuous(breaks = seq(min(newdataGal$year), max(newdataGal$year), by = 1))+ 
  theme(axis.title.y = element_text(size = rel(1.8), angle = 90))+ 
  theme(axis.title.x = element_text(size = rel(1.8), angle = 0))+
  theme(axis.text.x = element_text(angle = 45,size=13,vjust = 0.2))+#vjust align the labels under the tick (in the center)+
  theme(axis.text.y = element_text(size = rel(1.5), angle = 45, margin = margin(t = 0, r = 10, b = 0, l = 0)))+
  theme(axis.text.x = element_text(size = rel(1.5), angle = 45, margin = margin(t = 5, r = 0, b = 0, l = 0)))+
  labs(y="# hunted rabbits",title="Galicia")+
  theme(legend.position = c(0.9,0.9),legend.text = element_text(size = 12),legend.title=element_blank())+
  theme(plot.margin = margin(t = 1, r = 1, b = 1, l = 1, unit = "cm"))
p10

# dev.off()

La Rioja

LaRioja<- comunidad[comunidad$community=="LaRioja",]

gam1lar <- gam(N ~ s(year, k=20) , data=LaRioja, select=T, method="REML") 
summary(gam1lar)# summary of results
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## N ~ s(year, k = 20)
## 
## Parametric coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    54235       1619   33.51   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Approximate significance of smooth terms:
##           edf Ref.df     F p-value    
## s(year) 12.21     19 28.66  <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## R-sq.(adj) =  0.935   Deviance explained = 95.6%
## -REML =  429.8  Scale est. = 1.0218e+08  n = 39
simgam2and<- simulateResiduals(gam1lar,plot=T)# problems

gam.check(gam1lar)# problems

## 
## Method: REML   Optimizer: outer newton
## full convergence after 8 iterations.
## Gradient range [-1.147485e-06,-1.032252e-07]
## (score 429.7967 & scale 102180507).
## Hessian positive definite, eigenvalue range [8.29943e-07,21.20956].
## Model rank =  20 / 20 
## 
## Basis dimension (k) checking results. Low p-value (k-index<1) may
## indicate that k is too low, especially if edf is close to k'.
## 
##           k'  edf k-index p-value
## s(year) 19.0 12.2    1.38    0.98

Creating a new, toy dataframe to make predictions from the model and use them to visualize them.

newdataLar<- data.frame(year=sort(unique(LaRioja$year)),N=LaRioja[order(LaRioja$year),]$N)# there is no data for 2004! do not care about the warning message!
predizioniLar<- predict(gam1lar,newdataLar = newdataLar, type="terms",se=T)
newdataLar$predsgam1lar<- as.numeric(predizioniLar$fit)+gam1lar$coefficients[1]
newdataLar$predsgam1larse<- as.numeric(predizioniLar$se.fit)
newdataLar$RHD<- LaRioja$RHD
newdataLar$RHD<- relevel(newdataLar$RHD,"no RHD")

La Rioja yearly numbers of hunted rabbits

This figure represents the GAM curve depicting the variation in the number of hunted rabbits between 1980 and 2018 before and after GI.1 and GI.2 outbreaks in La Rioja.

# png("Figure1lar.png",width=480*1.5)
p11<- ggplot(newdataLar, aes(x = year, y = N, fill=RHD))+
  geom_smooth(aes(ymin=predsgam1lar-1.96*predsgam1larse,ymax=predsgam1lar+1.96*predsgam1larse,fill= RHD),stat="identity",linetype=0)+
  scale_fill_brewer(palette = "BuGn")+
  geom_point()+
  scale_x_continuous(breaks = seq(min(newdataLar$year), max(newdataLar$year), by = 1))+ 
  theme(axis.title.y = element_text(size = rel(1.8), angle = 90))+ 
  theme(axis.title.x = element_text(size = rel(1.8), angle = 0))+
  theme(axis.text.x = element_text(angle = 45,size=13,vjust = 0.2))+#vjust align the labels under the tick (in the center)+
  theme(axis.text.y = element_text(size = rel(1.5), angle = 45, margin = margin(t = 0, r = 10, b = 0, l = 0)))+
  theme(axis.text.x = element_text(size = rel(1.5), angle = 45, margin = margin(t = 5, r = 0, b = 0, l = 0)))+
  labs(y="# hunted rabbits",title="La Rioja")+
  theme(legend.position = c(0.9,0.9),legend.text = element_text(size = 12),legend.title=element_blank())+
  theme(plot.margin = margin(t = 1, r = 1, b = 1, l = 1, unit = "cm"))
p11

dev.off()
## null device 
##           1

Madrid

Madrid<- comunidad[comunidad$community=="Madrid",]
gam1mad <- gam(N ~ s(year, k=20) , data=Madrid, select=T, method="REML") 
summary(gam1mad)# summary of results
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## N ~ s(year, k = 20)
## 
## Parametric coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   356754       5424   65.77   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Approximate significance of smooth terms:
##           edf Ref.df     F p-value    
## s(year) 13.55     19 23.87  <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## R-sq.(adj) =  0.923   Deviance explained =   95%
## -REML = 479.51  Scale est. = 1.1474e+09  n = 39
simgam2and<- simulateResiduals(gam1mad,plot=T)# OK

gam.check(gam1mad)# OK

## 
## Method: REML   Optimizer: outer newton
## full convergence after 6 iterations.
## Gradient range [-4.928378e-05,-4.231532e-06]
## (score 479.5116 & scale 1147446061).
## Hessian positive definite, eigenvalue range [4.927972e-05,21.62304].
## Model rank =  20 / 20 
## 
## Basis dimension (k) checking results. Low p-value (k-index<1) may
## indicate that k is too low, especially if edf is close to k'.
## 
##           k'  edf k-index p-value
## s(year) 19.0 13.5    1.35    0.97

Creating a new, toy dataframe to make predictions from the model and use them to visualize them.

newdataMad<- data.frame(year=sort(unique(Madrid$year)),N=Madrid[order(Madrid$year),]$N)# there is no data for 2004! do not care about the warning message!
predizioniMad<- predict(gam1mad,newdataMad = newdataMad, type="terms",se=T)
newdataMad$predsgam1mad<- as.numeric(predizioniMad$fit)+gam1mad$coefficients[1]
newdataMad$predsgam1madse<- as.numeric(predizioniMad$se.fit)
newdataMad$RHD<- Madrid$RHD
newdataMad$RHD<- relevel(newdataMad$RHD,"no RHD")

Madrid yearly numbers of hunted rabbits

This figure represents the GAM curve depicting the variation in the number of hunted rabbits between 1980 and 2018 before and after GI.1 and GI.2 outbreaks in Madrid.

# png("Figure1mad.png",width=480*1.5)
p7<- ggplot(newdataMad, aes(x = year, y = N, fill=RHD))+
  geom_smooth(aes(ymin=predsgam1mad-1.96*predsgam1madse,ymax=predsgam1mad+1.96*predsgam1madse,fill= RHD),stat="identity",linetype=0,size=15)+
  scale_fill_brewer(palette = "BuGn")+
  geom_point()+
  scale_x_continuous(breaks = seq(min(newdataMad$year), max(newdataMad$year), by = 1))+ 
  theme(axis.title.y = element_text(size = rel(1.8), angle = 90))+ 
  theme(axis.title.x = element_text(size = rel(1.8), angle = 0))+
  theme(axis.text.x = element_text(angle = 45,size=13,vjust = 0.2))+#vjust align the labels under the tick (in the center)+
  theme(axis.text.y = element_text(size = rel(1.5), angle = 45, margin = margin(t = 0, r = 10, b = 0, l = 0)))+
  theme(axis.text.x = element_text(size = rel(1.5), angle = 45, margin = margin(t = 5, r = 0, b = 0, l = 0)))+
  labs(y="# hunted rabbits",title="Madrid")+
  theme(legend.position = c(0.9,0.9),legend.text = element_text(size = 12),legend.title=element_blank())+
  theme(plot.margin = margin(t = 1, r = 1, b = 1, l = 1, unit = "cm"))
p7

# dev.off()

Valencian Community

Valencia<- comunidad[comunidad$community=="C.Valenciana",]
gam1val <- gam(N ~ s(year, k=20) , data=Valencia, select=T, method="REML") 
summary(gam1val)# summary of results
## 
## Family: gaussian 
## Link function: identity 
## 
## Formula:
## N ~ s(year, k = 20)
## 
## Parametric coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   271192       5956   45.53   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Approximate significance of smooth terms:
##           edf Ref.df    F p-value    
## s(year) 3.368     19 7.75  <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## R-sq.(adj) =  0.795   Deviance explained = 81.3%
## -REML = 461.12  Scale est. = 1.3836e+09  n = 39
simgam2and<- simulateResiduals(gam1val,plot=T)# OK

gam.check(gam1val)# OK

## 
## Method: REML   Optimizer: outer newton
## full convergence after 9 iterations.
## Gradient range [-1.383943e-06,-1.067039e-07]
## (score 461.118 & scale 1383559590).
## Hessian positive definite, eigenvalue range [0.3645777,19.09443].
## Model rank =  20 / 20 
## 
## Basis dimension (k) checking results. Low p-value (k-index<1) may
## indicate that k is too low, especially if edf is close to k'.
## 
##            k'   edf k-index p-value
## s(year) 19.00  3.37    0.99     0.4

Creating a new, toy dataframe to make predictions from the model and use them to visualize them.

newdataVal<- data.frame(year=sort(unique(Valencia$year)),N=Valencia[order(Valencia$year),]$N)
predizioniVal<- predict(gam1val,newdataVal = newdataVal, type="terms",se=T)
newdataVal$predsgam1val<- as.numeric(predizioniVal$fit)+gam1val$coefficients[1]
newdataVal$predsgam1valse<- as.numeric(predizioniVal$se.fit)
newdataVal$RHD<- Valencia$RHD
newdataVal$RHD<- relevel(newdataVal$RHD,"no RHD")

Valencian Community yearly numbers of hunted rabbits

This figure represents the GAM curve depicting the variation in the number of hunted rabbits between 1980 and 2018 before and after GI.1 and GI.2 outbreaks in Valencian Community.

# png("Figure1val.png",width=480*1.5)
p8<- ggplot(newdataVal, aes(x = year, y = N, fill=RHD))+
  geom_smooth(aes(ymin=predsgam1val-1.96*predsgam1valse,ymax=predsgam1val+1.96*predsgam1valse,fill= RHD),stat="identity",linetype=0)+
  scale_fill_brewer(palette = "BuGn")+
  geom_point()+
  scale_x_continuous(breaks = seq(min(newdataVal$year), max(newdataVal$year), by = 1))+ 
  theme(axis.title.y = element_text(size = rel(1.8), angle = 90))+ 
  theme(axis.title.x = element_text(size = rel(1.8), angle = 0))+
  theme(axis.text.x = element_text(angle = 45,size=13,vjust = 0.2))+#vjust align the labels under the tick (in the center)+
  theme(axis.text.y = element_text(size = rel(1.5), angle = 45, margin = margin(t = 0, r = 10, b = 0, l = 0)))+
  theme(axis.text.x = element_text(size = rel(1.5), angle = 45, margin = margin(t = 5, r = 0, b = 0, l = 0)))+
  labs(y="# hunted rabbits",title="Valencian Community")+
  theme(legend.position = c(0.9,0.9),legend.text = element_text(size = 12),legend.title=element_blank())+
  theme(plot.margin = margin(t = 1, r = 1, b = 1, l = 1, unit = "cm"))
p8

# dev.off()