annotate FunctTrendSTOCGalaxy.r @ 1:fd0687e91bf6 draft default tip

"planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit d49a4da1ffac1f33a15fdb7ae98827d0034a7879"
author ecology
date Mon, 11 May 2020 17:44:48 -0400
parents 2e45ae3b297a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
1 #!/usr/bin/env Rscript
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
2
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
3
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
4 ##################################################################################################################################
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
5 ############## FUNCTION TO CALCULATE AND PLOT EVOLUTION OF SPECIES POPULATION function:main.glm ##############################
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
6 ##################################################################################################################################
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
7
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
8 #### Based on Romain Lorrillière R script
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
9 #### Modified by Alan Amosse and Benjamin Yguel for integrating within Galaxy-E
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
10
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
11 ##### workes with the R version 3.5.1 (2018-07-02)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
12 ##### Package used with the version:
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
13 #suppressMessages(library(lme4)) version 1.1.18.1
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
14 #suppressMessages(library(ggplot2)) version 3.0.0
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
15 #suppressMessages(library(speedglm)) version 0.3.2
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
16 #suppressMessages(library(arm)) version 1.10.1
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
17 #suppressMessages(library(reshape)) version 0.8.8
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
18 #suppressMessages(library(data.table)) version 1.12.0
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
19 #suppressMessages(library(reshape2)) version 1.4.3
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
20
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
21
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
22
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
23 ######################################### debut de la fonction makeTableAnalyse / stard of the function makeTableAnalyse
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
24 ## mise en colonne des especes et rajout de zero mais sur la base des carrés selectionné sans l'import / Species are placed in separated columns and addition of zero on plots where at least one selected species is present
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
25
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
26 makeTableAnalyse <- function(data) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
27 tab <- reshape(data
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
28 ,v.names="abond"
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
29 ,idvar=c("carre","annee")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
30 ,timevar="espece"
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
31 ,direction="wide")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
32 tab[is.na(tab)] <- 0 ###### remplace les na par des 0 / replace NAs by 0
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
33
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
34 colnames(tab) <- sub("abond.","",colnames(tab))### remplace le premier pattern "abond." par le second "" / replace the column names "abond." by ""
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
35 return(tab)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
36 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
37
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
38 ######################################### fin de la fonction makeTableAnalyse / end of the function makeTableAnalyse
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
39
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
40
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
41
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
42
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
43
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
44 ############################################# les fonctions qui filtrent les données pas suffisantes pour analyses fiables / The filtering functions removing species with not enough data to perform accurate analyses
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
45
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
46 filter_absent_species<-function(tab){
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
47 ##################### Filtre les espèces jamais présentes (abondance=0) / Filter of species with 0 abundance
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
48 ################################################################################# PARTIE POTENTIELLEMENT ISOLABLE ET INSERABLE AVANT LA BOUCLE = permet de gagner du temps sur la boucle car supprime sps pas vu, donc pas repris par la boucle
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
49
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
50 ## Fait la somme des abondances totales par espèce / calculate the sum of all abundance per species
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
51 if(ncol(tab)==3) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
52 tabSum <- sum(tab[,3])## cas d'une seule especes (problème de format et manip un peu differente) / when selecting only one species, use a different method
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
53 names(tabSum) <- colnames(tab)[3]
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
54 } else { ## cas de plusieurs espèce/ when selecting more than one species
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
55 tabSum <- colSums(tab[,-(1:2)])
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
56 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
57 ## colNull= espece(s) toujours absente /species with 0 total abundance
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
58 colNull <- names(which(tabSum==0))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
59 ## colconserve= espece(s) au moins presente 1 fois/ species at least with 1 presence
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
60 colConserve <- names(which(tabSum>0))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
61 ## Affichage des espèces rejetees / show species eliminated for the analyses
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
62 if(length(colNull)>0){
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
63 cat("\n",length(colNull)," Species removed from the analysis, abundance is always 0.\n\n",sep="") #Espèces enlevées de l'analyse car abondance toujours égale a 0\n\n",sep="")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
64 #tabNull <- data.frame(Code_espece = colNull, nom_espece = tabsp[colNull,"nom"])
1
fd0687e91bf6 "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit d49a4da1ffac1f33a15fdb7ae98827d0034a7879"
ecology
parents: 0
diff changeset
65 cat("Removed absent species : \n-",paste(colNull,collapse="\n-"),sep="")
0
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
66 tab <- tab[,c("carre","annee",colConserve)]
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
67 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
68 ################################################################################ FIN DE LA PARTIE ISOLABLE
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
69 return(tab)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
70 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
71
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
72
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
73
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
74
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
75 ###################### Filtre les especes trop rare pour avoir des analyses robustes i.e. espèce non presente la 1ère année, avec plus de 3 ans consecutif sans données et moins de 3 ans consécutif avec données
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
76 ###################### Filter too rare species for accurate analysis i.e. species absent the first year, with more than 3 consecutive years with 0 abundance, or with less than 3 consecutive years with presence
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
77
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
78 ###
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
79 filter_rare_species<-function(tab){
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
80 exclude_threshold <- NULL
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
81 ## calcul et filtre pour chaque (colonne) espece / measure and filter for each species
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
82 for(i in 3:ncol(tab)) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
83 ## v =abondance par annee / v= abundance per year
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
84 v <- tapply(tab[,i],tab$annee,sum) ####################
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
85 ## v0 =presence(1) abscence(0) per year
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
86 v0 <- ifelse(v>0,1,0) #####
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
87 tx <- paste(v0,collapse="") #### colle les 0 et 1 / stick the 0 and 1
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
88
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
89 p <- unlist(strsplit(tx,"0"))#### Enleve les 0, ce qui séparent les sequences de "1", les sequences de "1" = nbre d'années consécutives avec data / remove 0, splitting sequences of "1" which correspond to consecutve year with data (e.g. 111 = 3 years consecutive years with data)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
90 p <- p[p!=""] #### ne garde pas les partie sans 1 ou 0 dans les sequences
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
91 ## gsSup0 = plus grande serie temporelle de presence =calcul du nbre de 1 consécutif max / calcul of the biggest temporal series which corresponds to the maximum number of consecutive "1"
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
92 gsSup0 <- max(nchar(p))####
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
93 ## gsInf0 plus grande serie temporelle d'absccence ou sans données = enlève les 1 séparant sequence de 0 qui correspondent au nbre d'année consecutive sans données / calcul of the biggest temporal series without data which corresponds to max numbzer fo consecutive "0"
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
94 gsInf0 <- max(nchar(unlist(strsplit(tx,"1")))) ####
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
95 ## y0is0 absence la premiere annee
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
96 y0is0 <- v0[1]==0 #### True ou false pour presence de "0"(=pas de données) dans la 1ère année / look if the first year of the time sequence analyzed has no data
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
97 ## seuil d'exclusion / exclusion threshold
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
98 exclude_threshold <- c(exclude_threshold,as.vector(ifelse( y0is0 | gsInf0 > 3 | gsSup0 < 3 ,"exclu","bon"))) ############## exclu sps absente la 1ère année, avec plus de 3 ans consécutifs sans données, et avec moins de 3 années consécutives sans données / indicate if the max consecutive year with data and without data, as well as whether the first year of the time sequence analyzed has data
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
99 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
100 names(exclude_threshold) <- colnames(tab)[3:ncol(tab)]
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
101
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
102 ## colonnes conservees avec assez de données / Column with enough data
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
103 colConserve <- names(exclude_threshold)[exclude_threshold=="bon"]
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
104
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
105
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
106 ## colonnes supprimees / Column that will conserved
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
107 colSupr <- names(exclude_threshold)[exclude_threshold=="exclu"]
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
108 tabCLEAN <- tab[,c("carre","annee",colConserve)] #### Garde les sps à conserver / select only species with enough data
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
109 lfiltre <- list(tabCLEAN=tabCLEAN,colConserve=colConserve,colSupr=colSupr)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
110
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
111 #################################################################################
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
112
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
113 ## colConserve espece conservees / extract species that will be kept to print them
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
114 colConserve <- lfiltre$colConserve
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
115 ## colsupr espece trop rare et donc supprimée de l'analyse / extract species that will be deleted to print them
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
116 colSupr <- lfiltre$colSupr
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
117 ## affichage des especes retirer de l'analyse / print species that will be deleted
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
118 if(length(colSupr)>0){
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
119 cat("\n",length(colSupr)," Rare species removed from the analysis.\n\n",sep="")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
120 #tabSupr <- subset(tabsp,espece %in% colSupr ,select=c("espece","nom"))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
121 #tabSupr <- tabSupr[order(tabSupr$espece),]
1
fd0687e91bf6 "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit d49a4da1ffac1f33a15fdb7ae98827d0034a7879"
ecology
parents: 0
diff changeset
122 cat("Removed rare species : \n-",paste(colSupr,collapse="\n-"),sep="")
0
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
123
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
124 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
125 if(length(colConserve)==0) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
126 mess <- "No species available to calculate abundance variation in this dataset."
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
127 stop(mess)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
128 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
129
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
130 tabCLEAN <- lfiltre$tabCLEAN
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
131
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
132 #### MARCHE PAS NE SAIT PAS PQUOI
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
133 tabCLEAN <- melt(tabCLEAN, id.vars=c("carre", "annee")) #### remet le format de base :le nom d'espèce et abondance dans des colonnes séparées / back to the first format of the file: species name and abundance in separated column
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
134
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
135 colnames(tabCLEAN)[3:4] <- c("espece","abond")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
136 tabCLEAN$annee <- as.numeric(as.character(tabCLEAN$annee))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
137 ################################################################################
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
138 return(tabCLEAN)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
139 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
140
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
141 ####################################################################################################################### fin des 2 fonctions de filtre des données / end of the two function to filter the data
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
142
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
143
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
144
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
145
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
146
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
147
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
148
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
149
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
150
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
151
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
152
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
153
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
154
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
155
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
156
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
157
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
158
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
159
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
160
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
161
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
162
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
163
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
164
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
165
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
166
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
167
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
168 ############################################################################################ debut de la Function main.glm / start of the function main.glm
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
169
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
170 main.glm <- function(id="france",donneesAll=dataCLEAN,assessIC= TRUE,tabsp=tabsp,annees=annees,figure=TRUE,description=TRUE,tendanceSurFigure=TRUE, ###### declaration des arguments listSp=sp était avant declaré avant la fonction mais il me semble que ca marche aussi comme cela
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
171 seuilOccu=14,seuilAbond=NA) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
172
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
173
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
174
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
175 filesaveAn <- paste("Output/",id,"/variationsAnnuellesEspece_",id,".tabular", ##### Nom du dossier ET fichier de sortie des resultats par année / name of the output file with results for each years
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
176 sep = "")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
177 filesaveTrend <- paste("Output/",id,"/tendanceGlobalEspece_",id,".tabular", ##### Nom du dossier ET fichier de sortie des resultats pour la période "annee" complete / name of the output file with the results for the period
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
178 sep = "")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
179 fileSaveGLMs <- paste("Output/",id,"/listGLM_",id,sep = "") ##### Nom du dossier ET fichier de sortie des modèles lineaire generalisés / name of the output file of the generlized linear models
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
180
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
181
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
182
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
183
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
184 seuilSignif <- 0.05 ## seuil de significativite / significancy threshold
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
185
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
186
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
187 rownames(tabsp) <- tabsp$espece ## change nom des lignes de tabsp (table de reference des especes)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
188
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
189
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
190 ##vpan vecteur des panels de la figure ###### POUR FAIRE LES GRAPHIQUES
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
191 vpan <- c("Variation abondance")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
192 if(description) vpan <- c(vpan,"Occurrences","Abondances brutes")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
193
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
194
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
195 ## specifications des variables temporelles necesaires pour les analyses / specification of temporal variable necessary for the analyses
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
196 annee <- sort(unique(donneesAll$annee))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
197 nbans <- length(annee)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
198 pasdetemps <- nbans-1
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
199 firstY <- min(annee)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
200 lastY <- max(annee)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
201
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
202
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
203
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
204
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
205
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
206 ## Ordre de traitement des especes ### order of species to be analyzed
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
207 spOrdre <- aggregate(abond~espece,data=donneesAll,sum) #### calcul les sommes des abondances pour ordonner / calculate the sum for the ordination
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
208 spOrdre <- merge(spOrdre,tabsp,by="espece") #### rajoute la colonne avec les abondances totales par espece / add a new column with the sum
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
209
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
210 spOrdre <- spOrdre[order(as.numeric(spOrdre$indicateur),spOrdre$abond,decreasing = TRUE),] #### mets les especes plus abondantes en premiers (plus long pour faire tourner le modèle) / order the species by abundance, the most abundant species being the less fast analysis
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
211
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
212
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
213 listSp <- spOrdre$espece
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
214 i <- 0
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
215 nbSp <- length(listSp)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
216 # browser()
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
217 ## analyse par espece
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
218 ### browser()
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
219 ## affichage des especes conservees pour l'analyse ### PAS SUR QUE CE SOIT ENCORE UTILE
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
220 cat("\n",nbSp," Espèces conservées pour l'analyse\n\n",sep="")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
221 rownames(tabsp) <- tabsp$espece
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
222 print(tabsp[,1:2])
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
223 #tabCons <- data.frame(Code_espece = listSp, nom_espece = tabsp[as.character(listSp),"nom"])
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
224 #print(tabCons)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
225 cat("\n\n",sep="")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
226 flush.console()
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
227
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
228
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
229 ## initialisation de la liste de sauvegarde
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
230
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
231
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
232 ##browser()
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
233
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
234 for (sp in listSp) { ######## Boucle pour analyse par espèce / loop for the analysis by species
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
235
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
236
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
237 i <- i + 1
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
238
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
239 d <- subset(donneesAll,espece==sp) ## d data pour l'espece en court / cut the data keeping only the i species
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
240
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
241 #nomSp <- as.character(tabsp[sp,"nom"]) ## info sp
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
242 nomSp <- tabsp$nom[which(tabsp$espece==sp)] ## info sp
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
243 cat("\n(",i,"/",nbSp,") ",sp," | ", nomSp,"\n",sep="")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
244 flush.console()
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
245
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
246 #indic <- tabsp[sp,"indicateur"] ## indic :espece utilisee pour le calcul des indicateurs par groupe de specialisation / list the species used as species indicators by trophic specialization
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
247 indic <- tabsp$indicateur[which(tabsp$espece==sp)] ## indic :espece utilisee pour le calcul des indicateurs par groupe de specialisation / list the species used as species indicators by trophic specialization
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
248 nb_carre = tapply(rep(1,nrow(d)),d$annee,sum) ## nb_carre nombre de carre suivie par annee / number of plots per year
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
249
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
250 nb_carre_presence = tapply(ifelse(d$abond>0,1,0),d$annee,sum) ## nb_carre_presence nombre de carre de presence par annee / number the plots where the species were observed
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
251
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
252 tab2 <- data.frame(annee=rep(annee,2),val=c(nb_carre,nb_carre_presence),LL = NA,UL=NA, ## tab2 table de resultat d'analyse / data.frame of the analyses results
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
253 catPoint=NA,pval=NA,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
254 courbe=rep(c("carre","presence"),each=length(annee)),panel=vpan[2])
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
255 tab2$catPoint <- ifelse(tab2$val == 0,"0",ifelse(tab2$val < seuilOccu,"infSeuil",NA))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
256
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
257 abond <- tapply(d$abond,d$annee,sum) ## abond abondance par annee / abundance per year
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
258
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
259 tab3 <- data.frame(annee=annee,val=abond,LL = NA,UL=NA,catPoint=NA,pval=NA,courbe=vpan[3],panel=vpan[3]) ## table pour la figure / data.frame made to realize the graphical outputs
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
260 tab3$catPoint <- ifelse(tab3$val == 0,"0",ifelse(tab3$val < seuilAbond,"infSeuil",NA))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
261
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
262 ## GLM pour calcul des tendances annuelles de l'evolution des populations / GLM to measure annual tendency of population evolution
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
263 formule <- as.formula("abond~as.factor(carre)+as.factor(annee)") #### specification du modèle = log lineaire / specifying the model = log linear
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
264 if(assessIC) {##### OPTION A RENTRER AU DEBUT PEUT ËTRE A METTRE DANS LES ARGUMENTS SI LAISSE LE CHOIX SINON L ARG PAR DEFAUT LORS DE LA DECLARATION DE LA FONCTION
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
265 glm1 <- glm(formule,data=d,family=quasipoisson) ##### fit model lineaire general avec intervalle de confiance disponible / fit linear and generalized model with confidence intervalle available
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
266 } else {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
267 glm1 <- try(speedglm(formule,data=d,family=quasipoisson())) ##### fit modele lineaire et generaux pour les gros jeux de données / fit of linear and generalized model for large-medium dataset
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
268 if(class(glm1)[1]=="try-error")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
269 glm1 <- glm(formule,data=d,family=quasipoisson) ##### comprends pas mais je pense que c'est speedglm qui marche pas avec toutes les données
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
270 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
271 sglm1 <- summary(glm1) #### sortie du modele / output of the model
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
272 sglm1 <- coefficients(sglm1) ### coefficient regression de chaque variable avec les résultats des tests statistiques / regression coefficient of each predictive variables with results of the statistical tests
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
273 sglm1 <- tail(sglm1,pasdetemps) #### recupére les derniers elements du modèle avec la taille de l'objet "pasdetemps" car le nombre de coef = nbre d'année et pas les coefficient de regression de la variable carre / retrieve only the coefficient regression of the variable year
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
274 coefan <- as.numeric(as.character(sglm1[,1]))#### coefficient de regression de la variable année (1 pour chaque année)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
275
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
276 coefannee <- c(1,exp(coefan))## coefannee vecteur des variation d'abondance par annee avec transformation inverse du log :exp() / regression coefficient of the year back transformed from log(abundance) : exp()
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
277
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
278 erreuran <- as.numeric(as.character(sglm1[,2])) #### erreur standard sur le coefficient de regression de la variable annee / standard error on the regression coefficient of the year
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
279 erreurannee1 <- c(0,erreuran*exp(coefan))## erreur standard par année / the standard error per year ###### LA J AI UN DOUTE NORMALEMENT INTERVAL DE CONF C CI_lower <- coefficients(lin_mod)[2] - 1.96*summary(lin_mod)$coefficients[2,2]
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
280 ####CI_upper <- coefficients(lin_mod)[2] + 1.96*summary(lin_mod)$coefficients[2,2]
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
281
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
282 pval <- c(1,as.numeric(as.character(sglm1[,4])))###### p value
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
283
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
284 ## calcul des intervalle de confiance avec methode de bootstrap pour simuler des coef de regress sur lequel intervalle de conf sont mesurés/ calcul of the confidence interval using bootstrap method to simulate set regression coefficients and s.e.with uncertainty POURQUOI PAS UTILISE confint.glm() ou boot() ou ci.boot()
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
285
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
286 if(assessIC) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
287 glm1.sim <- sim(glm1)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
288 ic_inf_sim <- c(1,exp(tail(apply(coef(glm1.sim), 2, quantile,.025),pasdetemps)))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
289 ic_sup_sim <- c(1,exp(tail(apply(coef(glm1.sim), 2, quantile,.975),pasdetemps)))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
290 } else {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
291 ic_inf_sim <- NA
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
292 ic_sup_sim <- NA
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
293
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
294 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
295
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
296
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
297
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
298 tab1 <- data.frame(annee,val=coefannee, ## tab1 table pour la realisation des figures / table for the graphical outputs ### 2EME POUR GRAPH ici ce sont le coef de regress annee en fonction des annéés alors que tab3 c'est les abondance en fct des années et tab2 nombre de carré total et avec presence
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
299 LL=ic_inf_sim,UL=ic_sup_sim,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
300 catPoint=ifelse(pval<seuilSignif,"significatif",NA),pval,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
301 courbe=vpan[1],
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
302 panel=vpan[1])
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
303 ## netoyage des intervalle de confiance mal estimés et qd donnees pas suffisantes pour calcul d'IC /cleaning of wrong or biaised measures of the confidence interval
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
304 if(assessIC) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
305 tab1$UL <- ifelse( nb_carre_presence==0,NA,tab1$UL)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
306 tab1$UL <- ifelse(tab1$UL == Inf, NA,tab1$UL)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
307 tab1$UL <- ifelse(tab1$UL > 1.000000e+20, NA,tab1$UL)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
308 tab1$UL[1] <- 1
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
309 tab1$val <- ifelse(tab1$val > 1.000000e+20,1.000000e+20,tab1$val)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
310 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
311 ## indice de surdispersion / overdispersion index
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
312 ## browser()
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
313 if(assessIC) dispAn <- glm1$deviance/glm1$null.deviance else dispAn <- glm1$deviance/glm1$nulldev
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
314
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
315
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
316 ## tabAn table de sauvegarde des resultats par année / table of the results per year ###### reprends bcp de tabl DIFFERENCE AVEC tab2 c les abondances relatives, alors que nb de carre, nb de carre presnce, p val sont aussi ds tab2
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
317 tabAn <- data.frame(id,code_espece=sp, nom_espece = nomSp,indicateur = indic,annee = tab1$annee,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
318 abondance_relative=round(tab1$val,3),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
319 IC_inferieur = round(tab1$LL,3), IC_superieur = round(tab1$UL,3),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
320 erreur_standard = round(erreurannee1,4),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
321 p_value = round(tab1$pval,3),significatif = !is.na(tab1$catPoint),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
322 nb_carre,nb_carre_presence,abondance=abond)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
323
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
324 ## GLM pour calcul des tendance generale sur la periode avec modele log lineaire / GLM to measure the tendency of population evolution on the studied period with log linear model
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
325 formule <- as.formula(paste("abond~ as.factor(carre) + annee",sep="")) ###
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
326 # browser()
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
327
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
328
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
329 if(assessIC) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
330 md2 <- glm(formule,data=d,family=quasipoisson) }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
331 else {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
332 md2 <- try(speedglm(formule,data=d,family=quasipoisson()),silent=TRUE)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
333
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
334 if(class(md2)[1]=="try-error")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
335 md2 <- glm(formule,data=d,family=quasipoisson)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
336 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
337
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
338
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
339 smd2 <- summary(md2) #### sortie du modele / output of the model
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
340 smd2 <- coefficients(smd2) ### coefficient regression de chaque variable avec les résultats des tests statistiques / regression coefficient of each predictive variables with results of the statistical tests
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
341 smd2 <- tail(smd2,1) ### coefficient regression de variable annee avec les résultats des tests statistiques / regression coefficient of the variable year with results of the statistical tests
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
342
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
343
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
344 coefan <- as.numeric(as.character(smd2[,1])) ## tendences sur la periode = coefficient regression de variable annee / tendency of population evolution on the studied period = regression coefficient of the variable year
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
345 trend <- round(exp(coefan),3)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
346
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
347 pourcentage <- round((exp(coefan*pasdetemps)-1)*100,2) ## pourcentage de variation sur la periode / percentage of population variation on the studied period
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
348 pval <- as.numeric(as.character(smd2[,4]))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
349
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
350 erreuran <- as.numeric(as.character(smd2[,2])) #### récuperer l'erreur standard / retrieve the error
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
351 ## erreur standard
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
352 erreurannee2 <- erreuran*exp(coefan)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
353
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
354
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
355 ## calcul des intervalle de confiance avec methode de bootstrap pour simuler des coef de regress sur lequel intervalle de conf sont mesurés/ calculating the confidence interval based on bootstrap method to simulate set regression coefficients and s.e.with uncertainty
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
356 LL <- NA
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
357 UL <- NA
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
358 if(assessIC) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
359 md2.sim <- sim(md2)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
360 LL <- round(exp(tail(apply(coef(md2.sim), 2, quantile,.025),1)),3)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
361 UL <- round(exp(tail(apply(coef(md2.sim), 2, quantile,.975),1)),3)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
362 } else {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
363 LL <- NA
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
364 UL <- NA
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
365 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
366
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
367 ## tab1t table utile pour la realisation des figures / table used for the figures
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
368 tab1t <- data.frame(Est=trend,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
369 LL , UL,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
370 pourcent=pourcentage,signif=pval<seuilSignif,pval)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
371
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
372
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
373 trendsignif <- tab1t$signif
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
374 pourcent <- round((exp(coefan*pasdetemps)-1)*100,3)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
375 ## mesure de la surdispersion / overdispersion measurment
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
376
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
377 if(assessIC) dispTrend <- md2$deviance/md2$null.deviance else dispTrend <- md2$deviance/md2$nulldev
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
378
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
379
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
380
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
381 ## classement en categorie incertain /classifying wrong or not reliable results
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
382 # browser()
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
383 if(assessIC) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
384 if(dispTrend > 2 | dispAn > 2 | median( nb_carre_presence)<seuilOccu) catIncert <- "Incertain" else catIncert <-"bon" ##### en fonction de l'indice de surdispersion et presence < à seuil occurence / based on the overdispersion index and the presence on a minimum number of plots
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
385 vecLib <- NULL
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
386 if(dispTrend > 2 | dispAn > 2 | median( nb_carre_presence)<seuilOccu) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
387 if(median( nb_carre_presence)<seuilOccu) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
388 vecLib <- c(vecLib,"espece trop rare")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
389 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
390 if(dispTrend > 2 | dispAn > 2) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
391 vecLib <- c(vecLib,"deviance")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
392 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
393 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
394 raisonIncert <- paste(vecLib,collapse=" et ")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
395 } else {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
396 catIncert <- NA
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
397 raisonIncert <- NA
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
398 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
399
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
400
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
401
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
402 ## affectation des tendence EBCC / retrieve the trend of population evolution on the studied period
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
403 catEBCC <- NA
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
404 if(assessIC) catEBCC <- affectCatEBCC(trend = as.vector(trend),pVal = pval,ICinf=as.vector(LL),ICsup=as.vector(UL)) else catEBCC <- NA
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
405 ## table complete de resultats pour la periode etudiée / complete table with results for the studied period
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
406 # browser()
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
407 tabTrend <- data.frame(
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
408 id,code_espece=sp,nom_espece = nomSp,indicateur = indic,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
409 nombre_annees = pasdetemps,premiere_annee = firstY,derniere_annee = lastY,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
410 tendance = as.vector(trend) , IC_inferieur=as.vector(LL) , IC_superieur = as.vector(UL),pourcentage_variation=as.vector(pourcent),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
411 erreur_standard = as.vector(round(erreurannee2,4)), p_value = round(pval,3),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
412 significatif = trendsignif,categorie_tendance_EBCC=catEBCC,mediane_occurrence=median( nb_carre_presence) ,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
413 valide = catIncert,raison_incertitude = raisonIncert)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
414
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
415
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
416 if(assessIC) listGLMsp <- list(list(glm1,glm1.sim,md2,md2.sim)) else listGLMsp <- list(list(glm1,md2))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
417 names(listGLMsp)[[1]] <-sp
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
418 fileSaveGLMsp <- paste(fileSaveGLMs,"_",sp,".Rdata",sep="")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
419
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
420 save(listGLMsp,file=fileSaveGLMsp)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
421 cat("--->",fileSaveGLMsp,"\n")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
422 flush.console()
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
423
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
424 if(sp==listSp[1]) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
425 glmAn <- tabAn
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
426 glmTrend <- tabTrend
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
427 } else {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
428 glmAn <- rbind(glmAn,tabAn)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
429 glmTrend <- rbind(glmTrend,tabTrend)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
430 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
431 ## les figures
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
432 if(figure) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
433 ## table complete pour la figure en panel par ggplot2
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
434 ## table pour graphe en panel par ggplot2
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
435 if(description) dgg <- rbind(tab1,tab2,tab3) else dgg <- tab1
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
436 ## les figures
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
437
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
438 ggplot.espece(dgg,tab1t,id,serie=NULL,sp,valide=catIncert,nomSp,description,tendanceSurFigure,seuilOccu=14,vpan = vpan,assessIC=assessIC)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
439
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
440 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
441
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
442
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
443
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
444
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
445 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
446
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
447 write.table(glmAn,filesaveAn,row.names=FALSE,quote=FALSE,sep="\t",dec=".",fileEncoding="UTF-8")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
448 cat("--->",filesaveAn,"\n")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
449 write.table(glmTrend,filesaveTrend,row.names=FALSE,quote=FALSE,sep="\t",dec=".",fileEncoding="UTF-8")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
450 cat("--->",filesaveTrend,"\n")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
451
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
452
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
453 flush.console()
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
454
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
455
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
456
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
457 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
458 ########################################################################################################## Fin de la fonction main.glm / end of the function main.glm
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
459
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
460
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
461
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
462
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
463
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
464
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
465
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
466
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
467
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
468
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
469
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
470
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
471
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
472
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
473
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
474 ########################################################################################################### fonction appelée par main.glm renvoyant la categorie European Bird Census Council en fonction des resultats des modèles / function called by main.glm to classify results depending on the quality of the data and analyses
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
475 ## renvoie la categorie EBCC de la tendance en fonction
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
476 ## trend l'estimateur de la tendance / estimation of the trends
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
477 ## pVal la p value
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
478 ## ICinf ICsup l intervalle de confiance a 95 pourcent
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
479 affectCatEBCC <- function(trend,pVal,ICinf,ICsup){
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
480 catEBCC <- ifelse(pVal>0.05,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
481 ifelse(ICinf < 0.95 | ICsup > 1.05,"Incertain","Stable"),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
482 ifelse(trend<1,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
483 ifelse(ICsup<0.95,"Fort declin","Declin moderee"),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
484 ifelse(ICinf>1.05,"Forte augmentation","Augmentation modere")))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
485 return(catEBCC)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
486 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
487
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
488 ############################################################################################################ fin de la fonction renvoyant la categorie EBCC / end of the function main.glm
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
489
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
490
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
491
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
492
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
493
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
494
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
495
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
496
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
497 ############################################################################################################ fonction graphique appelée par main.glm / function called by main.glm for graphical output
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
498 ggplot.espece <- function(dgg,tab1t,id,serie=NULL,sp,valide,nomSp=NULL,description=TRUE,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
499 tendanceSurFigure=TRUE,seuilOccu=14, vpan,assessIC=TRUE) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
500
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
501 # serie=NULL;nomSp=NULL;description=TRUE;valide=catIncert
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
502 # tendanceSurFigure=TRUE;seuilOccu=14
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
503 require(ggplot2)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
504
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
505 figname<- paste("Output/",id,"/",ifelse(valide=="Incertain","Incertain/",""),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
506 sp,"_",id,serie, ".png",
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
507 sep = "")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
508 ## coordonnee des ligne horizontal de seuil pour les abondances et les occurences
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
509 hline.data1 <- data.frame(z = c(1), panel = c(vpan[1]),couleur = "variation abondance",type="variation abondance")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
510 hline.data2 <- data.frame(z = c(0,seuilOccu), panel = c(vpan[2],vpan[2]),couleur = "seuil",type="seuil")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
511 hline.data3 <- data.frame(z = 0, panel = vpan[3] ,couleur = "seuil",type="seuil")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
512 hline.data <- rbind(hline.data1,hline.data2,hline.data3)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
513 titre <- paste(nomSp)#,"\n",min(annee)," - ",max(annee),sep="")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
514
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
515 ## texte de la tendance / text for the population evolution trend
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
516 tab1 <- subset(dgg,panel =="Variation abondance")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
517 pasdetemps <- max(dgg$annee) - min(dgg$annee) + 1
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
518 if(assessIC){
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
519 txtPente1 <- paste(tab1t$Est,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
520 ifelse(tab1t$signif," *","")," [",tab1t$LL," , ",tab1t$UL,"]",
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
521 ifelse(tab1t$signif,paste("\n",ifelse(tab1t$pourcent>0,"+ ","- "),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
522 abs(tab1t$pourcent)," % en ",pasdetemps," ans",sep=""),""),sep="")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
523 }else{
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
524 txtPente1 <- ifelse(tab1t$signif,paste("\n",ifelse(tab1t$pourcent>0,"+ ","- "),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
525 abs(tab1t$pourcent)," % en ",pasdetemps," ans",sep=""),"")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
526
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
527 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
528 ## table du texte de la tendance / table of the text for the population evolution trend
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
529 tabTextPent <- data.frame(y=c(max(c(tab1$val,tab1$UL),na.rm=TRUE)*.9),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
530 x=median(tab1$annee),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
531 txt=ifelse(tendanceSurFigure,c(txtPente1),""),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
532 courbe=c(vpan[1]),panel=c(vpan[1]))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
533 ## les couleurs / the colors
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
534 vecColPoint <- c("#ffffff","#eeb40f","#ee0f59")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
535 names(vecColPoint) <- c("significatif","infSeuil","0")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
536 vecColCourbe <- c("#3c47e0","#5b754d","#55bb1d","#973ce0")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
537 names(vecColCourbe) <- c(vpan[1],"carre","presence",vpan[3])
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
538 vecColHline <- c("#ffffff","#e76060")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
539 names(vecColHline) <- c("variation abondance","seuil")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
540
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
541 col <- c(vecColPoint,vecColCourbe,vecColHline)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
542 names(col) <- c(names(vecColPoint),names(vecColCourbe),names(vecColHline))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
543
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
544 ## si description graphique en 3 panels
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
545 if(description) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
546 p <- ggplot(data = dgg, mapping = aes(x = annee, y = val))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
547 ## Titre, axes ...
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
548 p <- p + facet_grid(panel ~ ., scale = "free") +
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
549 theme(legend.position="none",
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
550 panel.grid.minor=element_blank(),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
551 panel.grid.major.y=element_blank()) +
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
552 ylab("") + xlab("Annee")+ ggtitle(titre) +
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
553 scale_colour_manual(values=col, name = "" ,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
554 breaks = names(col))+
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
555 scale_x_continuous(breaks=min(dgg$annee):max(dgg$annee))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
556 p <- p + geom_hline(data =hline.data,mapping = aes(yintercept=z, colour = couleur,linetype=type ),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
557 alpha=1,size=1.2)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
558 if(assessIC){ ############# ONLY FOR THE CONFIDENCE INTERVAL
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
559 p <- p + geom_ribbon(mapping=aes(ymin=LL,ymax=UL),fill=col[vpan[1]],alpha=.2)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
560 p <- p + geom_pointrange(mapping= aes(y=val,ymin=LL,ymax=UL),fill=col[vpan[1]],alpha=.2)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
561 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
562 p <- p + geom_line(mapping=aes(colour=courbe),size = 1.5)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
563 p <- p + geom_point(mapping=aes(colour=courbe),size = 3)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
564 p <- p + geom_point(mapping=aes(colour=catPoint,alpha=ifelse(!is.na(catPoint),1,0)),size = 2)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
565 p <- p + geom_text(data=tabTextPent, mapping=aes(x,y,label=txt),parse=FALSE,color=col[vpan[1]],fontface=2, size=4)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
566 ggsave(figname, p,width=16,height=21, units="cm")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
567 print (figname) ##### CAN BE REMOVED IF YOU DO NOT WANT THE GRAPH TO BE PLOTTED
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
568 } else {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
569
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
570 p <- ggplot(data = subset(dgg,panel=="Variation abondance"), mapping = aes(x = annee, y = val))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
571 ## Titre, axes ...
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
572 p <- p + facet_grid(panel ~ ., scale = "free") +
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
573 theme(legend.position="none",
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
574 panel.grid.minor=element_blank(),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
575 panel.grid.major.y=element_blank()) +
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
576 ylab("") + xlab("Annee")+ ggtitle(titre) +
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
577 scale_colour_manual(values=col, name = "" ,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
578 breaks = names(col))+
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
579 scale_x_continuous(breaks=min(dgg$annee):max(dgg$annee))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
580 p <- p + geom_hline(data =subset(hline.data,panel=="Variation abondance"),mapping = aes(yintercept=z, colour = couleur,linetype=type ),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
581 alpha=1,size=1.2)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
582
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
583 if(assessIC){ ############# ONLY FOR THE CONFIDENCE INTERVAL
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
584 p <- p + geom_ribbon(mapping=aes(ymin=LL,ymax=UL),fill=col[vpan[1]],alpha=.2)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
585 p <- p + geom_pointrange(mapping= aes(y=val,ymin=LL,ymax=UL),fill=col[vpan[1]],alpha=.2)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
586 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
587 p <- p + geom_line(mapping=aes(colour=courbe),size = 1.5)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
588 p <- p + geom_point(mapping=aes(colour=courbe),size = 3)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
589 p <- p + geom_point(mapping=aes(colour=catPoint,alpha=ifelse(!is.na(catPoint),1,0)),size = 2)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
590 p <- p + geom_text(data=tabTextPent, mapping=aes(x,y,label=txt),parse=FALSE,color=col[vpan[1]],fontface=2, size=4)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
591 ggsave(figname, p,width=15,height=9,units="cm")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
592 print (figname) ##### CAN BE REMOVED IF YOU DO NOT WANT THE GRAPH TO BE PLOTTED
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
593 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
594 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
595 ############################################################################################################ fin fonction graphique / end of function for graphical output
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
596
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
597
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
598
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
599
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
600 #################################################################################################################### debut de la fonction de moyenne geometrique pondere / start of the geometric weighted mean function
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
601 geometriqueWeighted <- function(x,w=1) exp(sum(w*log(x))/sum(w))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
602 #################################################################################################################### fin de la fonction de moyenne geometrique pondere / end of the geometric weighted mean function
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
603
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
604
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
605
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
606 ##################################################################################################################### debut de la fonction analyseGroupe / start of the function analyseGroupe
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
607 ## Analyse par groupe de specialisation a partir des resulats de variation d'abondance par especes / analysis by specialization group based on results of the analysis of population evolution trend
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
608 #
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
609
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
610
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
611 analyseGroupe <- function(id="france",tabsp=tabsp,donnees=donnees,donneesTrend=donneesTrend,ICfigureGroupeSp=TRUE,powerWeight=2,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
612 correctionAbondanceNull = 0.000001,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
613 groupeNom = c("generaliste","milieux batis","milieux forestiers","milieux agricoles"),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
614 groupeCouleur = c("black","firebrick3","chartreuse4","orange")) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
615
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
616
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
617
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
618
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
619
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
620 ## donnees tendances globales / results of the global trends
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
621 donneesTrend <- subset(donneesTrend, select = c(code_espece,valide,mediane_occurrence))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
622
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
623 ## table de reference espece / reference table for species
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
624 tabsp <- subset(tabsp, select= c(sp,nom,indicateur, specialisation))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
625 donnees <- merge(donnees,donneesTrend,by="code_espece")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
626 donnees <- merge(donnees,tabsp,by.x="code_espece",by.y="sp")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
627 ## table de correspondance de biais en fonction des medianes des occuerences
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
628
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
629
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
630 nameFileSpe <- paste("Output/",id,"/variationsAnnuellesGroupes_",id, ############# Declare le fichier de sortie des variations annuelles par groupe / declare the name of the outputfile for annual population evolution trend by group
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
631 ".tabular",sep="" )
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
632 nameFileSpepng <- paste("Output/",id,"/variationsAnnuellesGroupes_",id, ############# Declare le fichier de sortie graphique des variations annuelles par groupe / declare the name of the graphical output file for annual population evolution trend by group
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
633 ".png",sep="" )
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
634
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
635 grpe <- donnees$specialisation
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
636
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
637 ####### valeur seuil sont obtenues à partir de simulations / threshold values are obtained from simulations
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
638 ff <- function(x,y) max(which(y<=x)) ## fonction pour recherche le poid associé à valeur max parmi valeur seuil d'occurence inferieur ou egale à occurence mediane obs / function to retrieve the weight associated with the max occurence threshold equal or smaller than the occurence mediane observed
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
639
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
640 IncertW <- ifelse(donnees$valide=="Incertain",tBiais$biais[sapply(as.vector(donnees$mediane_occurrence),ff,y=tBiais$occurrenceMed)],1) ## pr verifier poids de l'espèce dans analyse, récupére seuil occurence minimum pour lequel tendance pas bonne, et compare avec mediane occurence des données / to check the weight of species in the analysis, this retrieve occurence threshold with wich real occurence measured on data are compared in order to verify the accuracy of the trend measurment
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
641 ## poids du a la qualite de l'estimation
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
642 # erreur_stW <- 1/((donnees$erreur_st+1)^powerWeight)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
643 # erreur_stW <- ifelse( is.na(donnees$IC_superieur),0,erreur_stW)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
644 erreur_stW <- ifelse(is.na(donnees$IC_superieur),0,1)##### si pas d'interval de confiance met 0 et donne un poid de 0 à l'esps (voir ci dessous) / if no confidence interval calculated give a weight of 0 for the sps
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
645 ## calcul du poids total de chaque espèce / calcul of the weight of each species
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
646 W <- IncertW * erreur_stW
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
647
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
648 ## variable de regroupement pour les calculs par groupe de specialisation et par an / variables gathered to identify group for the calculation (per specialization and per year)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
649 grAn <- paste(donnees$specialisation,donnees$annee,sep="_")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
650 ## data frame pour le calcul / dataframe made for the calcul
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
651 dd <- data.frame(grAn,annee = donnees$annee, grpe,W,ab=donnees$abondance_relative,ICinf= donnees$IC_inferieur, ICsup= ifelse(is.na(donnees$IC_superieur),10000,donnees$IC_superieur))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
652 ## table resumer de tous les poids / table to sum up the weights of each species depending on the incertainty in the calcul of the poulation evolution trends
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
653 ddd <- data.frame(code_espece = donnees$code_espece,nom_espece = donnees$nom_espece,annee = donnees$annee,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
654 groupe_indicateur = grpe,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
655 poids_erreur_standard = round(erreur_stW,3), poids_incertitude = round(IncertW,3),poids_final = round(W,3),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
656 abondance_relative=donnees$abondance_relative,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
657 IC_inferieur= donnees$IC_inferieur,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
658 IC_superieur= ifelse(is.na(donnees$IC_superieur),10000,donnees$IC_superieur),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
659 valide = donnees$valide, mediane_occurrence = donnees$mediane_occurrence)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
660
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
661 nomFileResum <- paste("Output/",id,"/donneesGroupes_",id, ###### declaration du nom du repertoire et des fichiers de sortie / declaring the name of the output folder and files
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
662 ".tabular",sep="" )
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
663 write.table(ddd,nomFileResum,row.names=FALSE,sep="\t",dec=".",fileEncoding="UTF-8")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
664 cat("-->",nomFileResum,"\n")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
665
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
666 ## calcul des moyennes ponderees par groupe par an et pour les abondance et les IC / calcul of weighted means per specialization group and per year for the abundance and confidence interval
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
667 for(j in 5:7) dd[,j] <- ifelse(dd[,j]==0,correctionAbondanceNull,dd[,j])
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
668 ag <- apply(dd[,5:7], 2, ######## sur les abondances relatives, les ICinf et ICsup
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
669 function(x) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
670 sapply(split(data.frame(dd[,1:4], x), dd$grAn), ###### fait les moyennes pondérés par groupe grAn / calculate the weighted mean by group grAn
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
671 function(y) round(geometriqueWeighted(y[,5], w = y$W),3))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
672 })
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
673 ## gg <- subset(dd,as.character(dd$grAn)=="milieux forestier_2014") #############################################################
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
674
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
675 ag <- ifelse(is.na(ag),1,ag)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
676 ag <- as.data.frame(ag)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
677 ag$grAn <- rownames(ag)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
678 dbon <- subset(donnees,valide=="bon")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
679 dIncert <- subset(donnees,valide=="Incertain")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
680 ## calcul nombre d'espece "bonne" pour le calcul / calculating the number of species with low level of incertainty, "good" species
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
681 bon <- tapply(dbon$nom,dbon$specialisation,FUN=function(X)length(unique(X)) )
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
682 bon <- ifelse(is.na(bon),0,bon)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
683 tbon <- data.frame(groupe=names(bon),bon)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
684 ## calcul nombre d'especes "incertaines" pour le calcul / calculating the number of species with high level of incertainty, "bad" species
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
685 Incert <- tapply(dIncert$nom,dIncert$specialisation,FUN=function(X)length(unique(X)) )
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
686 Incert <- ifelse(is.na(Incert),0,Incert)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
687 tIncert <- data.frame(groupe=names(Incert),Incertain=Incert)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
688
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
689 tIncert <- merge(tIncert,tbon,by="groupe")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
690
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
691 ## table de données avec les moyennes ponderees par groupe / table of the data with the weighted mean by group
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
692 da <- merge(unique(dd[,1:3]),ag,by="grAn")[,-1]
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
693 colnames(da) <- c("annee","groupe","abondance_relative","IC_inferieur","IC_superieur")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
694
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
695 da$annee <- as.numeric(da$annee)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
696 da <- merge(da,tIncert,by="groupe") #### ajoute le nombre d'espece "incertaines" et "bonne" aux resultats / add the number of "good" and "bad" species to the overall resutls
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
697 da <- subset(da, groupe != "non")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
698 colnames(da)[6:7] <- c("nombre_especes_incertaines","nombre_espece_bonnes")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
699 a <- data.frame(id,da)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
700 write.table(da,file=nameFileSpe,row.names=FALSE,quote=FALSE,sep="\t",dec=".",fileEncoding="UTF-8")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
701
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
702 cat("-->",nameFileSpe,"\n")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
703 yearsrange <- c(min(da$annee),max(da$annee))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
704
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
705 ## figure par ggplot2 / plots with ggplot2
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
706 titre <- paste("Variation de l'indicateur groupe de specialisation",sep="")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
707
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
708 vecCouleur <- setNames(groupeCouleur,groupeNom)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
709 #browser()
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
710 p <- ggplot(data = da, mapping = aes(x = annee, y = abondance_relative, colour=groupe,fill=groupe))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
711 p <- p + geom_hline(aes(yintercept = 1), colour="white", alpha=1,size=1.2)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
712 if(ICfigureGroupeSp)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
713 p <- p + geom_ribbon(mapping=aes(ymin=IC_inferieur,ymax=IC_superieur),linetype=2,alpha=.1,size=0.1)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
714 p <- p + geom_line(size=1.5)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
715 p <- p + ylab("") + xlab("Annee")+ ggtitle(titre)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
716 if(!is.null(groupeNom)) p <- p + scale_colour_manual(values=vecCouleur, name = "" )+
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
717 scale_x_continuous(breaks=unique(da$annee))
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
718 if(!is.null(groupeNom)) p <- p + scale_fill_manual(values=vecCouleur, name="")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
719 p <- p + theme(panel.grid.minor=element_blank(), panel.grid.major.y=element_blank())
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
720 ggsave(nameFileSpepng, p,width=17,height=10,units="cm")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
721
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
722 # cat(" <==",nameFileSpepng,"\n")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
723
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
724 ## calul pour chaque groupe une pente de regression d'evolution des abondances sur la periode étudiée / calculating for each group the regression slope for the abundance evolution on the studied period
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
725 vecSpe <- unique(da$groupe)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
726 datasum <- data.frame(groupe=NULL,tendance=NULL,pourcentage_variation=NULL)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
727 for(spe in 1:4){
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
728 # print(spe)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
729 subtab <- subset(da,groupe==vecSpe[spe])
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
730 if(nrow(subtab)>1) {
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
731 sumlm <- summary(lm(abondance_relative~annee,data=subtab)) ##### recupère les resultats du modèle linéaire / retrieve the results of the linear model
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
732 subdatasum <- data.frame(groupe=vecSpe[spe],
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
733 tendance=round(sumlm$coefficients[2,1],3),
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
734 pourcentage_variation=round(sumlm$coefficients[2,1]*(nrow(subtab)-1)*100,3)) #### assemble les resultats pour en faire une sortie / bring together the results for an output file
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
735 datasum <- rbind(datasum,subdatasum)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
736
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
737 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
738
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
739 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
740 datasum <- merge(datasum,tIncert,by="groupe") ####
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
741 datasum <- data.frame(id,datasum)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
742 #datasum$cat_tendance_EBCC <- affectCatEBCC(trend,pVal,ICinf,ICsup
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
743 namefilesum <- paste("Output/",id,"/tendancesGlobalesGroupes_",id,
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
744 ".tabular",sep="" )
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
745 write.table(datasum,file=namefilesum,row.names=FALSE,quote=FALSE,sep="\t",dec=".",fileEncoding="UTF-8")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
746 cat("-->",namefilesum,"\n")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
747 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
748
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
749 ################################################################################################################## fin de la fonction analyseGroupe / end of the function analyseGroupe
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
750
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
751
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
752
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
753
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
754
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
755
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
756
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
757 ################################################################################################################### debut de la fonction check_file / start of the function check_file
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
758 # Fonction pour verifier les données d'entrée / General function to check integrity of input file. Will check numbers and contents of variables(colnames).
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
759 #return an error message and exit if mismatch detected
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
760 #Faut rentrer le nom du jeu de données, le nbre et le nom des variables / Enter dataset name, expected number and names of variables. + an exit error message to guide user.
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
761
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
762 check_file<-function(dataset,err_msg,vars,nb_vars){
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
763 if(ncol(dataset)!=nb_vars){ #Verifiction de la présence du bon nb de colonnes, si c'est pas le cas= message d'erreur / checking for right number of columns in the file if not = error message
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
764 cat("\nerr nb var\n")
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
765 stop(err_msg, call.=FALSE)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
766 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
767
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
768 for(i in vars){
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
769 if(!(i %in% names(dataset))){
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
770 stop(err_msg,call.=FALSE)
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
771 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
772 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
773 }
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
774
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
775 #####################################################################################################################
2e45ae3b297a "planemo upload for repository https://github.com/Alanamosse/Galaxy-E/tree/stoctool/tools/stoc commit f82f897ab22464de40c878e17616333855814e25"
ecology
parents:
diff changeset
776