Skip to content
Snippets Groups Projects
Commit 8bb08d04 authored by Francesco Sabatini's avatar Francesco Sabatini
Browse files

aligned 00 99 session

parent 2f8e939d
No related branches found
No related tags found
No related merge requests found
...@@ -279,14 +279,12 @@ env <- env %>% ...@@ -279,14 +279,12 @@ env <- env %>%
# pull(RELEVE_NR) # pull(RELEVE_NR)
# #
species <- species %>%
rownames_to_column("RELEVE_NR")
##export for Valerio ##export for Valerio
write_delim(species, path="_data/Mesobromion/species.out.10perc.txt", delim="\t") write_delim(species, path="_data/Mesobromion/species.out.10perc.txt", delim="\t")
write_delim(traits, path="_data/Mesobromion/traits.out.10perc.cov.txt", delim="\t") write_delim(traits, path="_data/Mesobromion/traits.out.10perc.txt", delim="\t")
write_delim(env, path="_data/Mesobromion/env.10perc.cov.txt", delim="\t") write_delim(env, path="_data/Mesobromion/env.10perc.cov.txt", delim="\t")
...@@ -302,18 +300,24 @@ write_delim(species %>% ...@@ -302,18 +300,24 @@ write_delim(species %>%
dplyr::select(RELEVE_NR), dplyr::select(RELEVE_NR),
path="_derived/Mesobromion/ReleveList.txt", delim="\t") path="_derived/Mesobromion/ReleveList.txt", delim="\t")
###### 5. Species data with cover values #####
### version with cover values ### 4/08/2020 ### version with cover values ### 4/08/2020
env0 <- read_delim("_data/Mesobromion/GVRD_MES2_site.csv", delim = ",")
species.proz <- read_csv("_data/Mesobromion/GVRD_Mes2_proz.csv", locale = locale(encoding = 'latin1')) species.proz <- read_csv("_data/Mesobromion/GVRD_Mes2_proz.csv", locale = locale(encoding = 'latin1'))
species.proz$RELEVE_NR <- env0$RELEVE_NR species.proz$RELEVE_NR <- env0$RELEVE_NR
species.proz <- species.proz %>% species.proz <- species.proz %>%
filter(RELEVE_NR %in% (species %>% pull(RELEVE_NR))) %>% filter(RELEVE_NR %in% (species %>% pull(RELEVE_NR))) %>%
#transform percentage cover to relative.cover ## delete species not appearing in any plot
dplyr::select(colnames(.)[which(colSums(.)!=0)])
dim(species.proz)
write_delim(species.proz , path="_data/Mesobromion/species.out.10perc.proz.txt", delim="\t")
#transform percentage cover to relative.cover
species.proz <- species.proz %>%
mutate(sumVar = rowSums(.[-1])) %>% mutate(sumVar = rowSums(.[-1])) %>%
mutate_at(.vars=vars(-RELEVE_NR), mutate_at(.vars=vars(-RELEVE_NR),
.funs=~./sumVar) %>% .funs=~./sumVar) %>%
dplyr::select(-sumVar) %>% dplyr::select(-sumVar)
## delete species not appearing in any plot
dplyr::select(colnames(.)[which(colSums(.)!=0)])
dim(species.proz) #[1] 558 533 dim(species.proz) #[1] 558 533
write_delim(species.proz , path="_data/Mesobromion/species.out.10perc.cov.txt", delim="\t") write_delim(species.proz , path="_data/Mesobromion/species.out.10perc.cov.txt", delim="\t")
...@@ -349,3 +353,94 @@ write_delim(traits.proz, path="_data/Mesobromion/traits.out.10perc.cov.txt", del ...@@ -349,3 +353,94 @@ write_delim(traits.proz, path="_data/Mesobromion/traits.out.10perc.cov.txt", del
#### CORRELATION BETWEEN FUZZY WEIGHTED AND BEALS MATRICES #### CORRELATION BETWEEN FUZZY WEIGHTED AND BEALS MATRICES
#### WAS RUN IN THE CLUSTER WITH THE SCRIPT 01b_MesobromionCluster.R #### WAS RUN IN THE CLUSTER WITH THE SCRIPT 01b_MesobromionCluster.R
### PART 2 ####
source("01b_MesobromionCluster.R")
#### 1. Traits individually significant for COVER data####
traits <- read_delim("_data/Mesobromion/traits.out.10perc.cov.txt", delim="\t")
myfilelist <- list.files(path="_derived/Mesobromion/Cover", pattern="HIDDENproz_[0-9]+_.RData", full.names = T)
dataFiles = purrr::map(myfilelist, function(x){get(load(x))})
corXY = bind_rows(dataFiles) %>%
as_tibble()
rm( dataFiles)
trait.labs <- data.frame(Trait.comb=as.character(1:(ncol(traits)-1)),
trait.name=colnames(traits)[-1])
corXY.ci <- get.ci(corXY)
corXY.ci <- corXY.ci %>%
arrange(desc(sign_plus), desc(Coef.obs)) %>%
left_join(trait.labs, by="Trait.comb") %>%
dplyr::select(-Test)
## NO significant TRAITS when using Cover values
# traits.sign.alone <- corXY.ci %>%
# filter(sign_plus) %>%
# pull(trait.name)
#
# traits.sign <- traits %>%
# dplyr::select(species0, any_of(traits.sign.alone))
# write_delim(traits.sign, path="_data/Mesobromion/traits.out.10perc.cov.sign.txt", delim="\t")
"# A tibble: 50 x 11
Trait.comb Coef.obs Coef.perm q025 q975 greater.than.perm n sign_plus sign_minus ntraits trait.name
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <lgl> <lgl> <int> <fct>
1 17 0.335 0.205 0.275 0.436 0.903 999 FALSE FALSE 1 V_VER_Fragmentation
2 12 0.255 0.139 0.235 0.315 0.690 999 FALSE FALSE 1 V_VER_Rhizom
3 11 0.226 0.170 0.218 0.279 0.533 999 FALSE FALSE 1 V_VER_Ausläufer
4 5 0.199 0.340 0.194 0.247 0.502 999 FALSE FALSE 1 LEB_F_Hemiphanerophyt
5 2 0.198 0.232 0.191 0.247 0.447 999 FALSE FALSE 1 LEB_F_Nanophanerophyt
6 19 0.198 0.217 0.193 0.245 0.539 999 FALSE FALSE 1 V_VER_Sprossknolle
7 44 0.194 0.171 0.199 0.242 0.299 999 FALSE FALSE 1 BLU_KL
8 45 0.192 0.188 0.187 0.238 0.526 999 FALSE FALSE 1 REPR_T
9 10 0.191 0.187 0.187 0.240 0.366 999 FALSE FALSE 1 V_VER_Wurzelspross
10 42 0.190 0.235 0.192 0.236 0.261 999 FALSE FALSE 1 Disp.unit.leng
# … with 40 more rows"
#### 2. Traits individually significant for Presence|absence data####
traits <- read_delim("_data/Mesobromion/traits.out.10perc.txt", delim="\t")
myfilelist <- list.files(path="_derived/Mesobromion/PresAbs", pattern="HIDDENpa_[0-9]+_.RData", full.names = T)
dataFiles = purrr::map(myfilelist, function(x){get(load(x))})
corXY = bind_rows(dataFiles) %>%
as_tibble()
rm( dataFiles)
trait.labs <- data.frame(Trait.comb=as.character(1:(ncol(traits)-1)),
trait.name=colnames(traits)[-1])
corXY.ci <- get.ci(corXY)
corXY.ci <- corXY.ci %>%
arrange(desc(sign_plus), desc(Coef.obs)) %>%
left_join(trait.labs, by="Trait.comb") %>%
dplyr::select(-Test)
"# A tibble: 52 x 11
Trait.comb Coef.obs Coef.perm q025 q975 greater.than.perm n sign_plus sign_minus ntraits trait.name
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <lgl> <lgl> <int> <fct>
1 35 0.300 0.0714 0.270 0.350 0.993 999 TRUE FALSE 1 PlantHeight
2 34 0.279 0.201 0.250 0.326 0.993 999 TRUE FALSE 1 LeafP
3 31 0.253 0.165 0.231 0.303 0.987 999 TRUE FALSE 1 SLA
4 37 0.244 0.0847 0.218 0.293 0.986 999 TRUE FALSE 1 Seed.length
5 33 0.243 0.0984 0.218 0.290 0.994 999 TRUE FALSE 1 LeafN
6 32 0.240 0.0846 0.218 0.290 0.986 999 TRUE FALSE 1 LeafC.perdrymass
7 44 0.234 0.145 0.208 0.288 0.980 999 TRUE FALSE 1 Disp.unit.leng
8 2 0.234 0.263 0.216 0.283 0.593 1998 FALSE FALSE 1 LEB_F_Nanophanerophyt
9 5 0.233 0.267 0.214 0.287 0.571 999 FALSE FALSE 1 LEB_F_Hemiphanerophyt
10 30 0.227 0.177 0.203 0.281 0.970 999 FALSE FALSE 1 LeafArea
# … with 42 more rows"
traits.sign.alone <- corXY.ci %>%
filter(sign_plus) %>%
pull(trait.name)
traits.sign <- traits %>%
dplyr::select(species0, any_of(traits.sign.alone))
write_delim(traits.sign, path="_data/Mesobromion/traits.out.10perc.sign.txt", delim="\t")
...@@ -14,40 +14,6 @@ library(ade4) ...@@ -14,40 +14,6 @@ library(ade4)
library(energy) library(energy)
#### Function 1 - CorXY ####
get.corXY <- function(comm, traits, trait.sel="all", stat=c("mantel", "RV", "procrustes")){
if(identical(trait.sel, "all")) {trait.sel <- 1:ncol(traits)}
ii <- trait.sel
lab.tmp <- paste(ii, collapse="_")
### delete potential missing species
if(any(colSums(comm)==0)){
empty <- which(colSums(comm)==0)
traits <- traits[-empty,]
comm <- comm[,-empty]
}
syn.out.tmp <- matrix.x(comm=comm, traits=traits[,ii,drop=F], scale=T)$matrix.X
W.beals <- as.data.frame(beals(comm, include=T, type=2))
corXY <- NULL
if("mantel" %in% stat){
W.beals.d <- dist(W.beals)
mantel.tmp <- mantel(W.beals.d, dist(syn.out.tmp[]))
corXY <- rbind(corXY,
data.frame(Trait.comb=lab.tmp, Test="Mantel", Coef=mantel.tmp$statistic, pvalue=mantel.tmp$signif))
}
if("RV" %in% stat){
RV.tmp <- RV.rtest(W.beals, as.data.frame(syn.out.tmp))
corXY <- rbind(corXY,
data.frame(Trait.comb=lab.tmp, Test="RV", Coef=RV.tmp$obs, pvalue=RV.tmp$pvalue))
}
if("procrustes" %in% stat){
prot.tmp <- protest(W.beals, syn.out.tmp)
corXY <- rbind(corXY,
data.frame(Trait.comb=lab.tmp, Test="Procrustes", Coef=prot.tmp$t0, pvalue=prot.tmp$signif))
}
return(corXY)
}
#### Function 1b - CorXY bootstrap#### #### Function 1b - CorXY bootstrap####
get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){
if(identical(trait.sel, "all")) {trait.sel <- 1:ncol(traits)} if(identical(trait.sel, "all")) {trait.sel <- 1:ncol(traits)}
...@@ -107,6 +73,44 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){ ...@@ -107,6 +73,44 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){
##### NOT ACTIVELY MANTAINED BELOW ####
#### Function 1 - CorXY ####
get.corXY <- function(comm, traits, trait.sel="all", stat=c("mantel", "RV", "procrustes")){
if(identical(trait.sel, "all")) {trait.sel <- 1:ncol(traits)}
ii <- trait.sel
lab.tmp <- paste(ii, collapse="_")
### delete potential missing species
if(any(colSums(comm)==0)){
empty <- which(colSums(comm)==0)
traits <- traits[-empty,]
comm <- comm[,-empty]
}
syn.out.tmp <- matrix.x(comm=comm, traits=traits[,ii,drop=F], scale=T)$matrix.X
W.beals <- as.data.frame(beals(comm, include=T, type=2))
corXY <- NULL
if("mantel" %in% stat){
W.beals.d <- dist(W.beals)
mantel.tmp <- mantel(W.beals.d, dist(syn.out.tmp[]))
corXY <- rbind(corXY,
data.frame(Trait.comb=lab.tmp, Test="Mantel", Coef=mantel.tmp$statistic, pvalue=mantel.tmp$signif))
}
if("RV" %in% stat){
RV.tmp <- RV.rtest(W.beals, as.data.frame(syn.out.tmp))
corXY <- rbind(corXY,
data.frame(Trait.comb=lab.tmp, Test="RV", Coef=RV.tmp$obs, pvalue=RV.tmp$pvalue))
}
if("procrustes" %in% stat){
prot.tmp <- protest(W.beals, syn.out.tmp)
corXY <- rbind(corXY,
data.frame(Trait.comb=lab.tmp, Test="Procrustes", Coef=prot.tmp$t0, pvalue=prot.tmp$signif))
}
return(corXY)
}
#### Function 2 - CorTE #### #### Function 2 - CorTE ####
......
species.path <- "_data/Mesobromion/species.out.10perc.cov.txt" species.path <- "_data/Mesobromion/species.out.10perc.cov.txt"
traits.path <- "_data/Mesobromion/traits.out.10perc.cov.txt" traits.path <- "_data/Mesobromion/traits.out.10perc.cov.txt"
output <- "_derived/Mesobromion/HIDDEN" output <- "_derived/Mesobromion/Cover/HIDDENtest"
myfunction <- "get.corXY.bootstrap" myfunction <- "get.corXY.bootstrap"
max.inter.t <- 2 max.inter.t <- 1
chunk.i <- NA chunk.i <- 1
nperm <- 5 nperm <- 49
ncores <- 8 ncores <- 1
chunkn <- 3*ncores chunkn <- 1
combinations <- "sequential" combinations <- "all"
start.round <- 1 start.round <- 1
relax.round <- 2 relax.round <- 1
source("01b_MesobromionCluster.R") source("01b_MesobromionCluster.R")
#Mesobromion(species.path, traits.path, output, myfunction, max.inter.t, chunkn, chunk.i, nperm)
Mesobromion(species.path, traits.path, output, myfunction, Mesobromion(species.path, traits.path, output, myfunction,
combinations, start.round, relax.round, max.inter.t, combinations, start.round, relax.round, max.inter.t,
chunkn, chunk.i, nperm, ncores) chunkn, chunk.i, nperm, ncores)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment