Commit 6fd5b3c4 authored by Georges Kunstler's avatar Georges Kunstler
Browse files

run with cat

parent dedc93b2
......@@ -4,7 +4,7 @@ D3 := output/processed
D4 := figs/test.format.tree
D5 := figs/test.traits
D6 := figs/test.CWM
sites:= Fushan Paracou BCI Mbaiki Luquillo Japan Spain Sweden Canada France Swiss NSW NVS US
sites:= Fushan Paracou BCI Mbaiki Luquillo Japan Spain Sweden Canada France Swiss NSW NVS
D3Done := $(addsuffix /Done.txt,$(addprefix $(D3)/, $(sites) ))
D2traits := $(addsuffix /traits.csv,$(addprefix $(D2)/, $(sites) ))
D2tree := $(addsuffix /tree.csv,$(addprefix $(D2)/, $(sites) ))
......@@ -71,7 +71,7 @@ $(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
Rscript -e "source('$<'); process_bigplot_dataset('Mbaiki', Rlim=15,std.traits='no'); process_bigplot_dataset('Mbaiki', Rlim=15,std.traits='global');"
Rscript -e "source('$<'); 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
Rscript $< ; rm -f $(D5)/Done.txt
......@@ -84,7 +84,7 @@ $(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='no'); process_inventory_dataset('Canada',std.traits='global');"
Rscript -e "source('$<'); process_inventory_dataset('Canada',std.traits='global');"
$(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 $< ; rm -f $(D5)/Done.txt
......@@ -96,7 +96,7 @@ $(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
Rscript -e "source('$<'); process_inventory_dataset('France',std.traits='no'); process_inventory_dataset('France',std.traits='global');"
Rscript -e "source('$<'); 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
Rscript $< ; rm -f $(D5)/Done.txt
......@@ -109,7 +109,7 @@ $(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
Rscript -e "source('$<'); process_bigplot_dataset('Fushan', Rlim=15,std.traits='no'); process_bigplot_dataset('Fushan', Rlim=15,std.traits='global');"
Rscript -e "source('$<'); 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
......@@ -123,7 +123,7 @@ $(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
Rscript -e "source('$<'); process_inventory_dataset('NSW',std.traits='no'); process_inventory_dataset('NSW',std.traits='global');"
Rscript -e "source('$<'); 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
Rscript $< ; rm -f $(D5)/Done.txt
......@@ -136,7 +136,7 @@ $(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
Rscript -e "source('$<'); process_inventory_dataset('NVS',std.traits='no'); process_inventory_dataset('NVS',std.traits='global');"
Rscript -e "source('$<'); 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
Rscript $< ; rm -f $(D5)/Done.txt
......@@ -149,7 +149,7 @@ $(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
Rscript -e "source('$<'); process_bigplot_dataset('Paracou', Rlim=15,std.traits='no'); process_bigplot_dataset('Paracou', Rlim=15,std.traits='global');"
Rscript -e "source('$<'); 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
Rscript $< ; rm -f $(D5)/Done.txt
......@@ -162,7 +162,7 @@ $(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
Rscript -e "source('$<'); process_inventory_dataset('Spain',std.traits='no'); process_inventory_dataset('Spain',std.traits='global');"
Rscript -e "source('$<'); 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
Rscript $< ; rm -f $(D5)/Done.txt
......@@ -175,7 +175,7 @@ $(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
Rscript -e "source('$<'); process_inventory_dataset('Sweden',std.traits='no'); process_inventory_dataset('Sweden',std.traits='global');"
Rscript -e "source('$<'); 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
Rscript $< ; rm -f $(D5)/Done.txt
......@@ -188,7 +188,7 @@ $(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
Rscript -e "source('$<'); process_inventory_dataset('Swiss',std.traits='no'); process_inventory_dataset('Swiss',std.traits='global');"
Rscript -e "source('$<'); 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
Rscript $< ; rm -f $(D5)/Done.txt
......@@ -201,7 +201,7 @@ $(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='no'); process_inventory_dataset('US',std.traits='global');"
Rscript -e "source('$<'); process_inventory_dataset('US',std.traits='global');"
$(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 $< ; rm -f $(D5)/Done.txt
......@@ -218,13 +218,13 @@ $(D4)/Done.txt: R/format.data/test.tree.R $(D3tree)
#-------------------------------------------------------
TEST.TRAITS: $(D5)/Done.txt
$(D5)/Done.txt: R/find.trait/test.traits.R $(D4)/Done.txt $(D3traits)
$(D5)/Done.txt: R/find.trait/test.traits.R $(D3traits)
Rscript $<
#-------------------------------------------------------
TEST.CWM: $(D6)/Done.txt
$(D6)/Done.txt: R/process.data/test.tree.CWM.R $(D5)/Done.txt $(D3Done)
$(D6)/Done.txt: R/process.data/test.tree.CWM.R $(D3Done)
Rscript $<
#-------------------------------------------------------
......
......@@ -58,7 +58,8 @@ model.files.glmer.Tf.4 <-
fun.call.glmer.and.save <- function(formula,df.lmer,path.out){
Start <- Sys.time()
glmer.output <- glmer(formula=formula,data=df.lmer,family=binomial)
glmer.output <- glmer(formula=formula,data=df.lmer,
family=binomial(link = 'cloglog'))
end <- Sys.time()
print(end - Start)
print(summary(glmer.output))
......@@ -67,12 +68,14 @@ fun.call.glmer.and.save <- function(formula,df.lmer,path.out){
run.glmer <- function (model.file, trait,
min.obs=5, sample.size=NA,
type.filling) {
type.filling, fname = 'data.all.no.std.csv') {
require(lme4)
source(model.file, local = TRUE)
model <- load.model()
#= Path for output
path.out <- output.dir.glmer(model$name, trait,
if(fname == 'data.all.no.std.csv') dir <- 'all.no.log'
if(fname == 'data.all.csv') dir <- 'all.log'
path.out <- output.dir.glmer(dir, model$name, trait,
type.filling=type.filling)
print(path.out)
dir.create(path.out, recursive=TRUE, showWarnings=FALSE)
......@@ -81,7 +84,8 @@ run.glmer <- function (model.file, trait,
trait,"\n")
df.glmer <- load.and.prepare.data.for.glmer(trait,
min.obs, sample.size,
type.filling=type.filling) # return a DF
type.filling=type.filling,
fname = fname) # return a DF
cat("Ok data with Nobs",nrow(df.glmer),"\n")
#= Run model
fun.call.glmer.and.save(formula=model$glmer.formula,df.glmer,path.out)
......@@ -89,8 +93,25 @@ run.glmer <- function (model.file, trait,
#========================================================================
output.dir.glmer <- function (model, trait, type.filling) {
file.path("output/glmer", 'all',trait,type.filling,model)
output.dir.glmer <- function (dir, model, trait, type.filling) {
file.path("output/glmer", dir,trait,type.filling,model)
}
fun.load.data.all <- function(base.dir,fname){
data.all.sample <- read.csv(file = file.path(base.dir, fname),
stringsAsFactors = FALSE, nrows = 1000)
classes <- sapply(data.all.sample, class)
classes[classes=='integer'] <- "numeric"
nrows <- as.numeric(system(paste('wc -l < ',file.path(base.dir, fname)),
intern = TRUE))
data.tree.tot <- read.csv(file = file.path(base.dir, fname),
stringsAsFactors = FALSE,
nrows = nrows,
colClasses = classes)
return(data.tree.tot)
}
......@@ -99,37 +120,37 @@ output.dir.glmer <- function (model, trait, type.filling) {
#============================================================
load.and.prepare.data.for.glmer <- function(trait,
min.obs, sample.size, type.filling,
fname = 'data.all.no.std.csv',
base.dir = "output/processed/"){
### load data
data.all.sample <- read.csv(file=file.path(base.dir, "data.all.csv"),
stringsAsFactors=FALSE,nrows=1000)
classes <- sapply(data.all.sample,class)
classes[classes=='integer'] <- "numeric"
nrows <- as.numeric(system('wc -l < output/processed/data.all.csv',
intern=TRUE))
data.tree.tot <- read.csv(file=file.path(base.dir, "data.all.csv"),
stringsAsFactors=FALSE,
nrows=nrows,
colClasses=classes)
data.tree.tot <- fun.load.data.all(base.dir,fname)
fun.data.for.glmer(data.tree.tot,trait,type.filling=type.filling)
}
fun.select.data.for.analysis <- function(data.tree,abs.CWM.tntf,perc.neigh,
fun.select.data.for.analysis <- function(data.tree,abs.CWM.tntf,
perc.neigh.sp,
perc.neigh.gs,
BATOT,min.obs,
min.perc.neigh=0.80){
min.perc.neigh.sp = 0.90,
min.perc.neigh.gs = 0.95){
## remove tree with NA
data.tree <- subset(data.tree,subset=(!is.na(data.tree[["dead"]])) &
(!is.na(data.tree[["D"]])) )
(!is.na(data.tree[["D"]])) &
(!is.na(data.tree[['year']])))
## remove tree with zero
data.tree <- subset(data.tree,subset=data.tree[["D"]]>9.9)
## select species with missing traits
data.tree <- data.tree[(!is.na(data.tree[[abs.CWM.tntf]]) &
!is.na(data.tree[[BATOT]])),]
# select obs abov min perc.neigh
data.tree <- subset(data.tree,subset=data.tree[[perc.neigh]] > min.perc.neigh &
!is.na(data.tree[[perc.neigh]]))
# select obs abov min perc.neigh species
data.tree <- subset(data.tree, subset = data.tree[[perc.neigh.sp]] >
min.perc.neigh.sp &
!is.na(data.tree[[perc.neigh.sp]]))
# select obs abov min perc.neigh genus
data.tree <- subset(data.tree, subset = data.tree[[perc.neigh.gs]] >
min.perc.neigh.gs & !is.na(data.tree[[perc.neigh.gs]]))
# select species with minimum obs
data.tree <- subset(data.tree,subset=data.tree[["sp"]] %in%
names(table(factor(data.tree[["sp"]])))[table(factor(
......@@ -146,6 +167,7 @@ fun.get.the.variables.for.glmer.no.tree.id <- function(data.tree,BATOT,CWM.tn,
abs.CWM.tntf,tf,min.BA.G=50){
dead <- data.tree[["dead"]]
logD <- fun.center.and.standardized.var(log(data.tree[["D"]]))
logyear <- log(data.tree[["year"]])
MAT <- fun.center.and.standardized.var(data.tree[["MAT"]])
MAP <- fun.center.and.standardized.var(data.tree[["MAP"]])
species.id <- factor(data.tree[["sp"]])
......@@ -161,6 +183,7 @@ sumTnTfBn.diff <- sumTnBn-sumTfBn
sumBn <- data.tree[[BATOT]]
return(data.frame(dead=dead,
logD=logD,
logyear=logyear,
MAT = MAT,
MAP = MAP,
species.id=species.id,
......@@ -192,9 +215,13 @@ CWM.tn <- paste(trait,"CWM",'fill',sep=".")
abs.CWM.tntf <- paste(trait,"abs.CWM",'fill',sep=".")
tf <- paste(trait,"focal",sep=".")
BATOT <- "BATOT"
perc.neigh <- paste(trait,"perc",type.filling,sep=".")
data.tree <- fun.select.data.for.analysis(data.tree,abs.CWM.tntf,
perc.neigh,BATOT,min.obs)
perc.neigh.sp <- paste(trait, "perc", 'species', sep = ".")
perc.neigh.gs <- paste(trait, "perc", 'genus', sep = ".")
data.tree <- fun.select.data.for.analysis(data.tree,
abs.CWM.tntf,
perc.neigh.sp,
perc.neigh.gs,
BATOT,min.obs)
#= DATA LIST FOR JAGS
glmer.data <- fun.get.the.variables.for.glmer.no.tree.id(data.tree,BATOT,CWM.tn,abs.CWM.tntf,tf)
return(glmer.data)
......
......@@ -101,7 +101,7 @@ Rsquared.glmm.lmer <- function(i){
# Calculate conditional R-squared (fixed effects+random effects/total variance)
Rc <- (VarF+VarRand)/(VarF+VarRand+VarResid)
# Bind R^2s into a matrix and return with AIC values
Rsquared.mat <- data.frame(Class=class(i), Family="Gaussian", Marginal=Rm,
Rsquared.mat <- data.frame(Class=class(i), Family="Gaussian", Marginal=Rm,
Conditional=Rc, AIC=AIC(i))
return(Rsquared.mat)
}
......@@ -136,7 +136,7 @@ VarResid <- attr(VarCorr(i), "sc")^2
var.vec <- var.vec/(VarF+VarRand+VarResid)
}else{
var.vec <- NA
}
}
names(var.vec) <- paste("effect.response", "VAR", sep=".")
return(var.vec)
}
......@@ -151,7 +151,7 @@ names(dat.t) <- c(names.param, paste(names.param, "Std.Error", sep=".")
, paste(names.param, "VAR", sep="."))
dat.t[, match(names(list.res$lmer.summary$fixed.coeff.E), names(dat.t))] <-
list.res$lmer.summary$fixed.coeff.E
dat.t[, length(names.param)+match(names(list.res$lmer.summary$fixed.coeff.E),
dat.t[, length(names.param)+match(names(list.res$lmer.summary$fixed.coeff.E),
names(dat.t))] <-
list.res$lmer.summary$fixed.coeff.Std.Error
dat.t[, match(names(list.res$lmer.summary$fixed.var), names(dat.t))] <-
......@@ -213,7 +213,7 @@ return(df.res)
## function to compute ratio of variance explained by a trait variable over the variance explained by the BATOT
fun.ratio.var.fixed.effect <- function(DF.results){
mat.ratio <- DF.results[, c('sumTnTfBn.abs.VAR', 'sumTfBn.VAR', 'sumTnBn.VAR',
mat.ratio <- DF.results[, c('sumTnTfBn.abs.VAR', 'sumTfBn.VAR', 'sumTnBn.VAR',
'effect.response.var')]/
DF.results[, 'sumBn.VAR']
names(mat.ratio) <- c('abs.dist', 'Response', 'Effect', 'Effect.Response')
......@@ -222,25 +222,25 @@ return(mat.ratio)
### FUNCTION TO REPORT BEST MODEL PER ECOREGION AND TRAITS
fun.AIC <- function(id2.one, DF.results){
models <- c('lmer.LOGLIN.nocomp.Tf', 'lmer.LOGLIN.simplecomp.Tf',
'lmer.LOGLIN.HD.Tf',
'lmer.LOGLIN.E.Tf', 'lmer.LOGLIN.R.Tf', 'lmer.LOGLIN.ER.Tf',
models <- c('lmer.LOGLIN.nocomp.Tf', 'lmer.LOGLIN.simplecomp.Tf',
'lmer.LOGLIN.HD.Tf',
'lmer.LOGLIN.E.Tf', 'lmer.LOGLIN.R.Tf', 'lmer.LOGLIN.ER.Tf',
'lmer.LOGLIN.AD.Tf')
best <- as.vector(DF.results[DF.results$id2==id2.one, c('id2', 'trait', 'set',
best <- as.vector(DF.results[DF.results$id2==id2.one, c('id2', 'trait', 'set',
'ecocode', 'filling', 'MAT', 'MAP', 'model')])[
which.min(DF.results$AIC[DF.results$id2==id2.one]), ]
AIC.all <- as.vector(DF.results[DF.results$id2==id2.one, c('AIC')])
names(AIC.all) <- as.vector(DF.results[DF.results$id2==id2.one, c('model')])
AIC.all <- AIC.all[models]-min(AIC.all)
res <- data.frame((best), t(AIC.all))
names(res) <- c('id2', 'trait', 'set', 'ecocode', 'filling', 'MAT', 'MAP',
names(res) <- c('id2', 'trait', 'set', 'ecocode', 'filling', 'MAT', 'MAP',
'best.model', paste('AIC', models, sep='.'))
return(res)
}
fun.AICc <- function(id2.one, DF.results){
models <- c('lmer.LOGLIN.nocomp.Tf', 'lmer.LOGLIN.simplecomp.Tf',
'lmer.LOGLIN.HD.Tf', 'lmer.LOGLIN.E.Tf', 'lmer.LOGLIN.R.Tf',
models <- c('lmer.LOGLIN.nocomp.Tf', 'lmer.LOGLIN.simplecomp.Tf',
'lmer.LOGLIN.HD.Tf', 'lmer.LOGLIN.E.Tf', 'lmer.LOGLIN.R.Tf',
'lmer.LOGLIN.ER.Tf', 'lmer.LOGLIN.AD.Tf')
Deviance.all <- DF.results[DF.results$id2==id2.one, 'deviance']
names(Deviance.all) <- DF.results[DF.results$id2==id2.one, 'model']
......@@ -259,8 +259,8 @@ fun.AICc <- function(id2.one, DF.results){
#################################333
### function to get the data for a given model with criteria to select
fun.select.ecoregions.trait <- function(DF.results, trait.name, model.selected,
nobs.min=1000, filling.selected="species",
fun.select.ecoregions.trait <- function(DF.results, trait.name, model.selected,
nobs.min=1000, filling.selected="species",
threshold.delta.AIC = 100000){
DF.results[DF.results$nobs>nobs.min &
DF.results$filling==filling.selected &
......@@ -270,8 +270,8 @@ DF.results[DF.results$nobs>nobs.min &
}
### function to get the data for a given model with criteria to select only site with competition
fun.select.ecoregions.trait.compet <- function(DF.results, trait.name, model.selected,
nobs.min=1000, filling.selected="species",
fun.select.ecoregions.trait.compet <- function(DF.results, trait.name, model.selected,
nobs.min=1000, filling.selected="species",
threshold.delta.AIC = 100000){
DF.results[DF.results$nobs>nobs.min &
DF.results$filling==filling.selected &
......@@ -297,9 +297,9 @@ df.selected <- fun.select.ecoregions.trait(DF.results, trait.name=trait.name, mo
if(pch.AIC) {pch.vec <- c(1, 16)[as.numeric(df.selected[['delta.AIC']]==0)+1]}else{pch.vec <- 1}
if(cex.AIC) {cex.vec <- c(1, 1.5)[as.numeric(df.selected[['delta.AIC']]==0)+1]}else{cex.vec <- 1}
if(col.set) {col.vec2 <- col.vec[unclass(df.selected[['set']])]}else{col.vec2 <- 1}
plot(df.selected[[var.x]], df.selected[[var.y]],
pch=pch.vec,
cex=cex.vec,
plot(df.selected[[var.x]], df.selected[[var.y]],
pch=pch.vec,
cex=cex.vec,
col=col.vec2, ...)
}
......@@ -325,82 +325,82 @@ segments( x - small.bar, unlist(y + 1.96*sd), x + small.bar, unlist(y +1.96*s
fun.plot.param.error.bar <- function(df.selected, var.x, param, small.bar, col.vec){
segments( df.selected[[var.x]], df.selected[[param]] - 1.96*df.selected[[paste(
param, "Std.Error", sep=".")]],
param, "Std.Error", sep=".")]],
df.selected[[var.x]], df.selected[[param]] + 1.96*df.selected[[paste(
param, "Std.Error", sep=".")]], col=col.vec)
segments( df.selected[[var.x]]-small.bar, df.selected[[param]] - 1.96*
df.selected[[paste(param, "Std.Error", sep=".")]],
df.selected[[paste(param, "Std.Error", sep=".")]],
df.selected[[var.x]]+small.bar, df.selected[[param]] - 1.96*
df.selected[[paste(param, "Std.Error", sep=".")]], col=col.vec)
segments( df.selected[[var.x]]-small.bar, df.selected[[param]] + 1.96*
df.selected[[paste(param, "Std.Error", sep=".")]],
df.selected[[paste(param, "Std.Error", sep=".")]],
df.selected[[var.x]]+small.bar, df.selected[[param]] + 1.96*
df.selected[[paste(param, "Std.Error", sep=".")]], col=col.vec)
}
fun.plot.all.param.x.y.c <- function(model.selected, trait.name, DF.results, var.x,
params, small.bar, threshold.delta.AIC,
col.vec, col.set=TRUE, ylim=NA,
fun.plot.all.param.x.y.c <- function(model.selected, trait.name, DF.results, var.x,
params, small.bar, threshold.delta.AIC,
col.vec, col.set=TRUE, ylim=NA,
ylim.same=FALSE, add.name = FALSE, ...){
df.selected <- fun.select.ecoregions.trait(DF.results, trait.name=trait.name,
model.selected=model.selected,
df.selected <- fun.select.ecoregions.trait(DF.results, trait.name=trait.name,
model.selected=model.selected,
threshold.delta.AIC=threshold.delta.AIC)
if(col.set) {col.vec2 <- col.vec[as.character(df.selected[['set']])]}else{
col.vec2 <- 1}
if(!ylim.same) {ylim <- range(c(df.selected[[params[1]]] - 1.96*
df.selected[[paste(params[1], "Std.Error", sep=".")]],
df.selected[[paste(params[1], "Std.Error", sep=".")]],
df.selected[[params[1]]] + 1.96*
df.selected[[paste(params[1], "Std.Error", sep=".")]]), na.rm=TRUE)}
plot(df.selected[[var.x]], df.selected[[params[1]]], col=col.vec2, ylim=ylim, ...)
if (add.name) text(df.selected[[var.x]], df.selected[[params[1]]],
labels = paste(df.selected[['set']],
if (add.name) text(df.selected[[var.x]], df.selected[[params[1]]],
labels = paste(df.selected[['set']],
df.selected[['ecocode']]), cex = 0.5, pos = 2)
fun.plot.param.error.bar(df.selected, var.x, param=params[1],
fun.plot.param.error.bar(df.selected, var.x, param=params[1],
small.bar, col=col.vec2)
}
fun.plot.param.error.bar.std <- function(df.selected, var.x, param, small.bar, col.vec){
segments( df.selected[[var.x]], df.selected[[param]] + df.selected[['sumBn']] - 1.96*df.selected[[paste(
param, "Std.Error", sep=".")]],
param, "Std.Error", sep=".")]],
df.selected[[var.x]], df.selected[[param]] + df.selected[['sumBn']] + 1.96*df.selected[[paste(
param, "Std.Error", sep=".")]], col=col.vec)
segments( df.selected[[var.x]]-small.bar, df.selected[[param]] + df.selected[['sumBn']] - 1.96*
df.selected[[paste(param, "Std.Error", sep=".")]],
df.selected[[paste(param, "Std.Error", sep=".")]],
df.selected[[var.x]]+small.bar, df.selected[[param]] + df.selected[['sumBn']] - 1.96*
df.selected[[paste(param, "Std.Error", sep=".")]], col=col.vec)
segments( df.selected[[var.x]]-small.bar, df.selected[[param]] + df.selected[['sumBn']] + 1.96*
df.selected[[paste(param, "Std.Error", sep=".")]],
df.selected[[paste(param, "Std.Error", sep=".")]],
df.selected[[var.x]]+small.bar, df.selected[[param]] + df.selected[['sumBn']] + 1.96*
df.selected[[paste(param, "Std.Error", sep=".")]], col=col.vec)
}
fun.plot.all.param.x.y.std <- function(model.selected, trait.name,
DF.results, var.x,
params, small.bar, threshold.delta.AIC,
col.vec, col.set=TRUE, ylim=NA,
fun.plot.all.param.x.y.std <- function(model.selected, trait.name,
DF.results, var.x,
params, small.bar, threshold.delta.AIC,
col.vec, col.set=TRUE, ylim=NA,
ylim.same=FALSE, add.name = FALSE, ...){
df.selected <- fun.select.ecoregions.trait(DF.results, trait.name=trait.name,
model.selected=model.selected,
df.selected <- fun.select.ecoregions.trait(DF.results, trait.name=trait.name,
model.selected=model.selected,
threshold.delta.AIC=threshold.delta.AIC)
if(col.set) {col.vec2 <- col.vec[df.selected[['set']]]}else{
col.vec2 <- 1}
plot(df.selected[[var.x]], df.selected[[params[1]]] + df.selected[['sumBn']],
plot(df.selected[[var.x]], df.selected[[params[1]]] + df.selected[['sumBn']],
col = col.vec2, ...)
if (add.name) text(df.selected[[var.x]],
df.selected[[params[1]]] + df.selected[['sumBn']],
labels = paste(df.selected[['set']],
if (add.name) text(df.selected[[var.x]],
df.selected[[params[1]]] + df.selected[['sumBn']],
labels = paste(df.selected[['set']],
df.selected[['ecocode']]), cex = 0.5, pos = 2)
fun.plot.param.error.bar.std(df.selected, var.x, param=params[1],
fun.plot.param.error.bar.std(df.selected, var.x, param=params[1],
small.bar, col=col.vec2)
}
fun.plot.all.param.boxplot <- function(model.selected, trait.name, DF.results,
fun.plot.all.param.boxplot <- function(model.selected, trait.name, DF.results,
params, small.bar, ...){
df.selected <- fun.select.ecoregions.trait(DF.results, trait.name=trait.name,
df.selected <- fun.select.ecoregions.trait(DF.results, trait.name=trait.name,
model.selected=model.selected)
if(length(params)>1){
DF.t <- data.frame(param=rep(names(params), each=nrow(df.selected)), value=c(
......@@ -411,16 +411,16 @@ boxplot(df.selected[[params[1]]], ...)
}
}
fun.plot.all.param.er.diff.MAP <- function(model.selected, trait.name,
fun.plot.all.param.er.diff.MAP <- function(model.selected, trait.name,
DF.results, ...){
df.selected <- fun.select.ecoregions.trait(DF.results, trait.name=trait.name,
df.selected <- fun.select.ecoregions.trait(DF.results, trait.name=trait.name,
model.selected=model.selected)
plot(df.selected[['MAP']], df.selected[['sumTnBn']]-df.selected[['sumTfBn']], ...)
}
fun.plot.panel.lmer.res.x.y <- function(models, traits, DF.results, var.x, var.y.l,
fun.plot.panel.lmer.res.x.y <- function(models, traits, DF.results, var.x, var.y.l,
express, ...){
ncols = length(traits)
nrows = length(models)
......@@ -431,7 +431,7 @@ fun.plot.panel.lmer.res.x.y <- function(models, traits, DF.results, var.x, var.y
par(mfrow = c(nrows, ncols), mar = c(2, 2, 1, 1), oma = c(4, 4, 4, 1) )
for(i in 1:nrows)
for(j in 1:ncols){
fun.plot.lmer.res.x.y.2(models[i], traits[j],
fun.plot.lmer.res.x.y.2(models[i], traits[j],
DF.results, var.x, var.y=var.y.l[[i]], col.vec, ...)
abline(h=0, lty=3)
if(i==1 )
......@@ -439,16 +439,16 @@ fun.plot.panel.lmer.res.x.y <- function(models, traits, DF.results, var.x, var.y
if(i==nrows)
mtext(var.x, side=1, line =4)
if(j==1)
mtext(paste('Effect size', list.models[i]), side=2, line =4,
mtext(paste('Effect size', list.models[i]), side=2, line =4,
cex=0.9)
if(i==nrows & j==ncols)
legend('topright', legend=levels(DF.results$set), pch=16,
legend('topright', legend=levels(DF.results$set), pch=16,
col=col.vec, bty='n', ncol=2)
}
}
fun.plot.panel.lmer.res.boxplot <- function(models, traits, DF.results, var.y,
fun.plot.panel.lmer.res.boxplot <- function(models, traits, DF.results, var.y,
express, ...){
ncols = length(traits)
nrows = length(models)
......@@ -457,26 +457,26 @@ fun.plot.panel.lmer.res.boxplot <- function(models, traits, DF.results, var.y,
par(mfrow = c(nrows, ncols), mar = c(2, 2, 1, 1), oma = c(4, 4, 4, 1) )
for(i in 1:nrows)
for(j in 1:ncols){
fun.plot.lmer.res.boxplot(models[i], traits[j],
fun.plot.lmer.res.boxplot(models[i], traits[j],
DF.results, var.y[[j]], ...)
abline(h=0, lty=3)
if(i==1 )
mtext(traits[j], side=3, line =1)
if(j==1)
mtext(paste("Effect size", list.models[i], sep=" "), side=2,
mtext(paste("Effect size", list.models[i], sep=" "), side=2,
line =4, cex=0.9)
}
}
fun.plot.panel.lmer.res.boxplot.compare <- function(models, traits, DF.results,
fun.plot.panel.lmer.res.boxplot.compare <- function(models, traits, DF.results,
var.y, express, ...){
ncols = length(traits)
list.models <- as.list(names(models))
names(list.models) <- rep('model', length(list.models))
par(mfrow = c(1, ncols), mar = c(2, 2, 1, 1), oma = c(4, 4, 4, 1) )
for(j in 1:ncols){
fun.plot.lmer.res.boxplot.compare.model(models, traits[j],
fun.plot.lmer.res.boxplot.compare.model(models, traits[j],
DF.results, var.y, ...)
abline(h=0, lty=3)
mtext(traits[j], side=3, line =1, cex=2)
......@@ -485,9 +485,9 @@ fun.plot.panel.lmer.res.boxplot.compare <- function(models, traits, DF.results,
}
}
fun.plot.panel.lmer.parameters.c <- function(models, traits, DF.results, var.x,
list.params, threshold.delta.AIC,
small.bar=10, ylim=NA,
fun.plot.panel.lmer.parameters.c <- function(models, traits, DF.results, var.x,
list.params, threshold.delta.AIC,
small.bar=10, ylim=NA,
ylim.same=FALSE,
col.vec2=col.vec, ...){
ncols = length(traits)
......@@ -500,16 +500,16 @@ fun.plot.panel.lmer.parameters.c <- function(models, traits, DF.results, var.x,
for(i in 1:nrows)
for(j in 1:ncols){
try(fun.plot.all.param.x.y.c(models[i], traits[j], DF.results,
var.x,
params=list.params[[i]],
small.bar=small.bar,
threshold.delta.AIC=threshold.delta.AIC,