Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HIDDEN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sPlot
HIDDEN
Commits
bcc67857
Commit
bcc67857
authored
5 years ago
by
Francesco Sabatini
Browse files
Options
Downloads
Patches
Plain Diff
Improved data and trait pre-selection
parent
9bcd66e5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
01_Mesobromion.R
+50
-59
50 additions, 59 deletions
01_Mesobromion.R
with
50 additions
and
59 deletions
01_Mesobromion.R
+
50
−
59
View file @
bcc67857
...
@@ -4,9 +4,11 @@ library(foreign)
...
@@ -4,9 +4,11 @@ library(foreign)
source
(
"99_HIDDEN_functions.R"
)
source
(
"99_HIDDEN_functions.R"
)
#### 1. traits data
#### 1. traits data
####
traits0
<-
read_delim
(
"_data/Mesobromion/traits3.txt"
,
delim
=
";"
,
col_names
=
T
,
locale
=
locale
(
encoding
=
'latin1'
))
%>%
traits0
<-
read_delim
(
"_data/Mesobromion/traits3.txt"
,
delim
=
";"
,
col_names
=
T
,
locale
=
locale
(
encoding
=
'latin1'
))
%>%
dplyr
::
select
(
-
c
(
"PR_STAT_Indigen"
,
"PR_STAT_Neophyt"
,
"PR_STAT_Archaeophyt"
,
"URBAN_urbanophob"
,
"URBAN_maessig_urbanophob"
,
"URBAN_urbanoneutral"
,
"URBAN_maessig_urbanophil"
,
"URBAN_urbanophil"
,
"WUH_von"
,
"WUH_bis"
,
"ARL_c_I_von"
,
"ARL_c_I_bis"
))
%>%
mutate
(
species0
=
species
)
%>%
mutate
(
species0
=
species
)
%>%
rowwise
()
%>%
rowwise
()
%>%
# quick and dirty clean up names
# quick and dirty clean up names
...
@@ -14,18 +16,22 @@ traits0 <- read_delim("_data/Mesobromion/traits3.txt", delim =";", col_names = T
...
@@ -14,18 +16,22 @@ traits0 <- read_delim("_data/Mesobromion/traits3.txt", delim =";", col_names = T
mutate
(
species
=
gsub
(
pattern
=
" agg | x | spec$| agg$| s | Sec | "
,
replacement
=
" "
,
x
=
species
))
%>%
mutate
(
species
=
gsub
(
pattern
=
" agg | x | spec$| agg$| s | Sec | "
,
replacement
=
" "
,
x
=
species
))
%>%
mutate
(
species
=
gsub
(
pattern
=
" $"
,
replacement
=
""
,
x
=
species
))
%>%
mutate
(
species
=
gsub
(
pattern
=
" $"
,
replacement
=
""
,
x
=
species
))
%>%
mutate
(
species
=
ifelse
(
is.na
(
word
(
species
,
1
,
2
)),
species
,
word
(
species
,
1
,
2
)))
mutate
(
species
=
ifelse
(
is.na
(
word
(
species
,
1
,
2
)),
species
,
word
(
species
,
1
,
2
)))
str
(
traits0
)
#907 obs. of 85 variables:
dim
(
traits0
)
#907 obs. of 75 variables:
#keep only traits with >=88 completeness
#keep only traits with >=88 completeness
traits0
<-
traits0
%>%
traits0
<-
traits0
%>%
dplyr
::
select_if
(
~
mean
(
!
is.na
(
.
))
>=
0.88
)
#907
obs 79 variables
dplyr
::
select_if
(
~
mean
(
!
is.na
(
.
))
>=
0.88
)
#
907
x 67
## Import traits from TRY and match to species
## Import traits from TRY and match to species
load
(
"/data/sPlot2.0/TRY.all.mean.sd.3.by.genus.species.tree.Rdata"
)
load
(
"/data/sPlot2.0/TRY.all.mean.sd.3.by.genus.species.tree.Rdata"
)
alltry
<-
TRY.all.mean.sd.3.by.genus.species.tree
%>%
alltry
<-
TRY.all.mean.sd.3.by.genus.species.tree
%>%
dplyr
::
select
(
!
ends_with
(
".sd"
))
%>%
dplyr
::
select
(
!
ends_with
(
".sd"
))
%>%
dplyr
::
select
(
StandSpeciesName
,
LeafArea.mean
:
Wood.vessel.length.mean
)
dplyr
::
select
(
StandSpeciesName
,
LeafArea.mean
:
Wood.vessel.length.mean
)
%>%
dplyr
::
select
(
-
Wood.vessel.length.mean
,
-
StemDens.mean
,
-
Stem.cond.dens.mean
)
%>%
rename_all
(
.funs
=~
gsub
(
pattern
=
".mean$"
,
replacement
=
""
,
x
=
.
))
traits
<-
traits0
%>%
traits
<-
traits0
%>%
ungroup
()
%>%
ungroup
()
%>%
...
@@ -33,18 +39,18 @@ traits <- traits0 %>%
...
@@ -33,18 +39,18 @@ traits <- traits0 %>%
left_join
(
alltry
%>%
left_join
(
alltry
%>%
rename
(
species
=
StandSpeciesName
),
rename
(
species
=
StandSpeciesName
),
by
=
"species"
)
%>%
by
=
"species"
)
%>%
filter
(
!
is.na
(
LeafArea
.mean
))
filter
(
!
is.na
(
LeafArea
))
dim
(
traits
)
#[1] 805
97
dim
(
traits
)
#[1] 805
2
##### 2. Header Data
##### 2. Header Data
####
env0
<-
read_delim
(
"_data/Mesobromion/GVRD_MES2_site.csv"
,
delim
=
","
)
env0
<-
read_delim
(
"_data/Mesobromion/GVRD_MES2_site.csv"
,
delim
=
","
)
str
(
env0
)
#6868 obs. of 6 variables:
str
(
env0
)
#6868 obs. of 6 variables:
set.seed
(
1984
)
set.seed
(
1984
)
header
<-
"/data/sPlot/users/Francesco/Project_11/Germany/_data/tvhabita.dbf"
header
<-
"/data/sPlot/users/Francesco/Project_11/Germany/_data/tvhabita.dbf"
env
.all
<-
env0
%>%
env
<-
env0
%>%
left_join
(
foreign
::
read.dbf
(
header
)
%>%
left_join
(
foreign
::
read.dbf
(
header
)
%>%
as.data.frame
()
%>%
as.data.frame
()
%>%
dplyr
::
select
(
RELEVE_NR
,
LAT
,
LON
),
dplyr
::
select
(
RELEVE_NR
,
LAT
,
LON
),
...
@@ -52,13 +58,9 @@ env.all <- env0 %>%
...
@@ -52,13 +58,9 @@ env.all <- env0 %>%
filter
(
!
is.na
(
LAT
))
%>%
filter
(
!
is.na
(
LAT
))
%>%
filter
(
!
(
LAT
==
0
|
LON
==
0
))
filter
(
!
(
LAT
==
0
|
LON
==
0
))
env
<-
env.all
#env <- env.all %>%
# sample_frac(0.1) #Take 10% subset
###
2
. Import species data
###
3
. Import species data
####
# columns in species correspond to those in env
# columns in species correspond to those in env
# there is no PlotObservationID (yet)
# there is no PlotObservationID (yet)
species0
<-
read.table
(
"_data/Mesobromion/GVRD_Mes2_veg1.csv"
,
sep
=
","
,
header
=
T
)
species0
<-
read.table
(
"_data/Mesobromion/GVRD_Mes2_veg1.csv"
,
sep
=
","
,
header
=
T
)
...
@@ -71,10 +73,12 @@ species <- env %>%
...
@@ -71,10 +73,12 @@ species <- env %>%
left_join
(
species0
%>%
left_join
(
species0
%>%
mutate
(
RELEVE_NR
=
env0
$
RELEVE_NR
),
mutate
(
RELEVE_NR
=
env0
$
RELEVE_NR
),
by
=
"RELEVE_NR"
)
%>%
by
=
"RELEVE_NR"
)
%>%
column_to_rownames
(
"RELEVE_NR"
)
# %>%
column_to_rownames
(
"RELEVE_NR"
)
%>%
## delete species not appearing in any plot
dplyr
::
select
(
colnames
(
.
)[
which
(
colSums
(
.
)
!=
0
)])
#dplyr::select(traits$species0)
#dplyr::select(traits$species0)
dim
(
species
)
# [1] 5810
907
dim
(
species
)
# [1] 5810
881
releve08trait
<-
species
%>%
releve08trait
<-
species
%>%
rownames_to_column
(
"RELEVE_NR"
)
%>%
rownames_to_column
(
"RELEVE_NR"
)
%>%
...
@@ -86,17 +90,17 @@ releve08trait <- species %>%
...
@@ -86,17 +90,17 @@ releve08trait <- species %>%
## attach traits
## attach traits
left_join
(
traits
%>%
left_join
(
traits
%>%
dplyr
::
select
(
-
species
),
by
=
"species0"
)
%>%
dplyr
::
select
(
-
species
),
by
=
"species0"
)
%>%
mutate_at
(
.vars
=
vars
(
PR_STAT_Indigen
:
Wood.vessel.length.mean
),
mutate_at
(
.vars
=
vars
(
LEB_F_Makrophanerophyt
:
Disp.unit.leng
),
.funs
=
list
(
~
if_else
(
is.na
(
.
),
0
,
1
)
*
pres
))
%>%
.funs
=
list
(
~
if_else
(
is.na
(
.
),
0
,
1
)
*
pres
))
%>%
group_by
(
RELEVE_NR
)
%>%
group_by
(
RELEVE_NR
)
%>%
summarize_at
(
.vars
=
vars
(
PR_STAT_Indigen
:
Wood.vessel.length.mean
),
summarize_at
(
.vars
=
vars
(
LEB_F_Makrophanerophyt
:
Disp.unit.leng
),
.funs
=
list
(
~
mean
(
.
)))
%>%
.funs
=
list
(
~
mean
(
.
)))
%>%
dplyr
::
select
(
RELEVE_NR
,
order
(
colnames
(
.
)))
%>%
dplyr
::
select
(
RELEVE_NR
,
order
(
colnames
(
.
)))
%>%
reshape2
::
melt
(
id.vars
=
"RELEVE_NR"
,
value.name
=
"trait.coverage"
)
%>%
reshape2
::
melt
(
id.vars
=
"RELEVE_NR"
,
value.name
=
"trait.coverage"
)
%>%
group_by
(
RELEVE_NR
)
%>%
group_by
(
RELEVE_NR
)
%>%
summarize
(
ntraits08
=
sum
(
trait.coverage
>=
0.8
))
%>%
summarize
(
ntraits08
=
mean
(
trait.coverage
>=
0.8
))
%>%
#select only those
trait
s where
at least 75 traits
have a coverage of >0.8
of the specie
s
#select only those
releve
s where
we
have a coverage of >0.8
for all trait
s
#
filter(ntraits08==
95
) %>%
dim()
filter
(
ntraits08
==
1
)
%>%
pull
(
RELEVE_NR
)
pull
(
RELEVE_NR
)
set.seed
(
1984
)
set.seed
(
1984
)
...
@@ -105,9 +109,8 @@ species <- species %>%
...
@@ -105,9 +109,8 @@ species <- species %>%
rownames_to_column
(
"RELEVE_NR"
)
%>%
rownames_to_column
(
"RELEVE_NR"
)
%>%
filter
(
RELEVE_NR
%in%
releve08trait.samp
)
%>%
filter
(
RELEVE_NR
%in%
releve08trait.samp
)
%>%
column_to_rownames
(
"RELEVE_NR"
)
%>%
column_to_rownames
(
"RELEVE_NR"
)
%>%
dplyr
::
select
(
traits
%>%
pull
(
species0
))
%>%
as.tbl
()
%>%
#select only species occurring it at least one plot
dplyr
::
select
(
one_of
(
traits
$
species0
))
dplyr
::
select
(
names
(
which
(
colSums
(
.
)
!=
0
))
)
env
<-
env
%>%
env
<-
env
%>%
...
@@ -118,9 +121,9 @@ traits <- traits %>%
...
@@ -118,9 +121,9 @@ traits <- traits %>%
dplyr
::
select
(
species0
,
everything
())
%>%
dplyr
::
select
(
species0
,
everything
())
%>%
filter
(
species0
%in%
colnames
(
species
))
filter
(
species0
%in%
colnames
(
species
))
dim
(
species
)
#5
81 508
dim
(
species
)
#5
58 783
dim
(
traits
)
#
508 96
dim
(
traits
)
#
783 81
dim
(
env
)
#58
1
8
dim
(
env
)
#5
5
8 8
## Select only plots where >90% of species have trait info [TRY]
## Select only plots where >90% of species have trait info [TRY]
...
@@ -149,54 +152,42 @@ write_delim(species, path="_data/Mesobromion/species.out.10perc.txt", delim="\t"
...
@@ -149,54 +152,42 @@ write_delim(species, path="_data/Mesobromion/species.out.10perc.txt", delim="\t"
write_delim
(
traits
,
path
=
"_data/Mesobromion/traits.out.10perc.txt"
,
delim
=
"\t"
)
write_delim
(
traits
,
path
=
"_data/Mesobromion/traits.out.10perc.txt"
,
delim
=
"\t"
)
#### CORRELATION BETWEEN FUZZY WEIGHTED AND BEALS MATRICES #### #### ####
#### WAS RUN IN THE CLUSTER WITH THE SCRIPT 01b_MesobromionCluster.R
#### ## Reimport data ####
############################
#
############################
## calculate corr between species composition matrix and traits
## calculate corr between species composition matrix and traits
species
<-
read_delim
(
"_data/Mesobromion/species.out.10perc.txt"
,
delim
=
"\t"
)
species
<-
read_delim
(
"_data/Mesobromion/species.out.10perc.txt"
,
delim
=
"\t"
)
traits
<-
read_delim
(
"_data/Mesobromion/traits.out.10perc.txt"
,
delim
=
"\t"
)
traits
<-
read_delim
(
"_data/Mesobromion/traits.out.10perc.txt"
,
delim
=
"\t"
)
traits
<-
traits
%>%
traits
<-
traits
%>%
column_to_rownames
(
"species0"
)
%>%
column_to_rownames
(
"species0"
)
# %>%
rename_all
(
.funs
=~
gsub
(
pattern
=
".mean$"
,
replacement
=
""
,
x
=
.
))
# %>%
#dplyr::select(PlantHeight, LeafC.perdrymass, LeafN, StemDens, Stem.cond.dens, Seed.num.rep.unit, SLA)
#dplyr::select(PlantHeight, LeafC.perdrymass, LeafN, StemDens, Stem.cond.dens, Seed.num.rep.unit, SLA)
## create list of indices for each combination of traits up to a max number of interactions
n.traits
<-
ncol
(
traits
)
max.inter.t
<-
1
allcomb.t
<-
NULL
for
(
n.inter
in
1
:
max.inter.t
){
allcomb.t
<-
c
(
allcomb.t
,
combn
(
1
:
n.traits
,
n.inter
,
simplify
=
F
))
}
##Run on observed data
#Define get.corXY first!!
#### ## Import output ####
require
(
parallel
)
require
(
doParallel
)
cl
<-
makeForkCluster
(
8
,
outfile
=
""
)
registerDoParallel
(
cl
)
myfilelist
<-
list.files
(
path
=
"_derived/Mesobromion/"
,
pattern
=
"HIDDEN_[0-9]+.RData"
,
full.names
=
T
)
corXY
<-
NULL
corXY
<-
NULL
corXY
<-
foreach
(
i
=
1
:
length
(
allcomb.t
),
.packages
=
c
(
'SYNCSA'
,
"vegan"
,
"ade4"
,
"tidyverse"
),
.combine
=
rbind
)
%do%
{
corXY
.perm
<-
NULL
#
for(
i
in
1:length(allcomb.t)
){
for
(
ff
in
myfilelist
){
tt
<-
unlist
(
allcomb.t
[
i
])
index
<-
as.numeric
(
regmatches
(
ff
,
gregexpr
(
"[[:digit:]]+"
,
ff
))[[
1
]
])
corXY
<-
get.corXY
(
comm
=
species
,
trait
=
traits
,
trait.sel
=
tt
,
stat
=
"RV"
)
load
(
ff
)
print
(
i
)
corXY
<-
rbind
(
corXY
,
cor.obs
)
save
(
corXY
,
file
=
paste0
(
"_data/Mesobromion/corXY/corXY_"
,
i
,
".RData"
)
)
corXY.perm
<-
rbind
(
corXY.perm
,
cor.perm
)
return
(
corXY
)
print
(
index
)
}
}
stopCluster
(
cl
)
corXY
%>%
arrange
(
Test
,
desc
(
Coef
))
save
(
corXY
,
file
=
"_data/Mesobromion/corXY/corXY.RData"
)
aa
<-
matrix.x
(
comm
=
species
,
trait
=
traits
,
trait.sel
=
tt
,
stat
=
"RV"
)
corXY
%>%
arrange
(
Test
,
desc
(
Coef
))
aa
<-
data.frame
(
Trait.comb
=
paste0
(
"t"
,
1
:
95
),
trait.name
=
colnames
(
traits
)[
-
which
(
colnames
(
traits
)
%in%
c
(
"species"
,
"species0"
))])
bb
<-
get.SES
(
obs.df
=
corXY
,
perm.df
=
corXY.perm
,
stat
=
"RV"
)
%>%
left_join
(
aa
,
by
=
"Trait.comb"
)
%>%
arrange
(
desc
(
SES.np
))
print
(
bb
,
n
=
20
)
#### Map of plots
#### Map of plots
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment