Mercurial > repos > ecology > pampa_glmcomm
annotate FunctPAMPAGalaxy.r @ 1:61cc30e94df4 draft
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 30ad791ef2452487dc248d4266c0cf14eda79914"
author | ecology |
---|---|
date | Wed, 22 Jul 2020 11:53:35 -0400 |
parents | f0dc3958e65d |
children | 44b9069775ca |
rev | line source |
---|---|
0
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1 #Rscript |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
4 ################################################################################################################################## |
f0dc3958e65d
"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 ################################# |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
6 ################################################################################################################################## |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
7 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
8 #### Based on Yves Reecht R script |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
10 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
13 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
14 fact.det.f <- function (Obs, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
15 size.class="size.class", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
16 code.especes="species.code", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
17 unitobs="observation.unit") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
18 { |
f0dc3958e65d
"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]))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
20 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
21 factors <- c(unitobs, code.especes, size.class) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
22 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
23 factors <- c(unitobs, code.especes) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
24 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
25 return(factors) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
26 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
27 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
28 ######################################### end of the function fact.def.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
29 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
31 ####### Define observation type from colnames |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
32 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
33 def.typeobs.f <- function(Obs) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
34 { |
f0dc3958e65d
"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)))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
36 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
37 ObsType <- "SVR" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
38 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
39 ObsType <- "other" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
40 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
41 return(ObsType) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
42 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
43 ######################################### end of the function fact.def.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
44 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
46 ####### Create unitobs column when inexistant |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
48 { |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
50 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
51 unitab <- data |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
52 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
53 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
54 |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
56 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
57 return(unitab) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
58 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
59 ######################################### start of the function create.unitobs |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
60 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
62 ####### separate unitobs column when existant |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
64 { |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
66 { |
f0dc3958e65d
"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="_") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
68 }else{ |
f0dc3958e65d
"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)) |
f0dc3958e65d
"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")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
71 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
72 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
73 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
74 tab <- cbind(tab,observation.unit = data[,unitobs]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
75 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
76 return(tab) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
77 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
78 ######################################### start of the function create.unitobs |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
79 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
81 |
f0dc3958e65d
"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){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
83 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
85 ## check numbers and contents of variables(colnames). |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
87 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
88 ## Arguments: dataset : dataset name |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
89 ## err_msg : output error |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
90 ## vars : expected name of variables |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
91 ## nb_vars : expected number of variables |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
92 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
93 ## Author: Alan Amosse, Benjamin Yguel |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
94 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
96 cat("\nerr nb var\n") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
97 stop(err_msg, call.=FALSE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
98 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
99 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
100 for(i in vars){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
101 if(!(i %in% names(dataset))){ #checking colnames |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
102 stop(err_msg,call.=FALSE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
103 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
104 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
105 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
106 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
107 ######################################### end of the function check_file |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
108 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
109 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
111 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
112 statRotationsNumber.f <- function(factors, obs) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
113 { |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
115 ## on SVR data |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
116 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
117 ## Arguments: factors : Names of aggregation factors |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
118 ## obs : observation data |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
119 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
121 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
122 ## Identification of valid rotations : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
123 if (is.element("observation.unit", factors)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
124 { |
f0dc3958e65d
"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) : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
126 rotations <- tapply(obs$rotation, |
f0dc3958e65d
"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]), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
128 function(x)length(x) > 0) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
129 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
130 ## Changing NA rotations in FALSE : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
131 rotations[is.na(rotations)] <- FALSE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
132 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
133 #stop(mltext("statRotations.err.1")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
134 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
135 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
136 ## ########################################################### |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
137 ## Abundance per rotation at chosen aggregation factors : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
138 nombresR <- tapply(obs$number, |
f0dc3958e65d
"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]), |
f0dc3958e65d
"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,...))}, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
141 na.rm = TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
142 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
143 ## If valid rotation NA are considered 0 : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
144 nombresR <- sweep(nombresR, |
f0dc3958e65d
"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), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
146 rotations, # Tableau des secteurs valides (booléens). |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
147 function(x, y) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
148 { |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
150 return(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
151 }) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
152 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
153 ## ################################################## |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
154 ## Statistics : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
155 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
156 ## Means : |
f0dc3958e65d
"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)), |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
159 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
160 ## Maxima : |
f0dc3958e65d
"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)), |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
163 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
164 ## SD : |
f0dc3958e65d
"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)), |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
167 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
168 ## Valid rotations count : |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
170 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
171 ## Results returned as list : |
f0dc3958e65d
"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, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
173 nombresRotations=nombresRotations, nombresTot=nombresR)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
174 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
175 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
176 ######################################### end of the function statRotationsNumber.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
177 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
179 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
180 calcNumber.default.f <- function(obs, |
f0dc3958e65d
"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"), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
182 nbName="number") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
183 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
184 ## Purpose : Compute abundances at finest aggregation |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
185 ## --------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
186 ## Arguments: obs : observation table |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
187 ## factors : aggregation factors |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
188 ## nbName : name of abundance column. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
189 ## |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
190 ## Output: array with ndimensions = nfactors. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
191 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
193 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
194 ## Sum individuals number : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
195 nbr <- tapply(obs[ , nbName], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
196 as.list(obs[ , factors]), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
197 sum, na.rm = TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
198 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
199 ## Absences as "true zero" : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
200 nbr[is.na(nbr)] <- 0 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
201 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
202 return(nbr) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
203 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
204 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
205 ######################################### end of the function calcNumber.default.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
206 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
207 ######################################### start of the function calc.numbers.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
208 |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
210 { |
f0dc3958e65d
"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(). |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
212 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
213 ## Arguments: obs : observation table |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
214 ## ObsType : Type of observation (SVR, LIT, ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
215 ## factors : aggregation factors |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
216 ## nbName : name of abundance column |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
217 ## |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
219 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
221 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
222 if (ObsType == "SVR") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
223 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
224 ## Compute SVR abundances statistics : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
225 statRotations <- statRotationsNumber.f(factors=factors, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
226 obs=obs) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
227 |
f0dc3958e65d
"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) : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
229 nbr <- statRotations[["nombresMean"]] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
230 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
231 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
232 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
233 nbr <- calcNumber.default.f(obs, factors, nbName) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
234 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
235 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
237 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
238 if (is.element("size.class", colnames(res))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
239 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
240 res$size.class[res$size.class == ""] <- NA |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
241 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
242 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
243 ## If integer abundances : |
f0dc3958e65d
"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])))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
245 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
246 res[ , nbName] <- as.integer(res[ , nbName]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
247 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
248 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
249 if (ObsType == "SVR") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
250 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
251 ## statistics on abundances : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
252 res$number.max <- as.vector(statRotations[["nombresMax"]]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
253 res$number.sd <- as.vector(statRotations[["nombresSD"]]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
254 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
255 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
256 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
257 return(res) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
258 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
259 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
260 ######################################### end of the function calc.numbers.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
261 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
263 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
264 presAbs.f <- function(nombres, logical=FALSE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
265 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
266 ## Purpose: Compute presence absence from abundances |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
267 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
268 ## Arguments: nombres : vector of individuals count. |
f0dc3958e65d
"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 ? |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
270 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
272 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
273 if (any(nombres < 0, na.rm=TRUE)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
274 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
275 stop("Negative abundances!") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
276 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
277 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
278 if (logical) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
279 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
280 return(nombres > 0) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
281 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
282 nombres[nombres > 0] <- 1 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
283 return(nombres) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
284 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
285 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
286 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
287 ######################################### end of the function presAbs.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
288 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
290 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
291 betterCbind <- function(..., dfList=NULL, deparse.level = 1) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
292 { |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
294 ## redundancies. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
295 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
296 ## Arguments: same as cbind... |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
297 ## dfList : data.frames list |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
298 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
300 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
301 if (is.null(dfList)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
302 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
303 dfList <- list(...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
304 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
305 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
306 return(do.call(cbind, |
f0dc3958e65d
"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), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
308 head(colnames(dfList[[1]]), 1))]), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
309 lapply(dfList[-1], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
310 function(x, colDel) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
311 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
312 return(x[ , !is.element(colnames(x), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
313 colDel), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
314 drop=FALSE]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
315 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
316 colDel=colnames(dfList[[1]])), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
317 deparse.level=deparse.level))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
318 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
319 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
320 ######################################### end of the function betterCbind |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
321 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
323 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
324 agregation.f <- function(metric, Data, factors, casMetrique, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
325 nbName="number") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
326 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
327 ## Purpose: metric aggregation |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
328 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
329 ## Arguments: metric: colnames of chosen metric |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
330 ## Data: Unaggregated data table |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
331 ## factors: aggregation factors vector |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
332 ## casMetrique: named vector of observation types depending |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
333 ## on chosen metric |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
334 ## nbName : abundance column name |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
335 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
337 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
338 switch(casMetrique[metric], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
339 "sum"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
340 res <- tapply(Data[ , metric], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
341 as.list(Data[ , factors, drop=FALSE]), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
342 function(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
343 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
344 ifelse(all(is.na(x)), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
345 NA, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
346 sum(x, na.rm=TRUE)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
347 }) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
348 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
349 "w.mean"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
350 res <- tapply(1:nrow(Data), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
351 as.list(Data[ , factors, drop=FALSE]), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
352 function(ii) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
353 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
354 ifelse(all(is.na(Data[ii, metric])), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
355 NA, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
356 weighted.mean(Data[ii, metric], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
357 Data[ii, nbName], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
358 na.rm=TRUE)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
359 }) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
360 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
361 "w.mean.colonies"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
362 res <- tapply(1:nrow(Data), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
363 as.list(Data[ , factors, drop=FALSE]), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
364 function(ii) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
365 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
366 ifelse(all(is.na(Data[ii, metric])), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
367 NA, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
368 weighted.mean(Data[ii, metric], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
369 Data[ii, "colonies"], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
370 na.rm=TRUE)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
371 }) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
372 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
373 "w.mean.prop"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
374 res <- tapply(1:nrow(Data), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
375 as.list(Data[ , factors, drop=FALSE]), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
376 function(ii) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
377 { |
f0dc3958e65d
"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, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
379 NA, |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
381 0, |
f0dc3958e65d
"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) / |
f0dc3958e65d
"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)) * |
f0dc3958e65d
"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 |
f0dc3958e65d
"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) : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
386 ifelse(is.element("size.class", factors), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
387 100, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
388 100 * length(unique(Data$size.class))))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
389 }) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
390 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
391 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
392 "w.mean.prop.bio"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
393 res <- tapply(1:nrow(Data), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
394 as.list(Data[ , factors, drop=FALSE]), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
395 function(ii) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
396 { |
f0dc3958e65d
"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, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
398 NA, |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
400 0, |
f0dc3958e65d
"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) / |
f0dc3958e65d
"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)) * |
f0dc3958e65d
"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 |
f0dc3958e65d
"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) : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
405 ifelse(is.element("size.class", factors), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
406 100, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
407 100 * length(unique(Data$size.class))))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
408 }) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
409 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
410 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
411 "pres"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
412 res <- tapply(Data[ , metric], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
413 as.list(Data[ , factors, drop=FALSE]), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
414 function(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
415 { |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
417 NA, |
f0dc3958e65d
"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... |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
420 0)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
421 }) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
422 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
423 "nbMax"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
424 ## Recuperation of raw abundances with selections : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
425 nbTmp <- getReducedSVRdata.f(dataName=".NombresSVR", data=Data) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
426 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
427 ## Sum by factor cross / rotation : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
428 nbTmp2 <- apply(nbTmp, |
f0dc3958e65d
"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"))), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
430 function(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
431 { |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
433 }) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
434 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
435 ## Sum by factor cross : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
436 res <- as.array(apply(nbTmp2, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
437 which(is.element(names(dimnames(nbTmp)), factors)), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
438 function(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
439 { |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
441 })) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
442 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
443 "nbSD"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
444 ## Recuperation of raw abundances with selections : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
445 nbTmp <- getReducedSVRdata.f(dataName=".NombresSVR", data=Data) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
446 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
447 ## Sum by factor cross / rotation : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
448 nbTmp2 <- apply(nbTmp, |
f0dc3958e65d
"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"))), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
450 function(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
451 { |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
453 }) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
454 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
455 ## Sum by factor cross : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
456 res <- as.array(apply(nbTmp2, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
457 which(is.element(names(dimnames(nbTmp)), factors)), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
458 function(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
459 { |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
461 })) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
462 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
463 "densMax"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
464 ## Recuperation of raw abundances with selections : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
465 densTmp <- getReducedSVRdata.f(dataName=".DensitesSVR", data=Data) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
466 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
467 ## Sum by factor cross / rotation : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
468 densTmp2 <- apply(densTmp, |
f0dc3958e65d
"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"))), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
470 function(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
471 { |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
473 }) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
474 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
475 ## Sum by factor cross : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
476 res <- as.array(apply(densTmp2, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
477 which(is.element(names(dimnames(densTmp)), factors)), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
478 function(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
479 { |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
481 })) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
482 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
483 "densSD"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
484 ## Recuperation of raw abundances with selections : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
485 densTmp <- getReducedSVRdata.f(dataName=".DensitesSVR", data=Data) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
486 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
487 ## Sum by factor cross / rotation : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
488 densTmp2 <- apply(densTmp, |
f0dc3958e65d
"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"))), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
490 function(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
491 { |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
493 }) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
494 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
495 ## Sum by factor cross : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
496 res <- as.array(apply(densTmp2, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
497 which(is.element(names(dimnames(densTmp)), factors)), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
498 function(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
499 { |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
501 })) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
502 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
503 "%.nesting"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
504 res <- tapply(1:nrow(Data), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
505 as.list(Data[ , factors, drop=FALSE]), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
506 function(ii) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
507 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
508 ifelse(all(is.na(Data[ii, metric])), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
509 NA, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
510 weighted.mean(Data[ii, metric], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
511 Data[ii, "readable.tracks"], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
512 na.rm=TRUE)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
513 }) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
514 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
515 stop("Not implemented!") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
516 ) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
517 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
518 ## dimension names |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
519 names(dimnames(res)) <- c(factors) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
520 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
521 ## Transformation to long format : |
f0dc3958e65d
"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) |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
524 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
525 return(reslong) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
526 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
527 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
528 ######################################### end of the function agregation.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
529 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
531 |
f0dc3958e65d
"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, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
533 nbName="number") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
534 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
535 ## Purpose: Aggregate data |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
536 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
537 ## Arguments: Data : data set |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
538 ## metrics : aggregated metric |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
539 ## factors : aggregation factors |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
542 ## unitSp : Metrics table by unitobs/species |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
543 ## nbName : abundance colname |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
544 ## |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
545 ## Output : aggregated data frame |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
546 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
548 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
549 ## trt depending on metric type : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
550 casMetrique <- c("number"="sum", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
551 "mean.length"="w.mean", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
552 "taille_moy"="w.mean", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
553 "biomass"="sum", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
554 "Biomass"="sum", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
555 "weight"="sum", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
556 "mean.weight"="w.mean", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
557 "density"="sum", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
558 "Density"="sum", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
559 "CPUE"="sum", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
560 "CPUE.biomass"="sum", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
561 "pres.abs"="pres", |
f0dc3958e65d
"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 [!!!] ? |
f0dc3958e65d
"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 [!!!] ? |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
564 ## Benthos : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
565 "colonies"="sum", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
566 "coverage"="sum", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
567 "mean.size.colonies"="w.mean.colonies", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
568 ## SVR (expérimental) : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
569 "number.max"="nbMax", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
570 "number.sd"="nbSD", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
571 "density.max"="densMax", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
572 "density.sd"="densSD", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
573 "biomass.max"="sum", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
574 "spawning.success"="%.nesting", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
575 "spawnings"="sum", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
576 "readable.tracks"="sum", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
577 "tracks.number"="sum") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
578 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
579 ## add "readable.tracks" for egg laying percentage : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
580 if (any(casMetrique[metrics] == "%.nesting")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
581 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
582 if (is.element("size.class", colnames(Data))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
583 { |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
585 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
586 Data <- merge(Data, |
f0dc3958e65d
"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")], |
f0dc3958e65d
"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"), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
589 suffixes=c("", ".y")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
590 }else{ |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
592 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
593 Data <- merge(Data, |
f0dc3958e65d
"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")], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
595 by=c("species.code", "observation.unit"), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
596 suffixes=c("", ".y")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
597 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
598 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
599 |
f0dc3958e65d
"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 : |
f0dc3958e65d
"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")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
602 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
603 if (is.element("size.class", colnames(Data))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
604 { |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
606 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
607 Data <- merge(Data, |
f0dc3958e65d
"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)], |
f0dc3958e65d
"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"), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
610 suffixes=c("", ".y")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
611 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
612 ## add tot abundance / species / observation unit : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
613 nbTot <- tapply(unitSpSz[ , nbName], |
f0dc3958e65d
"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")]), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
615 sum, na.rm=TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
616 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
617 Data <- merge(Data, |
f0dc3958e65d
"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")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
619 }else{ |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
621 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
622 Data <- merge(Data, |
f0dc3958e65d
"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 ? |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
624 by=c("species.code", "observation.unit"), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
625 suffixes=c("", ".y")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
626 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
627 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
628 |
f0dc3958e65d
"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 : |
f0dc3958e65d
"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")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
631 { |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
633 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
634 Data <- merge(Data, |
f0dc3958e65d
"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")], |
f0dc3958e65d
"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"), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
637 suffixes=c("", ".y")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
638 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
639 ## add tot biomass / species / observation unit : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
640 biomTot <- tapply(unitSpSz$biomass, |
f0dc3958e65d
"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")]), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
642 function(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
643 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
644 ifelse(all(is.na(x)), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
645 NA, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
646 sum(x, na.rm=TRUE)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
647 }) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
648 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
649 Data <- merge(Data, |
f0dc3958e65d
"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")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
651 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
652 |
f0dc3958e65d
"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 : |
f0dc3958e65d
"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)))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
655 { |
f0dc3958e65d
"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")], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
657 1, paste, collapse="*"), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
658 apply(unitSp[ , c("species.code", "observation.unit")], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
659 1, paste, collapse="*")), "colonies"] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
660 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
661 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
662 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
663 ## Aggregation of metric depending on factors : |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
665 agregation.f, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
666 Data=Data, factors=factors, casMetrique=casMetrique, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
667 nbName=nbName)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
668 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
669 ## Aggregation and add other factors : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
670 if ( ! (is.null(listFact) || length(listFact) == 0)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
671 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
672 reslong <- cbind(reslong, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
673 sapply(Data[ , listFact, drop=FALSE], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
674 function(fact) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
675 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
676 tapply(fact, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
677 as.list(Data[ , factors, drop=FALSE]), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
678 function(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
679 { |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
681 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
682 return(NULL) # otherwise it is NULL |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
683 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
684 unique(as.character(x)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
685 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
686 }) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
687 })) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
688 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
689 |
f0dc3958e65d
"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 : |
f0dc3958e65d
"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))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
692 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
693 for (i in which(tmp)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
694 { |
f0dc3958e65d
"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], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
696 "integer"={ |
f0dc3958e65d
"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]])) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
698 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
699 "numeric"={ |
f0dc3958e65d
"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]])) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
701 }, |
f0dc3958e65d
"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="."), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
703 reslong[ , listFact[i]])) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
704 ) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
705 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
706 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
707 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
708 ## Initial order of factors levels : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
709 reslong <- as.data.frame(sapply(colnames(reslong), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
710 function(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
711 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
712 if (is.factor(reslong[ , x])) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
713 { |
f0dc3958e65d
"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]))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
715 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
716 return(reslong[ , x]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
717 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
718 }, simplify=FALSE)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
719 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
720 |
f0dc3958e65d
"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 : |
f0dc3958e65d
"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)))}))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
723 { |
f0dc3958e65d
"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", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
725 " of the observations grouping factor(s).", sep="")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
726 return(NULL) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
727 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
728 return(reslong) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
729 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
730 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
731 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
732 ######################################### end of the function agregations.generic.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
733 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
735 dropLevels.f <- function(df, which=NULL) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
736 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
737 ## Purpose: Suppress unused levels of factors |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
738 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
739 ## Arguments: df : a data.frame |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
740 ## which : included columns index (all by default) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
741 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
743 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
744 if (class(df) != "data.frame") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
745 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
746 stop("'df' must be a data.frame") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
747 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
748 if (is.null(which)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
749 { |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
751 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
752 return(x[ ,drop=TRUE]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
753 }, simplify=FALSE), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
754 stringsAsFactors=FALSE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
755 }else{ # Only some columns used |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
756 x <- df |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
757 |
f0dc3958e65d
"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], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
759 function(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
760 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
761 return(x[ , drop=TRUE]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
762 }, simplify=FALSE), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
763 stringsAsFactors=FALSE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
764 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
765 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
766 return(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
767 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
768 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
769 ######################################### end of the function dropLevels.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
770 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
772 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
773 subsetToutesTables.f <- function(metrique, tabMetrics, facteurs, selections, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
774 tabUnitobs, refesp, tableMetrique="", nbName="number", ObsType = "", |
f0dc3958e65d
"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")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
776 { |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
778 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
779 ## Arguments: metrique : chosen metric |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
780 ## facteurs : all chosen factors |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
781 ## selections : corresponding modality selected |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
782 ## tableMetrique : metrics table name |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
783 ## exclude : factors levels to exclude |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
784 ## add : field to add to data table |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
785 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
787 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
788 ## If no metrics table available : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
789 if (is.element(tableMetrique, c("", "TableOccurrences", "TablePresAbs"))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
790 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
791 tableMetrique <- "unitSp" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
792 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
793 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
794 casTables <- c("unitSp"="unitSp", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
795 "TablePresAbs"="unitSp", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
796 "unitSpSz"="unitSpSz") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
797 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
798 ## Recuperation of metrics table : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
799 dataMetrique <- tabMetrics |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
800 unitobs <- tabUnitobs |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
801 refesp <- refesp |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
802 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
803 ## If no metrics available or already computed : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
804 if (is.element(metrique, c("", "occurrence.frequency"))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
805 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
806 metrique <- "tmp" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
807 dataMetrique$tmp <- 0 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
808 dataMetrique$tmp[dataMetrique[ , nbName] > 0] <- 1 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
809 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
810 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
811 if (!is.null(add)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
812 { |
f0dc3958e65d
"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))]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
814 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
815 metriques <- metrique |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
816 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
817 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
818 ## Subset depending on metrics table |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
819 switch(casTables[tableMetrique], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
820 ## Observation table by unitobs and species : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
821 unitSp={ |
f0dc3958e65d
"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], |
f0dc3958e65d
"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])], |
f0dc3958e65d
"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 |
f0dc3958e65d
"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], |
f0dc3958e65d
"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])], |
f0dc3958e65d
"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 |
f0dc3958e65d
"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]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
829 }, |
f0dc3958e65d
"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 : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
831 unitSpSz={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
832 restmp <- cbind(dataMetrique[!is.na(dataMetrique[ , metrique]) , |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
833 c(metriques, "size.class"), drop=FALSE], |
f0dc3958e65d
"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])], |
f0dc3958e65d
"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 |
f0dc3958e65d
"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], |
f0dc3958e65d
"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])], |
f0dc3958e65d
"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 |
f0dc3958e65d
"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]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
840 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
841 ## Other cases : |
f0dc3958e65d
"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], |
f0dc3958e65d
"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])], |
f0dc3958e65d
"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. |
f0dc3958e65d
"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]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
846 ) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
847 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
848 selCol <- which(!is.na(selections)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
849 if (!is.null(exclude)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
850 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
851 selCol <- selCol[selCol != exclude] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
852 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
853 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
854 ## Particular case of size classes : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
855 if (is.element("size.class", colnames(restmp))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
856 { |
f0dc3958e65d
"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)) == |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
858 length(unique(as.character(restmp$size.class)))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
859 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
860 restmp$size.class <- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
861 factor(as.character(restmp$size.class), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
862 levels=unique(as.character(restmp$size.class))[ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
863 order(as.numeric(sub("^([[:digit:]]*)[-_][[:digit:]]*$", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
864 "\\1", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
865 unique(as.character(restmp$size.class)), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
866 perl=TRUE)), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
867 na.last=FALSE)]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
868 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
869 restmp$size.class <- factor(restmp$size.class) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
870 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
871 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
872 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
873 ## Biomass and density conversion -> /100m² : |
f0dc3958e65d
"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", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
875 "biomass.max", "density.max", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
876 "biomass.sd", "density.sd"))) && ObsType != "fishing") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
877 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
878 restmp[ , is.element(colnames(restmp), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
879 c("biomass", "density", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
880 "biomass.max", "density.max", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
881 "biomass.sd", "density.sd"))] <- 100 * |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
882 restmp[, is.element(colnames(restmp), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
883 c("biomass", "density", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
884 "biomass.max", "density.max", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
885 "biomass.sd", "density.sd"))] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
886 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
887 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
888 return(restmp) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
889 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
890 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
891 ######################################### end of the function subsetToutesTables.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
892 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
893 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
895 sortiesLM.f <- function(objLM, TabSum, #formule, |
f0dc3958e65d
"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, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
897 Log=FALSE, sufixe=NULL, type="espece") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
898 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
899 ## Purpose: Form GLM and LM results |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
900 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
901 ## Arguments: objLM : lm object |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
902 ## TabSum : output summary table |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
903 ## formule : LM formula |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
904 ## metrique : Chosen metric |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
905 ## factAna : separation factor |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
906 ## cut : level of separation factor |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
908 ## listFact : Analysis factors list |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
909 ## levels : Levels of analysis factors list |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
910 ## Data : Data used for analysis |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
911 ## Log : put log on metric ? (boolean) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
912 ## sufixe : sufix for file name |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
913 ## type : analysis type |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
914 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
916 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
917 sumLM <- summary(objLM) |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
919 { |
f0dc3958e65d
"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] |
f0dc3958e65d
"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] |
f0dc3958e65d
"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] |
f0dc3958e65d
"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] |
f0dc3958e65d
"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] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
925 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
927 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
928 TabCoef <- as.data.frame(sumLM$coefficients$cond) |
f0dc3958e65d
"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"}}) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
930 |
f0dc3958e65d
"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"] |
f0dc3958e65d
"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|)"] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
933 |
f0dc3958e65d
"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}})) |
f0dc3958e65d
"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}})) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
936 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
937 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
938 switch(as.character(length(sumLM$varcor$cond)), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
939 "1"={StdD <- c(sumLM$varcor$cond[[1]])}, |
f0dc3958e65d
"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]])}, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
941 StdD <- NULL) |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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])})) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
945 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
946 }else{ ## if fixed effects only |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
947 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
948 TabSum[TabSum[,colAna]==cut,"AIC"] <- sumLM$aic |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
953 TabCoef <- as.data.frame(sumLM$coefficients) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
954 |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
956 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
957 |
f0dc3958e65d
"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"}}) |
f0dc3958e65d
"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"] |
f0dc3958e65d
"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|)"] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
961 |
f0dc3958e65d
"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}})) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
963 |
f0dc3958e65d
"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}})) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
965 }else{ |
f0dc3958e65d
"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"}}) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
967 |
f0dc3958e65d
"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"] |
f0dc3958e65d
"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|)"] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
970 |
f0dc3958e65d
"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}})) |
f0dc3958e65d
"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}})) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
973 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
974 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
975 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
976 if (! is.null(lev)) ## if fixed effects |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
977 { |
f0dc3958e65d
"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"] |
f0dc3958e65d
"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"] |
f0dc3958e65d
"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"] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
981 |
f0dc3958e65d
"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}})) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
983 |
f0dc3958e65d
"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}})) |
f0dc3958e65d
"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}})) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
986 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
987 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
988 return(TabSum) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
989 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
990 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
991 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
992 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
993 ######################################### end of the function sortiesLM.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
994 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
996 |
f0dc3958e65d
"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", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
998 lang = getOption("P.lang")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
999 { |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1001 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1002 ## Arguments: |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1003 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1005 return(paste(ifelse(is.null(model), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1006 "Values of ", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1007 paste(model, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1008 " for", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1009 sep="")), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1010 metrique, |
f0dc3958e65d
"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)")), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1012 paste("aggregated"), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1013 ""), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1014 switch(type, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1015 "espece"=" per species and station", |
f0dc3958e65d
"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", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1017 "unitobs"=" per station", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1018 "unitobs(CL)"=" per station", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1019 "CL_unitobs"=" per size class and station", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1020 "biodiv"=" per station", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1021 ""), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1022 switch(type, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1023 "espece"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1024 ifelse(modGraphSel == "", # Only separation factor if defined |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1025 "", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1026 paste("\nfor the field", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1027 " '", factGraph, "' = ", modGraphSel, sep="")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1028 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1029 "CL_espece"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1030 ifelse(modGraphSel == "", # Only separation factor if defined |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1031 "", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1032 paste("\nfor the field", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1033 " '", factGraph, "' = ", modGraphSel, sep="")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1034 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1035 "unitobs"={ |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1037 "\nfor all species", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1038 paste("\nfor all species matching", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1039 " '", factGraph, "' = (", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1040 paste(modGraphSel, collapse=", "), ")", sep="")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1041 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1042 "unitobs(CL)"={ |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1044 "\nfor all size classes", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1045 paste("\nfor size classes matching", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1046 " '", factGraph, "' = (", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1047 paste(modGraphSel, collapse=", "), ")", sep="")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1048 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1049 "CL_unitobs"={ |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1051 "\nfor all species", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1052 paste("\nfor all species matching", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1053 " '", factGraph, "' = (", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1054 paste(modGraphSel, collapse=", "), ")", sep="")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1055 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1056 "biodiv"={ |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1058 "", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1059 paste("\nfor stations matching", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1060 " '", factGraph, "' = (", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1061 paste(modGraphSel, collapse=", "), ")", sep="")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1062 }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1063 ""), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1064 "\n by ", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1065 paste(sapply(listFact[length(listFact):1], |
f0dc3958e65d
"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"), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1067 "", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1068 x, collapse="")), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1069 collapse=" and"), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1070 "\n", sep=""))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1071 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1072 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1073 ######################################### end of the function graphTitle.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1074 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1076 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1078 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1079 ## Purpose: Note your GLM analysis |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1080 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1081 ## Arguments: data : Dataframe used for analysis |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1082 ## objLM : GLM assessed |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1083 ## metric : selected metric |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1084 ## listFact : Analysis factors list |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1085 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1086 ## Author: Coline ROYAUX, 26 june 2020 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1087 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1088 rate <- 0 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1090 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1091 #### Data criterions #### |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1092 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1093 ## Plan |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1094 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1095 plan <- as.data.frame(table(data[,listFact])) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1096 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1098 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1099 rate <- rate + 0.5 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1100 detres$complete_plan <- TRUE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1101 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1103 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1104 rate <- rate + 0.5 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1105 detres$balanced_plan <- TRUE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1106 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1107 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1108 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1109 detres$complete_plan <- FALSE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1110 detres$balanced_plan <- FALSE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1111 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1112 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1114 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1115 rate <- rate + 1 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1116 detres$NA_proportion_OK <- TRUE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1117 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1118 detres$NA_proportion_OK <- FALSE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1119 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1120 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1121 #### Model criterions #### |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1122 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1124 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1125 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1126 Residuals <- simulateResiduals(objLM) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1127 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1128 capture.output(testRes <- testResiduals(Residuals)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1129 testZero <- testZeroInflation(Residuals) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1130 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1131 ## dispersion of residuals |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1132 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1134 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1135 rate <- rate + 1.5 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1136 detres$no_residual_dispersion <- TRUE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1137 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1138 detres$no_residual_dispersion <- FALSE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1139 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1140 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1141 ## uniformity of residuals |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1142 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1144 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1145 rate <- rate + 1.5 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1146 detres$uniform_residuals <- TRUE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1147 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1148 detres$uniform_residuals <- FALSE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1149 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1150 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1151 ## residuals outliers |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1152 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1154 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1155 rate <- rate + 0.5 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1156 detres$outliers_proportion_OK <- TRUE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1157 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1158 detres$outliers_proportion_OK <- FALSE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1159 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1160 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1161 ## Zero inflation test |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1162 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1164 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1165 rate <- rate + 1.5 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1166 detres$no_zero_inflation <- TRUE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1167 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1168 detres$no_zero_inflation <- FALSE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1169 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1170 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1171 ## Factors/observations ratio |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1172 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1174 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1175 rate <- rate + 1 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1176 detres$observation_factor_ratio_OK <- TRUE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1177 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1178 detres$observation_factor_ratio_OK <- FALSE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1179 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1180 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1182 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1183 if (length(grep("^glmmTMB", objLM$call)) > 0) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1184 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1185 nlevRand <- c() |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1187 { |
f0dc3958e65d
"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])))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1189 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1190 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1192 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1193 rate <- rate + 1 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1194 detres$enough_levels_random_effect <- TRUE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1195 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1196 detres$enough_levels_random_effect <- FALSE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1197 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1198 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1199 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1200 detres$rate <- rate |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1201 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1202 if (details) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1203 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1204 return(detres) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1205 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1206 return(rate) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1207 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1208 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1209 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1210 return(NA) |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1212 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1213 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1214 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1215 ######################################### end of the function noteGLM.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1216 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1218 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1220 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1221 ## Purpose: Note your GLM analysis |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1222 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1223 ## Arguments: data : rates table from noteGLM.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1224 ## objLM : GLM assessed |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1225 ## metric : selected metric |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1226 ## listFact : Analysis factors list |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1227 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1228 ## Author: Coline ROYAUX, 26 june 2020 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1229 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1230 RateM <- mean(na.omit(tabRate[,"rate"])) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1231 sum <- summary(objLM) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1232 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1233 if (length(grep("^glmmTMB", objLM$call)) > 0) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1234 { |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1236 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1237 RateM <- RateM + 1 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1238 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1239 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1241 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1242 RateM <- RateM + 1 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1243 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1244 }else{ |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1246 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1247 RateM <- RateM + 1 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1248 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1249 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1251 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1252 RateM <- RateM + 1 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1253 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1254 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1255 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1256 if (file_out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1257 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1258 namefile <- "RatingGLM.txt" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1259 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1260 cat("###########################################################################", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1261 "\n########################### Analysis evaluation ###########################", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1262 "\n###########################################################################", file=namefile, fill=1,append=TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1263 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1264 ## Informations on model : |
f0dc3958e65d
"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) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1267 cat("Family: ", sum$family[[1]], |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1268 file=namefile,append=TRUE) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1270 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1271 ## Global rate : |
f0dc3958e65d
"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:", |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1274 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1275 ## details on every GLM : |
f0dc3958e65d
"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 |
f0dc3958e65d
"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) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1279 apply(tabRate, 1, FUN=function(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1280 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1281 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1283 { |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1285 }else{ |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1287 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1288 |
f0dc3958e65d
"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")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1290 { |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1292 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1293 cat("\tyes", file=namefile, append=TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1294 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1295 cat("\tno", file=namefile, append=TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1296 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1297 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1298 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1300 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1301 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1302 }) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1304 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1305 ## Red flags - advice : |
f0dc3958e65d
"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) |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1308 { |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1310 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1311 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1313 { |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1315 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1316 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1318 { |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1320 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1321 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1323 { |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1325 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1326 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1328 { |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1330 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1331 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1333 { |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1335 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1336 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1338 { |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1340 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1341 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1342 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1343 return(RateM) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1344 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1345 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1346 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1347 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1348 ######################################### end of the function noteGLM.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1349 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1351 |
f0dc3958e65d
"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"), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1353 metrique, factGraph, factGraphSel, listFact, listFactSel) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1354 { |
f0dc3958e65d
"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 à |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1356 ## un graphique ou analyse. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1357 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"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. |
f0dc3958e65d
"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. |
f0dc3958e65d
"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. |
f0dc3958e65d
"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). |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1362 ## metrique : la métrique choisie. |
f0dc3958e65d
"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. |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1367 ## dernier(s) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1368 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1370 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1371 ## Open file : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1372 File <- file(description=filename, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1373 open="w", encoding="latin1") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1374 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1375 ## if error : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1376 on.exit(if (exists("filename") && |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1377 tryCatch(isOpen(File), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1378 error=function(e)return(FALSE))) close(File)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1379 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1380 ## Metrics and factors infos : |
f0dc3958e65d
"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, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1382 listFact=listFact, #listFactSel=listFactSel, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1383 File=File, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1384 agregLevel=agregLevel, type=type) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1385 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1386 ## statistics : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1387 if (class(Data) == "list") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1388 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1389 cat("\n###################################################", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1390 "\nStatistics per level of splitting factor:\n", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1391 sep="", file=File,append=TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1392 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1393 invisible(sapply(1:length(Data), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1394 function(i) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1395 { |
f0dc3958e65d
"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, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1397 headline=factGraphSel[i]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1398 })) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1399 }else{ |
f0dc3958e65d
"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, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1401 headline=NULL) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1402 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1403 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1404 ## Close file : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1405 close(File) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1406 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1407 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1408 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1409 ######################################### end of the function infoStats.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1410 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1411 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1413 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1414 printSelectionInfo.f <- function(metrique, listFact, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1415 File, |
f0dc3958e65d
"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")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1417 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1418 ## Purpose: Write data informations |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1419 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1420 ## Arguments: metrique : chosen metric |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1421 ## listFact : factor's list |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1422 ## File : Results file name |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1423 ## agregLevel : aggregation level |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1424 ## type : function type |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1425 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1427 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1428 cat("\n##################################################\n", |
f0dc3958e65d
"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", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1430 sep="", file=File,append=TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1431 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1432 ## metric info : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1433 cat("\n Metrics:", metrique, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1434 "\n", file=File,append=TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1435 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1436 ## aggregation level : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1437 cat(" aggregated per ", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1438 switch(agregLevel, |
f0dc3958e65d
"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"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1440 "size class / " |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1441 }), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1442 switch(agregLevel, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1443 "CL_espece"=,"spCL_espece"=,"species"=,"spSpecies"=,"spEspece"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1444 "species / " |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1445 }), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1446 switch(agregLevel, |
f0dc3958e65d
"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"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1448 paste(listFact, " (mean over ", sep="") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1449 }), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1450 "observation units", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1451 switch(agregLevel, |
f0dc3958e65d
"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"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1453 ")" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1454 }), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1455 ".\n", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1456 sep="", file=File,append=TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1457 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1458 ## Separation factors : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1459 # switch(agregLevel, |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1461 # cat("\n", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1462 # switch(type, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1463 # "graph"="Graphics separation factor", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1464 # "stat"="Analyses separation factor"), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1465 # " : ", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1466 # ifelse(factGraph == "", "printSelectionInfo.f.11", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1467 # ifelse(is.na(factGraphSel[1]), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1468 # paste(varNames.f(factGraph, "nom"), "none!"), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1469 # paste(varNames.f(factGraph, "nom"), " (", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1470 # paste(factGraphSel, collapse=", "), ")", sep=""))), "\n", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1471 # sep="", file=File,append=TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1472 # }, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1473 # "unitobs"=,"CL_unitobs"=,"unitobs(CL)"=,"spUnitobs"={ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1474 # cat("(warning: no selection!!!)", |
f0dc3958e65d
"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: ", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1476 # ifelse(is.na(factGraphSel[1]), |
f0dc3958e65d
"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)!"), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1478 # paste(varNames.f(factGraph, "nom"), " (", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1479 # paste(factGraphSel, collapse=", "), ")", sep=""))), "\n", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1480 # sep="", file=File,append=TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1481 # }) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1482 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1483 ## Clustering factors : |
f0dc3958e65d
"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", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1485 "spUnitobs", "spUnitobs(CL)"))) {type <- "spatialGraph"} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1486 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1487 cat(switch(type, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1488 "graph"="\nGrouping factor(s): \n * ", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1489 "stat"="\nAnalyses factor(s): \n * ", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1490 "spatialGraph"="\nSpatial aggregation factor(s): \n * "), |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1492 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1493 # invisible(sapply(1:length(listFact), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1494 # function(i) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1495 # { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1496 # cat("\n * ", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1497 # ifelse(is.na(listFactSel[[i]][1]), |
f0dc3958e65d
"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)"), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1499 # paste(varNames.f(listFact[i], "nom"), " (", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1500 # paste(listFactSel[[i]], collapse=", "), ")", sep="")), "\n", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1501 # sep="", file=File,append=TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1502 # })) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1503 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1504 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1505 ######################################### end of the function printSelectionInfo.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1506 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1507 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1509 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1511 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1512 ## Purpose: Write general statistics table |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1513 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1514 ## Arguments: Data : Analysis data |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1515 ## metrique : metric's name |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1516 ## listFact : Factor's list |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1517 ## File : Simple statistics file name |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1518 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1520 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1521 ## Header : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1522 if ( ! is.null(headline)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1523 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1524 cat("\n", rep("#", nchar(headline) + 3), "\n", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1525 "## ", headline, "\n", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1526 sep="", file=File,append=TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1527 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1528 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1530 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1532 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1533 if ( ! is.null(listFact)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1534 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1535 cat("\n#########################################", |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1537 |
f0dc3958e65d
"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 : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1539 res <- with(Data, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1540 tapply(eval(parse(text=metrique)), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1541 INDEX=do.call(paste, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1542 c(lapply(listFact, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1543 function(y)eval(parse(text=y))), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1544 sep=".")), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1545 FUN=summary.fr)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1546 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1547 ## results in table |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1548 capture.output(print(do.call(rbind, res)), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1549 file=File, append=TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1550 }else{} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1551 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1552 ## empty line : |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1553 cat("\n", file=File,append=TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1554 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1555 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1556 ######################################### end of the function printStats.f |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1557 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1558 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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),...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1561 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1562 ## Purpose: Adding SD and N to summary |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1563 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1564 ## Arguments: object : Object to summarise |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1565 ## ---------------------------------------------------------------------- |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1567 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1568 if ( ! is.numeric(object)) stop("Programming error") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1569 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1570 ## Compute summary : |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1572 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1573 return(res) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1574 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1575 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1576 ######################################### start of the function summary.fr |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1577 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1578 ######################################### Package DHARMa |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1579 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1580 ################ simulateResiduals.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1581 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1582 #' Create simulated residuals |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1583 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1585 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"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. |
f0dc3958e65d
"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. |
f0dc3958e65d
"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. |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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. |
f0dc3958e65d
"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}} |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1595 #' |
f0dc3958e65d
"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: |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1597 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1599 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1601 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1603 #' |
f0dc3958e65d
"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))). |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1605 #' |
f0dc3958e65d
"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). |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1607 #' |
f0dc3958e65d
"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: |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1609 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1611 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1613 #' |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1615 #' |
f0dc3958e65d
"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}}. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1617 #' |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1619 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1620 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1621 #' @example inst/examples/simulateResidualsHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1622 #' @import stats |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1623 #' @export |
f0dc3958e65d
"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"), ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1625 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1626 ######## general assertions and startup calculations ########## |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1627 |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1629 checkModel(fittedModel) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1630 match.arg(method) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1631 randomState <-getRandomState(seed) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1632 on.exit({randomState$restoreCurrent()}) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1633 ptm <- proc.time() |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1634 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1635 ####### extract model info ############ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1636 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1637 out = list() |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1638 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1639 family = family(fittedModel) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1640 out$fittedModel = fittedModel |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1641 out$modelClass = class(fittedModel)[1] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1642 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1643 out$nObs = nobs(fittedModel) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1644 out$nSim = n |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1645 out$refit = refit |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1646 out$observedResponse = getObservedResponse(fittedModel) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1647 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1648 if(is.null(integerResponse)){ |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1650 else integerResponse = FALSE |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1651 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1652 out$integerResponse = integerResponse |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1653 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1654 out$problems = list() |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1655 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1657 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1658 if(out$modelClass %in% c("HLfit")){ |
f0dc3958e65d
"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] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1660 }else{ |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1662 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1663 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1664 out$fittedFixedEffects = getFixedEffects(fittedModel) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1665 out$fittedResiduals = residuals(fittedModel, type = "response") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1666 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1667 ######## refit = F ################## |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1668 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1669 if (refit == FALSE){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1670 |
f0dc3958e65d
"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", ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1672 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1673 checkSimulations(out$simulatedResponse, out$nObs, out$nSim) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1674 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1676 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1677 ######## refit = T ################## |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1678 } else { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1679 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1680 # Adding new outputs |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1681 |
f0dc3958e65d
"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 ) |
f0dc3958e65d
"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 ) |
f0dc3958e65d
"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 ) |
f0dc3958e65d
"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) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1687 |
f0dc3958e65d
"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", ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1689 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1690 for (i in 1:n){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1691 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1692 simObserved = out$simulatedResponse[[i]] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1693 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1694 try({ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1695 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1696 # for testing |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1697 # if (i==3) stop("x") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1698 # Note: also set silent = T for production |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1699 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1700 refittedModel = getRefit(fittedModel, simObserved) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1701 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1702 out$refittedPredictedResponse[,i] = predict(refittedModel, type = "response") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1703 out$refittedFixedEffects[,i] = getFixedEffects(refittedModel) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1704 out$refittedResiduals[,i] = residuals(refittedModel, type = "response") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1705 out$refittedPearsonResiduals[,i] = residuals(refittedModel, type = "pearson") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1706 #out$refittedRandomEffects[,i] = ranef(refittedModel) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1707 }, silent = TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1708 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1709 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1710 ######### residual checks ########### |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1711 |
f0dc3958e65d
"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.") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1713 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1714 ## check for convergence problems |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1715 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1716 dup = sum(duplicated(out$refittedFixedEffects, MARGIN = 2)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1717 if (dup > 0){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1718 if (dup < n/3){ |
f0dc3958e65d
"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.")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1720 } else { |
f0dc3958e65d
"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.")) |
f0dc3958e65d
"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" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1723 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1724 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1725 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1726 ######### residual calculations ########### |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1727 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1729 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1730 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1731 ########### Wrapup ############ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1732 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1733 out$time = proc.time() - ptm |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1734 out$randomState = randomState |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1735 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1736 class(out) = "DHARMa" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1737 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1738 if(plot == TRUE) plot(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1739 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1740 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1741 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1742 |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1744 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1745 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1746 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1748 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1750 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1751 #' @param fittedModel a fitted model |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1753 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1755 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1756 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1757 #' @keywords internal |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1758 checkModel <- function(fittedModel, stop = F){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1759 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1760 out = T |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1761 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1762 if(!(class(fittedModel)[1] %in% getPossibleModels())){ |
f0dc3958e65d
"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!") |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1765 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1766 |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1768 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1770 # #' @example inst/examples/checkModelHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1771 |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1773 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1774 |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1776 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1777 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1778 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1779 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1780 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1781 #' Check simulated data |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1782 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1784 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1785 #' @param simulatedResponse the simulated response |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1786 #' @param nObs number of observations |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1787 #' @param nSim number of simulations |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1788 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1789 #' @keywords internal |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1790 checkSimulations <- function(simulatedResponse, nObs, nSim){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1791 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1793 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1795 |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1797 |
f0dc3958e65d
"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) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1800 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1801 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1802 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1803 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1804 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1805 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1806 #' Recalculate residuals with grouping |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1807 #' |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1809 #' |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1811 #' @param group group of each data point |
f0dc3958e65d
"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. |
f0dc3958e65d
"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. |
f0dc3958e65d
"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}} |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1816 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1817 #' @example inst/examples/simulateResidualsHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1818 #' @export |
f0dc3958e65d
"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")){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1820 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1821 randomState <-getRandomState(seed) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1822 on.exit({randomState$restoreCurrent()}) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1823 match.arg(method) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1824 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1826 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1827 out = list() |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1828 out$original = simulationOutput |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1829 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1830 if(is.null(group)) return(simulationOutput) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1831 else group =as.factor(group) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1832 out$nGroups = nlevels(group) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1833 |
f0dc3958e65d
"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] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1835 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1836 out$observedResponse = aggregateByGroup(simulationOutput$observedResponse) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1837 out$fittedPredictedResponse = aggregateByGroup(simulationOutput$fittedPredictedResponse) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1838 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1839 if (simulationOutput$refit == F){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1840 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1841 out$simulatedResponse = apply(simulationOutput$simulatedResponse, 2, aggregateByGroup) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1843 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1844 ######## refit = T ################## |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1845 } else { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1846 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1847 out$refittedPredictedResponse <- apply(simulationOutput$refittedPredictedResponse, 2, aggregateByGroup) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1848 out$fittedResiduals = aggregateByGroup(simulationOutput$fittedResiduals) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1849 out$refittedResiduals = apply(simulationOutput$refittedResiduals, 2, aggregateByGroup) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1850 out$refittedPearsonResiduals = apply(simulationOutput$refittedPearsonResiduals, 2, aggregateByGroup) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1851 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1853 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1854 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1855 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1858 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1859 out$aggregateByGroup = aggregateByGroup |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1860 out = c(out, simulationOutput) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1861 out$randomState = randomState |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1862 class(out) = "DHARMa" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1863 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1864 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1865 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1866 ################ simulateResiduals.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1867 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1868 ################ DHARMa.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1869 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1871 #' @name DHARMa |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1872 #' @docType package |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1874 #' @details See index / vignette for details |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1875 #' @seealso \code{\link{simulateResiduals}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1876 #' @examples |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1877 #' vignette("DHARMa", package="DHARMa") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1878 NULL |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1879 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1880 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1881 #' Print simulated residuals |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1882 #' |
f0dc3958e65d
"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}} |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1885 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1886 print.DHARMa <- function(x, ...){ |
f0dc3958e65d
"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") |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1889 else { |
f0dc3958e65d
"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], "...") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1891 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1892 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1893 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1894 #' Return residuals of a DHARMa simulation |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1895 #' |
f0dc3958e65d
"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}} |
f0dc3958e65d
"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 |
f0dc3958e65d
"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. |
f0dc3958e65d
"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 |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1901 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1903 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1904 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1905 #' @example inst/examples/simulateResidualsHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1906 #' |
f0dc3958e65d
"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, ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1908 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1909 if(is.null(quantileFunction)){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1910 return(object$scaledResiduals) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1911 } else { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1912 res = quantileFunction(object$scaledResiduals) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1913 if(!is.null(outlierValues)){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1914 res = ifelse(res == -Inf, outlierValues[1], res) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1915 res = ifelse(res == Inf, outlierValues[2], res) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1916 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1917 return(res) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1918 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1919 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1920 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1921 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1922 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1923 #' Return outliers |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1924 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1925 #' Returns the outliers of a DHARMa object |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1926 #' |
f0dc3958e65d
"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}} |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1931 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1933 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1935 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1937 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1939 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1940 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1941 #' |
f0dc3958e65d
"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")){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1943 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1944 return = match.arg(return) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1945 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1946 out = residuals(object) >= upperQuantile | residuals(object) <= lowerQuantile |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1947 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1948 if(return == "logical") return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1949 else(return(which(out))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1950 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1951 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1952 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1953 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1955 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1957 #' @param observedResponse true observations |
f0dc3958e65d
"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. |
f0dc3958e65d
"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 |
f0dc3958e65d
"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. |
f0dc3958e65d
"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}} |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1964 #' @example inst/examples/createDharmaHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1965 #' @export |
f0dc3958e65d
"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")){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1967 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1968 randomState <-getRandomState(seed) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1969 on.exit({randomState$restoreCurrent()}) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1970 match.arg(method) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1971 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1972 out = list() |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1973 out$simulatedResponse = simulatedResponse |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1974 out$refit = F |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1975 out$integerResponse = integerResponse |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1976 out$observedResponse = observedResponse |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1977 |
f0dc3958e65d
"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") |
f0dc3958e65d
"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.") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1980 |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1982 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1983 out$nObs = length(observedResponse) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1984 |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1986 |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1988 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1989 out$nSim = ncol(simulatedResponse) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1990 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1992 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1993 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1995 if(is.null(fittedPredictedResponse)){ |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1997 fittedPredictedResponse = apply(simulatedResponse, 1, mean) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1998 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
1999 out$fittedPredictedResponse = fittedPredictedResponse |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2000 out$randomState = randomState |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2001 class(out) = "DHARMa" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2002 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2003 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2004 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2005 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2007 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2010 #' @details The |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2011 #' @return an object of class DHARMa |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2012 #' @keywords internal |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2013 ensureDHARMa <- function(simulationOutput, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2014 convert = F){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2015 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2016 if(inherits(simulationOutput, "DHARMa")){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2017 return(simulationOutput) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2018 } else { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2019 |
f0dc3958e65d
"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!") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2021 else { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2022 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2023 if (class(simulationOutput)[1] %in% getPossibleModels()){ |
f0dc3958e65d
"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)) |
f0dc3958e65d
"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) { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2026 out = list() |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2027 out$scaledResiduals = simulationOutput |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2028 out$nObs = length(out$scaledResiduals) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2029 class(out) = "DHARMa" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2030 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2031 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2032 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2033 } |
f0dc3958e65d
"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!") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2035 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2036 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2037 ####################### DHARMa.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2038 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2039 ####################### tests.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2040 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2041 #' DHARMa general residual test |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2042 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2043 #' Calls both uniformity and dispersion test |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2044 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2046 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2049 #' @author Florian Hartig |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2051 #' @example inst/examples/testsHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2052 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2053 testResiduals <- function(simulationOutput, plot = T){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2054 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2055 opar = par(mfrow = c(1,3)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2056 on.exit(par(opar)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2057 out = list() |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2058 out$uniformity = testUniformity(simulationOutput, plot = plot) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2059 out$dispersion = testDispersion(simulationOutput, plot = plot) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2060 out$outliers = testOutliers(simulationOutput, plot = plot) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2061 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2062 print(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2063 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2064 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2065 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2066 #' Residual tests |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2067 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2069 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2071 #' @author Florian Hartig |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2072 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2073 testSimulatedResiduals <- function(simulationOutput){ |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2075 testResiduals(simulationOutput) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2076 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2077 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2078 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2079 #' Test for overall uniformity |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2080 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2082 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2087 #' @author Florian Hartig |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2089 #' @example inst/examples/testsHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2090 #' @export |
f0dc3958e65d
"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){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2092 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2093 simulationOutput = ensureDHARMa(simulationOutput, convert = T) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2094 |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2096 if(plot == T) plotQQunif(simulationOutput = simulationOutput) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2097 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2098 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2099 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2100 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2101 # Experimental |
f0dc3958e65d
"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){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2103 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2104 simulationOutput = ensureDHARMa(simulationOutput, convert = T) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2105 |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2107 #if(plot == T) plotQQunif(simulationOutput = simulationOutput) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2108 out = NULL |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2109 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2110 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2111 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2112 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2113 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2114 #' Test for quantiles |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2115 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2116 #' This function tests |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2117 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2120 #' @param quantiles the quantiles to be tested |
f0dc3958e65d
"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 |
f0dc3958e65d
"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). |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2123 #' |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2125 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2127 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2128 #' @author Florian Hartig |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2129 #' @example inst/examples/testQuantilesHelp.R |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2131 #' @export |
f0dc3958e65d
"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){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2133 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2134 if(plot == F){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2135 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2136 out = list() |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2137 out$data.name = deparse(substitute(simulationOutput)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2138 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2139 simulationOutput = ensureDHARMa(simulationOutput, convert = T) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2140 res = simulationOutput$scaledResiduals |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2141 pred = ensurePredictor(simulationOutput, predictor) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2142 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2144 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2145 quantileFits <- list() |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2146 pval = rep(NA, length(quantiles)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2147 predictions = data.frame(pred = sort(dat$pred)) |
f0dc3958e65d
"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))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2149 for(i in 1:length(quantiles)){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2150 datTemp = dat |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2151 datTemp$res = datTemp$res - quantiles[i] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2152 |
f0dc3958e65d
"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. |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2155 dimSmooth = min(length(unique(datTemp$pred)), 10) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2157 if(inherits(quantResult, "try-error")){ |
f0dc3958e65d
"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.") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2159 } else { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2160 x = summary(quantileFits[[i]]) |
f0dc3958e65d
"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 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2163 predictions[, 2*i] = quantPre$fit + quantiles[i] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2164 predictions[, 2*i + 1] = quantPre$se.fit |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2165 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2166 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2167 |
f0dc3958e65d
"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" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2169 out$alternative = "both" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2170 out$pvals = pval |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2172 out$predictions = predictions |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2173 out$qgamFits = quantileFits |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2174 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2175 class(out) = "htest" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2176 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2177 } else if(plot == T) { |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2179 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2180 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2181 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2182 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2183 |
f0dc3958e65d
"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))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2185 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2186 #' Test for outliers |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2187 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2189 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2195 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2197 #' |
f0dc3958e65d
"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). |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2199 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2201 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2202 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2203 #' @author Florian Hartig |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2205 #' @example inst/examples/testOutliersHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2206 #' @export |
f0dc3958e65d
"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){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2208 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2209 # check inputs |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2210 alternative = match.arg(alternative) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2211 margin = match.arg(margin) |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2213 simulationOutput = ensureDHARMa(simulationOutput, convert = "Model") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2214 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2215 # calculation of outliers |
f0dc3958e65d
"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)) |
f0dc3958e65d
"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) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2219 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2220 # calculations of trials and H0 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2222 trials = simulationOutput$nObs |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2223 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2225 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2226 # overwrite information in binom.test |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2227 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2228 out$data.name = data.name |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2229 out$margin = margin |
f0dc3958e65d
"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" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2231 |
f0dc3958e65d
"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)") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2233 names(out$parameter) = "simulations" |
f0dc3958e65d
"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,")") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2235 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2236 out$interval = "tst" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2237 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2238 out$interval = |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2239 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2240 if(plot == T) { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2241 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2242 hist(simulationOutput, main = "") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2243 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2244 main = ifelse(out$p.value <= 0.05, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2245 "Outlier test significant", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2246 "Outlier test n.s.") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2247 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2248 title(main = main, cex.main = 1, |
f0dc3958e65d
"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")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2250 |
f0dc3958e65d
"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" )) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2252 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2253 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2254 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2255 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2256 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2257 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2258 #' DHARMa dispersion tests |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2259 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2261 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2263 #' @param plot whether to plot output |
f0dc3958e65d
"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. |
f0dc3958e65d
"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}} |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2267 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2269 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2271 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2273 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2274 #' @author Florian Hartig |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2276 #' @example inst/examples/testsHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2277 #' @export |
f0dc3958e65d
"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, ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2279 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2280 out = list() |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2281 out$data.name = deparse(substitute(simulationOutput)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2282 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2283 alternative <- match.arg(alternative) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2284 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2285 simulationOutput = ensureDHARMa(simulationOutput, convert = "Model") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2286 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2287 if(simulationOutput$refit == F){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2288 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2289 spread <- function(x) sd(x - simulationOutput$fittedPredictedResponse) |
f0dc3958e65d
"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, ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2291 } else { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2292 |
f0dc3958e65d
"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) { |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2295 return(NA) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2296 }) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2297 if(is.na(observed)) return(NA) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2298 expected = apply(simulationOutput$refittedPearsonResiduals^2 , 2, sum) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2299 out$statistic = c(dispersion = observed / mean(expected)) |
f0dc3958e65d
"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" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2301 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2303 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2304 out$alternative = alternative |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2305 out$p.value = p |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2306 class(out) = "htest" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2307 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2308 if(plot == T) { |
f0dc3958e65d
"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) |
f0dc3958e65d
"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 ="") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2311 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2313 abline(v = observed, lwd= 2, col = "red") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2314 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2315 main = ifelse(out$p.value <= 0.05, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2316 "Dispersion test significant", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2317 "Dispersion test n.s.") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2318 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2319 title(main = main, cex.main = 1, |
f0dc3958e65d
"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")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2321 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2322 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2323 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2324 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2325 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2326 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2327 #' Simulated overdisperstion tests |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2328 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2330 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2332 #' @param ... additional arguments to \code{\link{testDispersion}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2333 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2334 testOverdispersion <- function(simulationOutput, ...){ |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2336 testDispersion(simulationOutput, ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2337 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2338 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2339 #' Parametric overdisperstion tests |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2340 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2342 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2344 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2345 testOverdispersionParametric <- function(...){ |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2347 return(0) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2348 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2349 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2350 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2351 #' Tests for zero-inflation |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2352 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2354 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2356 #' @param ... further arguments to \code{\link{testGeneric}} |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2358 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2359 #' Some notes about common problems / questions: |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2360 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2362 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2364 #' |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2366 #' @author Florian Hartig |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2367 #' @example inst/examples/testsHelp.R |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2369 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2370 testZeroInflation <- function(simulationOutput, ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2371 countZeros <- function(x) sum( x == 0) |
f0dc3958e65d
"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", ... ) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2373 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2374 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2375 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2376 #' Generic simulation test of a summary statistic |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2377 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2379 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2385 #' |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2387 #' |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2389 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2390 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2391 #' @author Florian Hartig |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2392 #' @example inst/examples/testsHelp.R |
f0dc3958e65d
"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}} |
f0dc3958e65d
"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"){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2395 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2396 out = list() |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2397 out$data.name = deparse(substitute(simulationOutput)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2398 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2399 simulationOutput = ensureDHARMa(simulationOutput, convert = "Model") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2400 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2401 alternative <- match.arg(alternative) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2402 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2403 observed = summary(simulationOutput$observedResponse) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2404 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2405 simulated = apply(simulationOutput$simulatedResponse, 2, summary) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2406 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2408 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2409 out$statistic = c(ratioObsSim = observed / mean(simulated)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2410 out$method = methodName |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2411 out$alternative = alternative |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2412 out$p.value = p |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2413 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2414 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2415 class(out) = "htest" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2416 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2417 if(plot == T) { |
f0dc3958e65d
"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) |
f0dc3958e65d
"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 ="") |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2421 abline(v = observed, lwd= 2, col = "red") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2422 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2423 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2424 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2425 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2426 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2427 #' Test for temporal autocorrelation |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2428 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2430 #' |
f0dc3958e65d
"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}} |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2434 #' @param plot whether to plot output |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2436 #' |
f0dc3958e65d
"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). |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2438 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2440 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2442 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2444 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2446 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2447 #' @author Florian Hartig |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2449 #' @example inst/examples/testTemporalAutocorrelationHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2450 #' @export |
f0dc3958e65d
"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){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2452 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2453 simulationOutput = ensureDHARMa(simulationOutput, convert = T) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2454 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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.") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2457 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2458 alternative <- match.arg(alternative) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2459 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2460 if(is.null(time)){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2461 time = sample.int(simulationOutput$nObs, simulationOutput$nObs) |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2463 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2464 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2466 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2467 if(plot == T) { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2468 oldpar <- par(mfrow = c(1,2)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2469 on.exit(par(oldpar)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2470 |
f0dc3958e65d
"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)], |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2473 acf(simulationOutput$scaledResiduals[order(time)], main = "Autocorrelation") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2474 legend("topright", |
f0dc3958e65d
"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)), |
f0dc3958e65d
"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."))), |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2478 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2479 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2480 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2481 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2482 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2483 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2484 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2485 #' Test for spatial autocorrelation |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2486 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2488 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2494 #' @param plot whether to plot output |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2496 #' |
f0dc3958e65d
"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) |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2499 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2501 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2503 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2505 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2507 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2509 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2510 #' @author Florian Hartig |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2512 #' @import grDevices |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2513 #' @example inst/examples/testSpatialAutocorrelationHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2514 #' @export |
f0dc3958e65d
"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){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2516 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2517 alternative <- match.arg(alternative) |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2519 simulationOutput = ensureDHARMa(simulationOutput, convert = T) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2520 |
f0dc3958e65d
"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.") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2522 |
f0dc3958e65d
"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") |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2525 if(is.null(x)){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2526 x = runif(simulationOutput$nObs, -1,1) |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2528 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2529 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2530 if(is.null(y)){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2531 y = runif(simulationOutput$nObs, -1,1) |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2533 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2534 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2537 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2538 invDistMat <- 1/distMat |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2539 diag(invDistMat) <- 0 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2540 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2542 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2543 out = list() |
f0dc3958e65d
"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) |
f0dc3958e65d
"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" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2546 out$alternative = "Spatial autocorrelation" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2547 out$p.value = MI$p.value |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2548 out$data.name = data.name |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2549 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2550 class(out) = "htest" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2551 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2552 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2553 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2554 if(plot == T) { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2555 opar <- par(mfrow = c(1,1)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2556 on.exit(par(opar)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2557 |
f0dc3958e65d
"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) |
f0dc3958e65d
"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 ) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2560 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2561 # TODO implement correlogram |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2562 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2563 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2564 if(plot == T) { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2565 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2566 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2567 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2568 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2569 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2570 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2571 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2572 getP <- function(simulated, observed, alternative){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2573 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2574 if(alternative == "greater") p = mean(simulated >= observed) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2575 if(alternative == "less") p = mean(simulated <= observed) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2577 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2578 return(p) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2579 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2580 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2581 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2582 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2583 ####################### tests.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2584 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2585 ####################### compatibility.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2586 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2587 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2588 # New S3 methods |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2589 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2590 #' Get model response |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2591 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2592 #' Extract the response of a fitted model |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2593 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2595 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2596 #' @param object a fitted model |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2597 #' @param ... additional parameters |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2598 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2599 #' @example inst/examples/wrappersHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2600 #' |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2602 #' @author Florian Hartig |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2603 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2604 getObservedResponse <- function (object, ...) { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2605 UseMethod("getObservedResponse", object) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2606 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2607 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2608 #' @rdname getObservedResponse |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2609 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2610 getObservedResponse.default <- function (object, ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2611 out = model.frame(object)[,1] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2612 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2613 # check for weights in k/n case |
f0dc3958e65d
"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))){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2615 x = model.frame(object) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2616 out = out * x$`(weights)` |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2617 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2618 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2619 # check for k/n binomial |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2620 if(is.matrix(out)){ |
f0dc3958e65d
"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") |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2623 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2624 out = out[,1] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2625 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2626 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2629 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2630 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2631 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2632 |
f0dc3958e65d
"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" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2634 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2635 #' Get model simulations |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2636 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2637 #' Wrapper to simulate from a fitted model |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2638 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2640 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2641 #' @param object a fitted model |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2642 #' @param nsim number of simulations |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2645 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2646 #' @return a matrix with simulations |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2647 #' @example inst/examples/wrappersHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2648 #' |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2650 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2652 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2654 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2655 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2656 #' @author Florian Hartig |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2657 #' @export |
f0dc3958e65d
"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"), ...) { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2659 UseMethod("getSimulations", object) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2660 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2661 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2662 #' @rdname getSimulations |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2663 #' @export |
f0dc3958e65d
"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"), ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2665 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2666 type <- match.arg(type) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2667 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2668 out = simulate(object, nsim = nsim , ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2669 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2670 if (type == "normal"){ |
f0dc3958e65d
"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")){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2672 if("(weights)" %in% colnames(model.frame(object))){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2673 x = model.frame(object) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2674 out = out * x$`(weights)` |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2675 } else if (is.matrix(out[[1]])){ |
f0dc3958e65d
"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 |
f0dc3958e65d
"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)] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2678 } else if(is.factor(out[[1]])){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2679 if(nlevels(out[[1]]) != 2){ |
f0dc3958e65d
"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.") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2681 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2682 else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2683 out = data.matrix(out) - 1 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2684 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2685 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2686 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2687 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2689 } else{ |
f0dc3958e65d
"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")){ |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2692 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2693 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2694 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2695 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2696 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2697 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2698 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2699 #' Extract fixed effects of a supported model |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2700 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2702 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2703 #' @param fittedModel a fitted model |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2704 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2705 #' @example inst/examples/wrappersHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2706 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2707 #' @importFrom lme4 fixef |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2708 #' |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2710 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2711 getFixedEffects <- function(fittedModel){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2712 |
f0dc3958e65d
"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") ){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2714 out = coef(fittedModel) |
f0dc3958e65d
"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")){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2716 out = fixef(fittedModel) |
f0dc3958e65d
"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")){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2718 out = glmmTMB::fixef(fittedModel) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2719 out = out$cond |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2720 } else { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2721 out = coef(fittedModel) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2722 if(is.null(out)) out = fixef(fittedModel) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2723 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2724 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2725 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2726 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2727 #' Get model refit |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2728 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2729 #' Wrapper to refit a fitted model |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2730 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2731 #' @param object a fitted model |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2734 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2736 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2737 #' @example inst/examples/wrappersHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2738 #' |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2740 #' @author Florian Hartig |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2741 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2742 getRefit <- function (object, newresp, ...) { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2743 UseMethod("getRefit", object) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2744 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2745 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2746 #' @rdname getRefit |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2747 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2748 #' @importFrom lme4 refit |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2749 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2750 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2751 getRefit.default <- function (object, newresp, ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2752 refit(object, newresp, ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2753 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2754 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2755 #' Get model fitted |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2756 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2758 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2760 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2761 #' @param object a fitted model |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2763 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2764 #' @example inst/examples/wrappersHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2765 #' |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2767 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2768 #' @author Florian Hartig |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2769 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2770 getFitted <- function (object, ...) { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2771 UseMethod("getFitted", object) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2772 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2773 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2774 #' @rdname getFitted |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2775 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2776 getFitted.default <- function (object,...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2777 fitted(object, ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2778 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2779 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2780 #' has NA |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2781 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2783 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2784 #' @param object a fitted model |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2785 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2787 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2788 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2789 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2790 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2791 # hasNA <- function(object){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2792 # x = rownames(model.frame(object)) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2794 # else return(FALSE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2795 # } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2796 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2797 ######### LM ############# |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2798 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2799 #' @rdname getRefit |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2800 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2801 getRefit.lm <- function(object, newresp, ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2802 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2803 newData <-model.frame(object) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2804 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2805 if(is.vector(newresp)){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2806 newData[,1] = newresp |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2807 } else if (is.factor(newresp)){ |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2809 newData[,1] = as.numeric(newresp) - 1 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2810 } else { |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2812 newData[[1]] = NULL |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2813 newData = cbind(newresp, newData) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2814 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2815 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2816 refittedModel = update(object, data = newData) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2817 return(refittedModel) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2818 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2819 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2820 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2821 hasWeigths.lm <- function(object, ...){ |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2823 else return(FALSE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2824 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2825 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2826 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2827 ######### GLM ############# |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2828 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2829 #' @rdname getSimulations |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2830 #' @export |
f0dc3958e65d
"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"), ...){ |
f0dc3958e65d
"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) |
f0dc3958e65d
"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, ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2834 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2835 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2836 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2837 ######## MGCV ############ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2838 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2840 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2841 #' @rdname getFitted |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2842 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2843 getFitted.gam <- function(object, ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2844 class(object) = "glm" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2845 out = stats::fitted(object, ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2846 names(out) = as.character(1:length(out)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2847 out |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2848 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2849 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2850 # Check that this works |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2851 # plot(fitted(fittedModelGAM), predict(fittedModelGAM, type = "response")) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2852 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2853 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2854 ######## lme4 ############ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2855 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2856 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2857 #' @rdname getSimulations |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2858 #' @export |
f0dc3958e65d
"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"), ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2860 |
f0dc3958e65d
"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) |
f0dc3958e65d
"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, ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2863 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2864 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2865 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2866 ######## glmmTMB ###### |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2867 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2868 #' @rdname getRefit |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2869 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2870 getRefit.glmmTMB <- function(object, newresp, ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2871 newData <-model.frame(object) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2872 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2874 if(is.matrix(newresp)){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2875 tmp = colnames(newData[[1]]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2876 newData[[1]] = NULL |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2877 newData = cbind(newresp, newData) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2878 colnames(newData)[1:2] = tmp |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2879 } else { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2880 newData[[1]] = newresp |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2881 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2882 refittedModel = update(object, data = newData) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2883 return(refittedModel) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2884 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2885 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2886 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2889 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2890 #' @rdname getSimulations |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2891 #' @export |
f0dc3958e65d
"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"), ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2893 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2895 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2896 type <- match.arg(type) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2897 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2898 out = simulate(object, nsim = nsim, ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2899 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2900 if (type == "normal"){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2901 if (is.matrix(out[[1]])){ |
f0dc3958e65d
"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 |
f0dc3958e65d
"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)] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2904 } |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2906 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2907 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2908 # check for weights in k/n case |
f0dc3958e65d
"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")){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2910 if("(weights)" %in% colnames(model.frame(object))){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2911 w = model.frame(object) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2912 w = w$`(weights)` |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2913 tmp <- function(x)x/w |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2914 out = apply(out, 2, tmp) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2915 out = as.data.frame(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2916 } |
f0dc3958e65d
"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]])){ |
f0dc3958e65d
"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)]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2919 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2920 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2921 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2922 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2923 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2924 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2925 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2926 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2927 # matrixResp = |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2928 # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2929 # if(matrixResp & !is.null(ncol(newresp))){ |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2931 # tmp = colnames(newData[[1]]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2932 # newData[[1]] = NULL |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2933 # newData = cbind(newresp, newData) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2934 # colnames(newData)[1:2] = tmp |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2935 # } else if(!is.null(ncol(newresp))){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2936 # newData[[1]] = newresp[,1] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2937 # } else { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2938 # newData[[1]] = newresp |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2939 # } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2940 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2941 |
f0dc3958e65d
"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)))] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2943 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2944 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2946 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2947 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2948 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2949 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2950 ####### spaMM ######### |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2951 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2952 #' @rdname getObservedResponse |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2953 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2954 getObservedResponse.HLfit <- function(object, ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2955 out = spaMM::response(object, ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2956 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2957 nKcase = is.matrix(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2958 if(nKcase){ |
f0dc3958e65d
"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") |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2961 out = out[,1] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2962 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2963 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2965 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2966 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2967 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2968 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2969 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2970 #' @rdname getSimulations |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2971 #' @export |
f0dc3958e65d
"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"), ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2973 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2974 type <- match.arg(type) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2975 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2976 capture.output({out = simulate(object, nsim = nsim, ...)}) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2977 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2978 if(type == "normal"){ |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2980 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2981 out = as.data.frame(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2982 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2983 return(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2984 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2985 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2986 #' @rdname getRefit |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2987 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2988 getRefit.HLfit <- function(object, newresp, ...) { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2989 spaMM::update_resp(object, newresp, evaluate = TRUE) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2990 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2991 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2992 ####################### compatibility.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2993 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2994 ####################### helper.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2995 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2996 #' Modified ECDF function |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2997 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
2999 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3000 #' @keywords internal |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3001 DHARMa.ecdf <- function (x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3002 { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3003 x <- sort(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3004 n <- length(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3005 if (n < 1) |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3007 vals <- unique(x) |
f0dc3958e65d
"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), |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3010 class(rval) <- c("ecdf", "stepfun", class(rval)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3011 assign("nobs", n, envir = environment(rval)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3012 attr(rval, "call") <- sys.call() |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3013 rval |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3014 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3015 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3016 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3017 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3018 #' calculate quantiles |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3019 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3020 #' calculates residual quantiles from a given simulation |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3021 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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" |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3026 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3028 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3030 #' |
f0dc3958e65d
"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). |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3032 #' |
f0dc3958e65d
"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). |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3034 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3035 #' @references |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3036 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3038 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3040 #' |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3042 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3043 #' @export |
f0dc3958e65d
"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")){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3045 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3046 method = match.arg(method) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3047 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3048 n = length(observed) |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3050 nSim = ncol(simulations) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3051 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3052 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3053 if(method == "traditional"){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3054 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3055 if(integerResponse == F){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3056 |
f0dc3958e65d
"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.") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3058 |
f0dc3958e65d
"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))] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3060 if(length(values) > 0){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3061 if (all(values%%1==0)){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3062 integerResponse = T |
f0dc3958e65d
"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)") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3064 } else { |
f0dc3958e65d
"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.") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3066 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3067 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3068 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3069 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3070 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3071 scaledResiduals = rep(NA, n) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3072 for (i in 1:n){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3073 if(integerResponse == T){ |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3075 }else{ |
f0dc3958e65d
"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]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3077 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3078 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3079 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3080 } else { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3081 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3082 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3083 scaledResiduals = rep(NA, n) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3084 for (i in 1:n){ |
f0dc3958e65d
"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,]) |
f0dc3958e65d
"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,]) |
f0dc3958e65d
"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]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3088 else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3089 scaledResiduals[i] = runif(1, min, max) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3090 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3091 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3092 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3093 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3094 return(scaledResiduals) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3095 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3096 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3097 # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3098 # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3099 # testData = createData(sampleSize = 200, family = gaussian(), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3100 # randomEffectVariance = 0, numGroups = 5) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3101 # fittedModel <- glmmTMB(observedResponse ~ Environment1, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3102 # data = testData) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3103 # simulationOutput <- simulateResiduals(fittedModel = fittedModel) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3104 # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3105 # sims = simulationOutput$simulatedResponse |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3106 # sims[1, c(1,6,8)] = 0 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3107 # any(apply(sims, 1, anyDuplicated)) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3109 # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3110 # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3111 # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3112 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3113 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3114 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3115 #' Check dot operator |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3116 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3117 #' @param name variable name |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3118 #' @param default variable default |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3119 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3121 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3122 #' @keywords internal |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3123 checkDots <- function(name, default, ...) { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3124 args <- list(...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3125 if(!name %in% names(args)) { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3126 ## Default value |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3127 return(default) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3128 } else { |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3130 return(args[[name]]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3131 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3132 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3133 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3134 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3135 securityAssertion <- function(context = "Not provided", stop = F){ |
f0dc3958e65d
"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:" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3137 if (stop == F) warning(paste(generalMessage, context)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3138 else stop(paste(generalMessage, context)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3139 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3140 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3141 ####################### helper.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3142 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3143 ####################### plot.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3144 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3145 #' DHARMa standard residual plots |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3146 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"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}} |
f0dc3958e65d
"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. |
f0dc3958e65d
"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. |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3152 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3154 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3156 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3158 #' |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3160 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3162 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3163 #' @seealso \code{\link{plotResiduals}}, \code{\link{plotQQunif}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3164 #' @example inst/examples/plotsHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3165 #' @import graphics |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3166 #' @import utils |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3167 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3168 plot.DHARMa <- function(x, rank = TRUE, ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3169 |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3171 on.exit(par(oldpar)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3172 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3173 plotQQunif(x) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3174 plotResiduals(x, rank = rank, ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3175 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3176 mtext("DHARMa residual diagnostics", outer = T) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3177 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3178 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3179 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3180 #' Histogram of DHARMa residuals |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3181 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3183 #' |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3185 #' @param breaks breaks for hist() function |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3186 #' @param col col for hist bars |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3187 #' @param main plot main |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3188 #' @param xlab plot xlab |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3189 #' @param cex.main plot cex.main |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3191 #' @seealso \code{\link{plotSimulatedResiduals}}, \code{\link{plotResiduals}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3192 #' @example inst/examples/plotsHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3193 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3194 hist.DHARMa <- function(x, |
f0dc3958e65d
"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), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3196 col = c("red",rep("lightgrey",50), "red"), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3197 main = "Hist of DHARMa residuals", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3198 xlab = "Residuals (outliers are marked red)", |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3199 cex.main = 1, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3200 ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3201 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3202 x = ensureDHARMa(x, convert = T) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3203 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3204 val = x$scaledResiduals |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3205 val[val == 0] = -0.01 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3206 val[val == 1] = 1.01 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3207 |
f0dc3958e65d
"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, ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3209 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3210 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3211 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3212 #' DHARMa standard residual plots |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3213 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3214 #' DEPRECATED, use plot() instead |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3215 #' |
f0dc3958e65d
"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}} |
f0dc3958e65d
"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. |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3219 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3220 #' @seealso \code{\link{plotResiduals}}, \code{\link{plotQQunif}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3221 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3222 plotSimulatedResiduals <- function(simulationOutput, ...){ |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3224 plot(simulationOutput, ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3225 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3226 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3227 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3228 #' Quantile-quantile plot for a uniform distribution |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3229 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3231 #' |
f0dc3958e65d
"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) |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"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}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3237 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3239 #' @seealso \code{\link{plotSimulatedResiduals}}, \code{\link{plotResiduals}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3240 #' @example inst/examples/plotsHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3241 #' @export |
f0dc3958e65d
"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, ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3243 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3244 simulationOutput = ensureDHARMa(simulationOutput, convert = "Model") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3245 |
f0dc3958e65d
"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, ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3247 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3248 if(testUniformity == TRUE){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3249 temp = testUniformity(simulationOutput, plot = F) |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3251 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3252 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3253 if(testOutliers == TRUE){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3254 temp = testOutliers(simulationOutput, plot = F) |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3256 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3257 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3258 if(testDispersion == TRUE){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3259 temp = testDispersion(simulationOutput, plot = F) |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3261 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3262 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3263 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3264 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3265 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3267 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3269 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"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) |
f0dc3958e65d
"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. |
f0dc3958e65d
"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. |
f0dc3958e65d
"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. |
f0dc3958e65d
"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. |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3277 #' @param ... additional arguments to plot / boxplot. |
f0dc3958e65d
"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). |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3279 #' |
f0dc3958e65d
"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}}). |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3281 #' |
f0dc3958e65d
"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). |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3283 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3285 #' |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3287 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3289 #' |
f0dc3958e65d
"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. |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3291 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3292 #' @seealso \code{\link{plotQQunif}} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3293 #' @example inst/examples/plotsHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3294 #' @export |
f0dc3958e65d
"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), ...){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3296 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3297 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3298 ##### Checks ##### |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3299 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3300 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3301 a <- list(...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3302 a$ylab = checkDots("ylab", "Standardized residual", ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3303 if(is.null(form)){ |
f0dc3958e65d
"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"), ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3305 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3306 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3307 simulationOutput = ensureDHARMa(simulationOutput, convert = T) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3308 res = simulationOutput$scaledResiduals |
f0dc3958e65d
"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.") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3310 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3311 pred = ensurePredictor(simulationOutput, form) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3312 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3313 ##### Rank transform and factor conversion##### |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3314 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3315 if(!is.factor(pred)){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3316 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3317 if (rank == T){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3318 pred = rank(pred, ties.method = "average") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3319 pred = pred / max(pred) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3320 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3321 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3322 nuniq = length(unique(pred)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3323 ndata = length(pred) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3325 if (asFactor) pred = factor(pred) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3326 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3327 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3328 ##### Residual scatter plots ##### |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3329 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3331 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3332 switchScatter = 10000 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3334 |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3336 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3337 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3338 # categorical plot |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3339 if(is.factor(pred)){ |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3341 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3342 # smooth scatter |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3343 else if (smoothScatter == TRUE) { |
f0dc3958e65d
"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) |
f0dc3958e65d
"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)) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3347 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3348 # normal plot |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3349 else{ |
f0dc3958e65d
"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) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3352 a$col = checkDots("col", defaultCol, ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3353 a$pch = checkDots("pch", defaultPch, ...) |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3355 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3356 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3357 axis(1) |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3359 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3360 ##### Quantile regressions ##### |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3361 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3362 main = checkDots("main", "Residual vs. predicted", ...) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3363 out = NULL |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3364 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3365 if(is.numeric(pred)){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3366 if(quantreg == F){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3367 title(main = main, cex.main = 1) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3369 try({ |
f0dc3958e65d
"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") |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3372 }, silent = T) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3373 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3374 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3376 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3377 |
f0dc3958e65d
"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)){ |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3380 if(out$p.value <= 0.05){ |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3382 } else { |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3384 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3385 maincol = "red" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3386 } else { |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3388 maincol = "black" |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3389 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3390 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3391 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3392 title(main = main, cex.main = 0.8, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3393 col.main = maincol) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3394 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3395 for(i in 1:length(quantiles)){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3396 |
f0dc3958e65d
"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") |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3399 |
f0dc3958e65d
"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) |
f0dc3958e65d
"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)), |
f0dc3958e65d
"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])), |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3403 col = "#00000020", border = F) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3405 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3406 |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3408 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3409 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3410 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3411 invisible(out) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3412 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3413 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3414 x = 0.01 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3415 x <= 0.05 & !(is.na(x)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3416 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3417 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3419 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3422 #' @keywords internal |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3423 ensurePredictor <- function(simulationOutput, |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3424 predictor = NULL){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3425 if(!is.null(predictor)){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3426 |
f0dc3958e65d
"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.") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3428 } else { |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3429 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3430 predictor = simulationOutput$fittedPredictedResponse |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3432 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3433 return(predictor) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3434 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3435 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3436 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3437 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3438 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3439 #plot(simulationOutput) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3440 |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3442 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3443 #plot(simulationOutput$observedResponse, simulationOutput$fittedPredictedResponse - simulationOutput$observedResponse) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3444 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3445 #plot(cumsum(sort(simulationOutput$scaledResiduals))) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3446 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3447 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3448 #plotConventionalResiduals(fittedModel) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3449 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3450 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3451 #' Conventional residual plot |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3452 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3453 #' Convenience function to draw conventional residual plots |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3454 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3455 #' @param fittedModel a fitted model object |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3456 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3457 plotConventionalResiduals <- function(fittedModel){ |
f0dc3958e65d
"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)) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3459 on.exit(par(opar)) |
f0dc3958e65d
"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") |
f0dc3958e65d
"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") |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3463 mtext("Conventional residual plots", outer = T) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3464 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3465 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3466 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3467 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3468 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3469 # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3470 # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3471 # if(quantreg == F){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3472 # |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3474 # |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3476 # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3477 # }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3478 # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3479 # #library(gamlss) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3480 # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3481 # # qrnn |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3482 # |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3484 # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3485 # #require(quantreg) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3486 # #dat <- plyr::arrange(dat,pred) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3488 # |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3490 # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3491 # w <- p <- list() |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3492 # for(i in seq_along(probs)){ |
f0dc3958e65d
"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)) |
f0dc3958e65d
"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]]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3495 # } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3496 # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3497 # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3498 # |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3500 # |
f0dc3958e65d
"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") |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3502 # |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3504 # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3505 # # as.vector(p[[1]]) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3506 # # |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3507 # # |
f0dc3958e65d
"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) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3510 # # |
f0dc3958e65d
"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) |
f0dc3958e65d
"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) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3514 # # |
f0dc3958e65d
"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) |
f0dc3958e65d
"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) |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3518 # } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3519 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3520 ####################### plot.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3521 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3522 ####################### random.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3523 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3524 #' Record and restore a random state |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3525 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3527 #' |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3529 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3530 #' a) record the current random state |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3531 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3533 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3535 #' |
f0dc3958e65d
"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 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3537 #' @export |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3538 #' @example inst/examples/getRandomStateHelp.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3539 #' @author Florian Hartig |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3540 #' |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3541 getRandomState <- function(seed = NULL){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3542 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3543 # better to explicitly access the global RS? |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3544 # current = get(".Random.seed", .GlobalEnv, ifnotfound = NULL) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3545 |
f0dc3958e65d
"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]] |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3547 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3548 if(is.logical(seed) & seed == F){ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3549 restoreCurrent <- function(){} |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3550 }else{ |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3551 restoreCurrent <- function(){ |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3553 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3554 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3555 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3556 # setting seed |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3557 if(is.numeric(seed)) set.seed(seed) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3558 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3559 # ensuring that RNG has been initialized |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3560 if (is.null(current))runif(1) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3561 |
f0dc3958e65d
"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) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3563 return(randomState) |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3564 } |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3565 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3566 ####################### random.R |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3567 |
f0dc3958e65d
"planemo upload for repository https://github.com/ColineRoyaux/PAMPA-Galaxy commit 07f1028cc764f920b1e6419c151f04ab4e3600fa"
ecology
parents:
diff
changeset
|
3568 ######################################### Package DHARMa |