Mercurial > repos > ecology > pampa_presabs
annotate FunctPAMPAGalaxy.r @ 2:f1bfdeb5ebfe draft
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit e8643d3d2e48d2ec7fcb2bd5abf77869a8687422"
author | ecology |
---|---|
date | Mon, 27 Jul 2020 09:46:51 -0400 |
parents | c9dfe4e20a45 |
children | 8d8aec182fb1 |
rev | line source |
---|---|
0
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1 #Rscript |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
4 ################################################################################################################################## |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
5 ####################### PAMPA Galaxy tools functions : Calculate metrics, compute GLM and plot ################################# |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
6 ################################################################################################################################## |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
7 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
8 #### Based on Yves Reecht R script |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
9 #### Modified by Coline ROYAUX for integrating within Galaxy-E |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
10 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
11 ######################################### start of the function fact.def.f called by FunctExeCalcCommIndexesGalaxy.r and FunctExeCalcPresAbsGalaxy.r |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
12 ####### Define the finest aggregation with the observation table |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
13 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
14 fact.det.f <- function (Obs, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
15 size.class="size.class", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
16 code.especes="species.code", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
17 unitobs="observation.unit") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
18 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
19 if (any(is.element(c(size.class), colnames(obs))) && all(! is.na(obs[, size.class]))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
20 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
21 factors <- c(unitobs, code.especes, size.class) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
22 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
23 factors <- c(unitobs, code.especes) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
24 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
25 return(factors) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
26 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
27 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
28 ######################################### end of the function fact.def.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
29 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
30 ######################################### start of the function def.typeobs.f called by FunctExeCalcCommIndexesGalaxy.r and FunctExeCalcPresAbsGalaxy.r |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
31 ####### Define observation type from colnames |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
32 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
33 def.typeobs.f <- function(Obs) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
34 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
35 if (any(is.element(c("rotation","rot","rotate"),colnames(obs)))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
36 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
37 ObsType <- "SVR" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
38 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
39 ObsType <- "other" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
40 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
41 return(ObsType) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
42 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
43 ######################################### end of the function fact.def.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
44 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
45 ######################################### start of the function create.unitobs called by FunctExeCalcCommIndexesGalaxy.r and FunctExeCalcPresAbsGalaxy.r |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
46 ####### Create unitobs column when inexistant |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
47 create.unitobs <- function(data,year="year",point="point", unitobs="observation.unit") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
48 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
49 if (is.element(paste(unitobs),colnames(data)) && all(grepl("[1-2][0|8|9][0-9]{2}_.*",data[,unitobs])==FALSE)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
50 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
51 unitab <- data |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
52 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
53 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
54 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
55 unitab <- unite(data,col="observation.unit",c(year,point)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
56 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
57 return(unitab) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
58 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
59 ######################################### start of the function create.unitobs |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
60 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
61 ######################################### start of the function create.year.point called by FunctExeCalcCommIndexesGalaxy.r and FunctExeCalcPresAbsGalaxy.r |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
62 ####### separate unitobs column when existant |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
63 create.year.point <- function(data,year="year",point="point", unitobs="observation.unit") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
64 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
65 if (all(grepl("[1-2][0|8|9][0-9]{2}_.*",data[,unitobs]))==TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
66 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
67 tab <- separate(data,col=unitobs,into=c(year,point),sep="_") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
68 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
69 tab <- separate(data,col=unitobs,into=c("site1", year,"obs"),sep=c(2,4)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
70 tab <- unite(tab, col=point, c("site1","obs")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
71 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
72 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
73 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
74 tab <- cbind(tab,observation.unit = data[,unitobs]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
75 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
76 return(tab) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
77 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
78 ######################################### start of the function create.unitobs |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
79 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
80 ######################################### start of the function check_file called by every Galaxy Rscripts |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
81 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
82 check_file<-function(dataset,err_msg,vars,nb_vars){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
83 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
84 ## Purpose: General function to check integrity of input file. Will |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
85 ## check numbers and contents of variables(colnames). |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
86 ## return an error message and exit if mismatch detected |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
87 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
88 ## Arguments: dataset : dataset name |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
89 ## err_msg : output error |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
90 ## vars : expected name of variables |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
91 ## nb_vars : expected number of variables |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
92 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
93 ## Author: Alan Amosse, Benjamin Yguel |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
94 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
95 if(ncol(dataset) < nb_vars){ #checking for right number of columns in the file if not = error message |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
96 cat("\nerr nb var\n") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
97 stop(err_msg, call.=FALSE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
98 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
99 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
100 for(i in vars){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
101 if(!(i %in% names(dataset))){ #checking colnames |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
102 stop(err_msg,call.=FALSE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
103 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
104 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
105 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
106 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
107 ######################################### end of the function check_file |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
108 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
109 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
110 ######################################### start of the function statRotationsNumber.f called by calc.numbers.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
111 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
112 statRotationsNumber.f <- function(factors, obs) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
113 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
114 ## Purpose: Computing abundance statistics by rotation (max, sd) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
115 ## on SVR data |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
116 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
117 ## Arguments: factors : Names of aggregation factors |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
118 ## obs : observation data |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
119 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
120 ## Author: Yves Reecht, Date: 29 oct. 2012, 16:01 modified by Coline ROYAUX 04 june 2020 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
121 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
122 ## Identification of valid rotations : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
123 if (is.element("observation.unit", factors)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
124 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
125 ## valid rotations (empty must be there as well) : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
126 rotations <- tapply(obs$rotation, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
127 as.list(obs[ , c("observation.unit", "rotation"), drop=FALSE]), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
128 function(x)length(x) > 0) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
129 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
130 ## Changing NA rotations in FALSE : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
131 rotations[is.na(rotations)] <- FALSE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
132 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
133 #stop(mltext("statRotations.err.1")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
134 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
135 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
136 ## ########################################################### |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
137 ## Abundance per rotation at chosen aggregation factors : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
138 nombresR <- tapply(obs$number, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
139 as.list(obs[ , c(factors, "rotation"), drop=FALSE]), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
140 function(x,...){ifelse(all(is.na(x)), NA, sum(x,...))}, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
141 na.rm = TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
142 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
143 ## If valid rotation NA are considered 0 : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
144 nombresR <- sweep(nombresR, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
145 match(names(dimnames(rotations)), names(dimnames(nombresR)), nomatch=NULL), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
146 rotations, # Tableau des secteurs valides (booléens). |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
147 function(x, y) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
148 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
149 x[is.na(x) & y] <- 0 # Lorsque NA et secteur valide => 0. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
150 return(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
151 }) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
152 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
153 ## ################################################## |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
154 ## Statistics : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
155 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
156 ## Means : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
157 nombresMean <- apply(nombresR, which(is.element(names(dimnames(nombresR)), factors)), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
158 function(x,...){ifelse(all(is.na(x)), NA, mean(x,...))}, na.rm=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
159 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
160 ## Maxima : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
161 nombresMax <- apply(nombresR, which(is.element(names(dimnames(nombresR)), factors)), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
162 function(x,...){ifelse(all(is.na(x)), NA, max(x,...))}, na.rm=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
163 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
164 ## SD : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
165 nombresSD <- apply(nombresR, which(is.element(names(dimnames(nombresR)), factors)), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
166 function(x,...){ifelse(all(is.na(x)), NA, sd(x,...))}, na.rm=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
167 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
168 ## Valid rotations count : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
169 nombresRotations <- apply(rotations, 1, sum, na.rm=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
170 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
171 ## Results returned as list : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
172 return(list(nombresMean=nombresMean, nombresMax=nombresMax, nombresSD=nombresSD, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
173 nombresRotations=nombresRotations, nombresTot=nombresR)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
174 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
175 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
176 ######################################### end of the function statRotationsNumber.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
177 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
178 ######################################### start of the function calcNumber.default.f called by calc.numbers.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
179 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
180 calcNumber.default.f <- function(obs, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
181 factors=c("observation.unit", "species.code", "size.class"), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
182 nbName="number") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
183 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
184 ## Purpose : Compute abundances at finest aggregation |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
185 ## --------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
186 ## Arguments: obs : observation table |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
187 ## factors : aggregation factors |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
188 ## nbName : name of abundance column. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
189 ## |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
190 ## Output: array with ndimensions = nfactors. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
191 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
192 ## Author: Yves Reecht, Date: 19 déc. 2011, 13:38 modified by Coline ROYAUX 04 june 2020 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
193 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
194 ## Sum individuals number : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
195 nbr <- tapply(obs[ , nbName], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
196 as.list(obs[ , factors]), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
197 sum, na.rm = TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
198 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
199 ## Absences as "true zero" : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
200 nbr[is.na(nbr)] <- 0 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
201 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
202 return(nbr) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
203 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
204 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
205 ######################################### end of the function calcNumber.default.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
206 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
207 ######################################### start of the function calc.numbers.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
208 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
209 calc.numbers.f <- function(obs, ObsType="", factors=c("observation.unit", "species.code", "size.class"), nbName="number") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
210 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
211 ## Purpose: Produce data.frame used as table from output of calcNumber.default.f(). |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
212 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
213 ## Arguments: obs : observation table |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
214 ## ObsType : Type of observation (SVR, LIT, ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
215 ## factors : aggregation factors |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
216 ## nbName : name of abundance column |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
217 ## |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
218 ## Output: data.frame with (N aggregation factors + 1) columns |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
219 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
220 ## Author: Yves Reecht, Date: 19 déc. 2011, 13:46 modified by Coline ROYAUX 04 june 2020 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
221 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
222 if (ObsType == "SVR") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
223 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
224 ## Compute SVR abundances statistics : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
225 statRotations <- statRotationsNumber.f(factors=factors, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
226 obs=obs) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
227 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
228 ## Mean for rotating videos (3 rotations at most times) : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
229 nbr <- statRotations[["nombresMean"]] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
230 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
231 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
232 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
233 nbr <- calcNumber.default.f(obs, factors, nbName) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
234 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
235 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
236 res <- as.data.frame(as.table(nbr), responseName=nbName) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
237 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
238 if (is.element("size.class", colnames(res))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
239 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
240 res$size.class[res$size.class == ""] <- NA |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
241 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
242 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
243 ## If integer abundances : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
244 if (isTRUE(all.equal(res[ , nbName], as.integer(res[ , nbName])))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
245 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
246 res[ , nbName] <- as.integer(res[ , nbName]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
247 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
248 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
249 if (ObsType == "SVR") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
250 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
251 ## statistics on abundances : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
252 res$number.max <- as.vector(statRotations[["nombresMax"]]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
253 res$number.sd <- as.vector(statRotations[["nombresSD"]]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
254 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
255 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
256 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
257 return(res) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
258 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
259 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
260 ######################################### end of the function calc.numbers.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
261 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
262 ######################################### start of the function presAbs.f called by calcBiodiv.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
263 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
264 presAbs.f <- function(nombres, logical=FALSE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
265 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
266 ## Purpose: Compute presence absence from abundances |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
267 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
268 ## Arguments: nombres : vector of individuals count. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
269 ## logical : (boolean) results as boolean or 0/1 ? |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
270 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
271 ## Author: Yves Reecht, Date: 29 oct. 2010, 10:20 modified by Coline ROYAUX 04 june 2020 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
272 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
273 if (any(nombres < 0, na.rm=TRUE)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
274 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
275 stop("Negative abundances!") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
276 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
277 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
278 if (logical) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
279 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
280 return(nombres > 0) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
281 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
282 nombres[nombres > 0] <- 1 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
283 return(nombres) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
284 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
285 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
286 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
287 ######################################### end of the function presAbs.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
288 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
289 ######################################### start of the function betterCbind called by agregations.generic.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
290 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
291 betterCbind <- function(..., dfList=NULL, deparse.level = 1) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
292 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
293 ## Purpose: Apply cbind to data frame with mathcing columns but without |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
294 ## redundancies. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
295 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
296 ## Arguments: same as cbind... |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
297 ## dfList : data.frames list |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
298 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
299 ## Author: Yves Reecht, Date: 17 janv. 2012, 21:10 modified by Coline ROYAUX 04 june 2020 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
300 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
301 if (is.null(dfList)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
302 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
303 dfList <- list(...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
304 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
305 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
306 return(do.call(cbind, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
307 c(list(dfList[[1]][ , c(tail(colnames(dfList[[1]]), -1), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
308 head(colnames(dfList[[1]]), 1))]), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
309 lapply(dfList[-1], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
310 function(x, colDel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
311 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
312 return(x[ , !is.element(colnames(x), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
313 colDel), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
314 drop=FALSE]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
315 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
316 colDel=colnames(dfList[[1]])), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
317 deparse.level=deparse.level))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
318 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
319 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
320 ######################################### end of the function betterCbind |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
321 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
322 ######################################### start of the function agregation.f called by agregations.generic.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
323 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
324 agregation.f <- function(metric, Data, factors, casMetrique, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
325 nbName="number") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
326 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
327 ## Purpose: metric aggregation |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
328 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
329 ## Arguments: metric: colnames of chosen metric |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
330 ## Data: Unaggregated data table |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
331 ## factors: aggregation factors vector |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
332 ## casMetrique: named vector of observation types depending |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
333 ## on chosen metric |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
334 ## nbName : abundance column name |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
335 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
336 ## Author: Yves Reecht, Date: 20 déc. 2011, 14:29 modified by Coline ROYAUX 04 june 2020 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
337 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
338 switch(casMetrique[metric], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
339 "sum"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
340 res <- tapply(Data[ , metric], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
341 as.list(Data[ , factors, drop=FALSE]), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
342 function(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
343 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
344 ifelse(all(is.na(x)), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
345 NA, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
346 sum(x, na.rm=TRUE)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
347 }) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
348 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
349 "w.mean"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
350 res <- tapply(1:nrow(Data), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
351 as.list(Data[ , factors, drop=FALSE]), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
352 function(ii) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
353 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
354 ifelse(all(is.na(Data[ii, metric])), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
355 NA, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
356 weighted.mean(Data[ii, metric], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
357 Data[ii, nbName], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
358 na.rm=TRUE)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
359 }) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
360 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
361 "w.mean.colonies"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
362 res <- tapply(1:nrow(Data), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
363 as.list(Data[ , factors, drop=FALSE]), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
364 function(ii) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
365 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
366 ifelse(all(is.na(Data[ii, metric])), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
367 NA, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
368 weighted.mean(Data[ii, metric], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
369 Data[ii, "colonies"], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
370 na.rm=TRUE)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
371 }) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
372 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
373 "w.mean.prop"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
374 res <- tapply(1:nrow(Data), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
375 as.list(Data[ , factors, drop=FALSE]), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
376 function(ii) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
377 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
378 ifelse(all(is.na(Data[ii, metric])) || sum(Data[ii, "nombre.tot"], na.rm=TRUE) == 0, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
379 NA, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
380 ifelse(all(na.omit(Data[ii, metric]) == 0), # Pour ne pas avoir NaN. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
381 0, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
382 (sum(Data[ii, nbName][ !is.na(Data[ii, metric])], na.rm=TRUE) / |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
383 sum(Data[ii, "nombre.tot"], na.rm=TRUE)) * |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
384 ## Correction if size class isn't an aggregation factor |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
385 ## (otherwise value divided by number of present classes) : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
386 ifelse(is.element("size.class", factors), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
387 100, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
388 100 * length(unique(Data$size.class))))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
389 }) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
390 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
391 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
392 "w.mean.prop.bio"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
393 res <- tapply(1:nrow(Data), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
394 as.list(Data[ , factors, drop=FALSE]), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
395 function(ii) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
396 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
397 ifelse(all(is.na(Data[ii, metric])) || sum(Data[ii, "tot.biomass"], na.rm=TRUE) == 0, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
398 NA, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
399 ifelse(all(na.omit(Data[ii, metric]) == 0), # Pour ne pas avoir NaN. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
400 0, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
401 (sum(Data[ii, "biomass"][ !is.na(Data[ii, metric])], na.rm=TRUE) / |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
402 sum(Data[ii, "tot.biomass"], na.rm=TRUE)) * |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
403 ## Correction if size class isn't an aggregation factor |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
404 ## (otherwise value divided by number of present classes) : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
405 ifelse(is.element("size.class", factors), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
406 100, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
407 100 * length(unique(Data$size.class))))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
408 }) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
409 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
410 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
411 "pres"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
412 res <- tapply(Data[ , metric], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
413 as.list(Data[ , factors, drop=FALSE]), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
414 function(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
415 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
416 ifelse(all(is.na(x)), # When only NAs. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
417 NA, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
418 ifelse(any(x > 0, na.rm=TRUE), # Otherwise... |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
419 1, # ... presence if at least one observation in the group. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
420 0)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
421 }) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
422 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
423 "nbMax"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
424 ## Recuperation of raw abundances with selections : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
425 nbTmp <- getReducedSVRdata.f(dataName=".NombresSVR", data=Data) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
426 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
427 ## Sum by factor cross / rotation : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
428 nbTmp2 <- apply(nbTmp, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
429 which(is.element(names(dimnames(nbTmp)), c(factors, "rotation"))), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
430 function(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
431 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
432 ifelse(all(is.na(x)), NA, sum(x, na.rm=TRUE)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
433 }) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
434 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
435 ## Sum by factor cross : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
436 res <- as.array(apply(nbTmp2, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
437 which(is.element(names(dimnames(nbTmp)), factors)), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
438 function(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
439 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
440 ifelse(all(is.na(x)), NA, max(x, na.rm=TRUE)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
441 })) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
442 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
443 "nbSD"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
444 ## Recuperation of raw abundances with selections : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
445 nbTmp <- getReducedSVRdata.f(dataName=".NombresSVR", data=Data) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
446 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
447 ## Sum by factor cross / rotation : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
448 nbTmp2 <- apply(nbTmp, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
449 which(is.element(names(dimnames(nbTmp)), c(factors, "rotation"))), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
450 function(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
451 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
452 ifelse(all(is.na(x)), NA, sum(x, na.rm=TRUE)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
453 }) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
454 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
455 ## Sum by factor cross : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
456 res <- as.array(apply(nbTmp2, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
457 which(is.element(names(dimnames(nbTmp)), factors)), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
458 function(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
459 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
460 ifelse(all(is.na(x)), NA, sd(x, na.rm=TRUE)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
461 })) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
462 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
463 "densMax"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
464 ## Recuperation of raw abundances with selections : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
465 densTmp <- getReducedSVRdata.f(dataName=".DensitesSVR", data=Data) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
466 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
467 ## Sum by factor cross / rotation : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
468 densTmp2 <- apply(densTmp, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
469 which(is.element(names(dimnames(densTmp)), c(factors, "rotation"))), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
470 function(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
471 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
472 ifelse(all(is.na(x)), NA, sum(x, na.rm=TRUE)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
473 }) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
474 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
475 ## Sum by factor cross : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
476 res <- as.array(apply(densTmp2, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
477 which(is.element(names(dimnames(densTmp)), factors)), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
478 function(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
479 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
480 ifelse(all(is.na(x)), NA, max(x, na.rm=TRUE)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
481 })) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
482 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
483 "densSD"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
484 ## Recuperation of raw abundances with selections : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
485 densTmp <- getReducedSVRdata.f(dataName=".DensitesSVR", data=Data) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
486 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
487 ## Sum by factor cross / rotation : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
488 densTmp2 <- apply(densTmp, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
489 which(is.element(names(dimnames(densTmp)), c(factors, "rotation"))), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
490 function(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
491 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
492 ifelse(all(is.na(x)), NA, sum(x, na.rm=TRUE)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
493 }) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
494 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
495 ## Sum by factor cross : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
496 res <- as.array(apply(densTmp2, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
497 which(is.element(names(dimnames(densTmp)), factors)), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
498 function(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
499 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
500 ifelse(all(is.na(x)), NA, sd(x, na.rm=TRUE)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
501 })) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
502 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
503 "%.nesting"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
504 res <- tapply(1:nrow(Data), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
505 as.list(Data[ , factors, drop=FALSE]), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
506 function(ii) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
507 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
508 ifelse(all(is.na(Data[ii, metric])), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
509 NA, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
510 weighted.mean(Data[ii, metric], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
511 Data[ii, "readable.tracks"], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
512 na.rm=TRUE)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
513 }) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
514 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
515 stop("Not implemented!") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
516 ) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
517 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
518 ## dimension names |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
519 names(dimnames(res)) <- c(factors) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
520 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
521 ## Transformation to long format : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
522 reslong <- as.data.frame(as.table(res), responseName=metric) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
523 reslong <- reslong[ , c(tail(colnames(reslong), 1), head(colnames(reslong), -1))] # metric first |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
524 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
525 return(reslong) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
526 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
527 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
528 ######################################### end of the function agregation.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
529 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
530 ######################################### start of the function agregations.generic.f called y calcBiodiv.f in FucntExeCalcCommIndexesGalaxy.r |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
531 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
532 agregations.generic.f <- function(Data, metrics, factors, listFact=NULL, unitSpSz=NULL, unitSp=NULL, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
533 nbName="number") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
534 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
535 ## Purpose: Aggregate data |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
536 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
537 ## Arguments: Data : data set |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
538 ## metrics : aggregated metric |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
539 ## factors : aggregation factors |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
540 ## listFact : other factors to aggregate and add to output |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
541 ## unitSpSz : Metrics table by unitobs/species/Size Class |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
542 ## unitSp : Metrics table by unitobs/species |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
543 ## nbName : abundance colname |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
544 ## |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
545 ## Output : aggregated data frame |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
546 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
547 ## Author: Yves Reecht, Date: 18 oct. 2010, 15:47 modified by Coline ROYAUX 04 june 2020 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
548 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
549 ## trt depending on metric type : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
550 casMetrique <- c("number"="sum", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
551 "mean.length"="w.mean", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
552 "taille_moy"="w.mean", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
553 "biomass"="sum", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
554 "Biomass"="sum", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
555 "weight"="sum", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
556 "mean.weight"="w.mean", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
557 "density"="sum", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
558 "Density"="sum", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
559 "CPUE"="sum", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
560 "CPUE.biomass"="sum", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
561 "pres.abs"="pres", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
562 "abundance.prop.SC"="w.mean.prop", # Not OK [!!!] ? |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
563 "biomass.prop.SC"="w.mean.prop.bio", # Not OK [!!!] ? |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
564 ## Benthos : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
565 "colonies"="sum", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
566 "coverage"="sum", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
567 "mean.size.colonies"="w.mean.colonies", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
568 ## SVR (expérimental) : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
569 "number.max"="nbMax", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
570 "number.sd"="nbSD", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
571 "density.max"="densMax", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
572 "density.sd"="densSD", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
573 "biomass.max"="sum", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
574 "spawning.success"="%.nesting", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
575 "spawnings"="sum", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
576 "readable.tracks"="sum", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
577 "tracks.number"="sum") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
578 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
579 ## add "readable.tracks" for egg laying percentage : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
580 if (any(casMetrique[metrics] == "%.nesting")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
581 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
582 if (is.element("size.class", colnames(Data))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
583 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
584 if (is.null(unitSpSz)) stop("unitSpSz doit être défini") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
585 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
586 Data <- merge(Data, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
587 unitSpSz[ , c("species.code", "observation.unit", "size.class", "readable.tracks")], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
588 by=c("species.code", "observation.unit", "size.class"), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
589 suffixes=c("", ".y")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
590 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
591 if (is.null(unitSp)) stop("unitSp must be defined") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
592 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
593 Data <- merge(Data, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
594 unitSp[ , c("species.code", "observation.unit", "readable.tracks")], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
595 by=c("species.code", "observation.unit"), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
596 suffixes=c("", ".y")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
597 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
598 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
599 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
600 ## Add "number" field for computing ponderate means if absent : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
601 if (any(casMetrique[metrics] == "w.mean" | casMetrique[metrics] == "w.mean.prop")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
602 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
603 if (is.element("size.class", colnames(Data))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
604 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
605 if (is.null(unitSpSz)) stop("unitSpSz must be defined") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
606 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
607 Data <- merge(Data, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
608 unitSpSz[ , c("species.code", "observation.unit", "size.class", nbName)], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
609 by=c("species.code", "observation.unit", "size.class"), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
610 suffixes=c("", ".y")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
611 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
612 ## add tot abundance / species / observation unit : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
613 nbTot <- tapply(unitSpSz[ , nbName], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
614 as.list(unitSpSz[ , c("species.code", "observation.unit")]), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
615 sum, na.rm=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
616 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
617 Data <- merge(Data, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
618 as.data.frame(as.table(nbTot), responseName="nombre.tot")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
619 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
620 if (is.null(unitSp)) stop("unitSp must be defined") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
621 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
622 Data <- merge(Data, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
623 unitSp[ , c("species.code", "observation.unit", nbName)], # [!!!] unitSpSz ? |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
624 by=c("species.code", "observation.unit"), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
625 suffixes=c("", ".y")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
626 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
627 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
628 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
629 ## Add biomass field of biomass proportion by size class : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
630 if (any(casMetrique[metrics] == "w.mean.prop.bio")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
631 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
632 if (is.null(unitSpSz)) stop("unitSpSz doit être défini") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
633 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
634 Data <- merge(Data, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
635 unitSpSz[ , c("species.code", "observation.unit", "size.class", "biomass")], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
636 by=c("species.code", "observation.unit", "size.class"), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
637 suffixes=c("", ".y")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
638 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
639 ## add tot biomass / species / observation unit : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
640 biomTot <- tapply(unitSpSz$biomass, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
641 as.list(unitSpSz[ , c("species.code", "observation.unit")]), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
642 function(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
643 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
644 ifelse(all(is.na(x)), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
645 NA, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
646 sum(x, na.rm=TRUE)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
647 }) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
648 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
649 Data <- merge(Data, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
650 as.data.frame(as.table(biomTot), responseName="tot.biomass")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
651 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
652 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
653 ## add colony field for ponderate means pondérées if absent : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
654 if (any(casMetrique[metrics] == "w.mean.colonies" & ! is.element("colonies", colnames(Data)))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
655 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
656 Data$colonies <- unitSp[match(apply(Data[ , c("species.code", "observation.unit")], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
657 1, paste, collapse="*"), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
658 apply(unitSp[ , c("species.code", "observation.unit")], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
659 1, paste, collapse="*")), "colonies"] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
660 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
661 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
662 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
663 ## Aggregation of metric depending on factors : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
664 reslong <- betterCbind(dfList=lapply(metrics, # sapply used to have names |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
665 agregation.f, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
666 Data=Data, factors=factors, casMetrique=casMetrique, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
667 nbName=nbName)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
668 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
669 ## Aggregation and add other factors : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
670 if ( ! (is.null(listFact) || length(listFact) == 0)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
671 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
672 reslong <- cbind(reslong, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
673 sapply(Data[ , listFact, drop=FALSE], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
674 function(fact) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
675 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
676 tapply(fact, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
677 as.list(Data[ , factors, drop=FALSE]), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
678 function(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
679 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
680 if (length(x) > 1 && length(unique(x)) > 1) # must be one modality |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
681 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
682 return(NULL) # otherwise it is NULL |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
683 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
684 unique(as.character(x)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
685 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
686 }) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
687 })) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
688 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
689 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
690 ## If some factors aren't at the right class : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
691 if (any(tmp <- sapply(reslong[ , listFact, drop=FALSE], class) != sapply(Data[ , listFact, drop=FALSE], class))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
692 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
693 for (i in which(tmp)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
694 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
695 switch(sapply(Data[ , listFact, drop=FALSE], class)[i], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
696 "integer"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
697 reslong[ , listFact[i]] <- as.integer(as.character(reslong[ , listFact[i]])) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
698 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
699 "numeric"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
700 reslong[ , listFact[i]] <- as.numeric(as.character(reslong[ , listFact[i]])) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
701 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
702 reslong[ , listFact[i]] <- eval(call(paste("as", sapply(Data[ , listFact, drop=FALSE], class)[i], sep="."), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
703 reslong[ , listFact[i]])) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
704 ) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
705 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
706 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
707 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
708 ## Initial order of factors levels : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
709 reslong <- as.data.frame(sapply(colnames(reslong), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
710 function(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
711 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
712 if (is.factor(reslong[ , x])) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
713 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
714 return(factor(reslong[ , x], levels=levels(Data[ , x]))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
715 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
716 return(reslong[ , x]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
717 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
718 }, simplify=FALSE)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
719 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
720 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
721 ## Check of other aggregated factors supplémentaires. There must be no NULL elements : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
722 if (any(sapply(reslong[ , listFact], function(x){any(is.null(unlist(x)))}))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
723 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
724 warning(paste("One of the suppl. factors is probably a subset", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
725 " of the observations grouping factor(s).", sep="")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
726 return(NULL) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
727 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
728 return(reslong) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
729 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
730 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
731 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
732 ######################################### end of the function agregations.generic.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
733 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
734 ######################################### start of the function dropLevels.f called y calcBiodiv.f in FucntExeCalcCommIndexesGalaxy.r and modeleLineaireWP2.unitobs.f in FunctExeCalcGLMGalaxy.r |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
735 dropLevels.f <- function(df, which=NULL) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
736 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
737 ## Purpose: Suppress unused levels of factors |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
738 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
739 ## Arguments: df : a data.frame |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
740 ## which : included columns index (all by default) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
741 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
742 ## Author: Yves Reecht, Date: 10 août 2010, 13:29 modified by Coline ROYAUX 04 june 2020 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
743 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
744 if (class(df) != "data.frame") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
745 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
746 stop("'df' must be a data.frame") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
747 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
748 if (is.null(which)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
749 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
750 x <- as.data.frame(sapply(df, function(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
751 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
752 return(x[ ,drop=TRUE]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
753 }, simplify=FALSE), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
754 stringsAsFactors=FALSE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
755 }else{ # Only some columns used |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
756 x <- df |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
757 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
758 x[ , which] <- as.data.frame(sapply(df[ , which, drop=FALSE], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
759 function(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
760 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
761 return(x[ , drop=TRUE]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
762 }, simplify=FALSE), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
763 stringsAsFactors=FALSE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
764 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
765 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
766 return(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
767 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
768 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
769 ######################################### end of the function dropLevels.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
770 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
771 ######################################### start of the function subsetToutesTables.f called by modeleLineaireWP2.unitobs.f in FunctExeCalcGLMGalaxy.r |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
772 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
773 subsetToutesTables.f <- function(metrique, tabMetrics, facteurs, selections, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
774 tabUnitobs, refesp, tableMetrique="", nbName="number", ObsType = "", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
775 exclude=NULL, add=c("species.code", "observation.unit")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
776 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
777 ## Purpose: Extract useful data only from chosen metrics and factors |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
778 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
779 ## Arguments: metrique : chosen metric |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
780 ## facteurs : all chosen factors |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
781 ## selections : corresponding modality selected |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
782 ## tableMetrique : metrics table name |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
783 ## exclude : factors levels to exclude |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
784 ## add : field to add to data table |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
785 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
786 ## Author: Yves Reecht, Date: 6 août 2010, 16:46 modified by Coline ROYAUX 04 june 2020 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
787 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
788 ## If no metrics table available : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
789 if (is.element(tableMetrique, c("", "TableOccurrences", "TablePresAbs"))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
790 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
791 tableMetrique <- "unitSp" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
792 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
793 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
794 casTables <- c("unitSp"="unitSp", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
795 "TablePresAbs"="unitSp", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
796 "unitSpSz"="unitSpSz") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
797 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
798 ## Recuperation of metrics table : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
799 dataMetrique <- tabMetrics |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
800 unitobs <- tabUnitobs |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
801 refesp <- refesp |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
802 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
803 ## If no metrics available or already computed : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
804 if (is.element(metrique, c("", "occurrence.frequency"))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
805 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
806 metrique <- "tmp" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
807 dataMetrique$tmp <- 0 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
808 dataMetrique$tmp[dataMetrique[ , nbName] > 0] <- 1 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
809 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
810 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
811 if (!is.null(add)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
812 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
813 metriques <- c(metrique, add[is.element(add, colnames(dataMetrique))]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
814 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
815 metriques <- metrique |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
816 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
817 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
818 ## Subset depending on metrics table |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
819 switch(casTables[tableMetrique], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
820 ## Observation table by unitobs and species : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
821 unitSp={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
822 restmp <- cbind(dataMetrique[!is.na(dataMetrique[ , metrique]) , metriques, drop=FALSE], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
823 unitobs[match(dataMetrique$observation.unit[!is.na(dataMetrique[ , metrique])], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
824 unitobs$observation.unit), # ajout des colonnes sélectionnées d'unitobs |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
825 facteurs[is.element(facteurs, colnames(unitobs))], drop=FALSE], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
826 refesp[match(dataMetrique$species.code[!is.na(dataMetrique[ , metrique])], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
827 refesp$species.code), # ajout des colonnes sélectionnées d'especes |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
828 facteurs[is.element(facteurs, colnames(refesp))], drop=FALSE]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
829 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
830 ## Observation table by unitobs, species and size class : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
831 unitSpSz={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
832 restmp <- cbind(dataMetrique[!is.na(dataMetrique[ , metrique]) , |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
833 c(metriques, "size.class"), drop=FALSE], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
834 unitobs[match(dataMetrique$observation.unit[!is.na(dataMetrique[ , metrique])], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
835 unitobs$observation.unit), # ajout des colonnes sélectionnées d'unitobs |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
836 facteurs[is.element(facteurs, colnames(unitobs))], drop=FALSE], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
837 refesp[match(dataMetrique$species.code[!is.na(dataMetrique[ , metrique])], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
838 refesp$species.code), # ajout des colonnes sélectionnées d'especes |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
839 facteurs[is.element(facteurs, colnames(refesp))], drop=FALSE]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
840 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
841 ## Other cases : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
842 restmp <- cbind(dataMetrique[!is.na(dataMetrique[ , metrique]) , metriques, drop=FALSE], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
843 unitobs[match(dataMetrique$observation.unit[!is.na(dataMetrique[ , metrique])], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
844 unitobs$observation.unit), # ajout des colonnes sélectionnées d'unitobs. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
845 facteurs[is.element(facteurs, colnames(unitobs))], drop=FALSE]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
846 ) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
847 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
848 selCol <- which(!is.na(selections)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
849 if (!is.null(exclude)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
850 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
851 selCol <- selCol[selCol != exclude] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
852 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
853 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
854 ## Particular case of size classes : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
855 if (is.element("size.class", colnames(restmp))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
856 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
857 if (length(grep("^[[:digit:]]*[-_][[:digit:]]*$", unique(as.character(restmp$size.class)), perl=TRUE)) == |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
858 length(unique(as.character(restmp$size.class)))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
859 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
860 restmp$size.class <- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
861 factor(as.character(restmp$size.class), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
862 levels=unique(as.character(restmp$size.class))[ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
863 order(as.numeric(sub("^([[:digit:]]*)[-_][[:digit:]]*$", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
864 "\\1", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
865 unique(as.character(restmp$size.class)), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
866 perl=TRUE)), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
867 na.last=FALSE)]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
868 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
869 restmp$size.class <- factor(restmp$size.class) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
870 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
871 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
872 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
873 ## Biomass and density conversion -> /100m² : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
874 if (any(is.element(colnames(restmp), c("biomass", "density", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
875 "biomass.max", "density.max", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
876 "biomass.sd", "density.sd"))) && ObsType != "fishing") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
877 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
878 restmp[ , is.element(colnames(restmp), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
879 c("biomass", "density", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
880 "biomass.max", "density.max", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
881 "biomass.sd", "density.sd"))] <- 100 * |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
882 restmp[, is.element(colnames(restmp), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
883 c("biomass", "density", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
884 "biomass.max", "density.max", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
885 "biomass.sd", "density.sd"))] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
886 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
887 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
888 return(restmp) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
889 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
890 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
891 ######################################### end of the function subsetToutesTables.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
892 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
893 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
894 ######################################### start of the function sortiesLM.f called by modeleLineaireWP2.unitobs.f in FunctExeCalcGLMGalaxy.r |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
895 sortiesLM.f <- function(objLM, TabSum, #formule, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
896 metrique, factAna, cut, colAna, listFact, lev = NULL, Data, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
897 Log=FALSE, sufixe=NULL, type="espece") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
898 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
899 ## Purpose: Form GLM and LM results |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
900 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
901 ## Arguments: objLM : lm object |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
902 ## TabSum : output summary table |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
903 ## formule : LM formula |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
904 ## metrique : Chosen metric |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
905 ## factAna : separation factor |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
906 ## cut : level of separation factor |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
907 ## colAna : colname for separation factor in output summary table |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
908 ## listFact : Analysis factors list |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
909 ## levels : Levels of analysis factors list |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
910 ## Data : Data used for analysis |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
911 ## Log : put log on metric ? (boolean) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
912 ## sufixe : sufix for file name |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
913 ## type : analysis type |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
914 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
915 ## Author: Yves Reecht, Date: 25 août 2010, 16:19 modified by Coline ROYAUX 04 june 2020 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
916 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
917 sumLM <- summary(objLM) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
918 if (length(grep("^glmmTMB", objLM$call)) > 0) #if random effects |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
919 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
920 TabSum[TabSum[,colAna]==cut,"AIC"] <- sumLM$AICtab[1] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
921 TabSum[TabSum[,colAna]==cut,"BIC"] <- sumLM$AICtab[2] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
922 TabSum[TabSum[,colAna]==cut,"logLik"] <- sumLM$AICtab[3] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
923 TabSum[TabSum[,colAna]==cut,"deviance"] <- sumLM$AICtab[4] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
924 TabSum[TabSum[,colAna]==cut,"df.resid"] <- sumLM$AICtab[5] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
925 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
926 if (! is.null(lev)) ## if fixed effects + random effects |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
927 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
928 TabCoef <- as.data.frame(sumLM$coefficients$cond) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
929 TabCoef$signif <- lapply(TabCoef[,"Pr(>|z|)"],FUN=function(x){if(!is.na(x) && x < 0.05){"yes"}else{"no"}}) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
930 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
931 TabSum[TabSum[,colAna]==cut,grepl("Intercept.*Zvalue",colnames(TabSum))] <- TabCoef[grepl("Intercept",rownames(TabCoef)),"z value"] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
932 TabSum[TabSum[,colAna]==cut,grepl("Intercept.*Pvalue",colnames(TabSum))] <- TabCoef[grepl("Intercept",rownames(TabCoef)),"Pr(>|z|)"] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
933 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
934 TabSum[TabSum[,colAna]==cut,grepl(paste(lev,"Zvalue",collapse="|"),colnames(TabSum))] <- unlist(lapply(lev,FUN=function(x){if (length(grep(x,rownames(TabCoef))) > 0) {TabCoef[grepl(x,rownames(TabCoef)),"z value"]}else{NA}})) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
935 TabSum[TabSum[,colAna]==cut,grepl(paste(lev,"Pvalue",collapse="|"),colnames(TabSum))] <- unlist(lapply(lev,FUN=function(x){if (length(grep(x,rownames(TabCoef))) > 0) {TabCoef[grepl(x,rownames(TabCoef)),"Pr(>|z|)"]}else{NA}})) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
936 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
937 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
938 switch(as.character(length(sumLM$varcor$cond)), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
939 "1"={StdD <- c(sumLM$varcor$cond[[1]])}, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
940 "2"={StdD <- c(sumLM$varcor$cond[[1]],sumLM$varcor$cond[[2]])}, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
941 StdD <- NULL) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
942 TabSum[TabSum[,colAna]==cut,grepl(paste(listRand,"Std.Dev",collapse="|"),colnames(TabSum))] <- StdD |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
943 TabSum[TabSum[,colAna]==cut,grepl(paste(listRand,"NbObservation",collapse="|"),colnames(TabSum))] <- sumLM$nobs |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
944 TabSum[TabSum[,colAna]==cut,grepl(paste(listRand,"NbLevels",collapse="|"),colnames(TabSum))] <- unlist(lapply(listRand,FUN=function(x){nlevels(Data[,x])})) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
945 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
946 }else{ ## if fixed effects only |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
947 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
948 TabSum[TabSum[,colAna]==cut,"AIC"] <- sumLM$aic |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
949 TabSum[TabSum[,colAna]==cut,"Resid.deviance"] <- sumLM$deviance |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
950 TabSum[TabSum[,colAna]==cut,"df.resid"] <- sumLM$df.residual |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
951 TabSum[TabSum[,colAna]==cut,"Null.deviance"] <- sumLM$null.deviance |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
952 TabSum[TabSum[,colAna]==cut,"df.null"] <- sumLM$df.null |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
953 TabCoef <- as.data.frame(sumLM$coefficients) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
954 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
955 if (sumLM$family[1] == "gaussian" || sumLM$family[1] == "quasipoisson") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
956 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
957 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
958 TabCoef$signif <- lapply(TabCoef[,"Pr(>|t|)"],FUN=function(x){if(!is.na(x) && x < 0.05){"yes"}else{"no"}}) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
959 TabSum[TabSum[,colAna]==cut,grepl("Intercept.*Tvalue",colnames(TabSum))] <- TabCoef[grepl("Intercept",rownames(TabCoef)),"t value"] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
960 TabSum[TabSum[,colAna]==cut,grepl("Intercept.*Pvalue",colnames(TabSum))] <- TabCoef[grepl("Intercept",rownames(TabCoef)),"Pr(>|t|)"] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
961 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
962 TabSum[TabSum[,colAna]==cut,grepl(paste(lev,"Tvalue",collapse="|"),colnames(TabSum))] <- unlist(lapply(lev,FUN=function(x){if (length(grep(x,rownames(TabCoef))) > 0) {TabCoef[grepl(x,rownames(TabCoef)),"t value"]}else{NA}})) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
963 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
964 TabSum[TabSum[,colAna]==cut,grepl(paste(lev,"Pvalue",collapse="|"),colnames(TabSum))] <- unlist(lapply(lev,FUN=function(x){if (length(grep(x,rownames(TabCoef))) > 0) {TabCoef[grepl(x,rownames(TabCoef)),"Pr(>|t|)"]}else{NA}})) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
965 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
966 TabCoef$signif <- lapply(TabCoef[,"Pr(>|z|)"],FUN=function(x){if(!is.na(x) && x < 0.05){"yes"}else{"no"}}) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
967 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
968 TabSum[TabSum[,colAna]==cut,grepl("Intercept.*Zvalue",colnames(TabSum))] <- TabCoef[grepl("Intercept",rownames(TabCoef)),"z value"] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
969 TabSum[TabSum[,colAna]==cut,grepl("Intercept.*Pvalue",colnames(TabSum))] <- TabCoef[grepl("Intercept",rownames(TabCoef)),"Pr(>|z|)"] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
970 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
971 TabSum[TabSum[,colAna]==cut,grepl(paste(lev,"Zvalue",collapse="|"),colnames(TabSum))] <- unlist(lapply(lev,FUN=function(x){if (length(grep(x,rownames(TabCoef))) > 0) {TabCoef[grepl(x,rownames(TabCoef)),"z value"]}else{NA}})) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
972 TabSum[TabSum[,colAna]==cut,grepl(paste(lev,"Pvalue",collapse="|"),colnames(TabSum))] <- unlist(lapply(lev,FUN=function(x){if (length(grep(x,rownames(TabCoef))) > 0) {TabCoef[grepl(x,rownames(TabCoef)),"Pr(>|z|)"]}else{NA}})) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
973 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
974 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
975 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
976 if (! is.null(lev)) ## if fixed effects |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
977 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
978 TabSum[TabSum[,colAna]==cut,grepl("Intercept.*Estimate",colnames(TabSum))] <- TabCoef[grepl("Intercept",rownames(TabCoef)),"Estimate"] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
979 TabSum[TabSum[,colAna]==cut,grepl("Intercept.*Std.Err",colnames(TabSum))] <- TabCoef[grepl("Intercept",rownames(TabCoef)),"Std. Error"] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
980 TabSum[TabSum[,colAna]==cut,grepl("Intercept.*signif",colnames(TabSum))] <- TabCoef[grepl("Intercept",rownames(TabCoef)),"signif"] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
981 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
982 TabSum[TabSum[,colAna]==cut,grepl(paste(lev,"Estimate",collapse="|"),colnames(TabSum))] <- unlist(lapply(lev,FUN=function(x){if (length(grep(x,rownames(TabCoef))) > 0) {TabCoef[grepl(x,rownames(TabCoef)),"Estimate"]}else{NA}})) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
983 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
984 TabSum[TabSum[,colAna]==cut,grepl(paste(lev,"Std.Err",collapse="|"),colnames(TabSum))] <- unlist(lapply(lev,FUN=function(x){if (length(grep(x,rownames(TabCoef))) > 0) {TabCoef[grepl(x,rownames(TabCoef)),"Std. Error"]}else{NA}})) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
985 TabSum[TabSum[,colAna]==cut,grepl(paste(lev,"signif",collapse="|"),colnames(TabSum))] <- unlist(lapply(lev,FUN=function(x){if (length(grep(x,rownames(TabCoef))) > 0) {TabCoef[grepl(x,rownames(TabCoef)),"signif"]}else{NA}})) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
986 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
987 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
988 return(TabSum) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
989 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
990 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
991 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
992 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
993 ######################################### end of the function sortiesLM.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
994 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
995 ######################################### start of the function graphTitle.f called by sortiesLM.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
996 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
997 graphTitle.f <- function(metrique, modGraphSel, factGraph, listFact, model=NULL, type="espece", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
998 lang = getOption("P.lang")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
999 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1000 ## Purpose: Automatically write a name for a graph |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1001 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1002 ## Arguments: |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1003 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1004 ## Author: Yves Reecht, Date: 14 oct. 2010, 15:44 modified by Coline ROYAUX 04 june 2020 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1005 return(paste(ifelse(is.null(model), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1006 "Values of ", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1007 paste(model, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1008 " for", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1009 sep="")), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1010 metrique, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1011 ifelse(is.element(type, c("espece", "unitobs", "CL_espece", "unitobs(CL)")), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1012 paste("aggregated"), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1013 ""), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1014 switch(type, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1015 "espece"=" per species and station", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1016 "CL_espece"=" per size class, species and station", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1017 "unitobs"=" per station", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1018 "unitobs(CL)"=" per station", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1019 "CL_unitobs"=" per size class and station", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1020 "biodiv"=" per station", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1021 ""), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1022 switch(type, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1023 "espece"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1024 ifelse(modGraphSel == "", # Only separation factor if defined |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1025 "", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1026 paste("\nfor the field", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1027 " '", factGraph, "' = ", modGraphSel, sep="")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1028 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1029 "CL_espece"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1030 ifelse(modGraphSel == "", # Only separation factor if defined |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1031 "", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1032 paste("\nfor the field", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1033 " '", factGraph, "' = ", modGraphSel, sep="")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1034 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1035 "unitobs"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1036 ifelse(modGraphSel[1] == "", # Only separation factor if defined |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1037 "\nfor all species", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1038 paste("\nfor all species matching", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1039 " '", factGraph, "' = (", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1040 paste(modGraphSel, collapse=", "), ")", sep="")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1041 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1042 "unitobs(CL)"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1043 ifelse(modGraphSel[1] == "", # Only separation factor if defined |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1044 "\nfor all size classes", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1045 paste("\nfor size classes matching", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1046 " '", factGraph, "' = (", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1047 paste(modGraphSel, collapse=", "), ")", sep="")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1048 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1049 "CL_unitobs"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1050 ifelse(modGraphSel[1] == "", # Only separation factor if defined |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1051 "\nfor all species", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1052 paste("\nfor all species matching", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1053 " '", factGraph, "' = (", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1054 paste(modGraphSel, collapse=", "), ")", sep="")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1055 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1056 "biodiv"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1057 ifelse(modGraphSel[1] == "", # Only separation factor if defined |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1058 "", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1059 paste("\nfor stations matching", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1060 " '", factGraph, "' = (", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1061 paste(modGraphSel, collapse=", "), ")", sep="")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1062 }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1063 ""), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1064 "\n by ", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1065 paste(sapply(listFact[length(listFact):1], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1066 function(x)paste(c(## varNames.f(x, "article"), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1067 "", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1068 x, collapse="")), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1069 collapse=" and"), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1070 "\n", sep=""))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1071 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1072 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1073 ######################################### end of the function graphTitle.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1074 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1075 ######################################### start of the function noteGLM.f called by modeleLineaireWP2.species.f and modeleLineaireWP2.unitobs.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1076 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1077 noteGLM.f <- function(data, objLM, metric, listFact, details = FALSE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1078 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1079 ## Purpose: Note your GLM analysis |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1080 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1081 ## Arguments: data : Dataframe used for analysis |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1082 ## objLM : GLM assessed |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1083 ## metric : selected metric |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1084 ## listFact : Analysis factors list |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1085 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1086 ## Author: Coline ROYAUX, 26 june 2020 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1087 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1088 rate <- 0 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1089 detres <- list(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) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1090 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1091 #### Data criterions #### |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1092 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1093 ## Plan |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1094 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1095 plan <- as.data.frame(table(data[,listFact])) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1096 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1097 if (nrow(plan[plan$Freq==0,]) < nrow(plan)*0.1) # +0.5 if less than 10% of possible factor's level combinations aren't represented in the sampling scheme |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1098 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1099 rate <- rate + 0.5 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1100 detres$complete_plan <- TRUE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1101 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1102 if (summary(as.factor(plan$Freq))[1] > nrow(plan)*0.9) # +0.5 if the frequency of the most represented frequency of possible factor's levels combinations is superior to 90% of the total number of possible factor's levels combinations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1103 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1104 rate <- rate + 0.5 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1105 detres$balanced_plan <- TRUE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1106 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1107 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1108 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1109 detres$complete_plan <- FALSE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1110 detres$balanced_plan <- FALSE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1111 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1112 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1113 if (nrow(data) - nrow(na.omit(data)) < nrow(data)*0.1) # +1 if less than 10% of the lines in the dataframe bares a NA |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1114 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1115 rate <- rate + 1 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1116 detres$NA_proportion_OK <- TRUE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1117 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1118 detres$NA_proportion_OK <- FALSE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1119 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1120 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1121 #### Model criterions #### |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1122 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1123 if (length(grep("quasi",objLM$family)) == 0) #DHARMa doesn't work with quasi distributions |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1124 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1125 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1126 Residuals <- simulateResiduals(objLM) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1127 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1128 capture.output(testRes <- testResiduals(Residuals)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1129 testZero <- testZeroInflation(Residuals) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1130 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1131 ## dispersion of residuals |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1132 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1133 if (testRes$dispersion$p.value > 0.05) # +1.5 if dispersion tests not significative |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1134 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1135 rate <- rate + 1.5 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1136 detres$no_residual_dispersion <- TRUE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1137 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1138 detres$no_residual_dispersion <- FALSE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1139 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1140 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1141 ## uniformity of residuals |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1142 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1143 if (testRes$uniformity$p.value > 0.05) # +1 if uniformity tests not significative |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1144 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1145 rate <- rate + 1.5 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1146 detres$uniform_residuals <- TRUE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1147 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1148 detres$uniform_residuals <- FALSE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1149 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1150 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1151 ## residuals outliers |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1152 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1153 if (testRes$outliers$p.value > 0.05) # +0.5 if outliers tests not significative |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1154 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1155 rate <- rate + 0.5 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1156 detres$outliers_proportion_OK <- TRUE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1157 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1158 detres$outliers_proportion_OK <- FALSE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1159 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1160 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1161 ## Zero inflation test |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1162 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1163 if (testZero$p.value > 0.05) # +1 if zero inflation tests not significative |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1164 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1165 rate <- rate + 1.5 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1166 detres$no_zero_inflation <- TRUE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1167 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1168 detres$no_zero_inflation <- FALSE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1169 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1170 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1171 ## Factors/observations ratio |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1172 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1173 if (length(listFact)/nrow(na.omit(data)) < 0.1) # +1 if quantity of factors is less than 10% of the quantity of observations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1174 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1175 rate <- rate + 1 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1176 detres$observation_factor_ratio_OK <- TRUE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1177 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1178 detres$observation_factor_ratio_OK <- FALSE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1179 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1180 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1181 ## less than 10 factors' level on random effect |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1182 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1183 if (length(grep("^glmmTMB", objLM$call)) > 0) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1184 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1185 nlevRand <- c() |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1186 for(fact in names(summary(objLM)$varcor$cond)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1187 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1188 nlevRand <- c(nlevRand,length(unlist(unique(data[,fact])))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1189 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1190 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1191 if (all(nlevRand > 10)) # +1 if more than 10 levels in one random effect |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1192 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1193 rate <- rate + 1 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1194 detres$enough_levels_random_effect <- TRUE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1195 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1196 detres$enough_levels_random_effect <- FALSE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1197 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1198 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1199 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1200 detres$rate <- rate |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1201 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1202 if (details) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1203 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1204 return(detres) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1205 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1206 return(rate) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1207 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1208 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1209 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1210 return(NA) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1211 cat("Models with quasi distributions can't be rated for now") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1212 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1213 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1214 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1215 ######################################### end of the function noteGLM.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1216 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1217 ######################################### start of the function noteGLMs.f called by modeleLineaireWP2.species.f and modeleLineaireWP2.unitobs.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1218 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1219 noteGLMs.f <- function(tabRate, exprML, objLM, file_out=FALSE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1220 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1221 ## Purpose: Note your GLM analysis |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1222 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1223 ## Arguments: data : rates table from noteGLM.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1224 ## objLM : GLM assessed |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1225 ## metric : selected metric |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1226 ## listFact : Analysis factors list |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1227 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1228 ## Author: Coline ROYAUX, 26 june 2020 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1229 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1230 RateM <- mean(na.omit(tabRate[,"rate"])) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1231 sum <- summary(objLM) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1232 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1233 if (length(grep("^glmmTMB", objLM$call)) > 0) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1234 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1235 if (median(na.omit(tabRate[,"rate"])) >= 6) # if 50% has a rate superior or equal to 6 +1 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1236 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1237 RateM <- RateM + 1 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1238 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1239 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1240 if (quantile(na.omit(tabRate[,"rate"]), probs=0.9) >= 6) # if 90% has a rate superior or equal to 6 +1 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1241 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1242 RateM <- RateM + 1 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1243 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1244 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1245 if (median(na.omit(tabRate[,"rate"])) >= 5) # if 50% has a rate superior or equal to 5 +1 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1246 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1247 RateM <- RateM + 1 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1248 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1249 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1250 if (quantile(na.omit(tabRate[,"rate"]), probs=0.9) >= 5) # if 90% has a rate superior or equal to 5 +1 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1251 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1252 RateM <- RateM + 1 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1253 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1254 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1255 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1256 if (file_out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1257 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1258 namefile <- "RatingGLM.txt" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1259 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1260 cat("###########################################################################", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1261 "\n########################### Analysis evaluation ###########################", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1262 "\n###########################################################################", file=namefile, fill=1,append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1263 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1264 ## Informations on model : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1265 cat("\n\n######################################### \nFitted model:", file=namefile, fill=1,append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1266 cat("\t", deparse(exprML), "\n\n", file=namefile, sep="",append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1267 cat("Family: ", sum$family[[1]], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1268 file=namefile,append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1269 cat("\n\nNumber of analysis: ", nrow(tabRate), file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1270 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1271 ## Global rate : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1272 cat("\n\n######################################### \nGlobal rate for all analysis:", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1273 "\n\n", RateM, "out of 10", file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1274 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1275 ## details on every GLM : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1276 #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 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1277 cat("\n\n######################################### \nDetails on every analysis:\n\n", file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1278 cat("Analysis\tC1\tC2\tC3\tC4\tC5\tC6\tC7\tC8\tC9\tFinal rate", file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1279 apply(tabRate, 1, FUN=function(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1280 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1281 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1282 if (!is.na(x["complete_plan"]) && x["complete_plan"]==TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1283 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1284 cat("\n",x[1],"\tyes", file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1285 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1286 cat("\n",x[1],"\tno", file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1287 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1288 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1289 for (i in c("balanced_plan","NA_proportion_OK", "no_residual_dispersion", "uniform_residuals", "outliers_proportion_OK", "no_zero_inflation", "observation_factor_ratio_OK", "enough_levels_random_effect")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1290 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1291 if (!is.na(x[i]) && x[i]==TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1292 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1293 cat("\tyes", file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1294 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1295 cat("\tno", file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1296 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1297 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1298 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1299 cat("\t",x["rate"], "/ 8", file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1300 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1301 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1302 }) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1303 cat("\n\nC1: Complete plan?\nC2: Balanced plan?\nC3: Few NA?\nC4: Regular dispersion?\nC5: Uniform residuals?\nC6: Regular outliers proportion?\nC7: No zero-inflation?\nC8: Enough observations for the amount of factors?\nC9: Enough levels on random effect?", file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1304 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1305 ## Red flags - advice : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1306 cat("\n\n######################################### \nRed flags - advice:\n\n", file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1307 if (all(na.omit(tabRate["NA_proportion_OK"]) == FALSE)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1308 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1309 cat("\n","\t- More than 10% of your dataset bares NAs", file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1310 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1311 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1312 if (length(grep("FALSE",tabRate["no_residual_dispersion"])) / length(na.omit(tabRate["no_residual_dispersion"])) > 0.5) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1313 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1314 cat("\n","\t- More than 50% of your analyses are over- or under- dispersed : Try with another distribution family", file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1315 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1316 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1317 if (length(grep("FALSE",tabRate["uniform_residuals"])) / length(na.omit(tabRate["uniform_residuals"])) > 0.5) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1318 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1319 cat("\n","\t- More than 50% of your analyses haven't an uniform distribution of residuals : Try with another distribution family", file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1320 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1321 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1322 if (length(grep("FALSE",tabRate["outliers_proportion_OK"])) / length(na.omit(tabRate["outliers_proportion_OK"])) > 0.5) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1323 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1324 cat("\n","\t- More than 50% of your analyses have too much outliers : Try with another distribution family or try to select your data", file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1325 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1326 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1327 if (length(grep("FALSE",tabRate["no_zero_inflation"])) / length(na.omit(tabRate["no_zero_inflation"])) > 0.5) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1328 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1329 cat("\n","\t- More than 50% of your analyses have zero inflation : Try to select your data", file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1330 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1331 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1332 if (length(grep("FALSE",tabRate["observation_factor_ratio_OK"])) / length(na.omit(tabRate["observation_factor_ratio_OK"])) > 0.5) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1333 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1334 cat("\n","\t- More than 50% of your analyses have not enough observations for the amount of factors : Try to use less factors in your analysis or try to use another separation factor", file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1335 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1336 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1337 if (any(tabRate["enough_levels_random_effect"] == FALSE, na.rm=TRUE) && length(grep("^glmmTMB", objLM$call)) > 0) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1338 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1339 cat("\n","\t- Random effect hasn't enough levels to be robust : If it has less than ten levels remove the random effect", file=namefile, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1340 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1341 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1342 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1343 return(RateM) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1344 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1345 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1346 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1347 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1348 ######################################### end of the function noteGLM.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1349 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1350 ######################################### start of the function infoStats.f called by modeleLineaireWP2.species.f and modeleLineaireWP2.unitobs.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1351 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1352 infoStats.f <- function(filename, Data, agregLevel=c("species", "unitobs"), type=c("graph", "stat"), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1353 metrique, factGraph, factGraphSel, listFact, listFactSel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1354 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1355 ## Purpose: Écrire les infos et statistic sur les données associées à |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1356 ## un graphique ou analyse. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1357 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1358 ## Arguments: filename : chemin du fichier de résultats. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1359 ## Data : données du graphique/de l'analyse. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1360 ## agregLevel : niveau d'agrégation de la fonction appelante. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1361 ## type : type de fonction appelante (grapique ou analyse). |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1362 ## metrique : la métrique choisie. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1363 ## factGraph : le facteur sélection des espèces. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1364 ## factGraphSel : la sélection de modalités pour ce dernier |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1365 ## listFact : liste du (des) facteur(s) de regroupement |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1366 ## listFactSel : liste des modalités sélectionnées pour ce(s) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1367 ## dernier(s) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1368 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1369 ## Author: Yves Reecht, Date: 10 sept. 2012, 15:26 modified by Coline ROYAUX 04 june 2020 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1370 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1371 ## Open file : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1372 File <- file(description=filename, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1373 open="w", encoding="latin1") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1374 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1375 ## if error : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1376 on.exit(if (exists("filename") && |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1377 tryCatch(isOpen(File), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1378 error=function(e)return(FALSE))) close(File)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1379 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1380 ## Metrics and factors infos : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1381 printSelectionInfo.f(metrique=metrique, #factGraph=factGraph, factGraphSel=factGraphSel, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1382 listFact=listFact, #listFactSel=listFactSel, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1383 File=File, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1384 agregLevel=agregLevel, type=type) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1385 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1386 ## statistics : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1387 if (class(Data) == "list") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1388 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1389 cat("\n###################################################", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1390 "\nStatistics per level of splitting factor:\n", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1391 sep="", file=File,append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1392 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1393 invisible(sapply(1:length(Data), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1394 function(i) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1395 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1396 printStats.f(Data=Data[[i]], metrique=metrique, listFact=listFact, File=File, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1397 headline=factGraphSel[i]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1398 })) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1399 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1400 printStats.f(Data=Data, metrique=metrique, listFact=listFact, File=File, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1401 headline=NULL) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1402 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1403 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1404 ## Close file : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1405 close(File) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1406 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1407 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1408 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1409 ######################################### end of the function infoStats.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1410 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1411 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1412 ######################################### start of the function printSelectionInfo.f called by infoStats.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1413 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1414 printSelectionInfo.f <- function(metrique, listFact, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1415 File, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1416 agregLevel=c("species", "unitobs"), type=c("graph", "stat")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1417 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1418 ## Purpose: Write data informations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1419 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1420 ## Arguments: metrique : chosen metric |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1421 ## listFact : factor's list |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1422 ## File : Results file name |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1423 ## agregLevel : aggregation level |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1424 ## type : function type |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1425 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1426 ## Author: Yves Reecht, Date: 11 sept. 2012, 10:41 modified by Coline ROYAUX 04 june 2020 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1427 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1428 cat("\n##################################################\n", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1429 "Metrics and factors (and possible units/selections):\n", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1430 sep="", file=File,append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1431 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1432 ## metric info : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1433 cat("\n Metrics:", metrique, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1434 "\n", file=File,append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1435 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1436 ## aggregation level : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1437 cat(" aggregated per ", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1438 switch(agregLevel, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1439 "CL_espece"=,"CL_unitobs"=,"spCL_unitobs"=,"spCL_espece"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1440 "size class / " |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1441 }), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1442 switch(agregLevel, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1443 "CL_espece"=,"spCL_espece"=,"species"=,"spSpecies"=,"spEspece"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1444 "species / " |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1445 }), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1446 switch(agregLevel, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1447 "spUnitobs"=,"spCL_unitobs"=,"spCL_espece"=,"spUnitobs(CL)"=,"spSpecies"=,"spEspece"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1448 paste(listFact, " (mean over ", sep="") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1449 }), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1450 "observation units", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1451 switch(agregLevel, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1452 "spUnitobs"=,"spCL_unitobs"=,"spCL_espece"=,"spUnitobs(CL)"=,"spSpecies"=,"spEspece"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1453 ")" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1454 }), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1455 ".\n", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1456 sep="", file=File,append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1457 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1458 ## Separation factors : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1459 # switch(agregLevel, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1460 # "species"=,"CL_espece"=,"espece"={ # Adapté également pour les LMs. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1461 # cat("\n", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1462 # switch(type, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1463 # "graph"="Graphics separation factor", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1464 # "stat"="Analyses separation factor"), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1465 # " : ", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1466 # ifelse(factGraph == "", "printSelectionInfo.f.11", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1467 # ifelse(is.na(factGraphSel[1]), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1468 # paste(varNames.f(factGraph, "nom"), "none!"), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1469 # paste(varNames.f(factGraph, "nom"), " (", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1470 # paste(factGraphSel, collapse=", "), ")", sep=""))), "\n", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1471 # sep="", file=File,append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1472 # }, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1473 # "unitobs"=,"CL_unitobs"=,"unitobs(CL)"=,"spUnitobs"={ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1474 # cat("(warning: no selection!!!)", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1475 # ifelse(factGraph == "", "\nSelection factor for aggregation of observations: ", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1476 # ifelse(is.na(factGraphSel[1]), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1477 # paste(varNames.f(factGraph, "nom"), "none (all species/size classes)!"), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1478 # paste(varNames.f(factGraph, "nom"), " (", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1479 # paste(factGraphSel, collapse=", "), ")", sep=""))), "\n", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1480 # sep="", file=File,append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1481 # }) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1482 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1483 ## Clustering factors : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1484 if (is.element(agregLevel, c("spCL_unitobs", "spCL_espece", "spSpecies", "spEspece", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1485 "spUnitobs", "spUnitobs(CL)"))) {type <- "spatialGraph"} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1486 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1487 cat(switch(type, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1488 "graph"="\nGrouping factor(s): \n * ", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1489 "stat"="\nAnalyses factor(s): \n * ", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1490 "spatialGraph"="\nSpatial aggregation factor(s): \n * "), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1491 paste(listFact,collaspe="\n * "),"\n",file=File,append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1492 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1493 # invisible(sapply(1:length(listFact), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1494 # function(i) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1495 # { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1496 # cat("\n * ", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1497 # ifelse(is.na(listFactSel[[i]][1]), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1498 # paste(varNames.f(listFact[i], "nom"), "(no selection)"), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1499 # paste(varNames.f(listFact[i], "nom"), " (", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1500 # paste(listFactSel[[i]], collapse=", "), ")", sep="")), "\n", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1501 # sep="", file=File,append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1502 # })) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1503 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1504 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1505 ######################################### end of the function printSelectionInfo.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1506 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1507 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1508 ######################################### start of the function printStats.f called by infoStats.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1509 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1510 printStats.f <- function(Data, metrique, listFact, File, headline=NULL) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1511 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1512 ## Purpose: Write general statistics table |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1513 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1514 ## Arguments: Data : Analysis data |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1515 ## metrique : metric's name |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1516 ## listFact : Factor's list |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1517 ## File : Simple statistics file name |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1518 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1519 ## Author: Yves Reecht, Date: 11 sept. 2012, 10:09 modified by Coline ROYAUX 04 june 2020 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1520 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1521 ## Header : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1522 if ( ! is.null(headline)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1523 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1524 cat("\n", rep("#", nchar(headline) + 3), "\n", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1525 "## ", headline, "\n", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1526 sep="", file=File,append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1527 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1528 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1529 cat("\n########################\nBase statistics:\n\n", file=File,append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1530 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1531 capture.output(print(summary.fr(Data[ , metrique])), file=File, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1532 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1533 if ( ! is.null(listFact)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1534 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1535 cat("\n#########################################", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1536 "\nStatistics per combination of factor levels:\n\n", file=File, sep="",append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1537 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1538 ## Compute summary for each existing factor's cross : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1539 res <- with(Data, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1540 tapply(eval(parse(text=metrique)), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1541 INDEX=do.call(paste, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1542 c(lapply(listFact, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1543 function(y)eval(parse(text=y))), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1544 sep=".")), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1545 FUN=summary.fr)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1546 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1547 ## results in table |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1548 capture.output(print(do.call(rbind, res)), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1549 file=File, append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1550 }else{} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1551 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1552 ## empty line : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1553 cat("\n", file=File,append=TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1554 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1555 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1556 ######################################### end of the function printStats.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1557 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1558 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1559 ######################################### start of the function summary.fr called by printStats.f |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1560 summary.fr <- function(object, digits = max(3, getOption("digits") - 3),...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1561 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1562 ## Purpose: Adding SD and N to summary |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1563 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1564 ## Arguments: object : Object to summarise |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1565 ## ---------------------------------------------------------------------- |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1566 ## Author: Yves Reecht, Date: 13 sept. 2012, 15:47 modified by Coline ROYAUX 04 june 2020 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1567 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1568 if ( ! is.numeric(object)) stop("Programming error") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1569 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1570 ## Compute summary : |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1571 res <- c(summary(object=object, digits, ...), "sd"=signif(sd(x=object), digits=digits), "N"=length(object)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1572 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1573 return(res) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1574 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1575 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1576 ######################################### start of the function summary.fr |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1577 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1578 ######################################### Package DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1579 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1580 ################ simulateResiduals.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1581 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1582 #' Create simulated residuals |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1583 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1584 #' The function creates scaled residuals by simulating from the fitted model. Residuals can be extracted with \code{\link{residuals.DHARMa}}. See \code{\link{testResiduals}} for an overview of residual tests, \code{\link{plot.DHARMa}} for an overview of available plots. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1585 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1586 #' @param fittedModel a fitted model of a class supported by DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1587 #' @param n number of simulations. Default is 100. A more save value would be 250 or even 1000. The smaller the number, the higher the stochastic error on the residuals. Also, for very small n, discretization artefacts can influence the tests. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1588 #' @param refit if FALSE, new data will be simulated and scaled residuals will be created by comparing observed data with new data. If TRUE, the model will be refit on the simulated data (parametric bootstrap), and scaled residuals will be created by comparing observed with refitted residuals. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1589 #' @param integerResponse if TRUE, noise will be added at to the residuals to maintain a uniform expectations for integer responses (such as Poisson or Binomial). Usually, the model will automatically detect the appropriate setting, so there is no need to adjust this setting. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1590 #' @param plot if TRUE, \code{\link{plotResiduals}} will be directly run after the residuals have been calculated |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1591 #' @param ... parameters to pass to the simulate function of the model object. An important use of this is to specify whether simulations should be conditional on the current random effect estimates, e.g. via re.form. Note that not all models support syntax to specify conditionao or unconditional simulations. See also details |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1592 #' @param seed the random seed to be used within DHARMa. The default setting, recommended for most users, is keep the random seed on a fixed value 123. This means that you will always get the same randomization and thus teh same result when running the same code. NULL = no new seed is set, but previous random state will be restored after simulation. FALSE = no seed is set, and random state will not be restored. The latter two options are only recommended for simulation experiments. See vignette for details. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1593 #' @param method the quantile randomization method used. The two options implemented at the moment are probability integral transform (PIT-) residuals (current default), and the "traditional" randomization procedure, that was used in DHARMa until version 0.3.0. For details, see \code{\link{getQuantile}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1594 #' @return An S3 class of type "DHARMa", essentially a list with various elements. Implemented S3 functions include plot, print and \code{\link{residuals.DHARMa}}. Residuals returns the calculated scaled residuals. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1595 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1596 #' @details There are a number of important considerations when simulating from a more complex (hierarchical) model: |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1597 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1598 #' \strong{Re-simulating random effects / hierarchical structure}: in a hierarchical model, we have several stochastic processes aligned on top of each other. Specifically, in a GLMM, we have a lower level stochastic process (random effect), whose result enters into a higher level (e.g. Poisson distribution). For other hierarchical models such as state-space models, similar considerations apply. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1599 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1600 #' In such a situation, we have to decide if we want to re-simulate all stochastic levels, or only a subset of those. For example, in a GLMM, it is common to only simulate the last stochastic level (e.g. Poisson) conditional on the fitted random effects. This is often referred to as a conditional simuation. For controlling how many levels should be re-simulated, the simulateResidual function allows to pass on parameters to the simulate function of the fitted model object. Please refer to the help of the different simulate functions (e.g. ?simulate.merMod) for details. For merMod (lme4) model objects, the relevant parameters are parameters are use.u and re.form |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1601 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1602 #' If the model is correctly specified, the simulated residuals should be flat regardless how many hierarchical levels we re-simulate. The most thorough procedure would therefore be to test all possible options. If testing only one option, I would recommend to re-simulate all levels, because this essentially tests the model structure as a whole. This is the default setting in the DHARMa package. A potential drawback is that re-simulating the lower-level random effects creates more variability, which may reduce power for detecting problems in the upper-level stochastic processes. In particular dispersion tests may produce different results when switching from conditional to unconditional simulations, and often the conditional simulation is more sensitive. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1603 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1604 #' \strong{Integer responses}: a second complication is the treatment of inter responses. Imaging we have observed a 0, and we predict 30\% zeros - what is the quantile that we should display for the residual? To deal with this problem and maintain a uniform response, the option integerResponse adds a uniform noise from -0.5 to 0.5 on the simulated and observed response, which creates a uniform distribution - you can see this via hist(ecdf(runif(10000))(runif(10000))). |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1605 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1606 #' DHARMa will try to automatically if the fitted model has an integer or discrete distribution via the family argument. However, in some cases the family does not allow to uniquely identify the distribution type. For example, a tweedie distribution can be inter or continuous. Therefore, DHARMa will additionally check the simulation results for repeated values, and will change the distribution type if repeated values are found (a message is displayed in this case). |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1607 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1608 #' \strong{Refitting or not}: a third issue is how residuals are calculated. simulateResiduals has two options that are controlled by the refit parameter: |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1609 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1610 #' 1. if refit = FALSE (default), new data is simulated from the fitted model, and residuals are calculated by comparing the observed data to the new data |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1611 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1612 #' 2. if refit = TRUE, a parametric bootstrap is performed, meaning that the model is refit on the new data, and residuals are created by comparing observed residuals against refitted residuals. I advise against using this method per default (see more comments in the vignette), unless you are really sure that you need it. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1613 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1614 #' \strong{Residuals per group}: In many situations, it can be useful to look at residuals per group, e.g. to see how much the model over / underpredicts per plot, year or subject. To do this, use \code{\link{recalculateResiduals}}, together with a grouping variable (see also help) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1615 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1616 #' \strong{Transformation to other distributions}: DHARMa calculates residuals for which the theoretical expectation (assuming a correctly specified model) is uniform. To transfor this residuals to another distribution (e.g. so that a correctly specified model will have normal residuals) see \code{\link{residuals.DHARMa}}. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1617 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1618 #' @seealso \code{\link{testResiduals}}, \code{\link{plot.DHARMa}}, \code{\link{plotResiduals}}, \code{\link{print.DHARMa}}, \code{\link{residuals.DHARMa}}, \code{\link{recalculateResiduals}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1619 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1620 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1621 #' @example inst/examples/simulateResidualsHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1622 #' @import stats |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1623 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1624 simulateResiduals <- function(fittedModel, n = 250, refit = F, integerResponse = NULL, plot = F, seed = 123, method = c("PIT", "traditional"), ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1625 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1626 ######## general assertions and startup calculations ########## |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1627 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1628 if (n < 2) stop("error in DHARMa::simulateResiduals: n > 1 is required to calculate scaled residuals") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1629 checkModel(fittedModel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1630 match.arg(method) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1631 randomState <-getRandomState(seed) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1632 on.exit({randomState$restoreCurrent()}) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1633 ptm <- proc.time() |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1634 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1635 ####### extract model info ############ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1636 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1637 out = list() |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1638 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1639 family = family(fittedModel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1640 out$fittedModel = fittedModel |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1641 out$modelClass = class(fittedModel)[1] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1642 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1643 out$nObs = nobs(fittedModel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1644 out$nSim = n |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1645 out$refit = refit |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1646 out$observedResponse = getObservedResponse(fittedModel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1647 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1648 if(is.null(integerResponse)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1649 if (family$family %in% c("binomial", "poisson", "quasibinomial", "quasipoisson", "Negative Binom", "nbinom2", "nbinom1", "genpois", "compois", "truncated_poisson", "truncated_nbinom2", "truncated_nbinom1", "betabinomial", "Poisson", "Tpoisson", "COMPoisson", "negbin", "Tnegbin") | grepl("Negative Binomial",family$family) ) integerResponse = TRUE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1650 else integerResponse = FALSE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1651 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1652 out$integerResponse = integerResponse |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1653 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1654 out$problems = list() |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1655 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1656 # re-form should be set to ~0 to avoid spurious residual patterns, see https://github.com/florianhartig/DHARMa/issues/43 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1657 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1658 if(out$modelClass %in% c("HLfit")){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1659 out$fittedPredictedResponse = predict(fittedModel, type = "response", re.form = ~0)[,1L] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1660 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1661 out$fittedPredictedResponse = predict(fittedModel, type = "response", re.form = ~0) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1662 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1663 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1664 out$fittedFixedEffects = getFixedEffects(fittedModel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1665 out$fittedResiduals = residuals(fittedModel, type = "response") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1666 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1667 ######## refit = F ################## |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1668 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1669 if (refit == FALSE){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1670 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1671 out$simulatedResponse = getSimulations(fittedModel, nsim = n, type = "normal", ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1672 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1673 checkSimulations(out$simulatedResponse, out$nObs, out$nSim) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1674 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1675 out$scaledResiduals = getQuantile(simulations = out$simulatedResponse , observed = out$observedResponse , integerResponse = integerResponse, method = method) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1676 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1677 ######## refit = T ################## |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1678 } else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1679 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1680 # Adding new outputs |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1681 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1682 out$refittedPredictedResponse <- matrix(nrow = out$nObs, ncol = n ) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1683 out$refittedFixedEffects <- matrix(nrow = length(out$fittedFixedEffects), ncol = n ) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1684 #out$refittedRandomEffects <- matrix(nrow = length(out$fittedRandomEffects), ncol = n ) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1685 out$refittedResiduals = matrix(nrow = out$nObs, ncol = n) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1686 out$refittedPearsonResiduals = matrix(nrow = out$nObs, ncol = n) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1687 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1688 out$simulatedResponse = getSimulations(fittedModel, nsim = n, type = "refit", ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1689 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1690 for (i in 1:n){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1691 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1692 simObserved = out$simulatedResponse[[i]] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1693 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1694 try({ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1695 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1696 # for testing |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1697 # if (i==3) stop("x") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1698 # Note: also set silent = T for production |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1699 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1700 refittedModel = getRefit(fittedModel, simObserved) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1701 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1702 out$refittedPredictedResponse[,i] = predict(refittedModel, type = "response") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1703 out$refittedFixedEffects[,i] = getFixedEffects(refittedModel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1704 out$refittedResiduals[,i] = residuals(refittedModel, type = "response") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1705 out$refittedPearsonResiduals[,i] = residuals(refittedModel, type = "pearson") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1706 #out$refittedRandomEffects[,i] = ranef(refittedModel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1707 }, silent = TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1708 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1709 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1710 ######### residual checks ########### |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1711 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1712 if(anyNA(out$refittedResiduals)) warning("DHARMa::simulateResiduals warning: on refit = TRUE, at least one of the refitted models produced an error. Inspect the refitted model values. Results may not be reliable.") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1713 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1714 ## check for convergence problems |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1715 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1716 dup = sum(duplicated(out$refittedFixedEffects, MARGIN = 2)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1717 if (dup > 0){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1718 if (dup < n/3){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1719 warning(paste("There were", dup, "of", n ,"duplicate parameter estimates in the refitted models. This may hint towards a problem with optimizer convergence in the fitted models. Results may not be reliable. The suggested action is to not use the refitting procedure, and diagnose with tools available for the normal (not refitted) simulated residuals. If you absolutely require the refitting procedure, try changing tolerance / iterations in the optimizer settings.")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1720 } else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1721 warning(paste("There were", dup, "of", n ,"duplicate parameter estimates in the refitted models. This may hint towards a problem with optimizer convergence in the fitted models. Results are likely not reliable. The suggested action is to not use the refitting procedure, and diagnose with tools available for the normal (not refitted) simulated residuals. If you absolutely require the refitting procedure, try changing tolerance / iterations in the optimizer settings.")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1722 out$problems[[length(out$problems)+ 1]] = "error in refit" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1723 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1724 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1725 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1726 ######### residual calculations ########### |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1727 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1728 out$scaledResiduals = getQuantile(simulations = out$refittedResiduals, observed = out$fittedResiduals, integerResponse = integerResponse, method = method) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1729 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1730 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1731 ########### Wrapup ############ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1732 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1733 out$time = proc.time() - ptm |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1734 out$randomState = randomState |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1735 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1736 class(out) = "DHARMa" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1737 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1738 if(plot == TRUE) plot(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1739 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1740 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1741 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1742 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1743 getPossibleModels<-function()c("lm", "glm", "negbin", "lmerMod", "glmerMod", "gam", "bam", "glmmTMB", "HLfit") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1744 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1745 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1746 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1747 #' Check if the fitted model is supported by DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1748 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1749 #' The function checks if the fitted model is supported by DHARMa, and if there are other issues that could create problems |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1750 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1751 #' @param fittedModel a fitted model |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1752 #' @param stop whether to throw an error if the model is not supported by DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1753 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1754 #' @details The main purpose of this function os to check if the fitted model class is supported by DHARMa. The function additionally checks for properties of the fitted model that could create problems for calculating residuals or working with the resuls in DHARMa. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1755 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1756 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1757 #' @keywords internal |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1758 checkModel <- function(fittedModel, stop = F){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1759 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1760 out = T |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1761 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1762 if(!(class(fittedModel)[1] %in% getPossibleModels())){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1763 if(stop == FALSE) warning("DHARMa: fittedModel not in class of supported models. Absolutely no guarantee that this will work!") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1764 else stop("DHARMa: fittedModel not in class of supported models") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1765 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1766 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1767 # if(hasNA(fittedModel)) message("It seems there were NA values in the data used for fitting the model. This can create problems if you supply additional data to DHARMa functions. See ?checkModel for details") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1768 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1769 # TODO: check as implemented does not work reliably, check if there is any other option to check for NA |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1770 # #' @example inst/examples/checkModelHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1771 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1772 # NA values in the data: checkModel will detect if there were NA values in the data frame. For NA values, most regression models will remove the entire observation from the data. This is not a problem for DHARMa - residuals are then only calculated for non-NA rows in the data. However, if you provide additional predictors to DHARMa, for example to plot residuals against a predictor, you will have to remove all NA rows that were also removed in the model. For most models, you can get the rows of the data that were actually used in the fit via rownames(model.frame(fittedModel)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1773 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1774 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1775 if (class(fittedModel)[1] == "gam" ) if (class(fittedModel$family)[1] == "extended.family") stop("It seems you are trying to fit a model from mgcv that was fit with an extended.family. Simulation functions for these families are not yet implemented in DHARMa. See issue https://github.com/florianhartig/DHARMa/issues/11 for updates about this") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1776 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1777 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1778 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1779 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1780 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1781 #' Check simulated data |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1782 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1783 #' The function checks if the simulated data seems fine |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1784 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1785 #' @param simulatedResponse the simulated response |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1786 #' @param nObs number of observations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1787 #' @param nSim number of simulations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1788 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1789 #' @keywords internal |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1790 checkSimulations <- function(simulatedResponse, nObs, nSim){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1791 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1792 if(!inherits(simulatedResponse, "matrix")) securityAssertion("Simulation from the model produced wrong class", stop = T) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1793 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1794 if(any(dim(simulatedResponse) != c(nObs, nSim) )) securityAssertion("Simulation from the model produced wrong dimension", stop = T) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1795 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1796 if(any(!is.finite(simulatedResponse))) message("Simulations from your fitted model produce infinite values. Consider if this is sensible") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1797 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1798 if(any(is.nan(simulatedResponse))) securityAssertion("Simulations from your fitted model produce NaN values. DHARMa cannot calculated residuals for this. This is nearly certainly an error of the regression package you are using", stop = T) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1799 if(any(is.na(simulatedResponse))) securityAssertion("Simulations from your fitted model produce NA values. DHARMa cannot calculated residuals for this. This is nearly certainly an error of the regression package you are using", stop = T) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1800 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1801 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1802 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1803 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1804 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1805 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1806 #' Recalculate residuals with grouping |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1807 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1808 #' The purpose of this function is to recalculate scaled residuals per group, based on the simulations done by \code{\link{simulateResiduals}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1809 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1810 #' @param simulationOutput an object with simulated residuals created by \code{\link{simulateResiduals}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1811 #' @param group group of each data point |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1812 #' @param aggregateBy function for the aggregation. Default is sum. This should only be changed if you know what you are doing. Note in particular that the expected residual distribution might not be flat any more if you choose general functions, such as sd etc. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1813 #' @param seed the random seed to be used within DHARMa. The default setting, recommended for most users, is keep the random seed on a fixed value 123. This means that you will always get the same randomization and thus teh same result when running the same code. NULL = no new seed is set, but previous random state will be restored after simulation. FALSE = no seed is set, and random state will not be restored. The latter two options are only recommended for simulation experiments. See vignette for details. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1814 #' @param method the quantile randomization method used. The two options implemented at the moment are probability integral transform (PIT-) residuals (current default), and the "traditional" randomization procedure, that was used in DHARMa until version 0.3.0. For details, see \code{\link{getQuantile}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1815 #' @return an object of class DHARMa, similar to what is returned by \code{\link{simulateResiduals}}, but with additional outputs for the new grouped calculations. Note that the relevant outputs are 2x in the object, the first is the grouped calculations (which is returned by $name access), and later another time, under identical name, the original output. Moreover, there is a function 'aggregateByGroup', which can be used to aggregate predictor variables in the same way as the variables calculated here |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1816 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1817 #' @example inst/examples/simulateResidualsHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1818 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1819 recalculateResiduals <- function(simulationOutput, group = NULL, aggregateBy = sum, seed = 123, method = c("PIT", "traditional")){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1820 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1821 randomState <-getRandomState(seed) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1822 on.exit({randomState$restoreCurrent()}) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1823 match.arg(method) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1824 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1825 if(!is.null(simulationOutput$original)) simulationOutput = simulationOutput$original |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1826 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1827 out = list() |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1828 out$original = simulationOutput |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1829 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1830 if(is.null(group)) return(simulationOutput) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1831 else group =as.factor(group) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1832 out$nGroups = nlevels(group) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1833 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1834 aggregateByGroup <- function(x) aggregate(x, by=list(group), FUN=aggregateBy)[,2] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1835 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1836 out$observedResponse = aggregateByGroup(simulationOutput$observedResponse) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1837 out$fittedPredictedResponse = aggregateByGroup(simulationOutput$fittedPredictedResponse) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1838 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1839 if (simulationOutput$refit == F){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1840 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1841 out$simulatedResponse = apply(simulationOutput$simulatedResponse, 2, aggregateByGroup) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1842 out$scaledResiduals = getQuantile(simulations = out$simulatedResponse , observed = out$observedResponse , integerResponse = simulationOutput$integerResponse, method = method) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1843 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1844 ######## refit = T ################## |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1845 } else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1846 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1847 out$refittedPredictedResponse <- apply(simulationOutput$refittedPredictedResponse, 2, aggregateByGroup) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1848 out$fittedResiduals = aggregateByGroup(simulationOutput$fittedResiduals) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1849 out$refittedResiduals = apply(simulationOutput$refittedResiduals, 2, aggregateByGroup) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1850 out$refittedPearsonResiduals = apply(simulationOutput$refittedPearsonResiduals, 2, aggregateByGroup) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1851 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1852 out$scaledResiduals = getQuantile(simulations = out$refittedResiduals , observed = out$fittedResiduals , integerResponse = simulationOutput$integerResponse, method = method) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1853 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1854 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1855 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1856 # hack - the c here will result in both old and new outputs to be present resulting output, but a named access should refer to the new, grouped calculations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1857 # question to myself - what's the use of that, why not erase the old outputs? they are anyway saved in the old object |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1858 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1859 out$aggregateByGroup = aggregateByGroup |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1860 out = c(out, simulationOutput) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1861 out$randomState = randomState |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1862 class(out) = "DHARMa" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1863 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1864 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1865 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1866 ################ simulateResiduals.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1867 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1868 ################ DHARMa.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1869 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1870 #' @title DHARMa - Residual Diagnostics for HierArchical (Multi-level / Mixed) Regression Models |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1871 #' @name DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1872 #' @docType package |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1873 #' @description The 'DHARMa' package uses a simulation-based approach to create readily interpretable scaled (quantile) residuals for fitted (generalized) linear mixed models. Currently supported are linear and generalized linear (mixed) models from 'lme4' (classes 'lmerMod', 'glmerMod'), 'glmmTMB' and 'spaMM', generalized additive models ('gam' from 'mgcv'), 'glm' (including 'negbin' from 'MASS', but excluding quasi-distributions) and 'lm' model classes. Moreover, externally created simulations, e.g. posterior predictive simulations from Bayesian software such as 'JAGS', 'STAN', or 'BUGS' can be processed as well. The resulting residuals are standardized to values between 0 and 1 and can be interpreted as intuitively as residuals from a linear regression. The package also provides a number of plot and test functions for typical model misspecification problems, such as over/underdispersion, zero-inflation, and residual spatial and temporal autocorrelation. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1874 #' @details See index / vignette for details |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1875 #' @seealso \code{\link{simulateResiduals}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1876 #' @examples |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1877 #' vignette("DHARMa", package="DHARMa") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1878 NULL |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1879 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1880 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1881 #' Print simulated residuals |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1882 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1883 #' @param x an object with simulated residuals created by \code{\link{simulateResiduals}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1884 #' @param ... optional arguments for compatibility with the generic function, no function implemented |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1885 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1886 print.DHARMa <- function(x, ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1887 cat(paste("Object of Class DHARMa with simulated residuals based on", x$nSim, "simulations with refit =", x$refit , ". See ?DHARMa::simulateResiduals for help."), "\n", "\n") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1888 if (length(x$scaledResiduals) < 20) cat("Scaled residual values:", x$scaledResiduals) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1889 else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1890 cat("Scaled residual values:", x$scaledResiduals[1:20], "...") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1891 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1892 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1893 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1894 #' Return residuals of a DHARMa simulation |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1895 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1896 #' @param object an object with simulated residuals created by \code{\link{simulateResiduals}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1897 #' @param quantileFunction optional - a quantile function to transform the uniform 0/1 scaling of DHARMa to another distribution |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1898 #' @param outlierValues if a quantile function with infinite support (such as dnorm) is used, residuals that are 0/1 are mapped to -Inf / Inf. outlierValues allows to convert -Inf / Inf values to an optional min / max value. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1899 #' @param ... optional arguments for compatibility with the generic function, no function implemented |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1900 #' @details the function accesses the slot $scaledResiduals in a fitted DHARMa object, and optionally transforms the standard DHARMa quantile residuals (which have a uniform distribution) to a particular pdf. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1901 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1902 #' @note some of the papers on simulated quantile residuals transforming the residuals (which are natively uniform) back to a normal distribution. I presume this is because of the larger familiarity of most users with normal residuals. Personally, I never considered this desirable, for the reasons explained in https://github.com/florianhartig/DHARMa/issues/39, but with this function, I wanted to give users the option to plot normal residuals if they so wish. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1903 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1904 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1905 #' @example inst/examples/simulateResidualsHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1906 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1907 residuals.DHARMa <- function(object, quantileFunction = NULL, outlierValues = NULL, ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1908 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1909 if(is.null(quantileFunction)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1910 return(object$scaledResiduals) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1911 } else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1912 res = quantileFunction(object$scaledResiduals) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1913 if(!is.null(outlierValues)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1914 res = ifelse(res == -Inf, outlierValues[1], res) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1915 res = ifelse(res == Inf, outlierValues[2], res) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1916 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1917 return(res) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1918 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1919 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1920 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1921 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1922 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1923 #' Return outliers |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1924 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1925 #' Returns the outliers of a DHARMa object |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1926 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1927 #' @param object an object with simulated residuals created by \code{\link{simulateResiduals}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1928 #' @param lowerQuantile lower threshold for outliers. Default is zero = outside simulation envelope |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1929 #' @param upperQuantile upper threshold for outliers. Default is 1 = outside simulation envelope |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1930 #' @param return wheter to return an indices of outliers or a logical vector |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1931 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1932 #' @details First of all, note that the standard definition of outlier in the DHARMa plots and outlier tests is an observation that is outside the simulation envelope. How far outside that is depends a lot on how many simulations you do. If you have 100 data points and to 100 simulations, you would expect to have one "outlier" on average, even with a perfectly fitting model. This is in fact what the outlier test tests. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1933 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1934 #' Thus, keep in mind that for a small number of simulations, outliers are mostly a technical term: these are points that are outside our simulations, but we don't know how far away they are. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1935 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1936 #' If you are seriously interested in HOW FAR outside the expected distribution a data point is, you should increase the number of simulations in \code{\link{simulateResiduals}} to be sure to get the tail of the data distribution correctly. In this case, it may make sense to adjust lowerQuantile and upperQuantile, e.g. to 0.025, 0.975, which would define outliers as values outside the central 95% of the distribution. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1937 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1938 #' Also, note that outliers are particularly concerning if they have a strong influence on the model fit. One could test the influence, for example, by removing them from the data, or by some meausures of leverage, e.g. generalisations for Cook's distance as in Pinho, L. G. B., Nobre, J. S., & Singer, J. M. (2015). Cook’s distance for generalized linear mixed models. Computational Statistics & Data Analysis, 82, 126–136. doi:10.1016/j.csda.2014.08.008. At the moment, however, no such function is provided in DHARMa. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1939 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1940 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1941 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1942 outliers <- function(object, lowerQuantile = 0, upperQuantile = 1, return = c("index", "logical")){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1943 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1944 return = match.arg(return) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1945 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1946 out = residuals(object) >= upperQuantile | residuals(object) <= lowerQuantile |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1947 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1948 if(return == "logical") return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1949 else(return(which(out))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1950 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1951 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1952 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1953 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1954 #' Create a DHARMa object from hand-coded simulations or Bayesian posterior predictive simulations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1955 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1956 #' @param simulatedResponse matrix of observations simulated from the fitted model - row index for observations and colum index for simulations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1957 #' @param observedResponse true observations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1958 #' @param fittedPredictedResponse optional fitted predicted response. For Bayesian posterior predictive simulations, using the median posterior prediction as fittedPredictedResponse is recommended. If not provided, the mean simulatedResponse will be used. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1959 #' @param integerResponse if T, noise will be added at to the residuals to maintain a uniform expectations for integer responses (such as Poisson or Binomial). Unlike in \code{\link{simulateResiduals}}, the nature of the data is not automatically detected, so this MUST be set by the user appropriately |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1960 #' @param seed the random seed to be used within DHARMa. The default setting, recommended for most users, is keep the random seed on a fixed value 123. This means that you will always get the same randomization and thus teh same result when running the same code. NULL = no new seed is set, but previous random state will be restored after simulation. FALSE = no seed is set, and random state will not be restored. The latter two options are only recommended for simulation experiments. See vignette for details. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1961 #' @param method the quantile randomization method used. The two options implemented at the moment are probability integral transform (PIT-) residuals (current default), and the "traditional" randomization procedure, that was used in DHARMa until version 0.3.0. For details, see \code{\link{getQuantile}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1962 #' @details The use of this function is to convert simulated residuals (e.g. from a point estimate, or Bayesian p-values) to a DHARMa object, to make use of the plotting / test functions in DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1963 #' @note Either scaled residuals or (simulatedResponse AND observed response) have to be provided |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1964 #' @example inst/examples/createDharmaHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1965 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1966 createDHARMa <- function(simulatedResponse , observedResponse , fittedPredictedResponse = NULL, integerResponse = F, seed = 123, method = c("PIT", "traditional")){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1967 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1968 randomState <-getRandomState(seed) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1969 on.exit({randomState$restoreCurrent()}) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1970 match.arg(method) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1971 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1972 out = list() |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1973 out$simulatedResponse = simulatedResponse |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1974 out$refit = F |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1975 out$integerResponse = integerResponse |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1976 out$observedResponse = observedResponse |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1977 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1978 if(!is.matrix(simulatedResponse) & !is.null(observedResponse)) stop("either scaled residuals or simulations and observations have to be provided") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1979 if(ncol(simulatedResponse) < 2) stop("simulatedResponse with less than 2 simulations provided - cannot calculate residuals on that.") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1980 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1981 if(ncol(simulatedResponse) < 10) warning("simulatedResponse with less than 10 simulations provided. This rarely makes sense") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1982 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1983 out$nObs = length(observedResponse) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1984 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1985 if (out$nObs < 3) stop("warning - number of observations < 3 ... this rarely makes sense") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1986 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1987 if(! (out$nObs == nrow(simulatedResponse))) stop("dimensions of observedResponse and simulatedResponse do not match") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1988 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1989 out$nSim = ncol(simulatedResponse) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1990 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1991 out$scaledResiduals = getQuantile(simulations = simulatedResponse , observed = observedResponse , integerResponse = integerResponse, method = method) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1992 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1993 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1994 # makes sure that DHARM plots that rely on this vector won't crash |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1995 if(is.null(fittedPredictedResponse)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1996 message("No fitted predicted response provided, using the mean of the simulations") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1997 fittedPredictedResponse = apply(simulatedResponse, 1, mean) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1998 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1999 out$fittedPredictedResponse = fittedPredictedResponse |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2000 out$randomState = randomState |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2001 class(out) = "DHARMa" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2002 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2003 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2004 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2005 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2006 #' Ensures that an object is of class DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2007 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2008 #' @param simulationOutput a DHARMa simulation output or an object that can be converted into a DHARMa simulation output |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2009 #' @param convert if TRUE, attempts to convert model + numeric to DHARMa, if "Model", converts only supported models to DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2010 #' @details The |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2011 #' @return an object of class DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2012 #' @keywords internal |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2013 ensureDHARMa <- function(simulationOutput, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2014 convert = F){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2015 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2016 if(inherits(simulationOutput, "DHARMa")){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2017 return(simulationOutput) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2018 } else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2019 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2020 if(convert == FALSE) stop("wrong argument to function, simulationOutput must be a DHARMa object!") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2021 else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2022 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2023 if (class(simulationOutput)[1] %in% getPossibleModels()){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2024 if (convert == "Model" | convert == T) return(simulateResiduals(simulationOutput)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2025 } else if(is.vector(simulationOutput, mode = "numeric") & convert == T) { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2026 out = list() |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2027 out$scaledResiduals = simulationOutput |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2028 out$nObs = length(out$scaledResiduals) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2029 class(out) = "DHARMa" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2030 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2031 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2032 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2033 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2034 stop("wrong argument to function, simulationOutput must be a DHARMa object or a numeric vector of quantile residuals!") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2035 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2036 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2037 ####################### DHARMa.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2038 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2039 ####################### tests.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2040 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2041 #' DHARMa general residual test |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2042 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2043 #' Calls both uniformity and dispersion test |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2044 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2045 #' This function is a wrapper for the various test functions implemented in DHARMa. Currently, this function calls the \code{\link{testUniformity}} and the \code{\link{testDispersion}} functions. All other tests (see list below) have to be called by hand. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2046 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2047 #' @param simulationOutput an object of class DHARMa with simulated quantile residuals, either created via \code{\link{simulateResiduals}} or by \code{\link{createDHARMa}} for simulations created outside DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2048 #' @param plot if T, plots functions of the tests are called |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2049 #' @author Florian Hartig |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2050 #' @seealso \code{\link{testUniformity}}, \code{\link{testOutliers}}, \code{\link{testDispersion}}, \code{\link{testZeroInflation}}, \code{\link{testGeneric}}, \code{\link{testTemporalAutocorrelation}}, \code{\link{testSpatialAutocorrelation}}, \code{\link{testQuantiles}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2051 #' @example inst/examples/testsHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2052 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2053 testResiduals <- function(simulationOutput, plot = T){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2054 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2055 opar = par(mfrow = c(1,3)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2056 on.exit(par(opar)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2057 out = list() |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2058 out$uniformity = testUniformity(simulationOutput, plot = plot) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2059 out$dispersion = testDispersion(simulationOutput, plot = plot) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2060 out$outliers = testOutliers(simulationOutput, plot = plot) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2061 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2062 print(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2063 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2064 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2065 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2066 #' Residual tests |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2067 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2068 #' @details Deprecated, switch your code to using the \code{\link{testResiduals}} function |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2069 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2070 #' @param simulationOutput an object of class DHARMa with simulated quantile residuals, either created via \code{\link{simulateResiduals}} or by \code{\link{createDHARMa}} for simulations created outside DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2071 #' @author Florian Hartig |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2072 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2073 testSimulatedResiduals <- function(simulationOutput){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2074 message("testSimulatedResiduals is deprecated, switch your code to using the testResiduals function") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2075 testResiduals(simulationOutput) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2076 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2077 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2078 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2079 #' Test for overall uniformity |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2080 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2081 #' This function tests the overall uniformity of the simulated residuals in a DHARMa object |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2082 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2083 #' @param simulationOutput an object of class DHARMa with simulated quantile residuals, either created via \code{\link{simulateResiduals}} or by \code{\link{createDHARMa}} for simulations created outside DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2084 #' @param alternative a character string specifying whether the test should test if observations are "greater", "less" or "two.sided" compared to the simulated null hypothesis. See \code{\link[stats]{ks.test}} for details |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2085 #' @param plot if T, plots calls \code{\link{plotQQunif}} as well |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2086 #' @details The function applies a \code{\link[stats]{ks.test}} for uniformity on the simulated residuals. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2087 #' @author Florian Hartig |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2088 #' @seealso \code{\link{testResiduals}}, \code{\link{testOutliers}}, \code{\link{testDispersion}}, \code{\link{testZeroInflation}}, \code{\link{testGeneric}}, \code{\link{testTemporalAutocorrelation}}, \code{\link{testSpatialAutocorrelation}}, \code{\link{testQuantiles}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2089 #' @example inst/examples/testsHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2090 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2091 testUniformity<- function(simulationOutput, alternative = c("two.sided", "less", "greater"), plot = T){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2092 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2093 simulationOutput = ensureDHARMa(simulationOutput, convert = T) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2094 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2095 out <- suppressWarnings(ks.test(simulationOutput$scaledResiduals, 'punif', alternative = alternative)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2096 if(plot == T) plotQQunif(simulationOutput = simulationOutput) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2097 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2098 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2099 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2100 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2101 # Experimental |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2102 testBivariateUniformity<- function(simulationOutput, alternative = c("two.sided", "less", "greater"), plot = T){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2103 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2104 simulationOutput = ensureDHARMa(simulationOutput, convert = T) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2105 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2106 #out <- suppressWarnings(ks.test(simulationOutput$scaledResiduals, 'punif', alternative = alternative)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2107 #if(plot == T) plotQQunif(simulationOutput = simulationOutput) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2108 out = NULL |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2109 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2110 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2111 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2112 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2113 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2114 #' Test for quantiles |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2115 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2116 #' This function tests |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2117 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2118 #' @param simulationOutput an object of class DHARMa with simulated quantile residuals, either created via \code{\link{simulateResiduals}} or by \code{\link{createDHARMa}} for simulations created outside DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2119 #' @param predictor an optional predictor variable to be used, instead of the predicted response (default) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2120 #' @param quantiles the quantiles to be tested |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2121 #' @param plot if T, the function will create an additional plot |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2122 #' @details The function fits quantile regressions (via package qgam) on the residuals, and compares their location to the expected location (because of the uniform distributionm, the expected location is 0.5 for the 0.5 quantile). |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2123 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2124 #' A significant p-value for the splines means the fitted spline deviates from a flat line at the expected location (p-values of intercept and spline are combined via Benjamini & Hochberg adjustment to control the FDR) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2125 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2126 #' The p-values of the splines are combined into a total p-value via Benjamini & Hochberg adjustment to control the FDR. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2127 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2128 #' @author Florian Hartig |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2129 #' @example inst/examples/testQuantilesHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2130 #' @seealso \code{\link{testResiduals}}, \code{\link{testUniformity}}, \code{\link{testDispersion}}, \code{\link{testZeroInflation}}, \code{\link{testGeneric}}, \code{\link{testTemporalAutocorrelation}}, \code{\link{testSpatialAutocorrelation}}, \code{\link{testOutliers}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2131 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2132 testQuantiles <- function(simulationOutput, predictor = NULL, quantiles = c(0.25,0.5,0.75), plot = T){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2133 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2134 if(plot == F){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2135 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2136 out = list() |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2137 out$data.name = deparse(substitute(simulationOutput)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2138 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2139 simulationOutput = ensureDHARMa(simulationOutput, convert = T) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2140 res = simulationOutput$scaledResiduals |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2141 pred = ensurePredictor(simulationOutput, predictor) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2142 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2143 dat=data.frame(res = simulationOutput$scaledResiduals , pred = pred) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2144 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2145 quantileFits <- list() |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2146 pval = rep(NA, length(quantiles)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2147 predictions = data.frame(pred = sort(dat$pred)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2148 predictions = cbind(predictions, matrix(ncol = 2 * length(quantiles), nrow = nrow(dat))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2149 for(i in 1:length(quantiles)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2150 datTemp = dat |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2151 datTemp$res = datTemp$res - quantiles[i] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2152 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2153 # settings for k = the dimension of the basis used to represent the smooth term. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2154 # see https://github.com/mfasiolo/qgam/issues/37 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2155 dimSmooth = min(length(unique(datTemp$pred)), 10) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2156 quantResult = try(capture.output(quantileFits[[i]] <- qgam::qgam(res ~ s(pred, k = dimSmooth) , data =datTemp, qu = quantiles[i])), silent = T) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2157 if(inherits(quantResult, "try-error")){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2158 message("Unable to calculate quantile regression for quantile ", quantiles[i], ". Possibly to few (unique) data points / predictions. Will be ommited in plots and significance calculations.") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2159 } else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2160 x = summary(quantileFits[[i]]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2161 pval[i] = min(p.adjust(c(x$p.table[1,4], x$s.table[1,4]), method = "BH")) # correction for test on slope and intercept |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2162 quantPre = predict(quantileFits[[i]], newdata = predictions, se = T) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2163 predictions[, 2*i] = quantPre$fit + quantiles[i] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2164 predictions[, 2*i + 1] = quantPre$se.fit |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2165 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2166 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2167 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2168 out$method = "Test for location of quantiles via qgam" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2169 out$alternative = "both" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2170 out$pvals = pval |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2171 out$p.value = min(p.adjust(pval, method = "BH")) # correction for multiple quantile tests |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2172 out$predictions = predictions |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2173 out$qgamFits = quantileFits |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2174 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2175 class(out) = "htest" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2176 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2177 } else if(plot == T) { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2178 out <- plotResiduals(simulationOutput = simulationOutput, predictor = predictor, quantiles = quantiles) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2179 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2180 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2181 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2182 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2183 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2184 #unif.2017YMi(X, type = c("Q1", "Q2", "Q3"), lower = rep(0, ncol(X)),upper = rep(1, ncol(X))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2185 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2186 #' Test for outliers |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2187 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2188 #' This function tests if the number of observations outside the simulatio envelope are larger or smaller than expected |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2189 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2190 #' @param simulationOutput an object of class DHARMa with simulated quantile residuals, either created via \code{\link{simulateResiduals}} or by \code{\link{createDHARMa}} for simulations created outside DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2191 #' @param alternative a character string specifying whether the test should test if observations are "greater", "less" or "two.sided" (default) compared to the simulated null hypothesis |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2192 #' @param margin whether to test for outliers only at the lower, only at the upper, or both sides (default) of the simulated data distribution |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2193 #' @param plot if T, the function will create an additional plot |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2194 #' @details DHARMa residuals are created by simulating from the fitted model, and comparing the simulated values to the observed data. It can occur that all simulated values are higher or smaller than the observed data, in which case they get the residual value of 0 and 1, respectively. I refer to these values as simulation outliers, or simply outliers. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2195 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2196 #' Because no data was simulated in the range of the observed value, we don't know "how strongly" these values deviate from the model expectation, so the term "outlier" should be used with a grain of salt - it's not a judgment about the magnitude of a deviation from an expectation, but simply that we are outside the simulated range, and thus cannot say anything more about the location of the residual. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2197 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2198 #' Note also that the number of outliers will decrease as we increase the number of simulations. Under the null hypothesis that the model is correct, we expect nData /(nSim +1) outliers at each margin of the distribution. For a reason, consider that if the data and the model distribution are identical, the probability that a given observation is higher than all simulations is 1/(nSim +1). |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2199 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2200 #' Based on this null expectation, we can test for an excess or lack of outliers. Per default, testOutliers() looks for both, so if you get a significant p-value, you have to check if you have to many or too few outliers. An excess of outliers is to be interpreted as too many values outside the simulation envelope. This could be caused by overdispersion, or by what we classically call outliers. A lack of outliers would be caused, for example, by underdispersion. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2201 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2202 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2203 #' @author Florian Hartig |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2204 #' @seealso \code{\link{testResiduals}}, \code{\link{testUniformity}}, \code{\link{testDispersion}}, \code{\link{testZeroInflation}}, \code{\link{testGeneric}}, \code{\link{testTemporalAutocorrelation}}, \code{\link{testSpatialAutocorrelation}}, \code{\link{testQuantiles}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2205 #' @example inst/examples/testOutliersHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2206 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2207 testOutliers <- function(simulationOutput, alternative = c("two.sided", "greater", "less"), margin = c("both", "upper", "lower"), plot = T){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2208 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2209 # check inputs |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2210 alternative = match.arg(alternative) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2211 margin = match.arg(margin) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2212 data.name = deparse(substitute(simulationOutput)) # remember: needs to be called before ensureDHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2213 simulationOutput = ensureDHARMa(simulationOutput, convert = "Model") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2214 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2215 # calculation of outliers |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2216 if(margin == "both") outliers = sum(simulationOutput$scaledResiduals %in% c(0, 1)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2217 if(margin == "upper") outliers = sum(simulationOutput$scaledResiduals == 1) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2218 if(margin == "lower") outliers = sum(simulationOutput$scaledResiduals == 0) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2219 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2220 # calculations of trials and H0 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2221 outFreqH0 = 1/(simulationOutput$nSim +1) * ifelse(margin == "both", 2, 1) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2222 trials = simulationOutput$nObs |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2223 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2224 out = binom.test(outliers, trials, p = outFreqH0, alternative = alternative) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2225 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2226 # overwrite information in binom.test |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2227 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2228 out$data.name = data.name |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2229 out$margin = margin |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2230 out$method = "DHARMa outlier test based on exact binomial test" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2231 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2232 names(out$statistic) = paste("outliers at", margin, "margin(s)") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2233 names(out$parameter) = "simulations" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2234 names(out$estimate) = paste("frequency of outliers (expected:", out$null.value,")") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2235 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2236 out$interval = "tst" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2237 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2238 out$interval = |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2239 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2240 if(plot == T) { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2241 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2242 hist(simulationOutput, main = "") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2243 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2244 main = ifelse(out$p.value <= 0.05, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2245 "Outlier test significant", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2246 "Outlier test n.s.") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2247 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2248 title(main = main, cex.main = 1, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2249 col.main = ifelse(out$p.value <= 0.05, "red", "black")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2250 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2251 # legend("center", c(paste("p=", round(out$p.value, digits = 5)), paste("Deviation ", ifelse(out$p.value < 0.05, "significant", "n.s."))), text.col = ifelse(out$p.value < 0.05, "red", "black" )) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2252 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2253 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2254 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2255 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2256 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2257 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2258 #' DHARMa dispersion tests |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2259 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2260 #' This function performs a simulation-based test for over/underdispersion |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2261 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2262 #' @param simulationOutput an object of class DHARMa with simulated quantile residuals, either created via \code{\link{simulateResiduals}} or by \code{\link{createDHARMa}} for simulations created outside DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2263 #' @param plot whether to plot output |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2264 #' @param alternative a character string specifying whether the test should test if observations are "greater", "less" or "two.sided" compared to the simulated null hypothesis. Greater corresponds to overdispersion. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2265 #' @param ... arguments to pass on to \code{\link{testGeneric}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2266 #' @details The function implements two tests, depending on whether it is applied on a simulation with refit = F, or refit = T. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2267 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2268 #' If refit = F, the function tests the sd of the data against the sd of the simulated data. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2269 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2270 #' If refit = T, the function compares the approximate deviance (via squared pearson residuals) with the same quantity from the models refitted with simulated data. Applying this is much slower than the previous alternative. Given the computational cost, I would suggest that most users will be satisfied with the standard dispersion test. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2271 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2272 #' @note The results of the dispersion test can can differ depending on whether it is evaluated on conditional (= conditional on fitted random effects) or unconditional (= REs are re-simulated) simulations. You can change between conditional or unconditional simulations in \code{\link{simulateResiduals}} if this is supported by the regression package that you use. The default in DHARMa is to use unconditional simulations, but I have often found that conditional simulations are more sensitive to dispersion problems. I recommend trying both, as neither test should be positive if the dispersion is correct. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2273 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2274 #' @author Florian Hartig |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2275 #' @seealso \code{\link{testResiduals}}, \code{\link{testUniformity}}, \code{\link{testOutliers}}, \code{\link{testZeroInflation}}, \code{\link{testGeneric}}, \code{\link{testTemporalAutocorrelation}}, \code{\link{testSpatialAutocorrelation}}, \code{\link{testQuantiles}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2276 #' @example inst/examples/testsHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2277 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2278 testDispersion <- function(simulationOutput, alternative = c("two.sided", "greater", "less"), plot = T, ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2279 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2280 out = list() |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2281 out$data.name = deparse(substitute(simulationOutput)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2282 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2283 alternative <- match.arg(alternative) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2284 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2285 simulationOutput = ensureDHARMa(simulationOutput, convert = "Model") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2286 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2287 if(simulationOutput$refit == F){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2288 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2289 spread <- function(x) sd(x - simulationOutput$fittedPredictedResponse) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2290 out = testGeneric(simulationOutput, summary = spread, alternative = alternative, methodName = "DHARMa nonparametric dispersion test via sd of residuals fitted vs. simulated", plot = plot, ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2291 } else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2292 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2293 observed = tryCatch(sum(residuals(simulationOutput$fittedModel, type = "pearson")^2), error = function(e) { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2294 message(paste("DHARMa: the requested tests requires pearson residuals, but your model does not implement these calculations. Test will return NA. Error message:", e)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2295 return(NA) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2296 }) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2297 if(is.na(observed)) return(NA) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2298 expected = apply(simulationOutput$refittedPearsonResiduals^2 , 2, sum) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2299 out$statistic = c(dispersion = observed / mean(expected)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2300 out$method = "DHARMa nonparametric dispersion test via mean deviance residual fitted vs. simulated-refitted" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2301 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2302 p = getP(simulated = expected, observed = observed, alternative = alternative) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2303 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2304 out$alternative = alternative |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2305 out$p.value = p |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2306 class(out) = "htest" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2307 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2308 if(plot == T) { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2309 #plotTitle = gsub('(.{1,50})(\\s|$)', '\\1\n', out$method) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2310 xLabel = paste("Simulated values, red line = fitted model. p-value (",out$alternative, ") = ", out$p.value, sep ="") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2311 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2312 hist(expected, xlim = range(expected, observed, na.rm=T ), col = "lightgrey", main = "", xlab = xLabel, breaks = 20, cex.main = 1) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2313 abline(v = observed, lwd= 2, col = "red") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2314 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2315 main = ifelse(out$p.value <= 0.05, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2316 "Dispersion test significant", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2317 "Dispersion test n.s.") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2318 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2319 title(main = main, cex.main = 1, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2320 col.main = ifelse(out$p.value <= 0.05, "red", "black")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2321 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2322 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2323 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2324 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2325 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2326 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2327 #' Simulated overdisperstion tests |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2328 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2329 #' @details Deprecated, switch your code to using the \code{\link{testDispersion}} function |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2330 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2331 #' @param simulationOutput an object of class DHARMa with simulated quantile residuals, either created via \code{\link{simulateResiduals}} or by \code{\link{createDHARMa}} for simulations created outside DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2332 #' @param ... additional arguments to \code{\link{testDispersion}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2333 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2334 testOverdispersion <- function(simulationOutput, ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2335 message("testOverdispersion is deprecated, switch your code to using the testDispersion function") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2336 testDispersion(simulationOutput, ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2337 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2338 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2339 #' Parametric overdisperstion tests |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2340 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2341 #' @details Deprecated, switch your code to using the \code{\link{testDispersion}} function. The function will do nothing, arguments will be ignored, the parametric tests is no longer recommend |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2342 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2343 #' @param ... arguments will be ignored, the parametric tests is no longer recommend |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2344 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2345 testOverdispersionParametric <- function(...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2346 message("testOverdispersionParametric is deprecated and no longer recommended, see release notes in DHARMA 0.2.0 - switch your code to using the testDispersion function") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2347 return(0) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2348 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2349 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2350 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2351 #' Tests for zero-inflation |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2352 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2353 #' This function compares the observed number of zeros with the zeros expected from simulations. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2354 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2355 #' @param simulationOutput an object of class DHARMa with simulated quantile residuals, either created via \code{\link{simulateResiduals}} or by \code{\link{createDHARMa}} for simulations created outside DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2356 #' @param ... further arguments to \code{\link{testGeneric}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2357 #' @details The plot shows the expected distribution of zeros against the observed values, the ratioObsSim shows observed vs. simulated zeros. A value < 1 means that the observed data has less zeros than expected, a value > 1 means that it has more zeros than expected (aka zero-inflation). Per default, the function tests both sides. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2358 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2359 #' Some notes about common problems / questions: |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2360 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2361 #' * Zero-inflation tests after fitting the model are crucial to see if you have zero-inflation. Just because there are a lot of zeros doesn't mean you have zero-inflation, see Warton, D. I. (2005). Many zeros does not mean zero inflation: comparing the goodness-of-fit of parametric models to multivariate abundance data. Environmetrics 16(3), 275-289. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2362 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2363 #' * That being said, zero-inflation tests are often not a reliable guide to decide wheter to add a zi term or not. In general, model structures should be decided on ideally a priori, if that is not possible via model selection techniques (AIC, BIC, WAIC, Bayes Factor). A zero-inflation test should only be run after that decision, and to validate the decision that was taken. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2364 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2365 #' @note This function is a wrapper for \code{\link{testGeneric}}, where the summary argument is set to function(x) sum(x == 0) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2366 #' @author Florian Hartig |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2367 #' @example inst/examples/testsHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2368 #' @seealso \code{\link{testResiduals}}, \code{\link{testUniformity}}, \code{\link{testOutliers}}, \code{\link{testDispersion}}, \code{\link{testGeneric}}, \code{\link{testTemporalAutocorrelation}}, \code{\link{testSpatialAutocorrelation}}, \code{\link{testQuantiles}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2369 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2370 testZeroInflation <- function(simulationOutput, ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2371 countZeros <- function(x) sum( x == 0) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2372 testGeneric(simulationOutput = simulationOutput, summary = countZeros, methodName = "DHARMa zero-inflation test via comparison to expected zeros with simulation under H0 = fitted model", ... ) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2373 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2374 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2375 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2376 #' Generic simulation test of a summary statistic |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2377 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2378 #' This function tests if a user-defined summary differs when applied to simulated / observed data. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2379 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2380 #' @param simulationOutput an object of class DHARMa with simulated quantile residuals, either created via \code{\link{simulateResiduals}} or by \code{\link{createDHARMa}} for simulations created outside DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2381 #' @param summary a function that can be applied to simulated / observed data. See examples below |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2382 #' @param alternative a character string specifying whether the test should test if observations are "greater", "less" or "two.sided" compared to the simulated null hypothesis |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2383 #' @param plot whether to plot the simulated summary |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2384 #' @param methodName name of the test (will be used in plot) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2385 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2386 #' @details This function tests if a user-defined summary differs when applied to simulated / observed data. the function can easily be remodeled to apply summaries on the residuals, by simply defining f = function(x) summary (x - predictions), as done in \code{\link{testDispersion}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2387 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2388 #' @note The function that you supply is applied on the data as it is represented in your fitted model, which may not always correspond to how you think. This is important in particular when you use k/n binomial data, and want to test for 1-inflation. As an example, if have k/20 observations, and you provide your data via cbind (y, y-20), you have to test for 20-inflation (because this is how the data is represented in the model). However, if you provide data via y/20, and weights = 20, you should test for 1-inflation. In doubt, check how the data is internally represented in model.frame(model), or via simulate(model) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2389 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2390 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2391 #' @author Florian Hartig |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2392 #' @example inst/examples/testsHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2393 #' @seealso \code{\link{testResiduals}}, \code{\link{testUniformity}}, \code{\link{testOutliers}}, \code{\link{testDispersion}}, \code{\link{testZeroInflation}}, \code{\link{testTemporalAutocorrelation}}, \code{\link{testSpatialAutocorrelation}}, \code{\link{testQuantiles}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2394 testGeneric <- function(simulationOutput, summary, alternative = c("two.sided", "greater", "less"), plot = T, methodName = "DHARMa generic simulation test"){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2395 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2396 out = list() |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2397 out$data.name = deparse(substitute(simulationOutput)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2398 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2399 simulationOutput = ensureDHARMa(simulationOutput, convert = "Model") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2400 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2401 alternative <- match.arg(alternative) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2402 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2403 observed = summary(simulationOutput$observedResponse) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2404 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2405 simulated = apply(simulationOutput$simulatedResponse, 2, summary) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2406 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2407 p = getP(simulated = simulated, observed = observed, alternative = alternative) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2408 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2409 out$statistic = c(ratioObsSim = observed / mean(simulated)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2410 out$method = methodName |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2411 out$alternative = alternative |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2412 out$p.value = p |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2413 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2414 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2415 class(out) = "htest" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2416 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2417 if(plot == T) { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2418 plotTitle = gsub('(.{1,50})(\\s|$)', '\\1\n', methodName) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2419 xLabel = paste("Simulated values, red line = fitted model. p-value (",out$alternative, ") = ", out$p.value, sep ="") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2420 hist(simulated, xlim = range(simulated, observed, na.rm=T ), col = "lightgrey", main = plotTitle, xlab = xLabel, breaks = max(round(simulationOutput$nSim / 5), 20), cex.main = 0.8) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2421 abline(v = observed, lwd= 2, col = "red") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2422 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2423 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2424 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2425 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2426 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2427 #' Test for temporal autocorrelation |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2428 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2429 #' This function performs a standard test for temporal autocorrelation on the simulated residuals |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2430 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2431 #' @param simulationOutput an object with simulated residuals created by \code{\link{simulateResiduals}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2432 #' @param time the time, in the same order as the data points. If not provided, random values will be created |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2433 #' @param alternative a character string specifying whether the test should test if observations are "greater", "less" or "two.sided" compared to the simulated null hypothesis |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2434 #' @param plot whether to plot output |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2435 #' @details The function performs a Durbin-Watson test on the uniformly scaled residuals, and plots the residuals against time. The DB test was originally be designed for normal residuals. In simulations, I didn't see a problem with this setting though. The alternative is to transform the uniform residuals to normal residuals and perform the DB test on those. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2436 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2437 #' If no time values are provided, random values will be created. The sense of being able to run the test with time = NULL (random values) is to test the rate of false positives under the current residual structure (random time corresponds to H0: no spatial autocorrelation), e.g. to check if the test has noninal error rates for particular residual structures (note that Durbin-Watson originally assumes normal residuals, error rates seem correct for uniform residuals, but may not be correct if there are still other residual problems). |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2438 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2439 #' Testing for temporal autocorrelation requires unique time values - if you have several observations per time value, either use the recalculateResiduals function to aggregate residuals per time step, or extract the residuals from the fitted object, and plot / test each of them independently for temporally repeated subgroups (typical choices would be location / subject etc.). Note that the latter must be done by hand, outside testSpatialAutocorrelation. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2440 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2441 #' @note Important to note for all autocorrelation tests (spatial / temporal): the autocorrelation tests are valid to check for residual autocorrelation in models that don't assume such a correlation (in this case, you can use conditional or unconditional simulations), or if there is remaining residual autocorrelation after accounting for it in a spatial/temporal model (in that case, you have to use conditional simulations), but if checking unconditional simulations from a model with an autocorrelation structure on data that corresponds to this model, they will be significant, even if the model fully accounts for this structure. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2442 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2443 #' This behavior is not really a bug, but rather originates from the definition of the quantile residuals: quantile residuals are calculated independently per data point, i.e. without consideratin of any correlation structure between data points that may exist in the simulations. As a result, the simulated distributions from a unconditional simulaton will typically not reflect the correlation structure that is present in each single simulation, and the same is true for the subsequently calculated quantile residuals. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2444 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2445 #' The bottomline here is that spatial / temporal / other autoregressive models should either be tested based on conditional simulations, or (ideally) custom tests should be used that are not based on quantile residuals, but rather compare the correlation structure in the simulated data with the correlation structure in the observed data. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2446 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2447 #' @author Florian Hartig |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2448 #' @seealso \code{\link{testResiduals}}, \code{\link{testUniformity}}, \code{\link{testOutliers}}, \code{\link{testDispersion}}, \code{\link{testZeroInflation}}, \code{\link{testGeneric}}, \code{\link{testSpatialAutocorrelation}}, \code{\link{testQuantiles}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2449 #' @example inst/examples/testTemporalAutocorrelationHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2450 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2451 testTemporalAutocorrelation <- function(simulationOutput, time = NULL , alternative = c("two.sided", "greater", "less"), plot = T){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2452 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2453 simulationOutput = ensureDHARMa(simulationOutput, convert = T) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2454 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2455 # actually not sure if this is neccessary for dwtest, but seems better to aggregate |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2456 if(any(duplicated(time))) stop("testing for temporal autocorrelation requires unique time values - if you have several observations per time value, either use the recalculateResiduals function to aggregate residuals per time step, or extract the residuals from the fitted object, and plot / test each of them independently for temporally repeated subgroups (typical choices would be location / subject etc.). Note that the latter must be done by hand, outside testSpatialAutocorrelation.") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2457 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2458 alternative <- match.arg(alternative) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2459 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2460 if(is.null(time)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2461 time = sample.int(simulationOutput$nObs, simulationOutput$nObs) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2462 message("DHARMa::testTemporalAutocorrelation - no time argument provided, using random times for each data point") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2463 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2464 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2465 out = lmtest::dwtest(simulationOutput$scaledResiduals ~ 1, order.by = time, alternative = alternative) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2466 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2467 if(plot == T) { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2468 oldpar <- par(mfrow = c(1,2)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2469 on.exit(par(oldpar)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2470 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2471 plot(simulationOutput$scaledResiduals[order(time)] ~ time[order(time)], |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2472 type = "l", ylab = "Scaled residuals", xlab = "Time", main = "Residuals vs. time") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2473 acf(simulationOutput$scaledResiduals[order(time)], main = "Autocorrelation") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2474 legend("topright", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2475 c(paste(out$method, " p=", round(out$p.value, digits = 5)), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2476 paste("Deviation ", ifelse(out$p.value < 0.05, "significant", "n.s."))), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2477 text.col = ifelse(out$p.value < 0.05, "red", "black" ), bty="n") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2478 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2479 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2480 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2481 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2482 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2483 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2484 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2485 #' Test for spatial autocorrelation |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2486 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2487 #' This function performs a standard test for spatial autocorrelation on the simulated residuals |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2488 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2489 #' @param simulationOutput an object of class DHARMa with simulated quantile residuals, either created via \code{\link{simulateResiduals}} or by \code{\link{createDHARMa}} for simulations created outside DHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2490 #' @param x the x coordinate, in the same order as the data points. If not provided, random values will be created |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2491 #' @param y the y coordinate, in the same order as the data points. If not provided, random values will be created |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2492 #' @param distMat optional distance matrix. If not provided, a distance matrix will be calculated based on x and y. See details for explanation |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2493 #' @param alternative a character string specifying whether the test should test if observations are "greater", "less" or "two.sided" compared to the simulated null hypothesis |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2494 #' @param plot whether to plot output |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2495 #' @details The function performs Moran.I test from the package ape, based on the provided distance matrix of the data points. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2496 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2497 #' There are several ways to specify this distance. If a distance matrix (distMat) is provided, calculations will be based on this distance matrix, and x,y coordinates will only used for the plotting (if provided) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2498 #' If distMat is not provided, the function will calculate the euclidian distances between x,y coordinates, and test Moran.I based on these distances. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2499 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2500 #' If no x/y values are provided, random values will be created. The sense of being able to run the test with x/y = NULL (random values) is to test the rate of false positives under the current residual structure (random x/y corresponds to H0: no spatial autocorrelation), e.g. to check if the test has nominal error rates for particular residual structures. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2501 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2502 #' Testing for spatial autocorrelation requires unique x,y values - if you have several observations per location, either use the recalculateResiduals function to aggregate residuals per location, or extract the residuals from the fitted object, and plot / test each of them independently for spatially repeated subgroups (a typical scenario would repeated spatial observation, in which case one could plot / test each time step separately for temporal autocorrelation). Note that the latter must be done by hand, outside testSpatialAutocorrelation. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2503 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2504 #' @note Important to note for all autocorrelation tests (spatial / temporal): the autocorrelation tests are valid to check for residual autocorrelation in models that don't assume such a correlation (in this case, you can use conditional or unconditional simulations), or if there is remaining residual autocorrelation after accounting for it in a spatial/temporal model (in that case, you have to use conditional simulations), but if checking unconditional simulations from a model with an autocorrelation structure on data that corresponds to this model, they will be significant, even if the model fully accounts for this structure. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2505 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2506 #' This behavior is not really a bug, but rather originates from the definition of the quantile residuals: quantile residuals are calculated independently per data point, i.e. without consideratin of any correlation structure between data points that may exist in the simulations. As a result, the simulated distributions from a unconditional simulaton will typically not reflect the correlation structure that is present in each single simulation, and the same is true for the subsequently calculated quantile residuals. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2507 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2508 #' The bottomline here is that spatial / temporal / other autoregressive models should either be tested based on conditional simulations, or (ideally) custom tests should be used that are not based on quantile residuals, but rather compare the correlation structure in the simulated data with the correlation structure in the observed data. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2509 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2510 #' @author Florian Hartig |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2511 #' @seealso \code{\link{testResiduals}}, \code{\link{testUniformity}}, \code{\link{testOutliers}}, \code{\link{testDispersion}}, \code{\link{testZeroInflation}}, \code{\link{testGeneric}}, \code{\link{testTemporalAutocorrelation}}, \code{\link{testQuantiles}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2512 #' @import grDevices |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2513 #' @example inst/examples/testSpatialAutocorrelationHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2514 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2515 testSpatialAutocorrelation <- function(simulationOutput, x = NULL, y = NULL, distMat = NULL, alternative = c("two.sided", "greater", "less"), plot = T){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2516 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2517 alternative <- match.arg(alternative) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2518 data.name = deparse(substitute(simulationOutput)) # needs to be before ensureDHARMa |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2519 simulationOutput = ensureDHARMa(simulationOutput, convert = T) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2520 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2521 if(any(duplicated(cbind(x,y)))) stop("testing for spatial autocorrelation requires unique x,y values - if you have several observations per location, either use the recalculateResiduals function to aggregate residuals per location, or extract the residuals from the fitted object, and plot / test each of them independently for spatially repeated subgroups (a typical scenario would repeated spatial observation, in which case one could plot / test each time step separately for temporal autocorrelation). Note that the latter must be done by hand, outside testSpatialAutocorrelation.") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2522 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2523 if( (!is.null(x) | !is.null(y)) & !is.null(distMat) ) message("both coordinates and distMat provided, calculations will be done based on the distance matrix, coordinates will only be used for plotting") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2524 # if not provided, fill x and y with random numbers (Null model) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2525 if(is.null(x)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2526 x = runif(simulationOutput$nObs, -1,1) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2527 message("DHARMa::testSpatialAutocorrelation - no x coordinates provided, using random values for each data point") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2528 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2529 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2530 if(is.null(y)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2531 y = runif(simulationOutput$nObs, -1,1) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2532 message("DHARMa::testSpatialAutocorrelation - no x coordinates provided, using random values for each data point") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2533 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2534 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2535 # if not provided, create distance matrix based on x and y |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2536 if(is.null(distMat)) distMat <- as.matrix(dist(cbind(x, y))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2537 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2538 invDistMat <- 1/distMat |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2539 diag(invDistMat) <- 0 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2540 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2541 MI = ape::Moran.I(simulationOutput$scaledResiduals, weight = invDistMat, alternative = alternative) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2542 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2543 out = list() |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2544 out$statistic = c(observed = MI$observed, expected = MI$expected, sd = MI$sd) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2545 out$method = "DHARMa Moran's I test for spatial autocorrelation" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2546 out$alternative = "Spatial autocorrelation" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2547 out$p.value = MI$p.value |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2548 out$data.name = data.name |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2549 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2550 class(out) = "htest" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2551 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2552 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2553 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2554 if(plot == T) { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2555 opar <- par(mfrow = c(1,1)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2556 on.exit(par(opar)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2557 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2558 col = colorRamp(c("red", "white", "blue"))(simulationOutput$scaledResiduals) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2559 plot(x,y, col = rgb(col, maxColorValue = 255), main = out$method, cex.main = 0.8 ) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2560 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2561 # TODO implement correlogram |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2562 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2563 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2564 if(plot == T) { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2565 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2566 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2567 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2568 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2569 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2570 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2571 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2572 getP <- function(simulated, observed, alternative){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2573 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2574 if(alternative == "greater") p = mean(simulated >= observed) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2575 if(alternative == "less") p = mean(simulated <= observed) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2576 if(alternative == "two.sided") p = min(min(mean(simulated <= observed), mean(simulated >= observed) ) * 2,1) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2577 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2578 return(p) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2579 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2580 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2581 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2582 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2583 ####################### tests.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2584 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2585 ####################### compatibility.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2586 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2587 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2588 # New S3 methods |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2589 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2590 #' Get model response |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2591 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2592 #' Extract the response of a fitted model |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2593 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2594 #' The purpose of this function is to savely extract the response (dependent variable) of the fitted model classes |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2595 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2596 #' @param object a fitted model |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2597 #' @param ... additional parameters |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2598 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2599 #' @example inst/examples/wrappersHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2600 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2601 #' @seealso \code{\link{getRefit}}, \code{\link{getSimulations}}, \code{\link{getFixedEffects}}, \code{\link{getFitted}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2602 #' @author Florian Hartig |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2603 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2604 getObservedResponse <- function (object, ...) { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2605 UseMethod("getObservedResponse", object) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2606 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2607 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2608 #' @rdname getObservedResponse |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2609 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2610 getObservedResponse.default <- function (object, ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2611 out = model.frame(object)[,1] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2612 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2613 # check for weights in k/n case |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2614 if(family(object)$family %in% c("binomial", "betabinomial") & "(weights)" %in% colnames(model.frame(object))){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2615 x = model.frame(object) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2616 out = out * x$`(weights)` |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2617 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2618 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2619 # check for k/n binomial |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2620 if(is.matrix(out)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2621 if(!(ncol(out) == 2)) securityAssertion("nKcase - wrong dimensions of response") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2622 if(!(family(object)$family %in% c("binomial", "betabinomial"))) securityAssertion("nKcase - wrong family") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2623 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2624 out = out[,1] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2625 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2626 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2627 # observation is factor - unlike lme4 and older, glmmTMB simulates nevertheless as numeric |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2628 if(is.factor(out)) out = as.numeric(out) - 1 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2629 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2630 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2631 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2632 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2633 weightsWarning = "Model was fit with prior weights. These will be ignored in the simulation. See ?getSimulations for details" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2634 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2635 #' Get model simulations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2636 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2637 #' Wrapper to simulate from a fitted model |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2638 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2639 #' The purpose of this wrapper for for the simulate function is to return the simulations from a model in a standardized way |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2640 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2641 #' @param object a fitted model |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2642 #' @param nsim number of simulations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2643 #' @param type if simulations should be prepared for getQuantile or for refit |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2644 #' @param ... additional parameters to be passed on, usually to the simulate function of the respective model class |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2645 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2646 #' @return a matrix with simulations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2647 #' @example inst/examples/wrappersHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2648 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2649 #' @seealso \code{\link{getObservedResponse}}, \code{\link{getRefit}}, \code{\link{getFixedEffects}}, \code{\link{getFitted}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2650 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2651 #' @details The function is a wrapper for for the simulate function is to return the simulations from a model in a standardized way. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2652 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2653 #' Note: if the model was fit with weights, the function will throw a warning if used with a model class whose simulate function does not include the weightsi in the simulations. Note that the results may or may not be appropriate in this case, depending on how you use the weights. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2654 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2655 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2656 #' @author Florian Hartig |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2657 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2658 getSimulations <- function (object, nsim = 1 , type = c("normal", "refit"), ...) { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2659 UseMethod("getSimulations", object) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2660 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2661 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2662 #' @rdname getSimulations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2663 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2664 getSimulations.default <- function (object, nsim = 1, type = c("normal", "refit"), ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2665 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2666 type <- match.arg(type) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2667 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2668 out = simulate(object, nsim = nsim , ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2669 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2670 if (type == "normal"){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2671 if(family(object)$family %in% c("binomial", "betabinomial")){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2672 if("(weights)" %in% colnames(model.frame(object))){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2673 x = model.frame(object) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2674 out = out * x$`(weights)` |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2675 } else if (is.matrix(out[[1]])){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2676 # this is for the k/n binomial case |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2677 out = as.matrix(out)[,seq(1, (2*nsim), by = 2)] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2678 } else if(is.factor(out[[1]])){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2679 if(nlevels(out[[1]]) != 2){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2680 warning("The fitted model has a factorial response with number of levels not equal to 2 - there is currently no sensible application in DHARMa that would lead to this situation. Likely, you are trying something that doesn't work.") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2681 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2682 else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2683 out = data.matrix(out) - 1 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2684 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2685 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2686 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2687 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2688 if(!is.matrix(out)) out = data.matrix(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2689 } else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2690 if(family(object)$family %in% c("binomial", "betabinomial")){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2691 if (!is.matrix(out[[1]]) & !is.numeric(out)) data.frame(data.matrix(out)-1) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2692 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2693 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2694 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2695 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2696 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2697 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2698 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2699 #' Extract fixed effects of a supported model |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2700 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2701 #' A wrapper to extract fixed effects of a supported model |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2702 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2703 #' @param fittedModel a fitted model |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2704 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2705 #' @example inst/examples/wrappersHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2706 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2707 #' @importFrom lme4 fixef |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2708 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2709 #' @seealso \code{\link{getObservedResponse}}, \code{\link{getSimulations}}, \code{\link{getRefit}}, \code{\link{getFitted}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2710 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2711 getFixedEffects <- function(fittedModel){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2712 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2713 if(class(fittedModel)[1] %in% c("glm", "lm", "gam", "bam", "negbin") ){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2714 out = coef(fittedModel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2715 } else if(class(fittedModel)[1] %in% c("glmerMod", "lmerMod", "HLfit")){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2716 out = fixef(fittedModel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2717 } else if(class(fittedModel)[1] %in% c("glmmTMB")){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2718 out = glmmTMB::fixef(fittedModel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2719 out = out$cond |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2720 } else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2721 out = coef(fittedModel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2722 if(is.null(out)) out = fixef(fittedModel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2723 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2724 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2725 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2726 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2727 #' Get model refit |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2728 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2729 #' Wrapper to refit a fitted model |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2730 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2731 #' @param object a fitted model |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2732 #' @param newresp the new response that should be used to refit the model |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2733 #' @param ... additional parameters to be passed on to the refit or update class that is used to refit the model |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2734 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2735 #' @details The purpose of this wrapper is to standardize the refit of a model. The behavior of this function depends on the supplied model. When available, it uses the refit method, otherwise it will use update. For glmmTMB: since version 1.0, glmmTMB has a refit function, but this didn't work, so I switched back to this implementation, which is a hack based on the update function. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2736 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2737 #' @example inst/examples/wrappersHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2738 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2739 #' @seealso \code{\link{getObservedResponse}}, \code{\link{getSimulations}}, \code{\link{getFixedEffects}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2740 #' @author Florian Hartig |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2741 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2742 getRefit <- function (object, newresp, ...) { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2743 UseMethod("getRefit", object) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2744 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2745 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2746 #' @rdname getRefit |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2747 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2748 #' @importFrom lme4 refit |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2749 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2750 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2751 getRefit.default <- function (object, newresp, ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2752 refit(object, newresp, ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2753 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2754 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2755 #' Get model fitted |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2756 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2757 #' Wrapper to get the fitted value a fitted model |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2758 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2759 #' The purpose of this wrapper is to standardize extract the fitted values |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2760 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2761 #' @param object a fitted model |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2762 #' @param ... additional parameters to be passed on, usually to the simulate function of the respective model class |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2763 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2764 #' @example inst/examples/wrappersHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2765 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2766 #' @seealso \code{\link{getObservedResponse}}, \code{\link{getSimulations}}, \code{\link{getRefit}}, \code{\link{getFixedEffects}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2767 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2768 #' @author Florian Hartig |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2769 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2770 getFitted <- function (object, ...) { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2771 UseMethod("getFitted", object) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2772 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2773 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2774 #' @rdname getFitted |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2775 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2776 getFitted.default <- function (object,...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2777 fitted(object, ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2778 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2779 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2780 #' has NA |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2781 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2782 #' checks if the fitted model excluded NA values |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2783 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2784 #' @param object a fitted model |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2785 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2786 #' @details Checks if the fitted model excluded NA values |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2787 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2788 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2789 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2790 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2791 # hasNA <- function(object){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2792 # x = rownames(model.frame(object)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2793 # if(length(x) < as.numeric(x[length(x) ])) return(TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2794 # else return(FALSE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2795 # } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2796 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2797 ######### LM ############# |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2798 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2799 #' @rdname getRefit |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2800 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2801 getRefit.lm <- function(object, newresp, ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2802 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2803 newData <-model.frame(object) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2804 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2805 if(is.vector(newresp)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2806 newData[,1] = newresp |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2807 } else if (is.factor(newresp)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2808 # Hack to make the factor binomial case work |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2809 newData[,1] = as.numeric(newresp) - 1 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2810 } else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2811 # Hack to make the binomial n/k case work |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2812 newData[[1]] = NULL |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2813 newData = cbind(newresp, newData) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2814 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2815 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2816 refittedModel = update(object, data = newData) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2817 return(refittedModel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2818 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2819 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2820 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2821 hasWeigths.lm <- function(object, ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2822 if(length(unique(object$prior.weights)) != 1) return(TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2823 else return(FALSE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2824 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2825 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2826 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2827 ######### GLM ############# |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2828 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2829 #' @rdname getSimulations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2830 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2831 getSimulations.negbin<- function (object, nsim = 1, type = c("normal", "refit"), ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2832 if("(weights)" %in% colnames(model.frame(object))) warning(weightsWarning) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2833 getSimulations.default(object = object, nsim = nsim, type = type, ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2834 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2835 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2836 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2837 ######## MGCV ############ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2838 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2839 # This function overwrites the standard fitted function for GAM |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2840 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2841 #' @rdname getFitted |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2842 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2843 getFitted.gam <- function(object, ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2844 class(object) = "glm" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2845 out = stats::fitted(object, ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2846 names(out) = as.character(1:length(out)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2847 out |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2848 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2849 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2850 # Check that this works |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2851 # plot(fitted(fittedModelGAM), predict(fittedModelGAM, type = "response")) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2852 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2853 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2854 ######## lme4 ############ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2855 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2856 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2857 #' @rdname getSimulations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2858 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2859 getSimulations.lmerMod <- function (object, nsim = 1, type = c("normal", "refit"), ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2860 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2861 if("(weights)" %in% colnames(model.frame(object))) warning(weightsWarning) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2862 getSimulations.default(object = object, nsim = nsim, type = type, ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2863 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2864 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2865 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2866 ######## glmmTMB ###### |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2867 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2868 #' @rdname getRefit |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2869 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2870 getRefit.glmmTMB <- function(object, newresp, ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2871 newData <-model.frame(object) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2872 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2873 # hack to make update work - for some reason, glmmTMB wants the matrix embedded in the df for update to work ... should be solved ideally, see https://github.com/glmmTMB/glmmTMB/issues/549 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2874 if(is.matrix(newresp)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2875 tmp = colnames(newData[[1]]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2876 newData[[1]] = NULL |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2877 newData = cbind(newresp, newData) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2878 colnames(newData)[1:2] = tmp |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2879 } else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2880 newData[[1]] = newresp |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2881 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2882 refittedModel = update(object, data = newData) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2883 return(refittedModel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2884 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2885 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2886 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2887 # glmmTMB simulates normal counts (and not proportions in any case, so the check for the other models is not needed), see #158 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2888 # note that if observation is factor - unlike lme4 and older, glmmTMB simulates nevertheless as numeric |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2889 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2890 #' @rdname getSimulations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2891 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2892 getSimulations.glmmTMB <- function (object, nsim = 1, type = c("normal", "refit"), ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2893 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2894 if("(weights)" %in% colnames(model.frame(object)) & ! family(object)$family %in% c("binomial", "betabinomial")) warning(weightsWarning) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2895 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2896 type <- match.arg(type) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2897 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2898 out = simulate(object, nsim = nsim, ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2899 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2900 if (type == "normal"){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2901 if (is.matrix(out[[1]])){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2902 # this is for the k/n binomial case |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2903 out = as.matrix(out)[,seq(1, (2*nsim), by = 2)] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2904 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2905 if(!is.matrix(out)) out = data.matrix(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2906 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2907 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2908 # check for weights in k/n case |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2909 if(family(object)$family %in% c("binomial", "betabinomial")){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2910 if("(weights)" %in% colnames(model.frame(object))){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2911 w = model.frame(object) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2912 w = w$`(weights)` |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2913 tmp <- function(x)x/w |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2914 out = apply(out, 2, tmp) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2915 out = as.data.frame(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2916 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2917 else if(is.matrix(out[[1]]) & !is.matrix(model.frame(object)[[1]])){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2918 out = as.data.frame(as.matrix(out)[,seq(1, (2*nsim), by = 2)]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2919 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2920 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2921 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2922 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2923 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2924 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2925 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2926 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2927 # matrixResp = |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2928 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2929 # if(matrixResp & !is.null(ncol(newresp))){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2930 # # Hack to make the factor binomial case work |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2931 # tmp = colnames(newData[[1]]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2932 # newData[[1]] = NULL |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2933 # newData = cbind(newresp, newData) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2934 # colnames(newData)[1:2] = tmp |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2935 # } else if(!is.null(ncol(newresp))){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2936 # newData[[1]] = newresp[,1] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2937 # } else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2938 # newData[[1]] = newresp |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2939 # } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2940 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2941 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2942 # if (out$modelClass == "glmmTMB" & ncol(simulations) == 2*n) simObserved = simulations[,(1+(2*(i-1))):(2+(2*(i-1)))] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2943 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2944 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2945 # else securityAssertion("Simulation results produced unsupported data structure", stop = TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2946 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2947 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2948 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2949 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2950 ####### spaMM ######### |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2951 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2952 #' @rdname getObservedResponse |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2953 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2954 getObservedResponse.HLfit <- function(object, ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2955 out = spaMM::response(object, ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2956 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2957 nKcase = is.matrix(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2958 if(nKcase){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2959 if(! (family(object) %in% c("binomial", "betabinomial"))) securityAssertion("nKcase - wrong family") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2960 if(! (ncol(out)==2)) securityAssertion("nKcase - wrong dimensions of response") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2961 out = out[,1] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2962 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2963 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2964 if(!is.numeric(out)) out = as.numeric(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2965 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2966 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2967 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2968 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2969 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2970 #' @rdname getSimulations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2971 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2972 getSimulations.HLfit <- function(object, nsim = 1, type = c("normal", "refit"), ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2973 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2974 type <- match.arg(type) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2975 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2976 capture.output({out = simulate(object, nsim = nsim, ...)}) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2977 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2978 if(type == "normal"){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2979 if(!is.matrix(out)) out = data.matrix(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2980 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2981 out = as.data.frame(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2982 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2983 return(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2984 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2985 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2986 #' @rdname getRefit |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2987 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2988 getRefit.HLfit <- function(object, newresp, ...) { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2989 spaMM::update_resp(object, newresp, evaluate = TRUE) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2990 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2991 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2992 ####################### compatibility.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2993 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2994 ####################### helper.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2995 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2996 #' Modified ECDF function |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2997 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2998 #' @details ensures symmetric ECDF (standard ECDF is <), and that 0 / 1 values are only produced if the data is strictly < > than the observed data |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2999 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3000 #' @keywords internal |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3001 DHARMa.ecdf <- function (x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3002 { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3003 x <- sort(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3004 n <- length(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3005 if (n < 1) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3006 stop(paste("DHARMa.ecdf - length vector < 1", x)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3007 vals <- unique(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3008 rval <- approxfun(vals, cumsum(tabulate(match(x, vals)))/ (n +1), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3009 method = "linear", yleft = 0, yright = 1, ties = "ordered") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3010 class(rval) <- c("ecdf", "stepfun", class(rval)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3011 assign("nobs", n, envir = environment(rval)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3012 attr(rval, "call") <- sys.call() |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3013 rval |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3014 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3015 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3016 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3017 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3018 #' calculate quantiles |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3019 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3020 #' calculates residual quantiles from a given simulation |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3021 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3022 #' @param simulations a matrix with simulations from a fitted model. Rows = observations, columns = replicate simulations |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3023 #' @param observed a vector with the observed data |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3024 #' @param integerResponse is the response integer-valued. Only has an effect for method = "traditional" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3025 #' @param method the quantile randomization method used. See details |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3026 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3027 #' @details The function calculates residual quantiles from the simulated data. For continous distributions, this will simply the the value of the ecdf. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3028 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3029 #' For discrete data, there are two options implemented. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3030 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3031 #' The current default (available since DHARMa 0.3.1) are probability integral transform (PIT-) residuals (Smith, 1985; Dunn & Smyth, 1996; see also see also Warton, et al., 2017). |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3032 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3033 #' Before DHARMa 0.3.1, a different randomization procedure was used, in which the a U(-0.5, 0.5) distribution was added on observations and simualtions for discrete distributions. For a completely discrete distribution, the two procedures should deliver equivalent results, but the second method has the disadvantage that a) one has to know if the distribution is discrete (DHARMa tries to recognize this automatically), and b) that it leads to inefficiencies for some distributions such as the the Tweedie, which are partly continous, partly discrte (see e.g. https://github.com/florianhartig/DHARMa/issues/168). |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3034 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3035 #' @references |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3036 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3037 #' Smith, J. Q. "Diagnostic checks of non-standard time series models." Journal of Forecasting 4.3 (1985): 283-291. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3038 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3039 #' Dunn, P.K., & Smyth, G.K. (1996). Randomized quantile residuals. Journal of Computational and Graphical Statistics 5, 236-244. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3040 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3041 #' Warton, David I., Loïc Thibaut, and Yi Alice Wang. "The PIT-trap—A “model-free” bootstrap procedure for inference about regression models with discrete, multivariate responses." PloS one 12.7 (2017) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3042 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3043 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3044 getQuantile <- function(simulations, observed, integerResponse, method = c("PIT", "traditional")){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3045 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3046 method = match.arg(method) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3047 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3048 n = length(observed) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3049 if (nrow(simulations) != n) stop("DHARMa::getquantile: wrong dimension of simulations") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3050 nSim = ncol(simulations) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3051 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3052 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3053 if(method == "traditional"){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3054 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3055 if(integerResponse == F){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3056 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3057 if(any(duplicated(observed))) message("Model family was recognized or set as continuous, but duplicate values were detected in the response. Consider if you are fitting an appropriate model.") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3058 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3059 values = as.vector(simulations)[duplicated(as.vector(simulations))] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3060 if(length(values) > 0){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3061 if (all(values%%1==0)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3062 integerResponse = T |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3063 message("Model family was recognized or set as continuous, but duplicate values were detected in the simulation - changing to integer residuals (see ?simulateResiduals for details)") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3064 } else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3065 message("Duplicate non-integer values found in the simulation. If this is because you are fitting a non-inter valued discrete response model, note that DHARMa does not perform appropriate randomization for such cases.") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3066 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3067 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3068 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3069 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3070 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3071 scaledResiduals = rep(NA, n) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3072 for (i in 1:n){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3073 if(integerResponse == T){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3074 scaledResiduals[i] <- DHARMa.ecdf(simulations[i,] + runif(nSim, -0.5, 0.5))(observed[i] + runif(1, -0.5, 0.5)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3075 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3076 scaledResiduals[i] <- DHARMa.ecdf(simulations[i,])(observed[i]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3077 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3078 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3079 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3080 } else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3081 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3082 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3083 scaledResiduals = rep(NA, n) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3084 for (i in 1:n){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3085 min <- sum(simulations[i,] < observed[i]) / length(simulations[i,]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3086 max <- sum(simulations[i,] <= observed[i]) / length(simulations[i,]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3087 if (min == max) scaledResiduals[i] = DHARMa.ecdf(simulations[i,])(observed[i]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3088 else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3089 scaledResiduals[i] = runif(1, min, max) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3090 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3091 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3092 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3093 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3094 return(scaledResiduals) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3095 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3096 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3097 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3098 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3099 # testData = createData(sampleSize = 200, family = gaussian(), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3100 # randomEffectVariance = 0, numGroups = 5) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3101 # fittedModel <- glmmTMB(observedResponse ~ Environment1, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3102 # data = testData) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3103 # simulationOutput <- simulateResiduals(fittedModel = fittedModel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3104 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3105 # sims = simulationOutput$simulatedResponse |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3106 # sims[1, c(1,6,8)] = 0 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3107 # any(apply(sims, 1, anyDuplicated)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3108 # getQuantile(simulations = sims, observed = testData$observedResponse, n = 200, integerResponse = F, nSim = 250) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3109 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3110 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3111 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3112 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3113 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3114 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3115 #' Check dot operator |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3116 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3117 #' @param name variable name |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3118 #' @param default variable default |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3119 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3120 #' @details modified from https://github.com/lcolladotor/dots |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3121 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3122 #' @keywords internal |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3123 checkDots <- function(name, default, ...) { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3124 args <- list(...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3125 if(!name %in% names(args)) { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3126 ## Default value |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3127 return(default) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3128 } else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3129 ## If the argument was defined in the ... part, return it |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3130 return(args[[name]]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3131 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3132 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3133 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3134 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3135 securityAssertion <- function(context = "Not provided", stop = F){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3136 generalMessage = "Message from DHARMa: During the execution of a DHARMa function, some unexpected conditions occurred. Even if you didn't get an error, your results may not be reliable. Please check with the help if you use the functions as intended. If you think that the error is not on your side, I would be grateful if you could report the problem at https://github.com/florianhartig/DHARMa/issues \n\n Context:" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3137 if (stop == F) warning(paste(generalMessage, context)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3138 else stop(paste(generalMessage, context)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3139 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3140 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3141 ####################### helper.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3142 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3143 ####################### plot.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3144 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3145 #' DHARMa standard residual plots |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3146 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3147 #' This function creates standard plots for the simulated residuals |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3148 #' @param x an object with simulated residuals created by \code{\link{simulateResiduals}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3149 #' @param rank if T (default), the values of pred will be rank transformed. This will usually make patterns easier to spot visually, especially if the distribution of the predictor is skewed. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3150 #' @param ... further options for \code{\link{plotResiduals}}. Consider in particular parameters quantreg, rank and asFactor. xlab, ylab and main cannot be changed when using plotSimulatedResiduals, but can be changed when using plotResiduals. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3151 #' @details The function creates two plots. To the left, a qq-uniform plot to detect deviations from overall uniformity of the residuals (calling \code{\link{plotQQunif}}), and to the right, a plot of residuals against predicted values (calling \code{\link{plotResiduals}}). Outliers are highlighted in red (for more on outliers, see \code{\link{testOutliers}}). For a correctly specified model, we would expect |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3152 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3153 #' a) a straight 1-1 line in the uniform qq-plot -> evidence for an overall uniform (flat) distribution of the residuals |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3154 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3155 #' b) uniformity of residuals in the vertical direction in the res against predictor plot |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3156 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3157 #' Deviations of this can be interpreted as for a linear regression. See the vignette for detailed examples. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3158 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3159 #' To provide a visual aid in detecting deviations from uniformity in y-direction, the plot of the residuals against the predicted values also performs an (optional) quantile regression, which provides 0.25, 0.5 and 0.75 quantile lines across the plots. These lines should be straight, horizontal, and at y-values of 0.25, 0.5 and 0.75. Note, however, that some deviations from this are to be expected by chance, even for a perfect model, especially if the sample size is small. See further comments on this plot, its interpretation and options, in \code{\link{plotResiduals}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3160 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3161 #' The quantile regression can take some time to calculate, especially for larger datasets. For that reason, quantreg = F can be set to produce a smooth spline instead. This is default for n > 2000. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3162 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3163 #' @seealso \code{\link{plotResiduals}}, \code{\link{plotQQunif}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3164 #' @example inst/examples/plotsHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3165 #' @import graphics |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3166 #' @import utils |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3167 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3168 plot.DHARMa <- function(x, rank = TRUE, ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3169 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3170 oldpar <- par(mfrow = c(1,2), oma = c(0,1,2,1)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3171 on.exit(par(oldpar)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3172 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3173 plotQQunif(x) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3174 plotResiduals(x, rank = rank, ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3175 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3176 mtext("DHARMa residual diagnostics", outer = T) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3177 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3178 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3179 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3180 #' Histogram of DHARMa residuals |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3181 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3182 #' The function produces a histogram from a DHARMa output |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3183 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3184 #' @param x a DHARMa simulation output (class DHARMa) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3185 #' @param breaks breaks for hist() function |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3186 #' @param col col for hist bars |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3187 #' @param main plot main |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3188 #' @param xlab plot xlab |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3189 #' @param cex.main plot cex.main |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3190 #' @param ... other arguments to be passed on to hist |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3191 #' @seealso \code{\link{plotSimulatedResiduals}}, \code{\link{plotResiduals}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3192 #' @example inst/examples/plotsHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3193 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3194 hist.DHARMa <- function(x, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3195 breaks = seq(-0.02, 1.02, len = 53), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3196 col = c("red",rep("lightgrey",50), "red"), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3197 main = "Hist of DHARMa residuals", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3198 xlab = "Residuals (outliers are marked red)", |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3199 cex.main = 1, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3200 ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3201 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3202 x = ensureDHARMa(x, convert = T) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3203 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3204 val = x$scaledResiduals |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3205 val[val == 0] = -0.01 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3206 val[val == 1] = 1.01 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3207 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3208 hist(val, breaks = breaks, col = col, main = main, xlab = xlab, cex.main = cex.main, ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3209 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3210 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3211 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3212 #' DHARMa standard residual plots |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3213 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3214 #' DEPRECATED, use plot() instead |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3215 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3216 #' @param simulationOutput an object with simulated residuals created by \code{\link{simulateResiduals}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3217 #' @param ... further options for \code{\link{plotResiduals}}. Consider in particular parameters quantreg, rank and asFactor. xlab, ylab and main cannot be changed when using plotSimulatedResiduals, but can be changed when using plotResiduals. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3218 #' @note This function is deprecated. Use \code{\link{plot.DHARMa}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3219 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3220 #' @seealso \code{\link{plotResiduals}}, \code{\link{plotQQunif}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3221 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3222 plotSimulatedResiduals <- function(simulationOutput, ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3223 message("plotSimulatedResiduals is deprecated, please switch your code to simply using the plot() function") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3224 plot(simulationOutput, ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3225 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3226 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3227 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3228 #' Quantile-quantile plot for a uniform distribution |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3229 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3230 #' The function produces a uniform quantile-quantile plot from a DHARMa output |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3231 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3232 #' @param simulationOutput a DHARMa simulation output (class DHARMa) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3233 #' @param testUniformity if T, the function \code{\link{testUniformity}} will be called and the result will be added to the plot |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3234 #' @param testOutliers if T, the function \code{\link{testOutliers}} will be called and the result will be added to the plot |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3235 #' @param testDispersion if T, the function \code{\link{testDispersion}} will be called and the result will be added to the plot |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3236 #' @param ... arguments to be passed on to \code{\link[gap]{qqunif}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3237 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3238 #' @details the function calls qqunif from the R package gap to create a quantile-quantile plot for a uniform distribution. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3239 #' @seealso \code{\link{plotSimulatedResiduals}}, \code{\link{plotResiduals}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3240 #' @example inst/examples/plotsHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3241 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3242 plotQQunif <- function(simulationOutput, testUniformity = T, testOutliers = T, testDispersion = T, ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3243 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3244 simulationOutput = ensureDHARMa(simulationOutput, convert = "Model") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3245 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3246 gap::qqunif(simulationOutput$scaledResiduals,pch=2,bty="n", logscale = F, col = "black", cex = 0.6, main = "QQ plot residuals", cex.main = 1, ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3247 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3248 if(testUniformity == TRUE){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3249 temp = testUniformity(simulationOutput, plot = F) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3250 legend("topleft", c(paste("KS test: p=", round(temp$p.value, digits = 5)), paste("Deviation ", ifelse(temp$p.value < 0.05, "significant", "n.s."))), text.col = ifelse(temp$p.value < 0.05, "red", "black" ), bty="n") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3251 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3252 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3253 if(testOutliers == TRUE){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3254 temp = testOutliers(simulationOutput, plot = F) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3255 legend("bottomright", c(paste("Outlier test: p=", round(temp$p.value, digits = 5)), paste("Deviation ", ifelse(temp$p.value < 0.05, "significant", "n.s."))), text.col = ifelse(temp$p.value < 0.05, "red", "black" ), bty="n") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3256 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3257 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3258 if(testDispersion == TRUE){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3259 temp = testDispersion(simulationOutput, plot = F) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3260 legend("center", c(paste("Dispersion test: p=", round(temp$p.value, digits = 5)), paste("Deviation ", ifelse(temp$p.value < 0.05, "significant", "n.s."))), text.col = ifelse(temp$p.value < 0.05, "red", "black" ), bty="n") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3261 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3262 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3263 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3264 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3265 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3266 #' Generic res ~ pred scatter plot with spline or quantile regression on top |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3267 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3268 #' The function creates a generic residual plot with either spline or quantile regression to highlight patterns in the residuals. Outliers are highlighted in red. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3269 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3270 #' @param simulationOutput on object, usually a DHARMa object, from which residual values can be extracted. Alternatively, a vector with residuals or a fitted model can be provided, which will then be transformed into a DHARMa object. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3271 #' @param form optional predictor against which the residuals should be plotted. Default is to used the predicted(simulationOutput) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3272 #' @param quantreg whether to perform a quantile regression on 0.25, 0.5, 0.75 on the residuals. If F, a spline will be created instead. Default NULL chooses T for nObs < 2000, and F otherwise. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3273 #' @param rank if T, the values provided in form will be rank transformed. This will usually make patterns easier to spot visually, especially if the distribution of the predictor is skewed. If form is a factor, this has no effect. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3274 #' @param asFactor should a numeric predictor provided in form be treated as a factor. Default is to choose this for < 10 unique values, as long as enough predictions are available to draw a boxplot. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3275 #' @param smoothScatter if T, a smooth scatter plot will plotted instead of a normal scatter plot. This makes sense when the number of residuals is very large. Default NULL chooses T for nObs < 10000, and F otherwise. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3276 #' @param quantiles for a quantile regression, which quantiles should be plotted |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3277 #' @param ... additional arguments to plot / boxplot. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3278 #' @details The function plots residuals against a predictor (by default against the fitted value, extracted from the DHARMa object, or any other predictor). |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3279 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3280 #' Outliers are highlighted in red (for information on definition and interpretation of outliers, see \code{\link{testOutliers}}). |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3281 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3282 #' To provide a visual aid in detecting deviations from uniformity in y-direction, the plot function calculates an (optional) quantile regression, which compares the empirical 0.25, 0.5 and 0.75 quantiles (default) in y direction (red solid lines) with the theoretical 0.25, 0.5 and 0.75 quantiles (dashed black line). |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3283 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3284 #' Asymptotically (i.e. for lots of data / residuals), if the model is correct, theoretical and the empirical quantiles should be identical (i.e. dashed and solid lines should match). A p-value for the deviation is calculated for each quantile line. Significant deviations are highlighted by red color. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3285 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3286 #' If form is a factor, a boxplot will be plotted instead of a scatter plot. The distribution for each factor level should be uniformly distributed, so the box should go from 0.25 to 0.75, with the median line at 0.5. Again, chance deviations from this will increases when the sample size is smaller. You can run null simulations to test if the deviations you see exceed what you would expect from random variation. If you want to create box plots for categorical predictors (e.g. because you only have a small number of unique numeric predictor values), you can convert your predictor with as.factor(pred) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3287 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3288 #' @return if quantile tests are performed, the function returns them invisibly. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3289 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3290 #' @note The quantile regression can take some time to calculate, especially for larger datasets. For that reason, quantreg = F can be set to produce a smooth spline instead. |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3291 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3292 #' @seealso \code{\link{plotQQunif}} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3293 #' @example inst/examples/plotsHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3294 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3295 plotResiduals <- function(simulationOutput, form = NULL, quantreg = NULL, rank = F, asFactor = NULL, smoothScatter = NULL, quantiles = c(0.25, 0.5, 0.75), ...){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3296 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3297 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3298 ##### Checks ##### |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3299 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3300 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3301 a <- list(...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3302 a$ylab = checkDots("ylab", "Standardized residual", ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3303 if(is.null(form)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3304 a$xlab = checkDots("xlab", ifelse(rank, "Model predictions (rank transformed)", "Model predictions"), ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3305 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3306 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3307 simulationOutput = ensureDHARMa(simulationOutput, convert = T) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3308 res = simulationOutput$scaledResiduals |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3309 if(inherits(form, "DHARMa"))stop("DHARMa::plotResiduals > argument form cannot be of class DHARMa. Note that the syntax of plotResiduals has changed since DHARMa 0.3.0. See ?plotResiduals.") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3310 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3311 pred = ensurePredictor(simulationOutput, form) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3312 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3313 ##### Rank transform and factor conversion##### |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3314 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3315 if(!is.factor(pred)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3316 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3317 if (rank == T){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3318 pred = rank(pred, ties.method = "average") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3319 pred = pred / max(pred) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3320 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3321 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3322 nuniq = length(unique(pred)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3323 ndata = length(pred) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3324 if(is.null(asFactor)) asFactor = (nuniq == 1) | (nuniq < 10 & ndata / nuniq > 10) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3325 if (asFactor) pred = factor(pred) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3326 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3327 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3328 ##### Residual scatter plots ##### |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3329 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3330 if(is.null(quantreg)) if (length(res) > 2000) quantreg = FALSE else quantreg = TRUE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3331 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3332 switchScatter = 10000 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3333 if(is.null(smoothScatter)) if (length(res) > switchScatter) smoothScatter = TRUE else smoothScatter = FALSE |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3334 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3335 blackcol = rgb(0,0,0, alpha = max(0.1, 1 - 3 * length(res) / switchScatter)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3336 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3337 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3338 # categorical plot |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3339 if(is.factor(pred)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3340 do.call(plot, append(list(res ~ pred, ylim = c(0,1), axes = FALSE), a)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3341 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3342 # smooth scatter |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3343 else if (smoothScatter == TRUE) { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3344 defaultCol = ifelse(res == 0 | res == 1, 2,blackcol) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3345 do.call(graphics::smoothScatter, append(list(x = pred, y = res , ylim = c(0,1), axes = FALSE, colramp = colorRampPalette(c("white", "darkgrey"))),a)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3346 points(pred[defaultCol == 2], res[defaultCol == 2], col = "red", cex = 0.5) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3347 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3348 # normal plot |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3349 else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3350 defaultCol = ifelse(res == 0 | res == 1, 2,blackcol) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3351 defaultPch = ifelse(res == 0 | res == 1, 8,1) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3352 a$col = checkDots("col", defaultCol, ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3353 a$pch = checkDots("pch", defaultPch, ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3354 do.call(plot, append(list(res ~ pred, ylim = c(0,1), axes = FALSE), a)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3355 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3356 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3357 axis(1) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3358 axis(2, at=c(0, 0.25, 0.5, 0.75, 1)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3359 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3360 ##### Quantile regressions ##### |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3361 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3362 main = checkDots("main", "Residual vs. predicted", ...) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3363 out = NULL |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3364 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3365 if(is.numeric(pred)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3366 if(quantreg == F){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3367 title(main = main, cex.main = 1) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3368 abline(h = c(0.25, 0.5, 0.75), col = "black", lwd = 0.5, lty = 2) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3369 try({ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3370 lines(smooth.spline(pred, res, df = 10), lty = 2, lwd = 2, col = "red") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3371 abline(h = 0.5, col = "red", lwd = 2) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3372 }, silent = T) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3373 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3374 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3375 out = testQuantiles(simulationOutput, pred, quantiles = quantiles, plot = F) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3376 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3377 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3378 if(any(out$pvals < 0.05, na.rm = TRUE)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3379 main = paste(main, "Quantile deviations detected (red curves)", sep ="\n") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3380 if(out$p.value <= 0.05){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3381 main = paste(main, "Combined adjusted quantile test significant", sep ="\n") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3382 } else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3383 main = paste(main, "Combined adjusted quantile test n.s.", sep ="\n") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3384 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3385 maincol = "red" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3386 } else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3387 main = paste(main, "No significant problems detected", sep ="\n") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3388 maincol = "black" |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3389 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3390 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3391 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3392 title(main = main, cex.main = 0.8, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3393 col.main = maincol) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3394 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3395 for(i in 1:length(quantiles)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3396 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3397 lineCol = ifelse(out$pvals[i] <= 0.05 & !(is.na(out$pvals[i])), "red", "black") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3398 filCol = ifelse(out$pvals[i] <= 0.05 & !(is.na(out$pvals[i])), "#FF000040", "#00000020") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3399 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3400 abline(h = quantiles[i], col = lineCol, lwd = 0.5, lty = 2) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3401 polygon(c(out$predictions$pred, rev(out$predictions$pred)), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3402 c(out$predictions[,2*i] - out$predictions[,2*i+1], rev(out$predictions[,2*i] + out$predictions[,2*i+1])), |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3403 col = "#00000020", border = F) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3404 lines(out$predictions$pred, out$predictions[,2*i], col = lineCol, lwd = 2) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3405 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3406 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3407 # legend("bottomright", c(paste("Quantile test: p=", round(out$p.value, digits = 5)), paste("Deviation ", ifelse(out$p.value < 0.05, "significant", "n.s."))), text.col = ifelse(out$p.value < 0.05, "red", "black" ), bty="n") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3408 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3409 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3410 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3411 invisible(out) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3412 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3413 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3414 x = 0.01 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3415 x <= 0.05 & !(is.na(x)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3416 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3417 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3418 #' Ensures the existence of a valid predictor to plot residuals against |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3419 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3420 #' @param simulationOutput a DHARMa simulation output or an object that can be converted into a DHARMa simulation output |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3421 #' @param predictor an optional predictor. If no predictor is provided, will try to extract the fitted value |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3422 #' @keywords internal |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3423 ensurePredictor <- function(simulationOutput, |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3424 predictor = NULL){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3425 if(!is.null(predictor)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3426 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3427 if(length(predictor) != length(simulationOutput$scaledResiduals)) stop("DHARMa: residuals and predictor do not have the same length. The issue is possibly that you have NAs in your predictor that were removed during the model fit. Remove the NA values from your predictor.") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3428 } else { |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3429 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3430 predictor = simulationOutput$fittedPredictedResponse |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3431 if(is.null(predictor)) stop("DHARMa: can't extract predictor from simulationOutput, and no predictor provided") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3432 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3433 return(predictor) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3434 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3435 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3436 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3437 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3438 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3439 #plot(simulationOutput) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3440 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3441 #plot(simulationOutput$observedResponse, simulationOutput$scaledResiduals, xlab = "predicted", ylab = "Residual", main = "Residual vs. predicted") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3442 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3443 #plot(simulationOutput$observedResponse, simulationOutput$fittedPredictedResponse - simulationOutput$observedResponse) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3444 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3445 #plot(cumsum(sort(simulationOutput$scaledResiduals))) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3446 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3447 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3448 #plotConventionalResiduals(fittedModel) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3449 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3450 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3451 #' Conventional residual plot |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3452 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3453 #' Convenience function to draw conventional residual plots |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3454 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3455 #' @param fittedModel a fitted model object |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3456 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3457 plotConventionalResiduals <- function(fittedModel){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3458 opar <- par(mfrow = c(1,3), oma = c(0,1,2,1)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3459 on.exit(par(opar)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3460 plot(predict(fittedModel), resid(fittedModel, type = "deviance"), main = "Deviance" , ylab = "Residual", xlab = "Predicted") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3461 plot(predict(fittedModel), resid(fittedModel, type = "pearson") , main = "Pearson", ylab = "Residual", xlab = "Predicted") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3462 plot(predict(fittedModel), resid(fittedModel, type = "response") , main = "Raw residuals" , ylab = "Residual", xlab = "Predicted") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3463 mtext("Conventional residual plots", outer = T) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3464 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3465 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3466 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3467 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3468 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3469 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3470 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3471 # if(quantreg == F){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3472 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3473 # lines(smooth.spline(simulationOutput$fittedPredictedResponse, simulationOutput$scaledResiduals, df = 10), lty = 2, lwd = 2, col = "red") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3474 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3475 # abline(h = 0.5, col = "red", lwd = 2) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3476 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3477 # }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3478 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3479 # #library(gamlss) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3480 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3481 # # qrnn |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3482 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3483 # # http://r.789695.n4.nabble.com/Quantile-GAM-td894280.html |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3484 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3485 # #require(quantreg) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3486 # #dat <- plyr::arrange(dat,pred) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3487 # #fit<-quantreg::rqss(resid~qss(pred,constraint="N"),tau=0.5,data = dat) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3488 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3489 # probs = c(0.25, 0.50, 0.75) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3490 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3491 # w <- p <- list() |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3492 # for(i in seq_along(probs)){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3493 # capture.output(w[[i]] <- qrnn::qrnn.fit(x = as.matrix(simulationOutput$fittedPredictedResponse), y = as.matrix(simulationOutput$scaledResiduals), n.hidden = 4, tau = probs[i], iter.max = 1000, n.trials = 1, penalty = 1)) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3494 # p[[i]] <- qrnn::qrnn.predict(as.matrix(sort(simulationOutput$fittedPredictedResponse)), w[[i]]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3495 # } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3496 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3497 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3498 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3499 # #plot(simulationOutput$fittedPredictedResponse, simulationOutput$scaledResiduals, xlab = "Predicted", ylab = "Residual", main = "Residual vs. predicted\n lines should match", cex.main = 1) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3500 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3501 # #lines(sort(simulationOutput$fittedPredictedResponse), as.vector(p[[1]]), col = "red") |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3502 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3503 # matlines(sort(simulationOutput$fittedPredictedResponse), matrix(unlist(p), nrow = length(simulationOutput$fittedPredictedResponse), ncol = length(p)), col = "red", lty = 1) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3504 # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3505 # # as.vector(p[[1]]) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3506 # # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3507 # # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3508 # # lines(simulationOutput$fittedPredictedResponse,p[[1]], col = "red", lwd = 2) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3509 # # abline(h = 0.5, col = "red", lwd = 2) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3510 # # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3511 # # fit<-quantreg::rqss(resid~qss(pred,constraint="N"),tau=0.25,data = dat) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3512 # # lines(unique(dat$pred)[-1],fit$coef[1] + fit$coef[-1], col = "green", lwd = 2, lty =2) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3513 # # abline(h = 0.25, col = "green", lwd = 2, lty =2) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3514 # # |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3515 # # fit<-quantreg::rqss(resid~qss(pred,constraint="N"),tau=0.75,data = dat) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3516 # # lines(unique(dat$pred)[-1],fit$coef[1] + fit$coef[-1], col = "blue", lwd = 2, lty = 2) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3517 # # abline(h = 0.75, col = "blue", lwd = 2, lty =2) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3518 # } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3519 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3520 ####################### plot.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3521 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3522 ####################### random.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3523 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3524 #' Record and restore a random state |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3525 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3526 #' The aim of this function is to record, manipualate and restor a random state |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3527 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3528 #' @details This function is intended for two (not mutually exclusive tasks) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3529 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3530 #' a) record the current random state |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3531 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3532 #' b) change the current random state in a way that the previous state can be restored |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3533 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3534 #' @return a list with various infos about the random state that after function execution, as well as a function to restore the previous state before the function execution |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3535 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3536 #' @param seed seed argument to set.seed(). NULL = no seed, but random state will be restored. F = random state will not be restored |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3537 #' @export |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3538 #' @example inst/examples/getRandomStateHelp.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3539 #' @author Florian Hartig |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3540 #' |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3541 getRandomState <- function(seed = NULL){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3542 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3543 # better to explicitly access the global RS? |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3544 # current = get(".Random.seed", .GlobalEnv, ifnotfound = NULL) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3545 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3546 current = mget(".Random.seed", envir = .GlobalEnv, ifnotfound = list(NULL))[[1]] |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3547 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3548 if(is.logical(seed) & seed == F){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3549 restoreCurrent <- function(){} |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3550 }else{ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3551 restoreCurrent <- function(){ |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3552 if(is.null(current)) rm(".Random.seed", envir = .GlobalEnv) else assign(".Random.seed", current , envir = .GlobalEnv) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3553 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3554 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3555 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3556 # setting seed |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3557 if(is.numeric(seed)) set.seed(seed) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3558 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3559 # ensuring that RNG has been initialized |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3560 if (is.null(current))runif(1) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3561 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3562 randomState = list(seed, state = get(".Random.seed", globalenv()), kind = RNGkind(), restoreCurrent = restoreCurrent) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3563 return(randomState) |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3564 } |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3565 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3566 ####################### random.R |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3567 |
c9dfe4e20a45
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3568 ######################################### Package DHARMa |