---
title: "Quantitative ethnobotany analysis with ethnobotanyR"
author: "Cory Whitney, University of Bonn"
output: rmarkdown::html_vignette
bibliography: [references/packages.bib, references/ethnobotanyR.bib]
vignette: >
  %\VignetteIndexEntry{Quantitative ethnobotany analysis with ethnobotanyR}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

<!-- Spelling -->
<!-- The ABC √ option (upper right on the Rmarkdown console)-->

<!-- Grammar -->
<!-- devtools::install_github("ropenscilabs/gramr") -->
<!-- gramr::run_grammar_checker("vignettes/ethnobotanyr_vignette.rmd") -->

<!-- Print pdf version -->
<!-- rmarkdown::render("vignettes/ethnobotanyr_vignette.Rmd", output_format = "pdf_document") -->

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

load("ethnobotanydata.rda")
library(bnlearn)
library(broom)
library(causaleffect)
library(circlize)
library(cowplot)
library(dplyr)
library(ethnobotanyR)
library(ggalluvial)
library(ggplot2)
library(ggridges)
library(magrittr)
library(pbapply)
library(purrr)
library(stringr)
library(tibble)
library(tidyr)
library(tidyselect)
library(vegan)
# install.packages(c('bnlearn','broom','causaleffect','circlize','cowplot','dplyr','ethnobotanyR','ggalluvial','ggplot2','ggridges','magrittr','pbapply','purrr','stringr','tibble','tidyr','tidyselect','vegan'))

# in case of rendering issues render with 
# rmarkdown::render('vignettes/ethnobotanyr_vignette.Rmd', output_file='ethnobotanyr_vignette.html', output_dir='vignettes')

knitr::write_bib(c(.packages(), 
                  "bnlearn",
                  "broom",
                  "causaleffect",
                  "circlize",
                  "cowplot",
                  "dplyr",
                  "ethnobotanyR",
                  "ggalluvial",
                  "ggplot2",
                  "ggridges",
                  "knitr",
                  "magrittr",
                  "pbapply",
                  "purrr",
                  "stringr",
                  "tibble",
                  "tidyr",
                  "tidyselect",
                  "vegan" ), file = "references/packages.bib")

