annotate FunctExeCalcGLMSpGalaxy.r @ 2:6c14021f678e draft

"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
author ecology
date Sun, 22 Nov 2020 18:40:40 +0000
parents 0778efa9eb2e
children c12897ba5f83
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
1 #Rscript
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
2
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
3 #####################################################################################################################
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
4 #####################################################################################################################
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
5 ################################# Compute a Generalized Linear Model from your data #################################
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
6 #####################################################################################################################
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
7 #####################################################################################################################
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
8
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
9 ###################### Packages
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
10 suppressMessages(library(multcomp))
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
11 suppressMessages(library(DHARMa))
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
12 suppressMessages(library(glmmTMB)) ###Version: 0.2.3
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
13 suppressMessages(library(gap))
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
14
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
15
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
16 ###################### Load arguments and declaring variables
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
17
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
18 args <- commandArgs(trailingOnly = TRUE)
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
19
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
20 if (length(args) < 10) {
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
21 stop("At least 4 arguments must be supplied : \n- two input dataset files (.tabular) : metrics table and unitobs table \n- Interest variable field from metrics table \n- Response variable from unitobs table.", call. = FALSE) # if no args -> error and exit1
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
22
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
23 } else {
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
24 import_data <- args[1] ###### file name : metrics table
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
25 import_unitobs <- args[2] ###### file name : unitobs informations
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
26 colmetric <- as.numeric(args[3]) ###### Selected interest metric for GLM
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
27 list_fact <- strsplit(args [4], ",")[[1]] ###### Selected response factors for GLM
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
28 list_rand <- strsplit(args [5], ",")[[1]] ###### Selected randomized response factors for GLM
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
29 col_fact_ana <- args[6] ####### (optional) Selected splitting factors for GLMs
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
30 distrib <- args[7] ###### (optional) Selected distribution for GLM
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
31 glm_out <- args[8] ###### (Optional) GLM object as Rdata output ?
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
32 aggreg <- args[9] ###### Aggregation level of the data table
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
33 source(args[10]) ###### Import functions
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
34
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
35 }
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
36 #### d_ata must be a dataframe with at least 3 variables : unitobs representing location and year ("observation.unit"), species code ("species.code") and abundance ("number")
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
37
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
38
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
39 #Import des données / Import data
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
40 obs <- read.table(import_data, sep = "\t", dec = ".", header = TRUE, encoding = "UTF-8") #
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
41 obs[obs == -999] <- NA
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
42 metric <- colnames(obs)[colmetric]
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
43 tab_unitobs <- read.table(import_unitobs, sep = "\t", dec = ".", header = TRUE, encoding = "UTF-8")
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
44 tab_unitobs[tab_unitobs == -999] <- NA
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
45
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
46 vars_data1 <- c("species.code")
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
47 err_msg_data1 <- "The input metrics dataset doesn't have the right format. It needs to have at least the following 3 variables :\n- species.code \n- observation.unit (or year and site)\n- numeric or integer metric\n"
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
48 check_file(obs, err_msg_data1, vars_data1, 3)
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
49
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
50 vars_data2 <- c("observation.unit", list_fact, list_rand)
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
51 err_msg_data2 <- "The input unitobs dataset doesn't have the right format. It needs to have at least the following 2 variables :\n- observation.unit (or year and site)\n- factors used in GLM (habitat, year and/or site)\n"
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
52 check_file(tab_unitobs, err_msg_data2, vars_data2[vars_data2 != "None"], 2)
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
53
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
54
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
55 if (col_fact_ana != "None") {
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
56 fact_ana <- col_fact_ana
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
57 if (class(obs[fact_ana]) == "numeric" || fact_ana == "observation.unit") {
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
58 stop("Wrong chosen separation factor : Analysis can't be separated by observation unit or numeric factor")
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
59 }
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
60 }else{
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
61 fact_ana <- col_fact_ana
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
62 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
63
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
64 if (all(c(list_fact, list_rand) == "None")) {
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
65 stop("GLM needs to have at least one response variable.")
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
66 }
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
67
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
68 if (list_fact[1] == "None" || all(is.element(list_fact, list_rand))) {
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
69 stop("GLM can't have only random effects.")
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
70 }
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
71
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
72 ####################################################################################################
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
73 ########## Computing Generalized Linear Model ## Function : glm_species ############
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
74 ####################################################################################################
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
75
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
76 glm_species <- function(metrique, list_fact, list_rand, fact_ana, distrib, tab_metrics, tab_metrique, tab_unitobs, unitobs = "observation.unit", nb_name = "number") {
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
77 ## Purpose: Monitoring steps for GLM on species data
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
78 ## ----------------------------------------------------------------------
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
79 ## Arguments: metrique : selected metric
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
80 ## list_fact : Factors for GLM
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
81 ## list_rand : Random factors for GLM
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
82 ## fact_ana : Separation factor for GLMs
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
83 ## distrib : selected distribution for model
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
84 ## tab_metrics : data table metrics
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
85 ## tab_metrique : data table's name
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
86 ## tab_unitobs : data table unitobs
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
87 ## ----------------------------------------------------------------------
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
88 ## Author: Yves Reecht, Date: 18 août 2010, 15:59 modified by Coline ROYAUX 04 june 2020
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
89
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
90 tmpd_ata <- tab_metrics
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
91
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
92 out_fact <- .GlobalEnv$organise_fact(list_rand = list_rand, list_fact = list_fact)
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
93 resp_fact <- out_fact[[1]]
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
94 list_f <- out_fact[[2]]
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
95 list_fact <- out_fact[[3]]
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
96
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
97 ##Creating model's expression :
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
98 expr_lm <- eval(parse(text = paste(metrique, "~", resp_fact)))
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
99
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
100 ##Creating analysis table :
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
101 list_fact_tab <- c(list_fact, fact_ana)
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
102 list_fact_tab <- list_fact_tab[list_fact_tab != "None"]
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
103
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
104 if (all(is.na(match(tmpd_ata[, unitobs], tab_unitobs[, unitobs])))) {
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
105 stop("Observation units doesn't match in the two input tables")
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
106 }
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
107
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
108 if (is.element("species.code", colnames(tmpd_ata))) {
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
109 col <- c(unitobs, metrique, fact_ana)
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
110 tmpd_ata <- cbind(tmpd_ata[, col], tab_unitobs[match(tmpd_ata[, unitobs], tab_unitobs[, unitobs]), list_fact])
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
111 colnames(tmpd_ata) <- c(col, list_fact)
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
112
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
113 for (i in list_fact_tab) {
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
114 tmpd_ata[, i] <- as.factor(tmpd_ata[, i])
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
115 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
116 }else{
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
117 stop("Warning : wrong data frame, data frame should be aggregated by observation unit (year and site) and species")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
118 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
119
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
120 ## Suppression des 'levels' non utilisés :
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
121 tmpd_ata <- .GlobalEnv$drop_levels_f(tmpd_ata)
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
122
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
123 ## Automatic choice of distribution if none is selected by user :
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
124
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
125 chose_distrib <- .GlobalEnv$distrib_choice(distrib = distrib, metrique = metrique, data = tmpd_ata)
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
126
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
127 ##Create results table :
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
128 lev <- unlist(lapply(list_f, FUN = function(x) {
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
129 levels(tmpd_ata[, x])
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
130 }))
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
131 row <- levels(tmpd_ata[, fact_ana])
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
132
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
133 if (is.element("year", list_f) && ! is.element("year", list_rand)) {
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
134 tab_sum <- .GlobalEnv$create_res_table(list_rand = list_rand, list_fact = list_fact, row = row, lev = unlist(c("year", lev)), distrib = chose_distrib)
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
135 }else{
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
136 tab_sum <- .GlobalEnv$create_res_table(list_rand = list_rand, list_fact = list_fact, row = row, lev = lev, distrib = chose_distrib)
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
137 }
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
138 ### creating rate table
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
139 tab_rate <- data.frame(species = row, complete_plan = NA, balanced_plan = NA, NA_proportion_OK = NA, no_residual_dispersion = NA, uniform_residuals = NA, outliers_proportion_OK = NA, no_zero_inflation = NA, observation_factor_ratio_OK = NA, enough_levels_random_effect = NA, rate = NA)
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
140
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
141 ## Compute Model(s) :
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
142
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
143 for (sp in levels(tmpd_ata[, fact_ana])) {
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
144 cutd_ata <- tmpd_ata[grep(sp, tmpd_ata[, fact_ana]), ]
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
145 cutd_ata <- .GlobalEnv$drop_levels_f(cutd_ata)
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
146
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
147 res <- ""
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
148 resy <- ""
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
149
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
150 if (list_rand[1] != "None") {
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
151 res <- tryCatch(glmmTMB(expr_lm, family = chose_distrib, data = cutd_ata), error = function(e) {
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
152 })
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
153
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
154 if (is.element("year", list_f) && ! is.element("year", list_rand)) { #Model with year as continuous
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
155 cutd_ata$year <- as.numeric(cutd_ata$year)
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
156 resy <- tryCatch(glmmTMB(expr_lm, family = chose_distrib, data = cutd_ata), error = function(e) {
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
157 })
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
158 cutd_ata$year <- as.factor(cutd_ata$year)
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
159 }else{
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
160 resy <- ""
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
161 }
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
162 }else{
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
163 res <- tryCatch(glm(expr_lm, data = cutd_ata, family = chose_distrib), error = function(e) {
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
164 })
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
165 if (is.element("year", list_f)) { #Model with year as continuous
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
166 cutd_ata$year <- as.numeric(cutd_ata$year)
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
167 resy <- tryCatch(glm(expr_lm, family = chose_distrib, data = cutd_ata), error = function(e) {
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
168 })
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
169 cutd_ata$year <- as.factor(cutd_ata$year)
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
170 }else{
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
171 resy <- ""
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
172 }
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
173 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
174
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
175 ## Write results :
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
176 if (! is.null(res)) {
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
177 file_save_glm_sp <- paste("GLM_", sp, ".Rdata", sep = "")
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
178 save(res, file = file_save_glm_sp)
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
179
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
180 tab_sum <- .GlobalEnv$sorties_lm_f(obj_lm = res, obj_lmy = resy, tab_sum = tab_sum, fact_ana = fact_ana, cut = sp, col_ana = "analysis", lev = lev, d_ata = cutd_ata, metrique = metrique, list_fact = list_fact, list_rand = list_rand)
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
181
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
182 tab_rate[tab_rate[, "species"] == sp, c(2:11)] <- .GlobalEnv$note_glm_f(data = cutd_ata, obj_lm = res, metric = metrique, list_fact = list_fact, details = TRUE)
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
183
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
184 }else{
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
185 cat("\nCannot compute GLM for species", sp, "Check if one or more factor(s) have only one level, or try with another distribution for the model in advanced settings \n\n")
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
186 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
187
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
188 }
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
189 .GlobalEnv$note_glms_f(tab_rate = tab_rate, expr_lm = expr_lm, obj_lm = res, file_out = TRUE)
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
190
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
191 ## simple statistics and infos :
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
192 filename <- "GLMSummaryFull.txt"
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
193
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
194 ## Save data on model :
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
195
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
196 info_stats_f(filename = filename, d_ata = tmpd_ata, agreg_level = aggreg, type = "stat",
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
197 metrique = metrique, fact_graph = fact_ana, #fact_graph_sel = modSel,
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
198 list_fact = list_fact)#, list_fact_sel = list_fact_sel)
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
199
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
200 return(tab_sum)
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
201 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
202
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
203 ################# Analysis
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
204
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
205 tab <- glm_species(metrique = metric, list_fact = list_fact, list_rand = list_rand, fact_ana = fact_ana, distrib = distrib, tab_metrics = obs, tab_metrique = aggreg, tab_unitobs = tab_unitobs, nb_name = "number")
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
206
2
6c14021f678e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 3df1978827a91be30e815dee2ed83a92862d1b1c"
ecology
parents: 0
diff changeset
207 write.table(tab, "GLMSummary.tabular", row.names = FALSE, sep = "\t", dec = ".", fileEncoding = "UTF-8")