data & packages

df = readRDS("ecd_obs_agathe.RDS") 
df <- df[!is.na(df$obs_ts),] 
df[is.na(df)] <- 0
library('mgcv')
## Loading required package: nlme
## This is mgcv 1.8-34. For overview type 'help("mgcv-package")'.
library('mgcViz')
## Loading required package: qgam
## Loading required package: ggplot2
## Loading required package: rgl
## This build of rgl does not include OpenGL functions.  Use
##  rglwidget() to display results, e.g. via options(rgl.printRglwidget = TRUE).
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
## Registered S3 method overwritten by 'mgcViz':
##   method from  
##   +.gg   GGally
## 
## Attaching package: 'mgcViz'
## The following objects are masked from 'package:stats':
## 
##     qqline, qqnorm, qqplot
library('ggpubr')
## Registered S3 methods overwritten by 'car':
##   method                          from
##   influence.merMod                lme4
##   cooks.distance.influence.merMod lme4
##   dfbeta.influence.merMod         lme4
##   dfbetas.influence.merMod        lme4

Species to consider + Stratification+ Legende+ Distribution

espece<-c("num_Other_bony_fishes","num_Silky_shark","num_Common_dolphinfish")

df$num_Other_bony_fishes=df$`num_Other bony fishes`
df$num_Common_dolphinfish=df$`num_Common dolphinfish`
df$num_Silky_shark=df$`num_Silky shark`

log transformation

df$num_Other_bony_fishes=log(df$num_Other_bony_fishes+1)
df$num_Silky_shark=log(df$num_Silky_shark+1)
df$num_Common_dolphinfish=log(df$num_Common_dolphinfish+1)
df$capture_total_target_tunas_corrigee=log(df$capture_total_target_tunas_corrigee+0.001)

Stratification & legende & distribution

df$group = paste0("O",df$ocean,"G",df$code_assoc_groupe) 
# Création d'une variable groupe 
# O1G1, O1G2, O2G1, O2G2
# O1: Atlantique 02: Indien
# G1: Floating object G2: Free swiming school 
## Par océan et banc 
df1<-df[df$group =="O1G1",] 
# df1 contient tous les calais qui sont sont O1G1
df2<-df[df$group =="O1G2",]
# df2 contient tous les calais qui sont O1G2
df3<-df[df$group =="O2G1",]
# df3 contient tous les calais qui sont O2G1
df4<-df[df$group =="O2G2",]
# df4 contient tous les calais qui sont O2G2

# légende -----------------------------------------------

strat<-c("O1G1","O1G2","O2G1","O2G2")
data_list<-list(O1G1=df1,O1G2=df2,O2G1=df3,O2G2=df4)

# Distribution----------------------------------------
famille<-"gaussian"

Results GAM

res_gamcapture<-list()
for (i in 1:length(espece)){
for (j in 1:length(data_list)){
data <- data_list[[j]]
form <- formula(paste(espece[i],"s(capture_total_target_tunas_corrigee,k=10)", sep="~"))
gam <- gam(form, data=data)
gr=strat[j]
sp=gsub("^num_","",espece[i])
fn=paste(gr,sp,sep=".")
res_gamcapture[[paste(gr,sp,sep=".")]] = list(sp=sp,gr=gr,fn=fn,gam=gam)
}
}

GAM for Atlantic ocean , Floating object

gam_O1G1<-list(res_gamcapture$O1G1.Other_bony_fishes,res_gamcapture$O1G1.Silky_shark,res_gamcapture$O1G1.Common_dolphinfish)

for (v in gam_O1G1){

  #Diagnostic
  par(mfrow=c(2,2))
  gam.check(v$gam)
  
  # plot gam 
  o <- getViz(v$gam)
  plot <- plot(o) + l_fitLine(colour = "red") + l_rug(mapping = aes(x=x, y=y), alpha = 0.8) + 
    l_ciLine(mul = 5, colour = "blue", linetype = 2) + 
    l_points(shape = 19, size = 1, alpha = 0.1) + theme_classic()+ 
    ggtitle(v$fn)+
    ylab(v$esp)+
    xlab("capture total target tunas corrigee (weight in tonnes)")
  print(plot)
}

## 
## Method: GCV   Optimizer: magic
## Smoothing parameter selection converged after 7 iterations.
## The RMS GCV score gradient at convergence was 1.736867e-07 .
## The Hessian was positive definite.
## Model rank =  10 / 10 
## 
## 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(capture_total_target_tunas_corrigee) 9.00 6.22    0.92  <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

## 
## Method: GCV   Optimizer: magic
## Smoothing parameter selection converged after 4 iterations.
## The RMS GCV score gradient at convergence was 1.33085e-07 .
## The Hessian was positive definite.
## Model rank =  10 / 10 
## 
## 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(capture_total_target_tunas_corrigee) 9.00 3.85       1    0.38

## 
## Method: GCV   Optimizer: magic
## Smoothing parameter selection converged after 4 iterations.
## The RMS GCV score gradient at convergence was 6.352695e-06 .
## The Hessian was positive definite.
## Model rank =  10 / 10 
## 
## 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(capture_total_target_tunas_corrigee) 9.00 2.17    0.95   0.005 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

GAM for Atlantic ocean, free school

gam_O1G2<-list(res_gamcapture$O1G2.Other_bony_fishes,res_gamcapture$O1G2.Silky_shark,res_gamcapture$O1G2.Common_dolphinfish)