```

<img src="ethnobotanyR.png" alt="ethnobotanyR logo" align="right" width = "25%" height="25%" style="background:none; border:none; box-shadow:none;"/>

Please remember to cite the `ethnobotanyR` package if you use it in your publications. Use `citation("ethnobotanyR")` to get a citation for the latest version.  

```{r cite_ethnobotanyR, comment=NA, echo=FALSE}
citation("ethnobotanyR")
```

## A Critical Perspective on Ethnobotany Indices

Quantitative ethnobotany is the study of the use and importance of plants in human cultures, using statistical and analytical methods to quantify and interpret data. This approach has emerged as a key tool for understanding the cultural and ecological significance of plant species, and for evaluating the impact of human activities on plant communities and ecosystems.

While widely used in the literature, traditional ethnobotany indices have significant limitations that researchers should consider:

- **Oversimplification**: Complex cultural relationships reduced to single numbers
- **Context stripping**: Remove cultural, ecological, and historical context
- **Methodological issues**: Sensitive to sampling design and interview methods
- **Theoretical concerns**: Often lack strong theoretical foundations

**When to use these indices:**
- Preliminary exploratory analysis
- Comparison with existing literature that uses similar methods
- As input variables for more sophisticated models (not as final results)

**When to avoid these indices:**
- As primary evidence for policy decisions
- For cross-cultural comparisons without careful validation
- As standalone measures of "importance"

The field of ethnobotany has a long history, with roots dating back to the early 20th century when researchers began to systematically study the relationships between humans and plants. In recent decades, advances in statistical and computational techniques have enabled researchers to more rigorously and systematically analyze and interpret ethnobotanical data, leading to a greater understanding of the complex and diverse ways in which plants are used and valued in different cultural and ecological contexts.

Today, quantitative ethnobotany is an interdisciplinary field that draws on a range of methods and approaches from the natural and social sciences, including anthropology, sociology, biology, and ecology. It is a rapidly growing field that is making significant contributions to our understanding of human-plant relationships, and to the conservation and management of plant biodiversity.

This manual offers an overview of the basic functions of the `ethnobotanyR` package for generating figures and performing some very basic quantitative ethnobotany analysis. It offers a general overview and some arguments for and against the use of indices and offers some guidance toward other options for quantitative ethnobotany analysis. It also offers some handy and useful tools for exploratory analysis of ethnobotany data. All analyses are done using the `ethnobotanyR` package [@R-ethnobotanyR] in the R programming language [@R-base]. 

## using the `ethnobotanyR` package

The `ethnobotanyR` package offers quantitative tools to assess the cultural significance of plant species based on informant consensus [@R-ethnobotanyR] ^[Please remember to cite this package if you use it in your publications. Use the R command `citation("ethnobotanyR")` to get the citation to the your loaded version of the package.]. The package closely follows two papers, one on cultural importance indices [@tardioCulturalImportanceIndices2008] and another on agrobiodiversity valuation [@whitneyEthnobotanyAgrobiodiversityValuation2018]. The goal is to provide an easy-to-use platform for ethnobotanists to perform quantitative ethnobotany assessments. Users are highly encouraged to familiarize themselves with ethnobotany theory [@albuquerqueEthnobotanyOneConcept2010] and social ecological theory [@albuquerqueSocialEcologicalTheoryMaximization2019]. An overview of this theoretical background will be helpful in understanding approaches in ethnobotany and formulating useful research questions.

An example data set called `ethnobotanydata` is provided to show how standard quantitative ethnobotany data should be formatted to interface with the `ethnobotanyR` package. This is an ethnobotany data set including one column of `r length(unique(ethnobotanydata$informant))` knowledge holder identifiers `informant` and one of `r length(unique(ethnobotanydata$sp_name))` species names `sp_name`. The rest of the columns are the identified ethnobotany use categories. The data in the use categories is populated with counts of uses per person (should be 0 or 1 values) ^[The example `ethnobotanydata` is included with the `ethnobotanyR` package but can also be downloaded from GitHub <https://github.com/CWWhitney/ethnobotanyR/tree/master/data>.].

```{r, echo= FALSE}
knitr::kable(head(ethnobotanydata), digits = 2, caption = "First six rows of the example ethnobotany data included with ethnobotanyR")
```

Many of the functions in `ethnobotanyR` make use of `select()` and `filter_all()` functions of the `dplyr` package [@R-dplyr] and pipe functions `%>%` from the `magrittr` package [@R-magrittr]. The intention is that these should be easy to understand and use, and that they should allow users the chance to pull the code for these functions and change anything they see fit.

## Working with figures

Figures can help to visually represent the main ideas or key results of ethnobotany work. Here we walk through a few of the functions within the `ethnobotanyR` package for generating figures [@R-ethnobotanyR]. 

## Chord diagrams with `circlize`

The following chord plots are made using functions from the `circlize` package [@R-circlize]. An example of the application of chord plots in ethnobotany is described in a study on agrobiodiversity in Uganda [@whitneyEthnobotanyAgrobiodiversityValuation2018]. 

The `ethnoChord()` function creates a chord diagram of ethnobotany uses and species.

```{r Chord_sp, fig.width=7, fig.height=7}
Chord_sp <- ethnobotanyR::ethnoChord(ethnobotanydata, by = "sp_name")
```

The `ethnoChord()` function can also be used to create a chord diagram of ethnobotany uses and informants.

```{r, fig.width=7, fig.height=7}
Chord_informant <- ethnobotanyR::ethnoChord(ethnobotanydata, by = "informant")
```

For an example of the application of a chord diagram in ethnobotany research see @tabutiPrioritySpeciesManagement2022 on values and challenges for woody species in Uganda and @monUsesFigFicus2020 on fig species use in Myanmar.

## Flow diagrams with `ggalluvial`

The `ethno_alluvial()` function uses the `ggplot2` extension `ggalluvial` to make flow diagrams. This may be a useful way to visualize frequency distributions across uses, experts and use categories. 

```{r, fig.width=7, fig.height=7}
ethnobotanyR::ethno_alluvial(ethnobotanydata)
```

Generate the same plot with labels on the strata and without the legend.

```{r, fig.width=7, fig.height=7}

