annotate FunctExeCalcGLMSpGalaxy.r @ 0:0778efa9eb2e draft

"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
author ecology
date Tue, 21 Jul 2020 06:00:51 -0400
parents
children 6c14021f678e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
1 #Rscript
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(MASS))
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
11 suppressMessages(library(multcomp))
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
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
15 ###################### Load arguments and declaring variables
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
16
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
17 args = commandArgs(trailingOnly=TRUE)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
18 #options(encoding = "UTF-8")
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) {
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
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) #si pas d'arguments -> affiche erreur et quitte / if no args -> error and exit1
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 {
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
24 Importdata <- args[1] ###### file name : metrics table
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
25 ImportUnitobs <- args[2] ###### file name : unitobs informations
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
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
27 listFact <- strsplit(args [4],",")[[1]] ###### Selected response factors for GLM
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
28 listRand <- strsplit(args [5],",")[[1]] ###### Selected randomized response factors for GLM
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
29 colFactAna <- args[6] ####### (optional) Selected splitting factors for GLMs
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
30 Distrib <- args[7] ###### (optional) Selected distribution for GLM
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
31 log <- args[8] ###### (Optional) Log on interest metric ?
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 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
36 #### Data must be a dataframe with at least 3 variables : unitobs representing location and year ("observation.unit"), species code ("species.code") and abundance ("number")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
37
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
38
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
39 #Import des données / Import data
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
40 obs<- read.table(Importdata,sep="\t",dec=".",header=TRUE,encoding="UTF-8") #
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
41 obs[obs == -999] <- NA
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
42 metric <- colnames(obs)[colmetric]
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
43 tabUnitobs <- read.table(ImportUnitobs,sep="\t",dec=".",header=TRUE,encoding="UTF-8")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
44 tabUnitobs[tabUnitobs == -999] <- NA
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
45
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
46 vars_data1<- c("species.code")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
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"
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
48 check_file(obs,err_msg_data1,vars_data1,3)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
49
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
50 vars_data2 <- c(listFact,listRand)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
51 vars_data2 <- vars_data2[vars_data2 != "None"]
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
52 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"
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
53 check_file(tabUnitobs,err_msg_data2,vars_data2,2)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
54
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
55
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
56 if (colFactAna != "None")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
57 {
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
58 FactAna <- colFactAna
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
59 if (class(obs[FactAna]) == "numeric" || FactAna == "observation.unit"){stop("Wrong chosen separation factor : Analysis can't be separated by observation unit or numeric factor")}
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
60 }else{
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
61 FactAna <- colFactAna
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
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
64
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
65 #factors <- fact.det.f(Obs=obs)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
66
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
67 ####################################################################################################
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
68 ########## Computing Generalized Linear Model ## Function : modeleLineaireWP2.unitobs.f ############
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
69 ####################################################################################################
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
70
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
71 modeleLineaireWP2.species.f <- function(metrique, listFact, listRand, FactAna, Distrib, log=FALSE, tabMetrics, tableMetrique, tabUnitobs, unitobs="observation.unit", outresiduals = FALSE, nbName="number")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
72 {
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
73 ## Purpose: Gestions des différentes étapes des modèles linéaires.
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 ## Arguments: metrique : la métrique choisie.
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
76 ## factAna : le facteur de séparation des graphiques.
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
77 ## factAnaSel : la sélection de modalités pour ce dernier
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
78 ## listFact : liste du (des) facteur(s) de regroupement
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
79 ## listFactSel : liste des modalités sélectionnées pour ce(s)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
80 ## dernier(s)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
81 ## tabMetrics : table de métriques.
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
82 ## tableMetrique : nom de la table de métriques.
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
83 ## dataEnv : environnement de stockage des données.
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
84 ## baseEnv : environnement de l'interface.
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
85 ## ----------------------------------------------------------------------
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
86 ## Author: Yves Reecht, Date: 18 août 2010, 15:59
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
87
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
88 tmpData <- tabMetrics
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
89
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
90 if (listRand[1] != "None")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
91 {
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
92 if (all(is.element(listFact,listRand)) || listFact[1] == "None")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
93 {
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
94 RespFact <- paste("(1|",paste(listRand,collapse=") + (1|"),")")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
95 listF <- NULL
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
96 listFact <- listRand
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
97 }else{
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
98 listF <- listFact[!is.element(listFact,listRand)]
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
99 RespFact <- paste(paste(listF, collapse=" + ")," + (1|",paste(listRand,collapse=") + (1|"),")")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
100 listFact <- c(listF,listRand)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
101 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
102 }else{
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
103 listF <- listFact
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
104 RespFact <- paste(listFact, collapse=" + ")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
105 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
106 ##Creating model's expression :
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
107 #if (log == FALSE) {
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
108 exprML <- eval(parse(text=paste(metrique, "~", RespFact)))
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
109 #}else{
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
110 # exprML <- eval(parse(text=paste("log(",metrique,")", "~", RespFact)))
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
111 #}
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
112
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
113 ##Creating analysis table :
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
114 listFactTab <- c(listFact,FactAna)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
115 listFactTab <- listFactTab[listFactTab != "None"]
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
116
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
117 if (all(is.na(match(tmpData[,unitobs],tabUnitobs[,unitobs])))) {stop("Observation units doesn't match in the two input tables")}
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 if(is.element("species.code",colnames(tmpData)))
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
120 {
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
121 col <- c(unitobs,metrique,FactAna)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
122 tmpData <- cbind(tmpData[,col], tabUnitobs[match(tmpData[,unitobs],tabUnitobs[,unitobs]),listFact])
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
123 colnames(tmpData) <- c(col,listFact)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
124
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
125 for (i in listFactTab) {
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
126 tmpData[,i] <- as.factor(tmpData[,i])
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
127 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
128 }else{
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
129 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
130 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
131
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
132 ## Suppression des 'levels' non utilisés :
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
133 tmpData <- dropLevels.f(tmpData)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
134
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
135 ## Aide au choix du type d'analyse :
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
136 if (Distrib == "None")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
137 {
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
138 if (metrique == "pres.abs")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
139 {
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
140 loiChoisie <- "binomial"
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
141 }else{
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
142 switch(class(tmpData[,metrique]),
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
143 "integer"={loiChoisie <- "poisson"},
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
144 "numeric"={loiChoisie <- "gaussian"},
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
145 stop("Selected metric class doesn't fit, you should select an integer or a numeric variable"))
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
146 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
147 }else{
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
148 loiChoisie <- Distrib
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
149 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
150
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
151 ##Create results table :
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
152 lev <- unlist(lapply(listF,FUN=function(x){levels(tmpData[,x])}))
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
153
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
154 if (listRand[1] != "None") ## if random effects
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
155 {
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
156 TabSum <- data.frame(species=levels(tmpData[,FactAna]),AIC=NA,BIC=NA,logLik=NA, deviance=NA,df.resid=NA)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
157 colrand <- unlist(lapply(listRand,
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
158 FUN=function(x){lapply(c("Std.Dev","NbObservation","NbLevels"),
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
159 FUN=function(y){paste(x,y,collapse = ":")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
160 })
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
161 }))
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
162 TabSum[,colrand] <- NA
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
163
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
164 if (! is.null(lev)) ## if fixed effects + random effects
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
165 {
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
166 colcoef <- unlist(lapply(c("(Intercept)",lev),
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
167 FUN=function(x){lapply(c("Estimate","Std.Err","Zvalue","Pvalue","signif"),
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
168 FUN=function(y){paste(x,y,collapse = ":")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
169 })
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
170 }))
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
171 }else{ ## if no fixed effects
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
172 colcoef <- NULL
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
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
175 }else{ ## if no random effects
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
176 TabSum <- data.frame(species=levels(tmpData[,FactAna]),AIC=NA,Resid.deviance=NA,df.resid=NA,Null.deviance=NA,df.null=NA)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
177
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
178 switch(loiChoisie,
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
179 "gaussian"={colcoef <- unlist(lapply(c("(Intercept)",lev),
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
180 FUN=function(x){lapply(c("Estimate","Std.Err","Tvalue","Pvalue","signif"),
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
181 FUN=function(y){paste(x,y,collapse = ":")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
182 })
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 "quasipoisson"={colcoef <- unlist(lapply(c("(Intercept)",lev),
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
185 FUN=function(x){lapply(c("Estimate","Std.Err","Tvalue","Pvalue","signif"),
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
186 FUN=function(y){paste(x,y,collapse = ":")
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 }))},
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
189 colcoef <- unlist(lapply(c("(Intercept)",lev),
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
190 FUN=function(x){lapply(c("Estimate","Std.Err","Zvalue","Pvalue","signif"),
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
191 FUN=function(y){paste(x,y,collapse = ":")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
192 })
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
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
195 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
196
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
197 TabSum[,colcoef] <- NA
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
198
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
199 ### creating rate table
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
200 TabRate <- data.frame(species=levels(tmpData[,FactAna]), 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)
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 ## Compute Model(s) :
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
203
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
204 for (sp in levels(tmpData[,FactAna]))
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
205 {
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
206 cutData <- tmpData[grep(sp,tmpData[,FactAna]),]
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
207 cutData <- dropLevels.f(cutData)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
208
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
209 res <-""
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
210
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
211 if (listRand[1] != "None")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
212 {
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
213 res <- tryCatch(glmmTMB(exprML,family=loiChoisie, data=cutData), error=function(e){})
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
214 }else{
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
215 res <- tryCatch(glm(exprML,data=cutData,family=loiChoisie), error=function(e){})
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
216 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
217
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
218 ## Écriture des résultats formatés dans un fichier :
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
219 if (! is.null(res))
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
220 {
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
221 TabSum <- sortiesLM.f(objLM=res, TabSum=TabSum, factAna=factAna, cut=sp, colAna="species", lev=lev, Data=cutData, metrique=metrique, type="espece", listFact=listFact)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
222
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
223 TabRate[TabRate[,"species"]==sp,c(2:11)] <- noteGLM.f(data=cutData, objLM=res, metric=metrique, listFact=listFact, details=TRUE)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
224
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
225 }else{
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
226 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")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
227 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
228
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
229 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
230 noteGLMs.f(tabRate=TabRate,exprML=exprML,objLM=res,file_out=TRUE)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
231
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
232 ## simple statistics and infos :
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
233 filename <- "GLMSummaryFull.txt"
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
234
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
235 ## Save data on model :
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
236
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
237 infoStats.f(filename=filename, Data=tmpData, agregLevel=aggreg, type="stat",
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
238 metrique=metrique, factGraph=factAna, #factGraphSel=modSel,
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
239 listFact=listFact)#, listFactSel=listFactSel)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
240
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
241 return(TabSum)
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
242 }
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
243
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
244 ################# Analysis
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
245
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
246 Tab <- modeleLineaireWP2.species.f(metrique=metric, listFact=listFact, listRand=listRand, FactAna=FactAna, Distrib=Distrib, tabMetrics=obs, tableMetrique=aggreg, tabUnitobs=tabUnitobs, outresiduals=SupprOutlay, nbName="number")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
247
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
248 write.table(Tab,"GLMSummary.tabular", row.names=FALSE, sep="\t", dec=".",fileEncoding="UTF-8")
0778efa9eb2e "planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff changeset
249