annotate FunctExePlotGLMGalaxy.r @ 0:3ab852a7ff53 draft

"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
author ecology
date Mon, 16 Nov 2020 11:02:43 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
1 #Rscript
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
2
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
3 #####################################################################################################################
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
4 #####################################################################################################################
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
5 ###################################### Create a plot from your community data #######################################
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
6 #####################################################################################################################
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
7 #####################################################################################################################
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
8
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
9 ###################### Packages
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
10 suppressMessages(library(ggplot2))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
11 suppressMessages(library(boot))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
12
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
13 ###################### Load arguments and declaring variables
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
14
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
15 args <- commandArgs(trailingOnly = TRUE)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
16
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
17
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
18 if (length(args) < 2) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
19 stop("At least 3 arguments must be supplied input dataset file with GLM results (.tabular)", call. = FALSE) #if no args -> error and exit1
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
20
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
21 } else {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
22 import_data <- args[1] ###### file name : glm results table
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
23 data_tab <- args[2] ###### file name : Metrics table
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
24 unitobs_tab <- args[3] ###### file name : Unitobs table
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
25 source(args[4]) ###### Import functions
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
26
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
27 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
28
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
29 #Import data
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
30 glmtable <- read.table(import_data, sep = "\t", dec = ".", header = TRUE, encoding = "UTF-8") #
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
31 datatable <- read.table(data_tab, sep = "\t", dec = ".", header = TRUE, encoding = "UTF-8") #
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
32 unitobs <- read.table(unitobs_tab, sep = "\t", dec = ".", header = TRUE, encoding = "UTF-8") #
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
33
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
34 #Check files
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
35
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
36 vars_data1 <- c("analysis", "Interest.var", "distribution")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
37 err_msg_data1 <- "The input GLM results dataset doesn't have the right format. It needs to have at least the following 3 fields :\n- analysis\n- Interest.var\n- distribution\n"
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
38 check_file(glmtable, err_msg_data1, vars_data1, 4)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
39
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
40 if (length(grep("[0-2][0|9][0-9][0-9].[Estimate|Pvalue]", colnames(glmtable))) == 0) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
41 stop("The input GLM results dataset doesn't have the right format or informations. This tool is to represent temporal trends, if your GLM doesn't take the year variable as a fixed effect this tool is not proper to make any representation of it. It needs to have at least estimates and p-value for every year from your time series GLM as columns with name formated as : yyyy Estimate (example : 2020 Estimate) and yyyy Pvalue (example : 2020 Pvalue).")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
42 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
43
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
44 if (length(grep("[0-2][0|9][0-9][0-9].IC_[up|inf]", colnames(glmtable))) == 0) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
45 assess_ic <- FALSE
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
46 }else{
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
47 assess_ic <- TRUE
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
48 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
49
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
50 metric <- as.character(glmtable[1, "Interest.var"])
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
51
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
52 vars_data2 <- c("observation.unit", "location", metric)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
53 err_msg_data2 <- "The input metrics dataset doesn't have the right format. It needs to have at least the following 3 fields :\n- observation.unit\n- location\n- the name of the interest metric\n"
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
54 check_file(datatable, err_msg_data2, vars_data2, 4)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
55
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
56 vars_data3 <- c("observation.unit", "year")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
57 err_msg_data3 <- "The input unitobs dataset doesn't have the right format. It needs to have at least the following 2 fields :\n- observation.unit\n- year\n"
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
58 check_file(unitobs, err_msg_data3, vars_data3, 2)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
59 if (length(grep("[0-2][0|9][0-9][0-9]", unitobs$year)) == 0) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
60 stop("The year column in the input unitobs dataset doesn't have the right format. Years must be fully written as : yyyy (example : 2020).")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
61 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
62
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
63 if (all(is.na(match(datatable[, "observation.unit"], unitobs[, "observation.unit"])))) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
64 stop("Observation units doesn't match in the inputs metrics dataset and unitobs dataset")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
65 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
66
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
67 ####################################################################################################################
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
68 ######################### Creating plot from time series GLM data ## Function : ggplot_glm #########################
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
69 ####################################################################################################################
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
70 ggplot_glm <- function(glmtable, datatable, unitobs, metric = metric, sp, description = TRUE,
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
71 trend_on_graph = TRUE, assess_ic = TRUE) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
72 ## Purpose: Creating plot from time series GLM data
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
73 ## ----------------------------------------------------------------------
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
74 ## Arguments: glmtable : GLM(s) results table
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
75 ## datatable : Metrics table
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
76 ## unitobs : Unitobs table
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
77 ## metric : Interest variable in GLM(s)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
78 ## sp : name of processed GLM
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
79 ## description : Two graphs ?
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
80 ## trend_on_graph : Write global trend of the time series on graph ?
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
81 ## assess_ic : Assess confidence intervals ?
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
82 ## ----------------------------------------------------------------------
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
83 ## Author: Coline ROYAUX 13 october 2020
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
84
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
85 s_signif <- 0.05 ## threshold when pvalue is considered significant
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
86 distrib <- as.character(glmtable[1, "distribution"]) ## extract GLM distribution
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
87
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
88 col <- c("observation.unit", "location", metric) ## names of needed columns in metrics table to construct the 2nd panel of the graph
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
89
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
90 if (colnames(glmtable)[length(glmtable)] == "separation") { ## if GLM is a community analysis
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
91 cut <- as.character(glmtable[1, "separation"])
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
92 if (cut != "None") { ## if there is plural GLM analysis performed
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
93 if (! is.element(as.character(cut), colnames(unitobs))) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
94 stop("The input unitobs dataset doesn't have the right format. If plural GLM analysis have been performed it needs to have the field used as separation factor.")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
95 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
96 datatable <- cbind(datatable[, col], unitobs[match(datatable[, "observation.unit"], unitobs[, "observation.unit"]), c("year", cut)]) ## extracting 'year' and analysis separation factor columns from unitobs table to merge with metrics table /// Matching lines with 'observation.unit' column
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
97 colnames(datatable) <- c(col, "year", cut)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
98 }else{
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
99 datatable <- cbind(datatable[, col], unitobs[match(datatable[, "observation.unit"], unitobs[, "observation.unit"]), "year"]) ## extracting 'year' column from unitobs table to merge with metrics table /// Matching lines with 'observation.unit' column
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
100 colnames(datatable) <- c(col, "year")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
101 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
102
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
103 }else{ ## GLM is a population analysis
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
104 cut <- "species.code"
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
105 if (! is.element("species.code", colnames(datatable))) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
106 stop("The input metrics dataset or the GLM results dataset doesn't have the right format. If the GLM is a population analysis, the field species.code needs to be informed in the metrics dataset. If the GLM is a community analysis the field separation (None if only one analysis and name of the separation factor if several analysis) needs to be informed in the last column of the GLM results dataset.")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
107 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
108 col <- c(col, cut)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
109 datatable <- cbind(datatable[, col], unitobs[match(datatable[, "observation.unit"], unitobs[, "observation.unit"]), "year"]) ## extracting 'year' column from unitobs table to merge with metrics table /// Matching lines with 'observation.unit' column
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
110 colnames(datatable) <- c(col, "year")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
111 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
112
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
113 ##vpan vector of names of the two panels in the ggplot
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
114
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
115 switch(as.character(metric),
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
116 "number" = vpan <- c("Abundance variation", "Raw abundance"),
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
117 "presence_absence" = vpan <- c("Presence-absence variation", "% presence in location"),
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
118 vpan <- c(paste(metric, " variation"), paste("Mean ", metric)))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
119
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
120 ##Cut table for 1 analysis
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
121 glmtab <- glmtable[glmtable[, "analysis"] == sp, ]
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
122
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
123 glmtab <- glmtab[, grep("FALSE", is.na(glmtab[1, ]))] ## Supress columns with NA only
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
124
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
125 ## specification of temporal variable necessary for the analyses
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
126 an <- as.numeric(unlist(strsplit(gsub("X", "", paste(colnames(glmtab)[grep("[0-2][0|9][0-9][0-9].Estimate", colnames(glmtab))], collapse = " ")), split = ".Estimate"))) ## Extract list of years studied in the GLM
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
127
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
128 year <- sort(c(min(an) - 1, an)) ## Add the first level, "reference" in the GLM
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
129 nbans <- length(year)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
130 pasdetemps <- nbans - 1
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
131
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
132 ##### Table 1
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
133
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
134 coefan <- unlist(lapply(an, FUN = function(x) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
135 if (length(glmtab[glmtab[, 1] == sp, grep(paste0("X", x, ".Estimate"), colnames(glmtab))]) > 0) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
136 glmtab[glmtab[, 1] == sp, grep(paste0("X", x, ".Estimate"), colnames(glmtab))]
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
137 }else{
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
138 NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
139 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
140 })) ## extract estimates for each years to contruct graph 1
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
141
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
142 ic_inf <- unlist(lapply(an, FUN = function(x) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
143 if (length(glmtab[glmtab[, 1] == sp, grep(paste0("X", x, ".IC_inf"), colnames(glmtab))]) > 0) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
144 glmtab[glmtab[, 1] == sp, grep(paste0("X", x, ".IC_inf"), colnames(glmtab))]
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
145 }else{
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
146 NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
147 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
148 }))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
149
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
150 ic_up <- unlist(lapply(an, FUN = function(x) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
151 if (length(glmtab[glmtab[, 1] == sp, grep(paste0("X", x, ".IC_up"), colnames(glmtab))]) > 0) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
152 glmtab[glmtab[, 1] == sp, grep(paste0("X", x, ".IC_up"), colnames(glmtab))]
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
153 }else{
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
154 NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
155 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
156 }))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
157
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
158 switch(distrib, ## Applying the reciprocal of the link function to coefficients and confidence intervals depending on distribution law
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
159 "poisson" = {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
160 coefyear <- c(1, exp(as.numeric(coefan))) ## link function : log
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
161 if (assess_ic) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
162 ic_inf_sim <- c(1, exp(as.numeric(ic_inf)))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
163 ic_sup_sim <- c(1, exp(as.numeric(ic_up)))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
164 } else {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
165 ic_inf_sim <- NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
166 ic_sup_sim <- NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
167 }},
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
168 "quasipoisson" = {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
169 coefyear <- c(1, exp(as.numeric(coefan))) ## link function : log
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
170 if (assess_ic) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
171 ic_inf_sim <- c(1, exp(as.numeric(ic_inf)))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
172 ic_sup_sim <- c(1, exp(as.numeric(ic_up)))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
173 } else {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
174 ic_inf_sim <- NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
175 ic_sup_sim <- NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
176 }},
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
177 "inverse.gaussian" = {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
178 coefyear <- c(0, as.numeric(coefan) ^ (- 1 / 2)) ## link function : x^ - 2
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
179 if (assess_ic) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
180 ic_inf_sim <- c(0, as.numeric(ic_inf) ^ (- 1 / 2))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
181 ic_sup_sim <- c(0, as.numeric(ic_up) ^ (- 1 / 2))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
182 } else {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
183 ic_inf_sim <- NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
184 ic_sup_sim <- NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
185 }},
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
186 "binomial" = {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
187 coefyear <- c(1, boot::inv.logit(as.numeric(coefan))) ## link function : logit
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
188 if (assess_ic) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
189 ic_inf_sim <- c(1, boot::inv.logit(as.numeric(ic_inf)))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
190 ic_sup_sim <- c(1, boot::inv.logit(as.numeric(ic_up)))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
191 } else {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
192 ic_inf_sim <- NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
193 ic_sup_sim <- NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
194 }},
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
195 "quasibinomial" = {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
196 coefyear <- c(1, boot::inv.logit(as.numeric(coefan))) ## link function : logit
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
197 if (assess_ic) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
198 ic_inf_sim <- c(1, boot::inv.logit(as.numeric(ic_inf)))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
199 ic_sup_sim <- c(1, boot::inv.logit(as.numeric(ic_up)))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
200 } else {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
201 ic_inf_sim <- NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
202 ic_sup_sim <- NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
203 }},
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
204 "Gamma" = {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
205 coefyear <- c(1, as.numeric(coefan) ^ (- 1)) ## link function : -x^ - 1
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
206 if (assess_ic) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
207 ic_inf_sim <- c(1, as.numeric(ic_inf) ^ (- 1))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
208 ic_sup_sim <- c(1, as.numeric(ic_up) ^ (- 1))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
209 } else {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
210 ic_inf_sim <- NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
211 ic_sup_sim <- NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
212 }}
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
213 , {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
214 coefyear <- c(0, as.numeric(coefan))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
215 if (assess_ic) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
216 ic_inf_sim <- c(0, as.numeric(ic_inf))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
217 ic_sup_sim <- c(0, as.numeric(ic_up))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
218 } else {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
219 ic_inf_sim <- NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
220 ic_sup_sim <- NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
221 }})
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
222
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
223 pval <- c(1, unlist(lapply(an, FUN = function(x) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
224 if (length(glmtab[glmtab[, 1] == sp, grep(paste0("X", x, ".Pvalue"), colnames(glmtab))]) > 0) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
225 glmtab[glmtab[, 1] == sp, grep(paste0("X", x, ".Pvalue"), colnames(glmtab))]
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
226 }else{
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
227 NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
228 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
229 }))) ## extract p value for each year
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
230
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
231
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
232 tab1 <- data.frame(year, val = coefyear, ## table for the graphical output 1
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
233 ll = unlist(ic_inf_sim), ul = unlist(ic_sup_sim),
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
234 catPoint = ifelse(pval < s_signif, "significatif", NA), pval,
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
235 courbe = vpan[1],
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
236 panel = vpan[1])
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
237 ## cleaning of wrong or biaised measures of the confidence interval
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
238 if (assess_ic) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
239 tab1$ul <- ifelse(tab1$ul == Inf, NA, tab1$ul)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
240 tab1$ul <- ifelse(tab1$ul > 1.000000e+20, NA, tab1$ul)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
241 tab1$val <- ifelse(tab1$val > 1.000000e+20, 1.000000e+20, tab1$val)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
242 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
243
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
244 coefancontinu <- as.numeric(as.character(glmtab[glmtab[, 1] == sp, grep("year.Estimate", colnames(glmtab))])) ## tendency of population evolution on the studied period = regression coefficient of the variable year as a continuous variable in the GLM
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
245 switch(distrib, ## Applying the reciprocal of the link function to coefficients and confidence intervals depending on distribution law
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
246 "poisson" = {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
247 trend <- round(exp(as.numeric(coefancontinu)), 3) ## link function : log
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
248 pourcentage <- round((exp(as.numeric(coefancontinu) * as.numeric(pasdetemps)) - 1) * 100, 2)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
249 },
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
250 "quasipoisson" = {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
251 trend <- round(exp(as.numeric(coefancontinu)), 3) ## link function : log
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
252 pourcentage <- round((exp(as.numeric(coefancontinu) * as.numeric(pasdetemps)) - 1) * 100, 2)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
253 },
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
254 "inverse.gaussian" = {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
255 trend <- round(as.numeric(coefancontinu) ^ (- 1 / 2), 3) ## link function : x^ - 2
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
256 pourcentage <- round((((as.numeric(coefancontinu) * as.numeric(pasdetemps)) ^ (- 1 / 2)) - 1) * 100, 2)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
257 },
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
258 "binomial" = {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
259 trend <- round(boot::inv.logit(as.numeric(coefancontinu)), 3) ## link function : logit
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
260 pourcentage <- round((boot::inv.logit(as.numeric(coefancontinu) * as.numeric(pasdetemps)) - 1) * 100, 2)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
261 },
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
262 "quasibinomial" = {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
263 trend <- round(boot::inv.logit(as.numeric(coefancontinu)), 3) ## link function : logit
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
264 pourcentage <- round((boot::inv.logit(as.numeric(coefancontinu) * as.numeric(pasdetemps)) - 1) * 100, 2)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
265 },
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
266 "Gamma" = {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
267 trend <- round(as.numeric(coefancontinu) ^ (- 1), 3) ## link function : -x^ - 1
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
268 pourcentage <- round((((as.numeric(coefancontinu) * as.numeric(pasdetemps)) ^ (- 1)) - 1) * 100, 2)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
269 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
270 , {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
271 trend <- round(as.numeric(coefancontinu), 3)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
272 pourcentage <- round((((as.numeric(coefancontinu) * as.numeric(pasdetemps))) - 1) * 100, 2)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
273 })
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
274
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
275 pval <- as.numeric(as.character(glmtab[glmtab[, 1] == sp, grep("year.Pvalue", colnames(glmtab))])) ## Extract p value
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
276
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
277 ## table for global trend on the whole time series
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
278 tab1t <- NULL
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
279 if (length(pval) > 0) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
280 tab1t <- data.frame(Est = trend, pourcent = pourcentage, signif = pval < s_signif, pval)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
281 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
282
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
283 ##### Table 2
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
284
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
285 if (sp == "global") { ## prepare metrics table to extract variables used in graph 2
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
286 datatablecut <- datatable[grep("FALSE", is.na(datatable[, as.character(metric)])), ]
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
287
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
288 }else{
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
289
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
290 datatablecut <- datatable[datatable[, as.character(cut)] == sp, ]
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
291 datatablecut <- datatablecut[grep("FALSE", is.na(datatablecut[, as.character(metric)])), ]
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
292 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
293
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
294 switch(as.character(metric), ## Different value represented graph 2 depending on the nature of the metric
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
295 "number" = {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
296 valplot <- lapply(sort(year), FUN = function(x) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
297 sum(na.omit(as.numeric(subset(datatablecut, year == x)[, as.character(metric)])))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
298 })
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
299 }, ## sum if abundance
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
300 "presence_absence" = {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
301 nb_loc <- lapply(sort(year), FUN = function(x) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
302 length(unique(subset(datatablecut, year == x)[, "location"]))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
303 }) ## number of plots per year
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
304 nb_loc_presence <- lapply(sort(year), FUN = function(x) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
305 length(unique(subset(datatablecut[datatablecut[, metric] > 0, ], year == x)[, "location"]))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
306 }) ## number of plots where the species were observed
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
307 valplot <- (na.omit(as.numeric(nb_loc_presence)) / na.omit(as.numeric(nb_loc))) * 100
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
308 } ## % of presence in observered plots if presence / absence
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
309 , {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
310 valplot <- lapply(sort(year), FUN = function(x) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
311 mean(na.omit(as.numeric(subset(datatablecut, year == x)[, as.character(metric)])))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
312 })
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
313 } ## mean if any other metric
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
314 )
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
315
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
316 tab2 <- data.frame(year, val = round(as.numeric(valplot), 2), ll = NA, ul = NA, catPoint = NA, pval = NA,
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
317 courbe = vpan[2], panel = vpan[2])
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
318
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
319 ## Creating ggplots
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
320
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
321 dgg <- tab1
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
322
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
323 figname <- paste(sp, ".png", sep = "")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
324
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
325 ## coord for horizontal lines in graphs
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
326 hline_data1 <- data.frame(z = tab1$val[1], panel = c(vpan[1]), couleur = "var estimates", type = "var estimates")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
327 hline_data3 <- data.frame(z = 0, panel = vpan[2], couleur = "seuil", type = "seuil")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
328 hline_data <- rbind(hline_data1, hline_data3)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
329 titre <- paste(sp)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
330
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
331 ## text for the population evolution trend
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
332
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
333 pasdetemps <- max(dgg$year) - min(dgg$year) + 1
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
334 if (! is.null(tab1t)) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
335 if (assess_ic) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
336 txt_pente1 <- paste("Global trend : ", tab1t$Est,
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
337 ifelse(tab1t$signif, " *", ""),
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
338 ifelse(tab1t$signif, paste("\n", ifelse(tab1t$pourcent > 0, "+ ", "- "),
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
339 abs(tab1t$pourcent), " % in ", pasdetemps, " years", sep = ""), ""), sep = "")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
340 }else{
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
341 txt_pente1 <- ifelse(tab1t$signif, paste("\n", ifelse(tab1t$pourcent > 0, "+ ", "- "),
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
342 abs(tab1t$pourcent), " % in ", pasdetemps, " years", sep = ""), "")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
343 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
344 }else{
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
345 trend_on_graph <- FALSE
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
346 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
347
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
348 ## table of the text for the population evolution trend
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
349 tab_text_pent <- data.frame(y = c(max(c(dgg$val, dgg$ul), na.rm = TRUE) * .9),
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
350 x = median(dgg$year),
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
351 txt = ifelse(trend_on_graph, c(txt_pente1), ""),
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
352 courbe = c(vpan[1]), panel = c(vpan[1]))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
353
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
354 dgg <- rbind(tab1, tab2)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
355
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
356 ## colors for plots
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
357 vec_col_point <- c("#ffffff", "#eeb40f", "#ee0f59")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
358 names(vec_col_point) <- c("significatif", "infSeuil", "0")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
359 vec_col_courbe <- c("#3c47e0", "#5b754d", "#55bb1d", "#973ce0")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
360 names(vec_col_courbe) <- c(vpan[1], "loc", "presence", vpan[2])
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
361 vec_col_hline <- c("#ffffff", "#e76060")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
362 names(vec_col_hline) <- c("var estimates", "seuil")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
363
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
364 col <- c(vec_col_point, vec_col_courbe, vec_col_hline)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
365 names(col) <- c(names(vec_col_point), names(vec_col_courbe), names(vec_col_hline))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
366
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
367 p <- ggplot2::ggplot(data = dgg, mapping = ggplot2::aes_string(x = "year", y = "val"))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
368 ## Titles and scales
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
369 p <- p + facet_grid(panel ~ ., scale = "free") +
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
370 theme(legend.position = "none",
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
371 panel.grid.minor = element_blank(),
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
372 panel.grid.major.y = element_blank(),
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
373 axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
374 ylab("") + xlab("year") + ggtitle(titre) +
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
375 scale_colour_manual(values = col, name = "",
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
376 breaks = names(col)) +
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
377 scale_x_continuous(breaks = min(dgg$year):max(dgg$year))
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
378 p <- p + ggplot2::geom_hline(data = hline_data, mapping = ggplot2::aes_string(yintercept = "z", colour = "couleur", linetype = "type"),
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
379 alpha = 1, size = 1.2)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
380 if (assess_ic) { ############# ONLY FOR THE CONFIDENCE INTERVAL
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
381 p <- p + ggplot2::geom_ribbon(mapping = ggplot2::aes_string(ymin = "ll", ymax = "ul"), fill = col[vpan[1]], alpha = .2)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
382 p <- p + ggplot2::geom_pointrange(mapping = ggplot2::aes_string(y = "val", ymin = "ll", ymax = "ul"), fill = col[vpan[1]], alpha = .2)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
383 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
384
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
385 p <- p + ggplot2::geom_line(mapping = ggplot2::aes_string(colour = "courbe"), size = 1.5)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
386 p <- p + ggplot2::geom_point(mapping = ggplot2::aes_string(colour = "courbe"), size = 3)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
387 alph <- ifelse(!is.na(dgg$catPoint), 1, 0)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
388 p <- p + ggplot2::geom_point(mapping = ggplot2::aes_string(colour = "catPoint", alpha = alph), size = 2)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
389 p <- p + ggplot2::geom_text(data = tab_text_pent, mapping = ggplot2::aes_string("x", "y", label = "txt"), parse = FALSE, color = col[vpan[1]], fontface = 2, size = 4)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
390 ggplot2::ggsave(figname, p, width = 16, height = 15, units = "cm")
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
391 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
392 ############################################################################################################ fin fonction graphique / end of function for graphical output
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
393
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
394 ################# Analysis
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
395
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
396 for (sp in glmtable[, 1]) {
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
397
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
398 if (!all(is.na(glmtable[glmtable[, 1] == sp, 4:(length(glmtable) - 1)]))) { ##ignore lines with only NA
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
399 ggplot_glm(glmtable = glmtable, datatable = datatable, unitobs = unitobs, metric = metric, sp = sp, description = TRUE, trend_on_graph = TRUE, assess_ic = assess_ic)
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
400 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
401 }
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
402
3ab852a7ff53 "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 04381ca7162ec3ec68419e308194b91d11cacb04"
ecology
parents:
diff changeset
403 sink("stdout.txt", split = TRUE)