# correct internal assignment for stat = "stratum" 
  StatStratum <- ggalluvial::StatStratum

ethnobotanyR::ethno_alluvial(ethnobotanydata, alpha = 0.2) + 
  ggplot2::theme(legend.position = "none") +  
             ggplot2::geom_label(stat = "stratum", 
                      ggplot2::aes(label = ggplot2::after_stat(stratum)))

```

For an exaple of the alluvial plot in ethnobotany paper see @monUsesFigFicus2020 on the traditional knowledge of edible fig tree species in Myanmar.

## `ethnobotanyR` indices functions

Ethnobotany indices are numerical measures that are used to quantify the importance of plant species in different cultural or ecological contexts. Some common ethnobotany indices are included here. These indices are often used to analyze ethnobotanical data and to compare the relative importance of different plant species within a particular culture or ecosystem. 

The standard quantitative ethnobotany indices are probably too narrow a tool for a proper assessment of human and ecological interactions of interest. Still, they can be a useful entry way into understanding some aspects of human populations and how they interact with nature. The steps required to calculate these indices offer a way to quantify intangible factors of how human communities interact with the world. They can come in handy as additive pieces for more holistic assessments and analyses. 

### Use Report (UR) per species

The use report `URs()` is the most basic ethnobotany calculation. The function calculates the reported uses for each species in the data set. 

\begin{equation}
UR_{s} = \sum_{u=u_1}^{^uNC} \sum_{i=i_1}^{^iN} UR_{ui}
\end{equation}

`URs()` calculates the total uses for the species by all informants (from $i_1$ to $^iN$) within each use-category for that species $(s)$. It is a count of the number of informants who mention each use-category $NC$ for the species and the sum of all uses in each use-category (from $u_1$ to $^uNC$) [see @pranceQuantitativeEthnobotanyCase1987].

```{r URs}
ethnobotanyR::URs(ethnobotanydata)
```

The `URsum()` function calculates the sum of all ethnobotany use reports (UR) for all species in the data set [see @pranceQuantitativeEthnobotanyCase1987].

```{r URsum}
ethnobotanyR::URsum(ethnobotanydata)
```

### Cultural Importance (CI) index

The `CIs()` function calculates the cultural importance index (CI) for each species in the data set.

\begin{equation}
CI_{s} = \sum_{u=u_1}^{^uNC} \sum_{i=i_1}^{^iN} UR_{ui/N}.
\end{equation}

`CIs()` is essentially `URs()` divided by the number of informants to account for the diversity of uses for the species [see @tardioCulturalImportanceIndices2008].

```{r CIs}
ethnobotanyR::CIs(ethnobotanydata)
```

### Frequency of Citation (FC) per species

The `FCs()` function calculates the frequency of citation (FC) for each species in the data set. 

\begin{equation}
FC_s = \sum_{i=i_1}^{^iN}{UR_i}
\end{equation}

`FCs()` is the sum of informants that cite a use for the species [see @pranceQuantitativeEthnobotanyCase1987].

```{r FCs}
ethnobotanyR::FCs(ethnobotanydata)
```

### Number of Uses (NU) per species

The `NUs()` function calculates the number of uses (NU) for each species in the data set.

\begin{equation}
NU_s = \sum_{u=u_1}^{^uNC}
\end{equation}

$NC$ are the number of use categories. `NUs()` is the sum of all categories for which a species is considered useful [see @pranceQuantitativeEthnobotanyCase1987].

```{r NUs}
ethnobotanyR::NUs(ethnobotanydata)
```

### Relative Frequency of Citation (RFC) index

The `RFCs()` function calculates the relative frequency of citation (RFC) for each species in the data set.

\begin{equation}
RFC_s = \frac{FC_s}{N} = \frac{\sum_{i=i_1}^{^iN} UR_i}{N}
\end{equation}

$FC_s$ is the frequency of citation for each species $s$, $UR_i$ are the use reports for all informants $i$ and $N$ is the total number of informants interviewed in the survey [see @tardioCulturalImportanceIndices2008].

```{r RFCs}
ethnobotanyR::RFCs(ethnobotanydata)
```

### Relative Importance (RI) index

The `RIs()` function calculates the relative importance index (RI) for each species in the data set.

\begin{equation}
RI_s = \frac{RFC_{s(max)}+RNU_{s(max)}}{2} 
\end{equation}

$RFC_{s(max)}$ is the relative frequency of citation for the species $s$ over the maximum, $RNU_{s(max)}$ is the relative number of uses for $s$ over the maximum [see @tardioCulturalImportanceIndices2008].

```{r RIs}
ethnobotanyR::RIs(ethnobotanydata)
```

### Use Value (UV) index

The `UVs()` function calculates the use value (UV) index for each species in the data set.

\begin{equation}
UV_{s} =  \sum_{i=i_1}^{^iN} \sum_{u=u_1}^{^uNC} UR_{ui/N} 
\end{equation}

`UVs()` is essentially the same as `CIs()` except that it starts with the sum of UR groupings by informants. $U_i$ is the number of different uses mentioned by each informant $i$ and $N$ is the total number of informants interviewed in the survey [see @tardioCulturalImportanceIndices2008]. 

```{r UVs}
ethnobotanyR::UVs(ethnobotanydata)
```

The `simple_UVs()` function calculates the simplified use value (UV) index for each species in the data set. 

\begin{equation}
UV_{s} = \sum U_i/N
\end{equation}

$U_i$ is the number of different uses mentioned by each informant $i$ and $N$ is the total number of informants interviewed in the survey [see @albuquerqueEvaluatingTwoQuantitative2006].

### Cultural Value (CVe) for ethnospecies 

The `CVe()` function calculates the cultural value (CVe) for ethnospecies. The index is one of three proposed for assessing the cultural, practical and economic dimensions (ethno) species importance. Reyes-Garcia et al. (2006) suggest several more indices but $CV_e$ is the most commonly used from that study [@reyes-garciaCulturalPracticalEconomic2006].

\begin{equation}
CV_{e} = {Uc_{e}}  \cdot{IC_{e}}  \cdot \sum {IUc_{e}}
\end{equation}

Where $UC_e$ is the number of uses reported for ethnospecies $e$ divided by all potential uses of an ethnospecies considered in the study. $Ic_e$ expresses the number of informants who listed the ethnospecies $e$ as useful divided by the total number of informants. $IUc_e$ expresses the number of informants who mentioned each use of the ethnospecies $e$ divided by the total number of informants [see @reyes-garciaCulturalPracticalEconomic2006].

```{r CVe}
ethnobotanyR::CVe(ethnobotanydata)
```

### Fidelity Level (FL) per species 

The `FLs()` function calculates the fidelity level (FL) per species in the study. It is a way of calculating the percentage of informants who use a plant for the same purpose as compared to all uses of the plant for any purpose.

\begin{equation}
FL_{s} = \frac {N_{s}*100}{FC_{s}}
\end{equation}

where $N_s$ is the number of informants that use a particular plant for a specific purpose, and $FC_s$ is the frequency of citation for the species [see @friedmanPreliminaryClassificationHealing1986]. 

```{r FLs}
ethnobotanyR::FLs(ethnobotanydata)
```

Divide FLs by 100 to get the percent FL, as it is reported in some studies.

### Plot all indices

For quick assessments of differences between indices use the `Radial_plot` function to show ethnobotanyR results as a radial bar plot using the `ggplot2` library. The `cowplot` package [@R-cowplot] can be useful for comparing several `Radial_plot` results for easy comparison across indices.

```{r, fig.width=7, fig.height=7}
URs_plot <- ethnobotanyR::Radial_plot(ethnobotanydata, ethnobotanyR::URs)

