#Ancillary function to change species names to lower case
firstup <- function(x) {
substr(x, 1, 1) <- toupper(substr(x, 1, 1))
x
}
try.species <- try.species %>%
mutate(Species=tolower(Species)) %>%
mutate(Species=firstup(Species))
try.allinfo <- try.allinfo %>%
mutate(Species=tolower(Species)) %>%
mutate(Species=firstup(Species))
#calculate statistics of data from TRY
#calculate statistics of data from TRY
n.indiv <- try.species %>%
n.indiv <- try.species %>%
...
@@ -66,10 +53,26 @@ n.indiv <- try.species %>%
...
@@ -66,10 +53,26 @@ n.indiv <- try.species %>%
summarize(n=n()) %>%
summarize(n=n()) %>%
pull(n)
pull(n)
```
```
There are `r nrow(try.species)` individual observations from `r nrow(try.species %>% distinct(Species))` distinct species in `r nrow(try.species %>% distinct(Genus))` distinct genera.
There are `r nrow(try.species)` individual observations from `r nrow(try.species %>% distinct(Species))` distinct (unresolved) species in `r nrow(try.species %>% distinct(Genus))` distinct (unresolved) genera.
\newline \newline
\newline \newline
```{r deprecated, echo=F, eval=F}
# #Ancillary function to change species names to lower case
After attaching resolved names, TRY data contains information on `r try.species.names %>% distinct(Name_short) %>% nrow()`.
After attaching resolved names, TRY data contains information on `r try.species.names %>% distinct(Name_short) %>% nrow()` species.
\newline
\newline \newline
Check for how many of the species in sPlot, trait information is available in TRY.
Check for how many of the species in sPlot, trait information is available in TRY.
```{r}
```{r}
sPlot.species <- DT2 %>%
sPlot.species <- DT2 %>%
...
@@ -91,9 +94,9 @@ sPlot.species <- DT2 %>%
...
@@ -91,9 +94,9 @@ sPlot.species <- DT2 %>%
sPlot.in.TRY <- sPlot.species %>%
sPlot.in.TRY <- sPlot.species %>%
filter(species %in% (try.species.names %>%
filter(species %in% (try.species.names %>%
distinct(Name_short) %>%
distinct(Name_short) %>%
pull(Name_short))) %>%
pull(Name_short)))
```
```
Out of the `r nrow(sPlot.species)` standardizes species names in sPlot 3.0, `r nrow(sPlot.in.TRY)` (`r round(nrow(sPlot.in.TRY)/nrow(sPlot.species)*100,1)`%) also occur in TRY 5.0.
Out of the `r nrow(sPlot.species)` standardizes species names in sPlot 3.0, `r nrow(sPlot.in.TRY)` (`r round(nrow(sPlot.in.TRY)/nrow(sPlot.species)*100,1)`%) also occur in TRY 5.0. This number does not account for matches at the genus level.
Use trait legend to change naming of `try.individuals0` data.frame of traits
```{r}
#create string to rename traits
col.to <- trait.legend %>%
filter(available==T) %>%
pull(short)
col.from <- trait.legend %>%
filter(available==T) %>%
mutate(traitcode=paste0("X", traitcode)) %>%
pull(traitcode)
try.individuals <- try.individuals0 %>%
rename_at(col.from, .funs=function(x) col.to)
```
There are some traits with unexpected negative entries:
Check traits at the individual level. There are some traits with unexpected negative entries:
```{r}
```{r}
try.species.names %>%
try.species.names %>%
dplyr::select(Species) %>%
dplyr::select(Name_short) %>%
bind_cols(try.individuals0 %>%
bind_cols(try.individuals %>%
rename_at(col.from, .funs=function(x) col.to) %>%
dplyr::select(-X1)) %>%
dplyr::select(-X1)) %>%
gather(variable, value, -Species) %>%
gather(variable, value, -Name_short) %>%
filter(value<0) %>%
filter(value<0) %>%
group_by(variable) %>%
group_by(variable) %>%
summarize(n=n())
summarize(n=n())
```
```
I asked Jens Kattget for clarifications.
According to Jens Kattge, the entries for `Leaf.delta.15N` are legitimate, while in the other cases, it may be due to bad predictions. He suggested to delete these negative records.
```{r}
toexclude <- try.individuals %>%
gather(variable, value, -X1) %>%
filter(variable != "Leaf.delta.15N") %>%
filter(value<0) %>%
pull(X1)
try.individuals <- try.species.names %>%
dplyr::select(Name_short) %>%
bind_cols(try.individuals) %>%
filter(!X1 %in% toexclude) %>%
dplyr::select(-X1)
```
This results in the exclusion of `r length(toexclude)` individuals. In this way the total number of species included in TRY reduces to `r try.individuals %>% distinct(Name_short) %>% nrow()`
## Calculate species and genus level trait means and sd
## Calculate species and genus level trait means and sd
```{r}
```{r}
#create string to rename traits
## Calculate species level trait means and sd.
col.to <- trait.legend %>%
filter(available==T) %>%
pull(short)
col.from <- trait.legend %>%
filter(available==T) %>%
mutate(traitcode=paste0("X", traitcode)) %>%
pull(traitcode)
## Calculate species level trait means and sd.
try.species.means <- try.individuals %>%
try.species.means <- try.species.names %>%
group_by(Name_short) %>%
dplyr::select(Species) %>%
#Add a field to indivate the number of observation per taxon
The average number of observations per species and genus is `r round(mean(try.species.means$n),1)` and `r round(mean(try.genus.means$n),1)`, respectively. As many as `r sum(try.species.means$n==1)` species have only one observation (`r sum(try.genus.means$n==1)` at the genus level).
The average number of observations per species and genus is `r round(mean(try.species.means$n),1)` and `r round(mean(try.genus.means$n),1)`, respectively. As many as `r sum(try.species.means$n==1)` species have only one observation (`r sum(try.genus.means$n==1)` at the genus level).
## Match taxa based on species, if available, or Genus (when rank_correct==Genus)
## Match taxa based on species, if available, or Genus
Combined the trait means based on species and genera into a single object, and check how many of these taxa match to the (resolved) species names in `DT2`.
Calculate CWMs and CWV, as well as plot coverage statistics (proportion of total cover for which trait info exist, and proportion of species for which we have trait info). To avoid misleading result, CWM is calculated ONLY for plots for which we have some abundance information. All plots where `Ab_scale`=="pa" in **ANY** of the layers are therefore excluded.
Calculate CWMs and CWV, as well as plot coverage statistics (proportion of total cover for which trait info exist, and proportion of species for which we have trait info). To avoid misleading results, CWM is calculated ONLY for plots for which we have some abundance information. All plots where `Ab_scale`=="pa" in **ANY** of the layers are therefore excluded.
```{r, cache=T, cache.lazy=F}
```{r, cache=T, cache.lazy=F, warning=F}
# Tag plots where at least one layer only has p\a information
# Tag plots where at least one layer has only p\a information
any_pa <- DT2 %>%
any_pa <- DT2 %>%
distinct(PlotObservationID, Ab_scale) %>%
distinct(PlotObservationID, Ab_scale) %>%
group_by(PlotObservationID) %>%
group_by(PlotObservationID) %>%
...
@@ -279,7 +298,7 @@ any_pa <- DT2 %>%
...
@@ -279,7 +298,7 @@ any_pa <- DT2 %>%
length(any_pa)
length(any_pa)
# Exclude plots above and merge species data table with traits
# Exclude plots above and merge species data table with traits