Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Kunstler Georges
traitcompet
Commits
1d1c1227
Commit
1d1c1227
authored
Feb 19, 2014
by
Georges Kunstler
Browse files
global format
parent
93926ca2
Changes
45
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
1d1c1227
...
...
@@ -4,7 +4,7 @@ D3 := output/processed
D4
:=
figs/test.format.tree
D5
:=
figs/test.traits
D5
:=
figs/test.CWM
sites
:=
Fushan Paracou BCI Mbaiki Luquillo
Canada France
Spain
US
Sweden Swiss NSW NVS
Japan
sites
:=
Fushan Paracou BCI Mbaiki Luquillo
Japan
Spain Sweden
Canada France
Swiss NSW NVS
US
D3Done
:=
$(
addsuffix
/Done.txt,
$(
addprefix
$(D3)
/,
$(sites)
))
D2traits
:=
$(
addsuffix
/traits.csv,
$(
addprefix
$(D2)
/,
$(sites)
))
D2tree
:=
$(
addsuffix
/tree.csv,
$(
addprefix
$(D2)
/,
$(sites)
))
...
...
@@ -26,10 +26,10 @@ $(D2)/TRY/data.TRY.std.rds:
BCI
:
$(D3)/BCI/Done.txt
$(D3)/BCI/Done.txt
:
R/process.data/process
.
fun.R $(D2)/BCI/traits.csv
$(D3)/BCI/Done.txt
:
R/process.data/process
-
fun.R $(D2)/BCI/traits.csv
Rscript
-e
"source('
$<
'); process_bigplot_dataset('BCI', Rlim=15,std.traits='local'); process_bigplot_dataset('BCI', Rlim=15,std.traits='no'); process_bigplot_dataset('BCI', Rlim=15,std.traits='global');"
$(D2)/BCI/traits.csv
:
R/find.trait/BCI.R R/find.trait/trait
.
fun.R $(D2)/BCI/tree.csv
$(D2)/TRY/data.TRY.std.rds
$(D2)/BCI/traits.csv
:
R/find.trait/BCI.R R/find.trait/trait
-
fun.R $(D2)/BCI/tree.csv
Rscript
$<
$(D2)/BCI/tree.csv
:
R/format.data/BCI.R $(shell find $(D1)/BCI -type f)
...
...
@@ -39,10 +39,10 @@ $(D2)/BCI/tree.csv: R/format.data/BCI.R $(shell find $(D1)/BCI -type f)
Japan
:
$(D3)/Japan/Done.txt
$(D3)/Japan/Done.txt
:
R/process.data/process
.
fun.R $(D2)/Japan/traits.csv
$(D3)/Japan/Done.txt
:
R/process.data/process
-
fun.R $(D2)/Japan/traits.csv
Rscript
-e
"source('
$<
'); process_bigplot_dataset('Japan', Rlim=15,std.traits='local'); process_bigplot_dataset('Japan', Rlim=15,std.traits='no'); process_bigplot_dataset('Japan', Rlim=15,std.traits='global');"
$(D2)/Japan/traits.csv
:
R/find.trait/Japan.R R/find.trait/trait
.
fun.R $(D2)/Japan/tree.csv
$(D2)/TRY/data.TRY.std.rds
$(D2)/Japan/traits.csv
:
R/find.trait/Japan.R R/find.trait/trait
-
fun.R $(D2)/Japan/tree.csv
Rscript
$<
$(D2)/Japan/tree.csv
:
R/format.data/Japan.R $(shell find $(D1)/Japan -type f)
...
...
@@ -51,10 +51,10 @@ $(D2)/Japan/tree.csv: R/format.data/Japan.R $(shell find $(D1)/Japan -type f)
Luquillo
:
$(D3)/Luquillo/Done.txt
$(D3)/Luquillo/Done.txt
:
R/process.data/process
.
fun.R $(D2)/Luquillo/traits.csv
$(D3)/Luquillo/Done.txt
:
R/process.data/process
-
fun.R $(D2)/Luquillo/traits.csv
Rscript
-e
"source('
$<
'); process_bigplot_dataset('Luquillo', Rlim=15,std.traits='local'); process_bigplot_dataset('Luquillo', Rlim=15,std.traits='no');process_bigplot_dataset('Luquillo', Rlim=15,std.traits='global');"
$(D2)/Luquillo/traits.csv
:
R/find.trait/Luquillo.R R/find.trait/trait
.
fun.R $(D2)/Luquillo/tree.csv
$(D2)/TRY/data.TRY.std.rds
$(D2)/Luquillo/traits.csv
:
R/find.trait/Luquillo.R R/find.trait/trait
-
fun.R $(D2)/Luquillo/tree.csv
Rscript
$<
$(D2)/Luquillo/tree.csv
:
R/format.data/Luquillo.R $(shell find $(D1)/Luquillo -type f)
...
...
@@ -64,10 +64,10 @@ $(D2)/Luquillo/tree.csv: R/format.data/Luquillo.R $(shell find $(D1)/Luquillo -t
Mbaiki
:
$(D3)/Mbaiki/Done.txt
$(D3)/Mbaiki/Done.txt
:
R/process.data/process
.
fun.R $(D2)/Mbaiki/traits.csv
$(D3)/Mbaiki/Done.txt
:
R/process.data/process
-
fun.R $(D2)/Mbaiki/traits.csv
Rscript
-e
"source('
$<
'); process_bigplot_dataset('Mbaiki', Rlim=15,std.traits='local'); process_bigplot_dataset('Mbaiki', Rlim=15,std.traits='no'); process_bigplot_dataset('Mbaiki', Rlim=15,std.traits='global');"
$(D2)/Mbaiki/traits.csv
:
R/find.trait/Mbaiki.R R/find.trait/trait
.
fun.R $(D2)/Mbaiki/tree.csv
$(D2)/TRY/data.TRY.std.rds
$(D2)/Mbaiki/traits.csv
:
R/find.trait/Mbaiki.R R/find.trait/trait
-
fun.R $(D2)/Mbaiki/tree.csv
Rscript
$<
$(D2)/Mbaiki/tree.csv
:
R/format.data/Mbaiki.R $(shell find $(D1)/Mbaiki -type f)
...
...
@@ -77,10 +77,10 @@ $(D2)/Mbaiki/tree.csv: R/format.data/Mbaiki.R $(shell find $(D1)/Mbaiki -type f)
Canada
:
$(D3)/Canada/Done.txt
$(D3)/Canada/Done.txt
:
R/process.data/process
.
fun.R $(D2)/Canada/traits.csv
Rscript
-e
"source('
$<
'); process_inventory_dataset('Canada',std.traits='local'); process_inventory_dataset('Canada',std.traits='
no
');process_inventory_dataset('Canada',std.traits='
global
');"
$(D3)/Canada/Done.txt
:
R/process.data/process
-
fun.R $(D2)/Canada/traits.csv
Rscript
-e
"source('
$<
'); process_inventory_dataset('Canada',std.traits='local'); process_inventory_dataset('Canada',std.traits='
global
');process_inventory_dataset('Canada',std.traits='
no
');"
$(D2)/Canada/traits.csv
:
R/find.trait/Canada.R R/find.trait/trait
.
fun.R $(D2)/Canada/tree.csv $(D2)/TRY/data.TRY.std.rds
$(D2)/Canada/traits.csv
:
R/find.trait/Canada.R R/find.trait/trait
-
fun.R $(D2)/Canada/tree.csv $(D2)/TRY/data.TRY.std.rds
Rscript
$<
$(D2)/Canada/tree.csv
:
R/format.data/Canada.R $(shell find $(D1)/Canada -type f)
...
...
@@ -89,10 +89,10 @@ $(D2)/Canada/tree.csv: R/format.data/Canada.R $(shell find $(D1)/Canada -type f)
#-------------------------------------------------------
France
:
$(D3)/France/Done.txt
$(D3)/France/Done.txt
:
R/process.data/process
.
fun.R $(D2)/France/traits.csv
$(D3)/France/Done.txt
:
R/process.data/process
-
fun.R $(D2)/France/traits.csv
Rscript
-e
"source('
$<
'); process_inventory_dataset('France',std.traits='local'); process_inventory_dataset('France',std.traits='no');process_inventory_dataset('France',std.traits='global');"
$(D2)/France/traits.csv
:
R/find.trait/France.R R/find.trait/trait
.
fun.R $(D2)/France/tree.csv $(D2)/TRY/data.TRY.std.rds
$(D2)/France/traits.csv
:
R/find.trait/France.R R/find.trait/trait
-
fun.R $(D2)/France/tree.csv $(D2)/TRY/data.TRY.std.rds
Rscript
$<
$(D2)/France/tree.csv
:
R/format.data/France.R $(shell find $(D1)/France -type f)
...
...
@@ -102,11 +102,11 @@ $(D2)/France/tree.csv: R/format.data/France.R $(shell find $(D1)/France -type f)
Fushan
:
$(D3)/Fushan/Done.txt
$(D3)/Fushan/Done.txt
:
R/process.data/process
.
fun.R $(D2)/Fushan/traits.csv
$(D3)/Fushan/Done.txt
:
R/process.data/process
-
fun.R $(D2)/Fushan/traits.csv
Rscript
-e
"source('
$<
'); process_bigplot_dataset('Fushan', Rlim=15,std.traits='local'); process_bigplot_dataset('Fushan', Rlim=15,std.traits='no');process_bigplot_dataset('Fushan', Rlim=15,std.traits='global');"
$(D2)/Fushan/traits.csv
:
R/find.trait/Fushan.R R/find.trait/trait
.
fun.R $(D2)/Fushan/tree.csv
$(D2)/TRY/data.TRY.std.rds
$(D2)/Fushan/traits.csv
:
R/find.trait/Fushan.R R/find.trait/trait
-
fun.R $(D2)/Fushan/tree.csv
Rscript
$<
$(D2)/Fushan/tree.csv
:
R/format.data/Fushan.R $(shell find $(D1)/Fushan -type f)
...
...
@@ -116,10 +116,10 @@ $(D2)/Fushan/tree.csv: R/format.data/Fushan.R $(shell find $(D1)/Fushan -type f)
NSW
:
$(D3)/NSW/Done.txt
$(D3)/NSW/Done.txt
:
R/process.data/process
.
fun.R $(D2)/NSW/traits.csv
$(D3)/NSW/Done.txt
:
R/process.data/process
-
fun.R $(D2)/NSW/traits.csv
Rscript
-e
"source('
$<
'); process_inventory_dataset('NSW',std.traits='local'); process_inventory_dataset('NSW',std.traits='no');process_inventory_dataset('NSW',std.traits='global');"
$(D2)/NSW/traits.csv
:
R/find.trait/NSW.R R/find.trait/trait
.
fun.R $(D2)/NSW/tree.csv $(D2)/TRY/data.TRY.std.rds
$(D2)/NSW/traits.csv
:
R/find.trait/NSW.R R/find.trait/trait
-
fun.R $(D2)/NSW/tree.csv $(D2)/TRY/data.TRY.std.rds
Rscript
$<
$(D2)/NSW/tree.csv
:
R/format.data/NSW.R $(shell find $(D1)/NSW -type f)
...
...
@@ -129,10 +129,10 @@ $(D2)/NSW/tree.csv: R/format.data/NSW.R $(shell find $(D1)/NSW -type f)
NVS
:
$(D3)/NVS/Done.txt
$(D3)/NVS/Done.txt
:
R/process.data/process
.
fun.R $(D2)/NVS/traits.csv
$(D3)/NVS/Done.txt
:
R/process.data/process
-
fun.R $(D2)/NVS/traits.csv
Rscript
-e
"source('
$<
'); process_inventory_dataset('NVS',std.traits='local'); process_inventory_dataset('NVS',std.traits='no'); process_inventory_dataset('NVS',std.traits='global');"
$(D2)/NVS/traits.csv
:
R/find.trait/NVS.R R/find.trait/trait
.
fun.R $(D2)/NVS/tree.csv
$(D2)/TRY/data.TRY.std.rds
$(D2)/NVS/traits.csv
:
R/find.trait/NVS.R R/find.trait/trait
-
fun.R $(D2)/NVS/tree.csv
Rscript
$<
$(D2)/NVS/tree.csv
:
R/format.data/NVS.R $(shell find $(D1)/NVS -type f)
...
...
@@ -142,10 +142,10 @@ $(D2)/NVS/tree.csv: R/format.data/NVS.R $(shell find $(D1)/NVS -type f)
Paracou
:
$(D3)/Paracou/Done.txt
$(D3)/Paracou/Done.txt
:
R/process.data/process
.
fun.R $(D2)/Paracou/traits.csv
$(D3)/Paracou/Done.txt
:
R/process.data/process
-
fun.R $(D2)/Paracou/traits.csv
Rscript
-e
"source('
$<
'); process_bigplot_dataset('Paracou', Rlim=15,std.traits='local'); process_bigplot_dataset('Paracou', Rlim=15,std.traits='no'); process_bigplot_dataset('Paracou', Rlim=15,std.traits='global');"
$(D2)/Paracou/traits.csv
:
R/find.trait/Paracou.R R/find.trait/trait
.
fun.R $(D2)/Paracou/tree.csv
$(D2)/TRY/data.TRY.std.rds
$(D2)/Paracou/traits.csv
:
R/find.trait/Paracou.R R/find.trait/trait
-
fun.R $(D2)/Paracou/tree.csv
Rscript
$<
$(D2)/Paracou/tree.csv
:
R/format.data/Paracou.R $(shell find $(D1)/Paracou -type f)
...
...
@@ -155,10 +155,10 @@ $(D2)/Paracou/tree.csv: R/format.data/Paracou.R $(shell find $(D1)/Paracou -type
Spain
:
$(D3)/Spain/Done.txt
$(D3)/Spain/Done.txt
:
R/process.data/process
.
fun.R $(D2)/Spain/traits.csv
$(D3)/Spain/Done.txt
:
R/process.data/process
-
fun.R $(D2)/Spain/traits.csv
Rscript
-e
"source('
$<
'); process_inventory_dataset('Spain',std.traits='local'); process_inventory_dataset('Spain',std.traits='no'); process_inventory_dataset('Spain',std.traits='global');"
$(D2)/Spain/traits.csv
:
R/find.trait/Spain.R R/find.trait/trait
.
fun.R $(D2)/Spain/tree.csv $(D2)/TRY/data.TRY.std.rds
$(D2)/Spain/traits.csv
:
R/find.trait/Spain.R R/find.trait/trait
-
fun.R $(D2)/Spain/tree.csv $(D2)/TRY/data.TRY.std.rds
Rscript
$<
$(D2)/Spain/tree.csv
:
R/format.data/Spain.R $(shell find $(D1)/Spain -type f)
...
...
@@ -168,10 +168,10 @@ $(D2)/Spain/tree.csv: R/format.data/Spain.R $(shell find $(D1)/Spain -type f)
Sweden
:
$(D3)/Sweden/Done.txt
$(D3)/Sweden/Done.txt
:
R/process.data/process
.
fun.R $(D2)/Sweden/traits.csv
$(D3)/Sweden/Done.txt
:
R/process.data/process
-
fun.R $(D2)/Sweden/traits.csv
Rscript
-e
"source('
$<
'); process_inventory_dataset('Sweden',std.traits='local'); process_inventory_dataset('Sweden',std.traits='no'); process_inventory_dataset('Sweden',std.traits='global');"
$(D2)/Sweden/traits.csv
:
R/find.trait/Sweden.R R/find.trait/trait
.
fun.R $(D2)/Sweden/tree.csv $(D2)/TRY/data.TRY.std.rds
$(D2)/Sweden/traits.csv
:
R/find.trait/Sweden.R R/find.trait/trait
-
fun.R $(D2)/Sweden/tree.csv $(D2)/TRY/data.TRY.std.rds
Rscript
$<
$(D2)/Sweden/tree.csv
:
R/format.data/Sweden.R $(shell find $(D1)/Sweden -type f)
...
...
@@ -181,10 +181,10 @@ $(D2)/Sweden/tree.csv: R/format.data/Sweden.R $(shell find $(D1)/Sweden -type f)
Swiss
:
$(D3)/Swiss/Done.txt
$(D3)/Swiss/Done.txt
:
R/process.data/process
.
fun.R $(D2)/Swiss/traits.csv
$(D3)/Swiss/Done.txt
:
R/process.data/process
-
fun.R $(D2)/Swiss/traits.csv
Rscript
-e
"source('
$<
'); process_inventory_dataset('Swiss',std.traits='local'); process_inventory_dataset('Swiss',std.traits='no'); process_inventory_dataset('Swiss',std.traits='global');"
$(D2)/Swiss/traits.csv
:
R/find.trait/Swiss.R R/find.trait/trait
.
fun.R $(D2)/Swiss/tree.csv $(D2)/TRY/data.TRY.std.rds
$(D2)/Swiss/traits.csv
:
R/find.trait/Swiss.R R/find.trait/trait
-
fun.R $(D2)/Swiss/tree.csv $(D2)/TRY/data.TRY.std.rds
Rscript
$<
$(D2)/Swiss/tree.csv
:
R/format.data/Swiss.R $(shell find $(D1)/Swiss -type f)
...
...
@@ -194,10 +194,10 @@ $(D2)/Swiss/tree.csv: R/format.data/Swiss.R $(shell find $(D1)/Swiss -type f)
US
:
$(D3)/US/Done.txt
$(D3)/US/Done.txt
:
R/process.data/process
.
fun.R $(D2)/US/traits.csv
Rscript
-e
"source('
$<
'); process_inventory_dataset('US',std.traits='local'); process_inventory_dataset('US',std.traits='no');
process_inventory_dataset('US',std.traits='global');
"
$(D3)/US/Done.txt
:
R/process.data/process
-
fun.R $(D2)/US/traits.csv
Rscript
-e
"source('
$<
');
process_inventory_dataset('US',std.traits='global');
process_inventory_dataset('US',std.traits='local'); process_inventory_dataset('US',std.traits='no');"
$(D2)/US/traits.csv
:
R/find.trait/US.R R/find.trait/trait
.
fun.R $(D2)/US/tree.csv $(D2)/TRY/data.TRY.std.rds
$(D2)/US/traits.csv
:
R/find.trait/US.R R/find.trait/trait
-
fun.R $(D2)/US/tree.csv $(D2)/TRY/data.TRY.std.rds
Rscript
$<
$(D2)/US/tree.csv
:
R/format.data/US.R $(shell find $(D1)/US -type f)
...
...
R/analysis/MCMCglmm
.
fun.R
→
R/analysis/MCMCglmm
-
fun.R
View file @
1d1c1227
File moved
R/analysis/lmer.nolog.output.figs.R
0 → 100644
View file @
1d1c1227
#!/usr/bin/env Rscript
rm
(
list
=
ls
())
source
(
"R/analysis/lmer.output-fun.R"
)
source
(
"R/utils/plot.R"
)
## load results
DF.results
<-
readRDS
(
'output/lmer.nolog.DF.rds'
)
## load climatic data
site.clim.all
<-
read.csv
(
file.path
(
"output/processed"
,
"all.sites.clim.csv"
),
stringsAsFactors
=
FALSE
)
site.clim.all
$
id
<-
paste
(
site.clim.all
$
set
,
site.clim.all
$
ecocode
,
sep
=
"."
)
## par(mfrow=c(1,2),mar=c(5, 9, 4, 1) +0.1)
## boxplot(site.clim.all$clim.all.MAT~site.clim.all$id,horizontal=TRUE,las=2,cex.axis=0.8)
## boxplot(site.clim.all$clim.all.MAP~site.clim.all$id,horizontal=TRUE,las=2,cex.axis=0.8)
mean.MAT
<-
tapply
(
site.clim.all
$
clim.all.MAT
,
INDEX
=
site.clim.all
$
id
,
FUN
=
mean
,
na.rm
=
TRUE
)
mean.MAP
<-
tapply
(
site.clim.all
$
clim.all.MAP
,
INDEX
=
site.clim.all
$
id
,
FUN
=
mean
,
na.rm
=
TRUE
)
data.clim.ecocode
<-
data.frame
(
id
=
names
(
mean.MAT
),
MAT
=
mean.MAT
,
MAP
=
mean.MAP
)
### merge climate and lmer results
DF.results
<-
merge
(
DF.results
,
data.clim.ecocode
,
by
=
"id"
)
DF.results
$
id2
<-
paste
(
DF.results
$
id
,
DF.results
$
trait
,
DF.results
$
filling
)
### save
saveRDS
(
DF.results
,
file
=
'output/lmer.nolog.DF.results.merged.rds'
)
DF.results
<-
readRDS
(
file
=
'output/lmer.nolog.DF.results.merged.rds'
)
### Analysis of the results
DF.R2m.diff
<-
do.call
(
"rbind"
,
lapply
(
1
:
nrow
(
DF.results
),
fun.compute.criteria.diff
,
DF.results
,
"R2m"
))
DF.R2c.diff
<-
do.call
(
"rbind"
,
lapply
(
1
:
nrow
(
DF.results
),
fun.compute.criteria.diff
,
DF.results
,
"R2c"
))
DF.AIC.diff
<-
do.call
(
"rbind"
,
lapply
(
1
:
nrow
(
DF.results
),
fun.compute.criteria.diff
,
DF.results
,
"AIC"
))
DF.delta.AIC
<-
do.call
(
"rbind"
,
lapply
(
1
:
nrow
(
DF.results
),
fun.compute.delta.AIC
,
DF.results
))
DF.var.fixed
<-
fun.ratio.var.fixed.effect
(
DF.results
)
DF.results
<-
cbind
(
DF.results
,
DF.R2m.diff
,
DF.R2c.diff
,
DF.AIC.diff
,
DF.delta.AIC
,
DF.var.fixed
)
### report best model based on AIC
DF.best.and.all.AIC
<-
do.call
(
'rbind'
,
lapply
(
unique
(
DF.results
$
id2
),
FUN
=
fun.AIC
,
DF.results
))
DF.best.and.all.AICc
<-
do.call
(
'rbind'
,
lapply
(
unique
(
DF.results
$
id2
),
FUN
=
fun.AICc
,
DF.results
))
table
(
DF.best.and.all.AIC
[
DF.best.and.all.AIC
$
filling
==
'species'
,]
$
best.model
,
DF.best.and.all.AIC
[
DF.best.and.all.AIC
$
filling
==
'species'
,]
$
trait
,
DF.best.and.all.AIC
[
DF.best.and.all.AIC
$
filling
==
'species'
,]
$
set
)
t
(
table
(
DF.best.and.all.AIC
[
DF.best.and.all.AIC
$
filling
==
'species'
,]
$
best.model
,
DF.best.and.all.AIC
[
DF.best.and.all.AIC
$
filling
==
'species'
,]
$
set
))
/
(
apply
(
table
(
DF.best.and.all.AIC
[
DF.best.and.all.AIC
$
filling
==
'species'
,]
$
best.model
,
DF.best.and.all.AIC
[
DF.best.and.all.AIC
$
filling
==
'species'
,]
$
set
),
MARGIN
=
2
,
sum
))
## AIC weights
AIC.weights
<-
do.call
(
'rbind'
,
lapply
(
1
:
nrow
(
DF.best.and.all.AICc
),
FUN
=
function
(
i
,
DF
)
exp
((
min
(
DF
[
i
,])
-
DF
[
i
,])
/
2
)
/
sum
(
exp
((
min
(
DF
[
i
,])
-
DF
[
i
,])
/
2
)),
DF.best.and.all.AIC
[,
9
:
15
]))
DF.AIC.weights
<-
data.frame
(
DF.best.and.all.AICc
[,
1
],
AIC.weights
)
names
(
DF.AIC.weights
)
<-
c
(
'id2'
,
paste
(
'AIC.weight'
,
names
(
DF.AIC.weights
)[
-1
],
sep
=
'.'
))
DF.best.and.all.AIC
<-
merge
(
DF.best.and.all.AIC
,
DF.AIC.weights
,
by
=
'id2'
)
#### compute percentage of variance explained by var
DF.results
$
abs.perc.var
<-
DF.results
$
sumTnTfBn.abs.VAR
/
DF.results
$
sumBn.VAR
DF.results
$
R.perc.var
<-
DF.results
$
sumTfBn.VAR
/
DF.results
$
sumBn.VAR
DF.results
$
E.perc.var
<-
DF.results
$
sumTnBn.VAR
/
DF.results
$
sumBn.VAR
DF.results
$
ER.perc.var
<-
DF.results
$
effect.response.var
/
DF.results
$
sumBn.VAR
#############################################
#############################################
### DO THE PLOT
models
<-
c
(
'lmer.LOGLIN.ER.Tf'
,
'lmer.LOGLIN.ER.Tf'
)
names
(
models
)
<-
c
(
'Effect/response effect'
,
'Effect/response response'
)
list.params
<-
list
(
c
(
Response
=
'sumTnBn'
),
c
(
Effect
=
'sumTfBn'
))
pdf
(
'figs/parameters.MAP.ER.all.pdf'
,
width
=
9
,
height
=
7
)
fun.plot.panel.lmer.parameters.c
(
models
=
models
,
traits
=
c
(
'Wood.density'
,
'SLA'
,
'Leaf.N'
,
'Max.height'
),
DF.results
,
var.x
=
'MAP'
,
list.params
=
list.params
,
small.bar
=
0.02
,
threshold.delta.AIC
=
10000
)
dev.off
()
R/analysis/stan
.
fun.R
→
R/analysis/stan
-
fun.R
View file @
1d1c1227
File moved
R/find.trait/BCI.R
View file @
1d1c1227
#!/usr/bin/env Rscript
##### FORMAT TRAIT FOR BCI - ACCOUNTS FOR ADDITIONAL SMALL PLOT DATA
source
(
"R/find.trait/trait
.
fun.R"
)
source
(
"R/find.trait/trait
-
fun.R"
)
### read species names
data.tree
<-
read.csv
(
"output/formatted/BCI/tree.csv"
,
stringsAsFactors
=
FALSE
)
...
...
R/find.trait/Canada.R
View file @
1d1c1227
#!/usr/bin/env Rscript
##### FORMAT TRAIT FOR Canada
source
(
"R/find.trait/trait
.
fun.R"
)
source
(
"R/find.trait/trait
-
fun.R"
)
### read species names
data.tree
<-
read.csv
(
"output/formatted/Canada/tree.csv"
,
stringsAsFactors
=
FALSE
)
...
...
@@ -10,8 +10,6 @@ species.clean <- data.frame(sp=data.tree[!duplicated(data.tree[["sp"]]),"sp"],
Latin_name_syn
=
data.tree
[
!
duplicated
(
data.tree
[[
"sp"
]]),
"sp.name"
],
stringsAsFactors
=
FALSE
)
## delete the sp code with no species
species.clean
<-
subset
(
species.clean
,
subset
=!
is.na
(
species.clean
$
Latin_name
))
## read in data
data.TRY.std
<-
readRDS
(
"output/formatted/TRY/data.TRY.std.rds"
)
...
...
R/find.trait/France.R
View file @
1d1c1227
#!/usr/bin/env Rscript
##### FORMAT TRAIT FOR France
source
(
"R/find.trait/trait
.
fun.R"
)
source
(
"R/find.trait/trait
-
fun.R"
)
source
(
"R/format.data/format.fun.R"
)
### read species names
...
...
R/find.trait/Fushan.R
View file @
1d1c1227
#!/usr/bin/env Rscript
##### FORMAT TRAIT FOR FUSHAN
source
(
"R/find.trait/trait
.
fun.R"
)
source
(
"R/find.trait/trait
-
fun.R"
)
### read species names
data.tree
<-
read.csv
(
"output/formatted/Fushan/tree.csv"
,
stringsAsFactors
=
FALSE
)
...
...
@@ -37,8 +37,8 @@ rm(data.trait)
## extract
data.traits
<-
fun.extract.format.sp.traits.NOT.TRY
(
sp
=
species.clean
$
sp
,
Latin_name
=
species.clean
$
sp
,
data
=
data.TRAITS.std
,
name.match.traits
=
"sp"
)
#### GET THE
ANGIO/CONIF AND EVERGREEN/DECIDUOUS
# TODO ASK SPECIES NAME OR EVERGREEN DECIDUOUS BECAUSE NO SPECIES NAME AVAILABLE
#### GET THE
latin name
data.traits
$
Latin_name
<-
species.clean
$
Latin_name
#### GET THE ANGIO/CONIF AND EVERGREEN/DECIDUOUS
# read try categrocial data
...
...
@@ -54,6 +54,13 @@ data.cat.extract <- fun.change.factor.pheno.try(data.cat.extract)
data.cat.extract
<-
fun.change.factor.angio.try
(
data.cat.extract
)
data.cat.extract
<-
fun.fill.pheno.try.with.zanne
(
data.cat.extract
)
data.cat.extract
[
data.cat.extract
$
Latin_name
%in%
c
(
'Machilus zuihoensis'
,
'Prunus phaeosticta'
,
'Cinnamomum micranthum'
,
'Symplocos theophrastifolia'
,
'Ehretia longiflora'
,
'Osmanthus matsumuranus'
,
'Symplocos wikstroemiifolia'
,
'Itea parviflora'
,
'Symplocos sonoharae'
,
'Cyclobalanopsis sessilifolia'
,
'Eriobotrya deflexa'
,
'Neolitsea konishii'
),
"Pheno.T"
]
<-
'EV'
data.cat.extract
[
is.na
(
data.cat.extract
$
Pheno.T
),]
data.traits
<-
merge
(
data.traits
,
data.cat.extract
[,
c
(
"sp"
,
"Phylo.group"
,
"Pheno.T"
)],
by
=
"sp"
)
...
...
R/find.trait/Japan.R
View file @
1d1c1227
#!/usr/bin/env Rscript
##### FORMAT TRAIT FOR JAPAN
source
(
"R/find.trait/trait
.
fun.R"
)
source
(
"R/find.trait/trait
-
fun.R"
)
### read species names
data.tree
<-
read.csv
(
"output/formatted/Japan/tree.csv"
,
stringsAsFactors
=
FALSE
)
...
...
R/find.trait/Luquillo.R
View file @
1d1c1227
#!/usr/bin/env Rscript
##### FORMAT TRAIT FOR Luquillo
source
(
"R/find.trait/trait
.
fun.R"
)
source
(
"R/find.trait/trait
-
fun.R"
)
### read species names
data.tree
<-
read.csv
(
"output/formatted/Luquillo/tree.csv"
,
stringsAsFactors
=
FALSE
)
...
...
@@ -62,8 +62,6 @@ data.trait$Max.height.sd <- NA
data.trait
$
h
<-
NULL
data.TRAITS.std
<-
data.trait
write.csv
(
data.TRAITS.std
,
file
=
"output/formatted/Luquillo/traits.std.csv"
,
row.names
=
FALSE
)
rm
(
data.trait
)
## extract
data.traits
<-
fun.extract.format.sp.traits.NOT.TRY
(
sp
=
species.clean
$
Latin_name
,
Latin_name
=
species.clean
$
Latin_name
,
data
=
data.TRAITS.std
,
name.match.traits
=
"Latin_name"
)
...
...
R/find.trait/Mbaiki.R
View file @
1d1c1227
...
...
@@ -139,7 +139,7 @@ names(data.species.3)
data.TRAITS.std
<-
data.species.3
[,
c
(
1
:
13
)]
names
(
data.TRAITS.std
)
data.TRAITS.std
$
Max.height.mean
<-
NA
source
(
"R/find.trait/trait
.
fun.R"
)
source
(
"R/find.trait/trait
-
fun.R"
)
#######################
##### GET IN GOOD FORMAT
...
...
R/find.trait/NSW.R
View file @
1d1c1227
##### FORMAT TRAIT FOR NSW
source
(
"R/find.trait/trait
.
fun.R"
)
source
(
"R/find.trait/trait
-
fun.R"
)
### read species names
data.tree
<-
read.csv
(
"output/formatted/NSW/tree.csv"
,
stringsAsFactors
=
FALSE
)
...
...
R/find.trait/NVS.R
View file @
1d1c1227
#!/usr/bin/env Rscript
##### FORMAT TRAIT FOR NVS
source
(
"R/find.trait/trait
.
fun.R"
)
source
(
"R/find.trait/trait
-
fun.R"
)
### read species names
data.tree
<-
read.csv
(
"output/formatted/NVS/tree.csv"
,
stringsAsFactors
=
FALSE
)
...
...
R/find.trait/Paracou.R
View file @
1d1c1227
...
...
@@ -300,7 +300,7 @@ names(data.species) <- c("Species","Genus",
data.species
$
Max.height.mean
<-
data.species
$
Max.height.sd
<-
data.species
$
Max.height.genus
<-
NA
##### FORMAT TRAIT FOR BCI
source
(
"R/find.trait/trait
.
fun.R"
)
source
(
"R/find.trait/trait
-
fun.R"
)
### read species names
data.tree
<-
read.csv
(
"output/formatted/Paracou/tree.csv"
,
stringsAsFactors
=
FALSE
)
...
...
R/find.trait/Spain.R
View file @
1d1c1227
#!/usr/bin/env Rscript
##### FORMAT TRAIT FOR SPAIN
source
(
"R/find.trait/trait
.
fun.R"
)
source
(
"R/find.trait/trait
-
fun.R"
)
### read species names
data.tree
<-
read.csv
(
"output/formatted/Spain/tree.csv"
,
stringsAsFactors
=
FALSE
)
...
...
R/find.trait/Sweden.R
View file @
1d1c1227
#!/usr/bin/env Rscript
##### FORMAT TRAIT FOR Sweden
source
(
"R/find.trait/trait
.
fun.R"
)
source
(
"R/find.trait/trait
-
fun.R"
)
### read species names
data.tree
<-
read.csv
(
"output/formatted/Sweden/tree.csv"
,
stringsAsFactors
=
FALSE
)
...
...
R/find.trait/Swiss.R
View file @
1d1c1227
#!/usr/bin/env Rscript
##### FORMAT TRAIT FOR Swiss
source
(
"R/find.trait/trait
.
fun.R"
)
source
(
"R/find.trait/trait
-
fun.R"
)
### read species names
data.tree
<-
read.csv
(
"output/formatted/Swiss/tree.csv"
,
stringsAsFactors
=
FALSE
)
...
...
R/find.trait/US.R
View file @
1d1c1227
#!/usr/bin/env Rscript
##### FORMAT TRAIT FOR US
source
(
"R/find.trait/trait
.
fun.R"
)
source
(
"R/find.trait/trait
-
fun.R"
)
### read species names
data.tree
<-
read.csv
(
"output/formatted/US/tree.csv"
,
stringsAsFactors
=
FALSE
)
...
...
@@ -60,11 +60,6 @@ data.cat.extract <- fun.change.factor.pheno.try(data.cat.extract)
data.cat.extract
<-
fun.change.factor.angio.try
(
data.cat.extract
)
data.cat.extract
<-
fun.fill.pheno.try.with.zanne
(
data.cat.extract
)
'Prestoea acuminata'
'D'
'Chione venosa'
'D_EV'
'Cecropia schreberiana'
'EV'
## fix pheno for species with issue
data.cat.extract
[
data.cat.extract
$
Latin_name
%in%
c
(
'Betula spp.'
,
'Crataegus spp.'
,
'Fraxinus spp.'
,
'Malus spp.'
,
'Sideroxylon lanuginosum'
,
'Quercus sinuata'
,
...
...
R/find.trait/test.traits-fun.R
0 → 100644
View file @
1d1c1227
###########
## FUNCTION TO TEST AND PLOTS TRAITS
source
(
"R/utils/plot.R"
)
## Fun to test that the range of traits is ok
## Leaf N mg g-1 between 2 and 50 Kattge et al 2011
## Seed mass mg between 0.0001 and 100000 (Moles et al. 2005) Coco nucifera 600000
## SLA mm2mg-1 between 1 and 100 Katgge et al 2011
## Wood.density.mean mg mm-3 0.1 1.5 (Chave et al. 2009)
## Max.height.mean m max 100 (115 max height)
fun.test.one.trait
<-
function
(
t
,
t.min
,
t.max
)
{
if
(
sum
(
!
is.na
(
t
)))
{
res
<-
(
max
(
t
,
na.rm
=
TRUE
)
>
t.max
)
|
(
min
(
t
,
na.rm
=
TRUE
)
<
t.min
)
}
else
{
res
<-
FALSE
}
return
(
res
)
}
fun.test.one.trait.data
<-
function
(
i
,
data
,
trait.name
,
t.min
,
t.max
)
{
fun.test.one.trait
(
data
[[
trait.name
[
i
]]],
t.min
[
i
],
t.max
[
i
])
}
fun.test.range.traits
<-
function
(
data.traits
,
set
)
{
trait.name
<-
c
(
"Leaf.N.mean"
,
"Seed.mass.mean"
,
"SLA.mean"
,
"Wood.density.mean"
,
"Max.height.mean"
)
t.min
<-
c
(
2
,
0.0001
,
1
,
0.1
,
1
)
t.max
<-
c
(
60
,
600000
,
100
,
1.5
,
100
)
vec.test
<-
sapply
(
1
:
5
,
fun.test.one.trait.data
,
data.traits
,
trait.name
,
t.min
,
t.max
)
if
(
any
(
vec.test
))
stop
(
paste
(
"Trait"
,
paste
(
trait.name
[
vec.test
],
collapse
=
" "
),
"out of range for set"
,
set
))
else
{
print
(
"All traits within suitable range"
)
}
}
fun.test.one.trait
<-
function
(
t
,
t.min
,
t.max
){
if
(
sum
(
!
is.na
(
t
)))
{
res
<-
(
max
(
t
,
na.rm
=
TRUE
)
>
t.max
)
|
(
min
(
t
,
na.rm
=
TRUE
)
<
t.min
)
}
else
{
res
<-
FALSE
}
return
(
res
)
}
fun.test.one.trait.data
<-
function
(
i
,
data
,
trait.name
,
t.min
,
t.max
)
{
fun.test.one.trait
(
data
[[
trait.name
[
i
]]],
t.min
[
i
],
t.max
[
i
])
}
fun.test.range.traits
<-
function
(
data.traits
,
set
)
{
trait.name
<-
c
(
"Leaf.N.mean"
,
"Seed.mass.mean"
,
"SLA.mean"
,
"Wood.density.mean"
,
"Max.height.mean"
)
t.min
<-
c
(
2
,
0.00001
,
1
,
0.1
,
1
)
t.max
<-
c
(
60
,
600000
,
140
,
1.5
,
100
)
vec.test
<-
sapply
(
1
:
5
,
fun.test.one.trait.data
,
data.traits
,
trait.name
,
t.min
,
t.max
)
if
(
any
(
vec.test
))
stop
(
paste
(
"Trait"
,
paste
(
trait.name
[
vec.test
],
collapse
=
" "
)
,
"out of range for set"
,
set
))
}
## test type of variable
fun.test.type.data
<-
function
(
t.name
,
data
,
type.t
,
set
)
{
t
<-
data
[[
t.name
]]
if
(
sum
(
!
is.na
(
t
)))
{
if
(
!
(
mode
(
t
)
==
type.t
))
stop
(
paste
(
"In set"
,
set
,
"variable"
,
t
,
"is not"
,
type.t
,
sep
=
" "
))
}
}
fun.test.data.type.traits
<-
function
(
data.traits
,
set
)
{
trait.n
<-
c
(
"Leaf.N"
,
"Seed.mass"
,
"SLA"
,
"Wood.density"
,
"Max.height"
)
character.var
<-
c
(
"sp"
,
"Latin_name"
,
'Phylo.group'
,
'Pheno.T'
)
numeric.var
<-
c
(
paste
(
trait.n
,
".mean"
,
sep
=
""
),
paste
(
trait.n
,
".sd"
,
sep
=
""
))
TF.var
<-
c
(
paste
(
trait.n
,
".genus"
,
sep
=
""
))
lapply
(
character.var
,
fun.test.type.data
,
data.traits
,
"character"
,
set
)
lapply
(
numeric.var
,
fun.test.type.data
,
data.traits
,
"numeric"
,
set
)
lapply
(
TF.var
,
fun.test.type.data
,
data.traits
,
"logical"
,
set
)
}
## plot fun
## plots xy for each traits combination
fun.plot.xy.traits
<-
function
(
get.traits
,
k
)
{
pdf
(
file.path
(
"figs/"
,
paste
(
k
,
"traits.XY.pdf"
,
sep
=
"."
)),
height
=
25
,
width
=
10
)
par
(
mfrow
=
c
(
5
,
2
))
for
(
i
in
1
:
4
)
{
for
(
j
in
(
i
+1
)
:
5
)
{
if
(
sum
(
!
is.na
(
get.traits
[[
trait.name
[
i
]]]
)
&
!
is.na
(
get.traits
[[
trait.name
[
j
]]]
))
>
0
)
{
plot
(
get.traits
[[
trait.name
[
i
]]]
,
get.traits
[[
trait.name
[
j
]]],
xlab
=
trait.name
[
i
],
ylab
=
trait.name
[
j
],
log
=
"xy"
,
main
=
k
)
}
else
{
plot
(
1
,
1
,
xlab
=
trait.name
[
i
],
ylab
=
trait.name
[
j
],
log
=
"xy"
,
main
=
k
)}
}
}
dev.off
()
}
## fun to run all test
fun.test.set
<-
function
(
set
,
filedir
)
{
get.traits
<-
read.csv
(
file.path
(
filedir
,
set
,
"traits.csv"
),
header
=
T
,
stringsAsFactors
=
FALSE
)
trait.n
<-
c
(
"Leaf.N"
,
"Seed.mass"
,
"SLA"
,
"Wood.density"
,
"Max.height"
)
character.var
<-
c
(
"sp"
,
"Latin_name"
,
'Phylo.group'
,
'Pheno.T'
)
numeric.var
<-
c
(
paste
(
trait.n
,
".mean"
,
sep
=
""
),
paste
(
trait.n
,
".sd"
,
sep
=
""
))
TF.var
<-
c
(
paste
(
trait.n
,
".genus"
,
sep
=
""
))
if
(
sum
(
!
c
(
character.var
,
numeric.var
,
TF.var
)
%in%
names
(
get.traits
))
>
0
)
stop
(
paste
(
"not good variables names"
,
set
))
## fun.plot.xy.traits(get.traits,set)
fun.test.range.traits
(
get.traits
,
set
)
fun.test.data.type.traits
(
get.traits
,
set
)
cat
(
set
,
"OK \n"
)
return
(
data.frame
(
set
=
rep
(
set
,
nrow
(
get.traits
)),
get.traits
))
}
R/find.trait/test.traits.R
View file @
1d1c1227
source
(
"R/utils/plot.R"
)
## Fun to test that the range of traits is ok
## Leaf N mg g-1 between 2 and 50 Kattge et al 2011
## Seed mass mg between 0.0001 and 100000 (Moles et al. 2005) Coco nucifera 600000
## SLA mm2mg-1 between 1 and 100 Katgge et al 2011
## Wood.density.mean mg mm-3 0.1 1.5 (Chave et al. 2009)
## Max.height.mean m max 100 (115 max height)
fun.test.one.trait
<-
function
(
t
,
t.min
,
t.max
)
{
if
(
sum
(
!
is.na
(
t
)))
{
res
<-
(
max
(
t
,
na.rm
=
TRUE
)
>
t.max
)
|
(
min
(
t
,
na.rm
=
TRUE
)
<
t.min
)
}
else
{
res
<-
FALSE
}
return
(
res
)
}
fun.test.one.trait.data
<-
function
(
i
,
data
,
trait.name
,
t.min
,
t.max
)
{
fun.test.one.trait
(
data
[[
trait.name
[
i
]]],
t.min
[
i
],
t.max
[
i
])
}
fun.test.range.traits
<-
function
(
data.traits
,
set
)
{
trait.name
<-
c
(
"Leaf.N.mean"
,
"Seed.mass.mean"
,
"SLA.mean"
,
"Wood.density.mean"
,
"Max.height.mean"
)
t.min
<-
c
(
2
,
0.0001
,
1
,
0.1
,
1
)
t.max
<-
c
(
60
,
600000
,
100
,
1.5
,
100
)
vec.test
<-
sapply
(
1
:
5
,
fun.test.one.trait.data
,
data.traits
,
trait.name
,
t.min
,
t.max
)
if
(
any
(
vec.test
))
stop
(
paste
(
"Trait"
,
paste
(
trait.name
[
vec.test
],
collapse
=
" "
),
"out of range for set"
,
set
))
else
{
print
(
"All traits within suitable range"
)
}
}
fun.test.one.trait
<-
function
(
t
,
t.min
,
t.max
){
if
(
sum
(
!
is.na
(
t
)))
{
res
<-
(
max
(
t
,
na.rm
=
TRUE
)
>
t.max
)
|
(
min
(
t
,
na.rm
=
TRUE
)
<
t.min
)
}
else
{<