NUs_plot <- ethnobotanyR::Radial_plot(ethnobotanydata, ethnobotanyR::NUs)

FCs_plot <- ethnobotanyR::Radial_plot(ethnobotanydata, ethnobotanyR::FCs)

CIs_plot <- ethnobotanyR::Radial_plot(ethnobotanydata, ethnobotanyR::CIs)

cowplot::plot_grid(URs_plot, NUs_plot, FCs_plot, CIs_plot, 
    labels = c('URs', 'NUs', 'FCs', 'CIs'), 
    nrow = 2, 
    align="hv",
    label_size = 12)
```

Despite their popularity, ethnobotany indices have been criticized for not accurately capturing the complexity and diversity of human-plant relationships. They may oversimplify or overlook important cultural or ecological factors. Additionally, ethnobotany indices are often based on subjective judgments and may be influenced by cultural biases or other factors that can affect the results of the analysis. Still, it is important to have an overview of ethnobotany indices, as they can provide useful insights into the role of plants in different cultural and ecological contexts. Additionally, understanding the background theory and limitations of these indices can help researchers to critically evaluate and interpret ethnobotanical data, and to design more accurate and comprehensive studies of human-plant interactions. Further exploratory methods may be helpful in understanding important relationships.

Critical Considerations

- Raw counts don't account for sampling effort or cultural significance
- Can be misleading if informant expertise varies significantly
- Best used as input for more sophisticated analyses rather than final results


## Exploratory analyses 

For the following examples we create some ethnobotany data for use in `ethnobotanyR`. 

```{r create_data}
eb_data <- data.frame(replicate(10,sample(0:1,20,rep=TRUE)))
names(eb_data) <- gsub(x = names(eb_data), pattern = "X", replacement = "Use_")  
eb_data$informant <- sample(c('User_1', 'User_2', 'User_3'), 20, replace=TRUE)
eb_data$sp_name <- sample(c('sp_1', 'sp_2', 'sp_3', 'sp_4'), 20, replace=TRUE)
```

## Ordination methods

Detrended correspondence analysis (DCA) and principal component analysis (PCA) are statistical techniques that can be useful for exploring patterns and trends in ethnobotany data. DCA is a multivariate statistical technique that is used to analyze patterns of species abundance or occurrence in relation to environmental variables, and to identify species groups or communities that are associated with different environmental conditions. PCA, on the other hand, is a statistical method that is used to identify the underlying structure of a dataset by reducing the number of variables and identifying the most important or influential factors.

Both DCA and PCA can be useful tools for exploratory analysis of ethnobotany data, as they can help to identify patterns and trends in the data that may not be immediately apparent. However, it is important for researchers to be aware of the limitations of these techniques and to use them with caution, as they can be sensitive to certain types of data and may not always produce reliable results.

In order to use these techniques effectively, it is important for researchers to have access to programming tools that allow them to run the analyses. The `ethnobotanyR` package offers a few handy tools to make these work with standard quantitative ethnobotany data. By having access to these tools, researchers can more easily and efficiently run these analyses and incorporate the results into their research projects.

Overall, it is important for researchers to be aware of tools like DCA and PCA and to have access to programming tools that allow them to run these analyses. These tools can be valuable tools for exploring and interpreting ethnobotany data, but they should be used with caution and within the confines of the predetermined research aims and objectives.

### Detrended correspondence analysis (DCA)

Detrended correspondence analysis (DCA) can be used to find the main factors or 'gradients' in large and sparse community data sets. This can be a useful tool for assessing important informant-species-use associations in ethnobotany. Here we use the  data set presented in `eb_data` to perform DCA using the `decorana()` function in the `vegan` package [@R-vegan]. 

The first step is to remove zero value row sums. The DCA can only work with data that is complete (i.e. we remove all NA cases as well as those where the species is listed by an informant but no specific use is recorded). This can be done quickly using the `select()` and `filter_all()` functions of the `dplyr` package [@R-dplyr] and pipe `%>%` functions of the `magrittr` package [@R-magrittr].

```{r remove_zero_DCA}