for (v in gam_O1G2){

  #Diagnostic
  par(mfrow=c(2,2))
  gam.check(v$gam)
  
  # plot gam 
  o <- getViz(v$gam)
  plot <- plot(o) + l_fitLine(colour = "red") + l_rug(mapping = aes(x=x, y=y), alpha = 0.8) + 
    l_ciLine(mul = 5, colour = "blue", linetype = 2) + 
    l_points(shape = 19, size = 1, alpha = 0.1) + theme_classic()+ 
    ggtitle(v$fn)+
    ylab(v$esp)+
    xlab("capture total target tunas corrigee (weight in tonnes)")
  print(plot)
}

## 
## Method: GCV   Optimizer: magic
## Smoothing parameter selection converged after 8 iterations.
## The RMS GCV score gradient at convergence was 7.132046e-08 .
## The Hessian was positive definite.
## Model rank =  10 / 10 
## 
## 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(capture_total_target_tunas_corrigee)  9   1    1.01     0.8

## 
## Method: GCV   Optimizer: magic
## Smoothing parameter selection converged after 5 iterations.
## The RMS GCV score gradient at convergence was 2.884136e-06 .
## The Hessian was positive definite.
## Model rank =  10 / 10 
## 
## 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(capture_total_target_tunas_corrigee) 9.00 2.48    0.96   0.005 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

## 
## Method: GCV   Optimizer: magic
## Smoothing parameter selection converged after 5 iterations.
## The RMS GCV score gradient at convergence was 1.246303e-07 .
## The Hessian was positive definite.
## Model rank =  10 / 10 
## 
## 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(capture_total_target_tunas_corrigee)  9   1       1    0.43

GAM for Indian ocean, floating object

gam_O2G1<-list(res_gamcapture$O2G1.Other_bony_fishes,res_gamcapture$O2G1.Silky_shark,res_gamcapture$O2G1.Common_dolphinfish)

for (v in gam_O2G1){

  #Diagnostic
  par(mfrow=c(2,2))
  gam.check(v$gam)
  
  # plot gam 
  o <- getViz(v$gam)
  plot <- plot(o) + l_fitLine(colour = "red") + l_rug(mapping = aes(x=x, y=y), alpha = 0.8) + 
    l_ciLine(mul = 5, colour = "blue", linetype = 2) + 
    l_points(shape = 19, size = 1, alpha = 0.1) + theme_classic()+ 
    ggtitle(v$fn)
    #ylab(v$esp)+
    #xlab("capture total target tunas corrigee (weight in tonnes)")
  print(plot)
}

## 
## Method: GCV   Optimizer: magic
## Smoothing parameter selection converged after 7 iterations.
## The RMS GCV score gradient at convergence was 2.503706e-05 .
## The Hessian was positive definite.
## Model rank =  10 / 10 
## 
## 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(capture_total_target_tunas_corrigee) 9.00 5.38    0.93  <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

## 
## Method: GCV   Optimizer: magic
## Smoothing parameter selection converged after 5 iterations.
## The RMS GCV score gradient at convergence was 5.711209e-06 .
## The Hessian was positive definite.
## Model rank =  10 / 10 
## 
## 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(capture_total_target_tunas_corrigee) 9.00 5.09    0.93  <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

## 
## Method: GCV   Optimizer: magic
## Smoothing parameter selection converged after 4 iterations.
## The RMS GCV score gradient at convergence was 3.214313e-08 .
## The Hessian was positive definite.
## Model rank =  10 / 10 
## 
## 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(capture_total_target_tunas_corrigee) 9.00 4.41    0.96   0.005 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

GAM for Indian ocean, free school

gam_O2G2<-list(res_gamcapture$O2G2.Other_bony_fishes,res_gamcapture$O2G2.Silky_shark,res_gamcapture$O2G2.Common_dolphinfish)

for (v in gam_O2G2){

  #Diagnostic
  par(mfrow=c(2,2))
  gam.check(v$gam)
  
  # plot gam 
  o <- getViz(v$gam)
  plot <- plot(o) + l_fitLine(colour = "red") + l_rug(mapping = aes(x=x, y=y), alpha = 0.8) + 
    l_ciLine(mul = 5, colour = "blue", linetype = 2) + 
    l_points(shape = 19, size = 1, alpha = 0.1) + theme_classic()+ 
    ggtitle(v$fn)+
    ylab(v$esp)+
    xlab("capture total target tunas corrigee (weight in tonnes)")
  print(plot)
}

## 
## Method: GCV   Optimizer: magic
## Smoothing parameter selection converged after 4 iterations.
## The RMS GCV score gradient at convergence was 1.207353e-07 .
## The Hessian was positive definite.
## Model rank =  10 / 10 
## 
## 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(capture_total_target_tunas_corrigee) 9.00 3.93    1.01    0.44

## 
## Method: GCV   Optimizer: magic
## Smoothing parameter selection converged after 8 iterations.
## The RMS GCV score gradient at convergence was 6.280597e-08 .
## The Hessian was positive definite.
## Model rank =  10 / 10 
## 
## 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(capture_total_target_tunas_corrigee)  9   1    0.99    0.18

## 
## Method: GCV   Optimizer: magic
## Smoothing parameter selection converged after 4 iterations.
## The RMS GCV score gradient at convergence was 1.286937e-06 .
## The Hessian was positive definite.
## Model rank =  10 / 10 
## 
## 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(capture_total_target_tunas_corrigee)  9   1    0.96    0.07 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1