data & packages

df = readRDS("ecd_obs_agathe.RDS") 
df <- df[!is.na(df$obs_ts),] 
df[is.na(df)] <- 0
library('rsq')
library(ggfortify)
## Loading required package: ggplot2
library('AER')
## Loading required package: car
## Loading required package: carData
## Registered S3 methods overwritten by 'car':
##   method                          from
##   influence.merMod                lme4
##   cooks.distance.influence.merMod lme4
##   dfbeta.influence.merMod         lme4
##   dfbetas.influence.merMod        lme4
## Loading required package: lmtest
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: sandwich
## Loading required package: survival
require(MASS)
## Loading required package: MASS

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`


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)

Results regression

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

Pvalues & overdispersion

pvalues<-list()
for (v in res_regression){
    pvalue<-summary(reg)$coefficients["capture_total_target_tunas_corrigee","Pr(>|z|)"]
    b<-c(pvalue,rsq(v$reg))
    pvalues[[v$fn]]<-b
}
## Warning: glm.fit: algorithm did not converge
colnames<-c("Pvalue capture","R-square")
pvalues.table<-t(as.data.frame(pvalues))
colnames(pvalues.table)<-colnames
pvalues.table
##                         Pvalue capture      R-square
## O1G1.Other_bony_fishes       0.1563268  7.432016e-05
## O1G2.Other_bony_fishes       0.1563268  9.550596e-07
## O2G1.Other_bony_fishes       0.1563268  7.846190e-05
## O2G2.Other_bony_fishes       0.1563268  1.000000e+00
## O1G1.Silky_shark             0.1563268 -1.516963e+00
## O1G2.Silky_shark             0.1563268 -3.808534e+00
## O2G1.Silky_shark             0.1563268 -5.116880e-03
## O2G2.Silky_shark             0.1563268  3.553796e-07
## O1G1.Common_dolphinfish      0.1563268  9.203726e-06
## O1G2.Common_dolphinfish      0.1563268  4.788532e-08
## O2G1.Common_dolphinfish      0.1563268  3.518824e-04
## O2G2.Common_dolphinfish      0.1563268 -2.627226e-04

regression by fishing mode

ocean 1 = Atlantic

reg_byocean_O1G1<-list(res_regression$O1G1.Other_bony_fishes, res_regression$O1G1.Silky_shark,res_regression$O1G1.Common_dolphinfish)

reg_byocean_O1G2<-list(res_regression$O1G2.Other_bony_fishes, res_regression$O1G2.Silky_shark,res_regression$O1G2.Common_dolphinfish)

  for (i in 1:3){
  v=reg_byocean_O1G1[[i]]
  b1<-summary(v$reg)$coefficients[1]
  a1<-summary(v$reg)$coefficients[2]
  p=reg_byocean_O1G2[[i]]
  b2<-summary(p$reg)$coefficients[1]
  a2<-summary(p$reg)$coefficients[2]
  
  #diagnostique
  par(mfrow = c(2, 2))
  plot(v$reg) 
  #diagnostique
  par(mfrow = c(2, 2))
  plot(p$reg)
  
  
  data1et2<-rbind(df1,df2)
  data1et2$group <- as.factor(data1et2$group)
  
  plot<-ggplot(data1et2, aes(x=capture_total_target_tunas_corrigee,y=get(paste("num_",v$sp,sep = ""),data1et2)))+
    geom_abline(slope = a1,intercept = b1,color="#20B2AA")+
    geom_abline(slope = a2,intercept = b2,color="#FF7F50")+
    ggtitle("Regression by fishing mode, Atlantic ocean" )+
    geom_point(aes(colour=group))+
    ylab(v$sp)
  
  print(plot)
 
}

Ocean 2 = Indien

reg_byocean_O2G1<-list(res_regression$O2G1.Other_bony_fishes, res_regression$O2G1.Silky_shark,res_regression$O2G1.Common_dolphinfish)

reg_byocean_O2G2<-list(res_regression$O2G2.Other_bony_fishes, res_regression$O2G2.Silky_shark,res_regression$O2G2.Common_dolphinfish)

  for (i in 1:3){
  v=reg_byocean_O2G1[[i]]
  b1<-summary(v$reg)$coefficients[1]
  a1<-summary(v$reg)$coefficients[2]
  p=reg_byocean_O2G2[[i]]
  b2<-summary(p$reg)$coefficients[1]
  a2<-summary(p$reg)$coefficients[2]
  
  #diagnostique
  par(mfrow = c(2, 2))
  plot(v$reg) 
  
   #diagnostique
  par(mfrow = c(2, 2))
  plot(p$reg)
  
  data1et2<-rbind(df3,df4)
  data1et2$group <- as.factor(data1et2$group)
  
  plot<-ggplot(data1et2, aes(x=capture_total_target_tunas_corrigee,y=get(paste("num_",v$sp,sep = ""),data1et2)))+
    geom_abline(slope = a1,intercept = b1,color="#20B2AA")+
    geom_abline(slope = a2,intercept = b2,color="#FF7F50")+
    ggtitle("Regression by fishing mode, Indian ocean" )+
    geom_point(aes(colour=group))+
    ylab(v$sp)
  
  print(plot)
 
}

Regression by ocean

Fishing mode 1 : Floating object

reg_fishingmode_O1G1<-list(res_regression$O1G1.Other_bony_fishes, res_regression$O1G1.Silky_shark,res_regression$O1G1.Common_dolphinfish)

reg_fishingmode_O2G1<-list(res_regression$O2G1.Other_bony_fishes, res_regression$O2G1.Silky_shark,res_regression$O2G1.Common_dolphinfish)

  for (i in 1:3){
  v=reg_byocean_O1G1[[i]]
  b1<-summary(v$reg)$coefficients[1]
  a1<-summary(v$reg)$coefficients[2]
  p=reg_byocean_O2G1[[i]]
  b2<-summary(p$reg)$coefficients[1]
  a2<-summary(p$reg)$coefficients[2]
  
  #diagnostique
  par(mfrow = c(2, 2))
  plot(v$reg) 
  #diagnostique
  par(mfrow = c(2, 2))
  plot(p$reg)
  
  
  data1et2<-rbind(df1,df3)
  data1et2$group <- as.factor(data1et2$group)
  
  plot<-ggplot(data1et2, aes(x=capture_total_target_tunas_corrigee,y=get(paste("num_",v$sp,sep = ""),data1et2)))+
    geom_abline(slope = a1,intercept = b1,color="#20B2AA")+
    geom_abline(slope = a2,intercept = b2,color="#FF7F50")+
    ggtitle("Regression by ocean, Floating object fishing")+
    geom_point(aes(colour=group))+
    ylab(v$sp)
  
  print(plot)
 
}

fishing mode 2 : free school

reg_fishingmode_O1G2<-list(res_regression$O1G2.Other_bony_fishes, res_regression$O1G2.Silky_shark,res_regression$O1G2.Common_dolphinfish)

reg_fishingmode_O2G2<-list(res_regression$O2G2.Other_bony_fishes, res_regression$O2G2.Silky_shark,res_regression$O2G2.Common_dolphinfish)

  for (i in 1:3){
  v=reg_byocean_O1G2[[i]]
  b1<-summary(v$reg)$coefficients[1]
  a1<-summary(v$reg)$coefficients[2]
  p=reg_byocean_O2G2[[i]]
  b2<-summary(p$reg)$coefficients[1]
  a2<-summary(p$reg)$coefficients[2]
  
  #diagnostique
  par(mfrow = c(2, 2))
  plot(v$reg) 
  #diagnostique
  par(mfrow = c(2, 2))
  plot(p$reg)
  
  
  data1et2<-rbind(df2,df4)
  data1et2$group <- as.factor(data1et2$group)
  
  plot<-ggplot(data1et2, aes(x=capture_total_target_tunas_corrigee,y=get(paste("num_",v$sp,sep = ""),data1et2)))+
    geom_abline(slope = a1,intercept = b1,color="#20B2AA")+
    geom_abline(slope = a2,intercept = b2,color="#FF7F50")+
    ggtitle("Regression by ocean, free school fishing")+
    geom_point(aes(colour=group))+
    ylab(v$sp)
  
  print(plot)
 
}

# Regression by Ocean and fishing mode

reg_O1G1<-list(res_regression$O1G1.Other_bony_fishes, res_regression$O1G1.Silky_shark,res_regression$O1G1.Common_dolphinfish)
reg_O1G2<-list(res_regression$O1G2.Other_bony_fishes, res_regression$O1G2.Silky_shark,res_regression$O1G2.Common_dolphinfish)
reg_O2G1<-list(res_regression$O2G1.Other_bony_fishes, res_regression$O2G1.Silky_shark,res_regression$O2G1.Common_dolphinfish)
reg_O2G2<-list(res_regression$O2G2.Other_bony_fishes, res_regression$O2G2.Silky_shark,res_regression$O2G2.Common_dolphinfish)

  for (i in 1:3){
    v<-reg_O1G1[[i]]
  b1<-summary(v$reg)$coefficients[1]
  a1<-summary(v$reg)$coefficients[2] 
    p<-reg_O1G2[[i]]
  b2<-summary(p$reg)$coefficients[1]
  a2<-summary(p$reg)$coefficients[2] 
    x<-reg_O2G1[[i]]
  b3<-summary(x$reg)$coefficients[1]
  a3<-summary(x$reg)$coefficients[2] 
    z<-reg_O2G2[[i]]
  b4<-summary(z$reg)$coefficients[1]
  a4<-summary(z$reg)$coefficients[2] 
  
  #diagnostique
  par(mfrow = c(2,2))
  plot(v$reg) 
  par(mfrow = c(2,2))
  plot(p$reg) 
  par(mfrow = c(2,2))
  plot(x$reg) 
  par(mfrow = c(2,2))
  plot(z$reg) 
    
df$group <- as.factor(df$group)

print<-ggplot(df, aes(x=capture_total_target_tunas_corrigee, y=get(paste("num_",v$sp,sep = ""),df)))+
  geom_abline(slope = a1,intercept = b1,color="#20B2AA")+
  geom_abline(slope = a2,intercept = b2,color="#008000")+
  geom_abline(slope = a3,intercept = b3,color="#FF7F50")+
  geom_abline(slope = a4,intercept = b4,color="#c541c5")+
  ggtitle("Regression by ocean and fishing mode")+
  geom_point(aes(colour=group))+
  ylab(v$sp)

print(plot)
}