#remove rows with zero rowsums
ethno_data_complete <- eb_data %>%  
  dplyr::select(-informant, -sp_name) %>% 
  dplyr::filter_all(any_vars(!is.na(.)))%>%
    dplyr::filter_all(any_vars(. != 0))

```

Use the `decorana` function of the `vegan` package [@R-vegan] to get the ordination results.

```{r ordination}
#Save ordination results
 ethno_ordination <- vegan::decorana(ethno_data_complete) 
```

Ordination results can be shown with the command `summary()` and the argument for the named ordination, i.e. `summary(ethno_ordination)` in our case. Likewise, ordination scores can be extracted with `scores()`. Calling the `plot()` function on the ordination results will plot the scores from the ordination.

```{r plot_ord, fig.width=7, fig.height=7}
#Plot ordination results
plot(ethno_ordination)
```

## Principal component analysis (PCA)

Principal component analysis (PCA) can be used to create sets of linearly uncorrelated variables from cases of informant-species-use associations. The resulting principal components are linear combinations of variables that are fed in and each contain all observations. We perform PCA using the `broom` [@R-broom], `tidyr` [@R-tidyr] and `purrr` [@R-purrr] packages using the `nest()` function along with the `mutate()` and `map()` functions to operate on the nested columns. This gives a `tibble` with one row and three columns: 1. our original data set, 2. the `prcomp` object and 3. a data frame of principal component values for each observation.

```{r nesting}
nested_ethno_pca <- eb_data %>% 
  tidyr::nest(., data = everything()) %>% 
  dplyr::mutate(pca = purrr::map(data, ~ stats::prcomp(.x %>% 
        dplyr::select(-informant, -sp_name), 
        center = TRUE, scale = TRUE)),
         pca_augmented = map2(pca, data, ~broom::augment(.x, data = .y)))
```

For PCA model evaluation we can check to see how much variance is explained by each principal component. This tells us how many of the components would be reasonable to assess when analyzing the results. To do this, we can use the data in the `pca_augmented` column of our `nested_ethno_pca` tibble along with `dplyr` [@R-dplyr] and `magrittr` [@R-magrittr] functions.

```{r variance_check}
var_exp_tidy <- nested_ethno_pca %>% 
  tidyr::unnest(pca_augmented) %>% 
  dplyr::summarize_at(.vars = dplyr::vars(contains("PC", ignore.case = FALSE)), .funs = tibble::lst(var)) %>% 
  tidyr::gather(key = pc, value = variance) %>% 
  dplyr::mutate(var_exp = variance/sum(variance),
         cum_var_exp = cumsum(var_exp),
         pc = stringr::str_replace(pc, ".fitted", ""))
```

The `r nrow(var_exp_tidy)` principle components selected explain `r sum(var_exp_tidy$var_exp)`% of variance. As a general rule the first few principal components explain much of the variation. To keep the analysis within reasonable bounds it makes sense to select the first four principle components (this choice may change according to the analysis).

```{r select_components}
var_exp <- var_exp_tidy %>% 
  head(4)
```

Plot the variance explained and the cumulative variance explained to see trends across components.

```{r plot_pca, fig.width=7, fig.height=3}
var_exp %>% 
  dplyr::rename(
    `Variance Explained` = var_exp,
    `Cumulative Variance Explained` = cum_var_exp
  ) %>% 
  tidyr::gather(key = key, value = value, `Variance Explained`:`Cumulative Variance Explained`) %>% 
  ggplot2::ggplot(ggplot2::aes(pc, value, group = key)) + 
  ggplot2::geom_point() + 
  ggplot2::geom_line() + 
  ggplot2::facet_wrap(~key, scales = "free_y") +
  ggplot2::theme_minimal() +
  ggplot2::lims(y = c(0, 1)) +
  ggplot2::labs(y = "Variance",
       title = "Variance explained by each principal component")

```


## Conclusions

Quantitative ethnobotany offers a way to study the use and importance of plants in human cultures, using statistical and analytical methods to quantify and interpret data. This approach can be useful in a variety of contexts, including understanding the cultural and ecological significance of plant species, evaluating the impact of human activities on plant communities, and conserving plant biodiversity.

One of the main benefits of quantitative ethnobotany is that it allows researchers to rigorously and systematically analyze and interpret data, providing more reliable and objective insights into the role of plants in different cultural and ecological settings. By using standardized methods and statistical analyses, researchers can more accurately compare and contrast the importance of different plant species and evaluate the significance of their findings.

In addition, the development of a set of standard practices and guidelines for quantitative ethnobotany can be helpful for the field in several ways. First, standard practices can help to ensure the reliability and validity of research findings, by providing a consistent and transparent approach to data collection, analysis, and interpretation. Second, standard practices can facilitate the sharing and dissemination of research findings, by providing a common language and framework for communication and collaboration among researchers. Finally, standard practices can help to advance the field of ethnobotany by promoting the use of rigorous and transparent methods, and by encouraging the development of new and innovative approaches to understanding the role of plants in human cultures.

## Acknowledgements

This work was written and formatted using the handy tools provided by the `knitr` package [@R-knitr]. 

## References

