Download Lab10.zip from the course data archive on Zenodo and unzip it into a folder called data/Lab10/ in your project directory.
Background
The number of species varies among locations. Some places host thousands of species, while other places host only a few species. Biologists have tried to explain these differences for at least 2 centuries and have developed numerous hypotheses invoking evolutionary time, climate, area, stability, and other factors to explain why some species are more diverse than others.
In landscape ecology, we are often interested in gradients in species diversity and composition in different locations within and among landscapes. Ecologists developed terms to describe “local” and “regional” species diversity and the relationship between diversity at these scales. Local diversity is the number of species you can count in a single site. We call this alpha (α) diversity. Regional diversity is the number of species you observe among sites. We call this gamma (γ) diversity. Regional gamma diversity can be similar to or much higher than local alpha diversity depending on how composition of species changes among sites. This change in composition is known as beta (β) diversity.
Beta diversity has been calculated many ways. The earliest and simplest forms were proposed by Robert Whittaker in the 1960s as γ/\(\bar{\alpha}\) - 1 or γ - \(\bar{\alpha}\). In other words, beta diversity is gamma diversity divided by mean alpha diversity minus 1 or gamma diversity minus mean alpha diversity. Consider a situation where every plot you sampled across a landscape contains the same species. In this case, gamma and mean alpha diversity would be equal and beta diversity would be 0. If every site has a completely different set of species, then gamma diversity will be high and related to the differences in species composition among sites. Differences in species composition among sites is known as species turnover.
A Venn diagram showing the shared and distinct species found in two sites (A and B). Site A has 5 species, and Site B has 4 species. Sites A and B have 2 species common to both. Seven species occur among both sites. We would say that Site A’s alpha diversity is 5. Site B’s alpha diversity is 4. Gamma diversity is 7. Beta diversity can be calculated as either gamma divided by mean alpha diversity minus 1 or gamma minus alpha diversity.
These measures of species diversity are clearly related to scale. The extent or size of the local site sampled (e.g., size of plots measured) and the regional extent of the study (distances among sites) will strongly influence the results. What is considered gamma diversity at one scale (regional diversity among sites) might be considered alpha diversity at another scale (e.g., a comparison of diversity among regions). Also, as the size of the area sampled (i.e., “grain size”) increases alpha diversity will increase and beta diversity will decrease as the number of species detected within each sample increases and the differences among samples decreases. This phenomenon is especially strong at lower latitudes.
Animated scatter plot showing tree beta diversity (y-axis, 2 to 6+) versus latitude (x-axis, 0 to 30), with data points represented as small tree icons and a black regression line with an orange shaded confidence band. The animation cycles through different sampling grain sizes (displayed in the upper right, e.g., ‘10 m x 10 m’), showing how the strength and shape of the latitude-diversity relationship changes with sampling resolution. In the frame shown here, at a 10 m x 10 m grain size, beta diversity declines from about 6 near latitude 0 to about 3.5 near latitude 30.
The relationship between the size of sampling units (i.e., the “grain” of analysis) and beta diversity changes with latitude. At low latitudes small grain sizes tend to be characterized by higher beta diversity than large grain sizes, especially near the equator. This is because small plots will tend to have very different compositions in species, but these differences are composites when plots get larger. Credit: Sreekar1988, Wikimedia Commons, licensed under CC BY-SA 4.0. Source: https://en.wikipedia.org/wiki/Beta_diversity
Considerations of alpha, gamma, and beta diversity are important in understanding and assessing biodiversity. These considerations are also important when developing strategies to conserve biodiversity across landscapes. For instance, goals of biodiversity conservation often include representing all species in a network of conservation reserves. Knowing the full suite of species (gamma diversity), patterns of local diversity (alpha diversity), and differences in species composition among sites (beta diversity) is necessary to design landscape strategies to conserve species.
Spatial conservation planning and site complementarity
It is common for ecologists to map biodiversity as alpha diversity (i.e., the total number of species expected to be in a site). These maps of species diversity reveal interesting patterns and tell us where species richness is highest across landscapes, regions, or continents. However, these maps of diversity have limited value as maps of biodiversity priorities. This is because maps of richness do not prioritize sites in a way that considers complementarity among sites (i.e., beta diversity) to maximize the representation of all species (i.e., gamma diversity).
Ecologists and conservation scientists have developed several methods and associated software packages that account for complementarity among sites and seek to maximize the representation of species with minimal area. Marxan is probably the most widely used software that uses a “simulated annealing algorithm” to do this. Zonation is also widely used and includes several algorithms that prioritize sites based on their ability to represent species. The R package prioritizr is increasingly used and involves using “solvers” that conduct linear integer programming to prioritize sites (e.g., pixels) to represent species or achieve other conservation targets. The resulting maps of biodiversity priorities are important resources in spatial conservation planning.
Ecologists have also calculated “rarity-weighted richness” by summing the inverse of species’ range sizes (i.e., 1 / range size). Thus, rarity-weighted richness creates an index and map that gives more “weight” to species with very small ranges. Several high profile maps of biodiversity importance have relied on this method to highlight regions with many endemic species, and some conservation scientists have demonstrated that rarity-weighted richness “performs” nearly as well as complementarity-based algorithms for prioritizing sites for biodiversity conservation.
Four alternative methods for prioritizing lands for biodiversity conservation (Richness, Rarity-Weighted Richness [RWR], Zonation Additive Benefit Function [ABF], and Zonation Core Area Zonation [CAZ]) for all species combined, mammals, birds, amphibians, and reptiles. From Belote, R.T., Barnett, K., et al. (2021), “Options for prioritizing sites for biodiversity conservation with implications for ‘30 by 30,’” Biological Conservation 264, 109378, https://doi.org/10.1016/j.biocon.2021.109378. Licensed under CC BY-NC-ND 4.0.
In this lab we will focus on mapping species richness by stacking and summing maps of suitable habitat for species from multiple taxa. We will consider the geographic patterns of species richness, calculate mean alpha diversity, and gamma diversity to measure beta diversity for the lower 48 states. We will also use the epm package to calculate and map beta diversity of moving windows. We will use range sizes to map rarity-weighted richness and compare patterns among ecoregions.
Tree diversity in the lower 48 states
We will be using maps of predicted tree species distributions from Ty Wilson, an ecologist with the US Forest Service to calculate species richness, rarity-weighted richness, and local beta diversity. You may often be working with datasets that include hundreds or even thousands of species. When feasible, I recommend looking at the range maps of all species. This is helpful to get a sense of the geographic distributions of different species and the variability in range sizes of species. This is also a good check on conspicuous errors of commission or omission. The map below shows the presence (green) and absence (grey) of tree species listed by the six letter codes (first 3 letters of genus and first 3 letters of species). The maps are rank-ordered by the range sizes. For instance, the map in the upper left shows Fraxinus pennsylvanica, green ash, as the species with the largest range in the contiguous U.S., whereas the map in the lower right shows Annona glabra, pond apple, which has a very limited range in Florida. Skim this map and notice which species only occur in the west, which species only occur in the east, which species occur in the Southeast, Upper Midwest, etc. Do you see any obvious errors of omission or commission?
Maps by Travis Belote, using data from Wilson, Barry Tyler; Lister, Andrew J.; Riemann, Rachel I.; Griffith, Douglas M. 2013. Live tree species basal area of the contiguous United States (2000-2009). Newtown Square, PA: USDA Forest Service, Rocky Mountain Research Station. https://doi.org/10.2737/RDS-2013-0013
Tree richness (alpha diversity), range sizes, and rarity-weighted richness
We will bring data of 1s (species likely present) and 0s (species likely absent) into R, stack them, and add them up to map tree species richness (i.e., alpha diversity of each pixel). We will use the range sizes of each species to calculate and map rarity-weighted richness. We will use a moving window to map beta diversity of small regions and compare this map with maps of alpha diversity.
Code
# Load libraries (install if you need to)library(terra)library(sf)library(epm)library(vegan)library(tidyverse)library(viridis)# Start off by loading a lookup table of tree species in the dataset# List and read raster files from the parent folderfolder <-"data/Lab10/trees"tree_files <-list.files(folder, pattern ="\\.tif$", full.names =TRUE)# Stack rasters and assign namestrees <-rast(tree_files)# Calculate species richness by simply summing the species presencesrichness <-sum(trees)# Look at the map and histogram of tree species richness.# Which regions of the contiguous US are the most diverse? Why?# How is species richness distributed? Normally? Or skewed? # This will show a map of tree richness for the contiguous U.S.plot(richness, axes = F)
Code
hist(richness)
Code
# Let's make the map and histogram colors matchncols <-20brks <-seq(minmax(richness)[1], minmax(richness)[2], length.out = ncols +1)cols <-viridis(ncols)# plot the map and histograms using the breaks and colors defined above.# This will show a map and histogram of tree richness for the contiguous U.S.plot(richness, breaks = brks, col = cols, axes =FALSE, legend =FALSE)
Code
hist(values(richness), breaks = brks, col = cols, border =NA,xlab ="Species richness", main =NA)
Code
# Now let's calculate and map rarity-weighted richness.# We will first sum up all the 1s WITHIN each layer as an estimate of range sizerange_size <-global(trees, "sum", na.rm = T)[,1]# Before we move on. Look at the distribution of range sizes. # Why are range sizes distributed this way? hist(range_size)
Code
# Then we want to multiple each species by 1/range size so that we "weight" # species by their rarity before summing them up.rwr <-sum(trees * (1/range_size), na.rm =TRUE)# Look at the map. This will show rarity-weighted richness for the contiguous U.S.# How does the map differ from the map of richness?plot(rwr)
Code
# Look at the histogram.# How does the distribution differ from richness?hist(rwr)
Code
# Let's make the map and histogram colors match, as abovencols <-20brksRWR <-seq(minmax(rwr)[1], minmax(rwr)[2], length.out = ncols +1)colsRWR <-viridis(ncols)# Plot the map and histogram. plot(rwr, breaks = brksRWR, col = colsRWR, axes =FALSE, legend =FALSE)
Code
hist(values(rwr), breaks = brksRWR, col = colsRWR, border =NA,xlab ="Rarity-weighted richness", main =NA)
Code
# Given the highly skewed nature of the data, we can bin the data into deciles# and remap itrwr$deciles <- rwr %>%values() %>%ntile(10)plot(rwr$deciles)
Code
# We can plot the histogram too.hist(rwr$deciles)
Notice the difference in histograms between the raw rarity-weighted richness and the classified rarity-weighted richness. Do you know why the histograms for the deciles looks like this?
Local beta diversity of tree species
Before we calculate overall beta diversity, we will use functions out of the epm package to calculate beta diversity within a moving window. This allows us to investigate how species composition varies within regions of our moving window size. In other words, we can ask: “which places have high beta diversity (species turnover) among local sites in the moving window region?” We will need to turn our raster stack into a grid that can be read by the package using createEPMgrid, then use betadiv_taxonomic() to calculate beta diversity within a circular moving window with a specified radius. The package allows you to calculate beta diversity based on species turnover or “nestedness”, but here we will focus on “full” beta diversity of the moving window, which is calculated as multisite Sørensen dissimilarity. Multisite beta diversity tells us what fraction of the total species diversity in the moving window is due to differences among sites. Values near 1 suggest that sites have different species. Values near 0 mean communities are very similar. The index is normalized by total diversity making it comparable among regions.
Code
# Create a grid for use in the epm package from the stack of treesm_grid_all <-createEPMgrid(trees)# Then run beta diversitybetaF <-betadiv_taxonomic(m_grid_all, radius =100000, component ="full")plot(betaF, axes = F)
Code
# Let's make the map and histogram colors matchncols <-20brksBeta <-seq(minmax(betaF)[1], minmax(betaF)[2], length.out = ncols +1)colsBeta <-viridis(ncols)# Plot the map and histogram.plot(betaF, breaks = brksBeta, col = colsBeta, axes =FALSE, legend =FALSE)
Code
hist(values(betaF), breaks = brksBeta, col = colsBeta, border =NA,xlab ="Local beta diversity", main =NA)
Beta diversity of 0.80 means that 80% of the species in the neighborhood are not shared among sites. Only about 20% of the regional species pool tends to appear in an average site. Put simply, nearby sites in the moving windows have very different species compositions.
How are the patterns of beta diversity different than the patterns of alpha diversity? Why?
Let’s stack up alpha diversity, rarity-weighted richness, and beta diversity for later.
Code
# We will stack our output from above for later. st <-c(richness, rwr$sum, betaF)# It is always a good idea to take control of the names in a raster stacknames(st) <-c("alpha", "rwr", "beta")
Now, let’s calculate mean alpha, gamma, and overall beta diversity in the vegan package. These values will provide estimates of biodiversity for the entire study area, in our case the contiguous United States. This will allow us to ask and answer “how many total species of trees occur in the contiguous United States?” and “on average, how many species occur in any one area?”. We can also ask
Code
# We can turn our raster stack into a data frame # where pixel locations are rows and species are columns.# This is site x species matrix is a very common way of working with data # on ecological communities.trees_df <- trees %>%as.data.frame(xy = T)# Look at the first few rows of data use View(trees_df) if you want to look at the # entire dataset# head(trees_df)# remove NAs in the datasettrees_df <- trees_df %>%drop_na()# We need to remove the coordinates (x and y) before working in vegantrees_df_noXY <- trees_df %>% dplyr::select(-c(x, y))# Use vegan to calculate alpha diversity (mean richness per site)alpha <- vegan::specnumber(trees_df_noXY) # Plot a histogram and compare with the one you created above.# The should be the samehist(alpha)
Code
# Now, calculate mean alpha diversity for CONUSmean_alpha <-mean(alpha)# We can calculate gamma diversity (total richness across all sites). # colSums calculates how many locations each species is in. # If a species is completely absent from all sites then the sum is 0, of course.# summing the species with > 0 occurences calculates the total number of species# in the site x species matrix. This can sometimes be calculated easily # by the total number of species in the data! # However, it is sometimes necessary to check in case some species have no records.gamma <-sum(colSums(trees_df_noXY) >0)# Now, we will use gamma diversity and mean alpha diversity to calculate beta diversitybeta_mult <- gamma / mean_alpha -1# multiplicative betabeta_add <- gamma - mean_alpha # additive betabeta_N <- (gamma - mean_alpha) / gamma # normalized beta diversity
Species accumulation curves
We will use the vegan package to plot a species accumulation curve. This step is optional. Species accumulation curves plot how many species are encountered as sites are added (or accumulated). The default approach using specaccum in R uses a Monte Carlo-like sampling to create an accumulation curve. In other words, R will randomly draw multiple combinations of two sites (pixels) and assess how many total species occur in the two sites. It will randomly draw multiple combinations of three sites and assess how many species occur among the three sites. And so on. It will run through these random draws 100 times unless you specify another number of samples in permutations.
Species accumulation curves have been used to assess biodiversity prioritization methods, decide on how many plots researchers need to ensure they sample a sufficient number of species, estimate total gamma diversity when it is unknown, and measure beta diversity. Species will “accumulate” faster when beta diversity is higher. Species accumulation curves are sometimes confused with species-area curves. Adding sites and accumulating species is similar to a species-area assessment, but researchers often differentiate species-area assessments based on nested sampling of different plot sizes. We will plot a species accumulation curve for trees in the contiguous US.
Code
# run species accumulation and store the output in an object called spec_accspec_acc <-specaccum(trees_df_noXY, method ="random", permutations =100)# Plot the species accumulation curve with a confidence interval based on the # variability among permutationsplot(spec_acc, ci.type ="poly", col ="darkgreen",lwd =2, ci.lty =0, ci.col ="lightgreen",xlab ="Number of grid cells sampled",ylab ="Species richness")
How does alpha diversity, local beta diversity, and rarity-weighted richness vary among ecoregions?
We created a raster stack of alpha diversity, rarity-weighted richness, and beta diversity above. We will bring in data on level 3 ecoregions, aggregate those to level 2 ecoregions, rasterize the polygons, and add to our stack. Then we will create some box and whisker plots sorted by the mean diversity of each plot. This will allow us to more easily assess and names the patterns you observed in the first part of this lab.
Code
#### Bring in ecoregion dataeco <-vect("data/Lab10/ecoregions_L3/us_eco_l3.shp")# We use "aggregate" to "disolve" level 3 ecoregions into level 2 ecoregionsecoL2 <- eco %>%aggregate("NA_L2NAME")# Convert the terra vector object to an sf objectecoL2 <-st_as_sf(ecoL2)# Turn the vector data into a raster dataset and assign the pixels tha level 2 name.ecoL2rast <-rasterize(ecoL2, st, field ="NA_L2NAME")# Stack the biodiversity data with the ecoregion data. # We create a stack above called "st". # We can stack this stack with the rasterized ecoregions.st_eco <-c(st, ecoL2rast)# Turn this raster stack into a data frame st_ecoDF <- st_eco %>%as.data.frame(xy = T)# We can create boxplots for each measure of biodiversity within ecoregions.# Alpha diversity among ecoregions.st_ecoDF %>%drop_na() %>%ggplot(aes(x =reorder(NA_L2NAME, alpha, FUN = mean), y = alpha)) +geom_boxplot(fill ="grey") +coord_flip() +# optional, makes it easier to read long nameslabs(x ="Ecoregion", y ="Alpha diversity") +theme_bw()
Code
# Local beta diversity among ecoregions.st_ecoDF %>%drop_na() %>%ggplot(aes(x =reorder(NA_L2NAME, beta, FUN = mean), y = beta)) +geom_boxplot(fill ="grey") +coord_flip() +# optional, makes it easier to read long nameslabs(x ="Ecoregion", y ="Beta diversity") +theme_bw()
Code
# Rarity-weighted richness among ecoregions.st_ecoDF %>%drop_na() %>%ggplot(aes(x =reorder(NA_L2NAME, rwr, FUN = mean), y = rwr)) +geom_boxplot(fill ="grey") +coord_flip() +# optional, makes it easier to read long nameslabs(x ="Ecoregion", y ="Rarity-weighted richness") +theme_bw()
TASK 1.
I have shared coarse data on mammals, birds, amphibians, and reptiles. Choose one of these four taxonomic groups and redo the analysis above to investigate patterns of alpha diversity, rarity-weighted richness, and local beta diversity among ecoregions. What are the causes and consequences of these patterns? Why do some places host high alpha diversity but low beta diversity and vice versa? Investigate the distribution of range sizes, mean alpha, gamma diversity, and “global” beta diversity, too. Write up your results as an abstract for Landscape Ecology.
Data source(s)
I coarsened the raster data for each of these datasets for ease of analysis in the lab.
---title: "Lab 10. Measuring Biodiversity at Multiple Scales"subtitle: "Alpha, gamma, and beta diversity"---::: {.callout-note appearance="minimal"}**Data for this lab.**Download `Lab10.zip` from the [course data archive on Zenodo](https://doi.org/10.5281/zenodo.22101926) and unzip it into a folder called `data/Lab10/` in your project directory.:::# BackgroundThe number of species varies among locations. Some places host thousands of species, while other places host only a few species. Biologists have tried to explain these differences for at least 2 centuries and have developed numerous hypotheses invoking evolutionary time, climate, area, stability, and other factors to explain why some species are more diverse than others.In landscape ecology, we are often interested in gradients in species diversity and composition in different locations within and among landscapes. Ecologists developed terms to describe "local" and "regional" species diversity and the relationship between diversity at these scales. Local diversity is the number of species you can count in a single site. We call this **alpha (α) diversity**. Regional diversity is the number of species you observe among sites. We call this **gamma (γ) diversity**. Regional gamma diversity can be similar to or much higher than local alpha diversity depending on how composition of species changes among sites. This change in composition is known as **beta (β) diversity**.Beta diversity has been calculated many ways. The earliest and simplest forms were proposed by Robert Whittaker in the 1960s as γ/$\bar{\alpha}$ - 1 or γ - $\bar{\alpha}$. In other words, beta diversity is gamma diversity divided by mean alpha diversity minus 1 or gamma diversity minus mean alpha diversity. Consider a situation where every plot you sampled across a landscape contains the same species. In this case, gamma and mean alpha diversity would be equal and beta diversity would be 0. If every site has a completely different set of species, then gamma diversity will be high and related to the differences in species composition among sites. Differences in species composition among sites is known as species turnover.{fig-alt="See figure caption." fig-align="center"}These measures of species diversity are clearly related to scale. The extent or size of the local site sampled (e.g., size of plots measured) and the regional extent of the study (distances among sites) will strongly influence the results. What is considered gamma diversity at one scale (regional diversity among sites) might be considered alpha diversity at another scale (e.g., a comparison of diversity among regions). Also, as the size of the area sampled (i.e., "grain size") increases alpha diversity will increase and beta diversity will decrease as the number of species detected within each sample increases and the differences among samples decreases. This phenomenon is especially strong at lower latitudes.::: {.content-visible when-format="html"}{fig-align="center"}:::::: {.content-visible when-format="pdf"}{fig-align="center"}:::*The relationship between the size of sampling units (i.e., the "grain" of analysis) and beta diversity changes with latitude. At low latitudes small grain sizes tend to be characterized by higher beta diversity than large grain sizes, especially near the equator. This is because small plots will tend to have very different compositions in species, but these differences are composites when plots get larger. Credit: Sreekar1988, Wikimedia Commons, licensed under CC BY-SA 4.0. Source: <https://en.wikipedia.org/wiki/Beta_diversity>*Considerations of alpha, gamma, and beta diversity are important in understanding and assessing biodiversity. These considerations are also important when developing strategies to conserve biodiversity across landscapes. For instance, goals of biodiversity conservation often include representing all species in a network of conservation reserves. Knowing the full suite of species (gamma diversity), patterns of local diversity (alpha diversity), and differences in species composition among sites (beta diversity) is necessary to design landscape strategies to conserve species.## Spatial conservation planning and site complementarityIt is common for ecologists to map biodiversity as alpha diversity (i.e., the total number of species expected to be in a site). These maps of species diversity reveal interesting patterns and tell us where species richness is highest across landscapes, regions, or continents. However, these maps of diversity have limited value as maps of biodiversity priorities. This is because maps of richness do not prioritize sites in a way that considers **complementarity** among sites (i.e., beta diversity) to maximize the representation of all species (i.e., gamma diversity).Ecologists and conservation scientists have developed several methods and associated software packages that account for complementarity among sites and seek to maximize the representation of species with minimal area. Marxan is probably the most widely used software that uses a "simulated annealing algorithm" to do this. Zonation is also widely used and includes several algorithms that prioritize sites based on their ability to represent species. The R package `prioritizr` is increasingly used and involves using "solvers" that conduct linear integer programming to prioritize sites (e.g., pixels) to represent species or achieve other conservation targets. The resulting maps of biodiversity priorities are important resources in spatial conservation planning.Ecologists have also calculated "rarity-weighted richness" by summing the inverse of species' range sizes (i.e., 1 / range size). Thus, rarity-weighted richness creates an index and map that gives more "weight" to species with very small ranges. Several high profile maps of biodiversity importance have relied on this method to highlight regions with many endemic species, and some conservation scientists have demonstrated that rarity-weighted richness "performs" nearly as well as complementarity-based algorithms for prioritizing sites for biodiversity conservation.{fig-align="center"}*Four alternative methods for prioritizing lands for biodiversity conservation (Richness, Rarity-Weighted Richness \[RWR\], Zonation Additive Benefit Function \[ABF\], and Zonation Core Area Zonation \[CAZ\]) for all species combined, mammals, birds, amphibians, and reptiles. From Belote, R.T., Barnett, K., et al. (2021), "Options for prioritizing sites for biodiversity conservation with implications for '30 by 30,'" Biological Conservation 264, 109378, https://doi.org/10.1016/j.biocon.2021.109378. Licensed under CC BY-NC-ND 4.0.*In this lab we will focus on mapping species richness by stacking and summing maps of suitable habitat for species from multiple taxa. We will consider the geographic patterns of species richness, calculate mean alpha diversity, and gamma diversity to measure beta diversity for the lower 48 states. We will also use the `epm` package to calculate and map beta diversity of moving windows. We will use range sizes to map rarity-weighted richness and compare patterns among ecoregions.## Tree diversity in the lower 48 statesWe will be using maps of predicted tree species distributions from Ty Wilson, an ecologist with the US Forest Service to calculate species richness, rarity-weighted richness, and local beta diversity. You may often be working with datasets that include hundreds or even thousands of species. When feasible, I recommend looking at the range maps of all species. This is helpful to get a sense of the geographic distributions of different species and the variability in range sizes of species. This is also a good check on conspicuous errors of commission or omission. The map below shows the presence (green) and absence (grey) of tree species listed by the six letter codes (first 3 letters of genus and first 3 letters of species). The maps are rank-ordered by the range sizes. For instance, the map in the upper left shows *Fraxinus pennsylvanica*, green ash, as the species with the largest range in the contiguous U.S., whereas the map in the lower right shows *Annona glabra*, pond apple, which has a very limited range in Florida. Skim this map and notice which species only occur in the west, which species only occur in the east, which species occur in the Southeast, Upper Midwest, etc. Do you see any obvious errors of omission or commission?{fig-align="center"}*Maps by Travis Belote, using data from Wilson, Barry Tyler; Lister, Andrew J.; Riemann, Rachel I.; Griffith, Douglas M. 2013. Live tree species basal area of the contiguous United States (2000-2009). Newtown Square, PA: USDA Forest Service, Rocky Mountain Research Station. https://doi.org/10.2737/RDS-2013-0013*### Tree richness (alpha diversity), range sizes, and rarity-weighted richnessWe will bring data of 1s (species likely present) and 0s (species likely absent) into R, stack them, and add them up to map tree species richness (i.e., alpha diversity of each pixel). We will use the range sizes of each species to calculate and map rarity-weighted richness. We will use a moving window to map beta diversity of small regions and compare this map with maps of alpha diversity.```{r}# Load libraries (install if you need to)library(terra)library(sf)library(epm)library(vegan)library(tidyverse)library(viridis)# Start off by loading a lookup table of tree species in the dataset# List and read raster files from the parent folderfolder <-"data/Lab10/trees"tree_files <-list.files(folder, pattern ="\\.tif$", full.names =TRUE)# Stack rasters and assign namestrees <-rast(tree_files)# Calculate species richness by simply summing the species presencesrichness <-sum(trees)# Look at the map and histogram of tree species richness.# Which regions of the contiguous US are the most diverse? Why?# How is species richness distributed? Normally? Or skewed? # This will show a map of tree richness for the contiguous U.S.plot(richness, axes = F)hist(richness)# Let's make the map and histogram colors matchncols <-20brks <-seq(minmax(richness)[1], minmax(richness)[2], length.out = ncols +1)cols <-viridis(ncols)# plot the map and histograms using the breaks and colors defined above.# This will show a map and histogram of tree richness for the contiguous U.S.plot(richness, breaks = brks, col = cols, axes =FALSE, legend =FALSE)hist(values(richness), breaks = brks, col = cols, border =NA,xlab ="Species richness", main =NA)``````{r}# Now let's calculate and map rarity-weighted richness.# We will first sum up all the 1s WITHIN each layer as an estimate of range sizerange_size <-global(trees, "sum", na.rm = T)[,1]# Before we move on. Look at the distribution of range sizes. # Why are range sizes distributed this way? hist(range_size)# Then we want to multiple each species by 1/range size so that we "weight" # species by their rarity before summing them up.rwr <-sum(trees * (1/range_size), na.rm =TRUE)# Look at the map. This will show rarity-weighted richness for the contiguous U.S.# How does the map differ from the map of richness?plot(rwr)# Look at the histogram.# How does the distribution differ from richness?hist(rwr)# Let's make the map and histogram colors match, as abovencols <-20brksRWR <-seq(minmax(rwr)[1], minmax(rwr)[2], length.out = ncols +1)colsRWR <-viridis(ncols)# Plot the map and histogram. plot(rwr, breaks = brksRWR, col = colsRWR, axes =FALSE, legend =FALSE)hist(values(rwr), breaks = brksRWR, col = colsRWR, border =NA,xlab ="Rarity-weighted richness", main =NA)# Given the highly skewed nature of the data, we can bin the data into deciles# and remap itrwr$deciles <- rwr %>%values() %>%ntile(10)plot(rwr$deciles)# We can plot the histogram too.hist(rwr$deciles)```Notice the difference in histograms between the raw rarity-weighted richness and the classified rarity-weighted richness. Do you know why the histograms for the deciles looks like this?### Local beta diversity of tree speciesBefore we calculate overall beta diversity, we will use functions out of the `epm` package to calculate beta diversity within a moving window. This allows us to investigate how species composition varies within regions of our moving window size. In other words, we can ask: "which places have high beta diversity (species turnover) among local sites in the moving window region?" We will need to turn our raster stack into a grid that can be read by the package using `createEPMgrid`, then use `betadiv_taxonomic()` to calculate beta diversity within a circular moving window with a specified radius. The package allows you to calculate beta diversity based on species turnover or "nestedness", but here we will focus on "full" beta diversity of the moving window, which is calculated as multisite Sørensen dissimilarity. Multisite beta diversity tells us what fraction of the total species diversity in the moving window is due to differences among sites. Values near 1 suggest that sites have different species. Values near 0 mean communities are very similar. The index is normalized by total diversity making it comparable among regions.```{r}# Create a grid for use in the epm package from the stack of treesm_grid_all <-createEPMgrid(trees)# Then run beta diversitybetaF <-betadiv_taxonomic(m_grid_all, radius =100000, component ="full")plot(betaF, axes = F)# Let's make the map and histogram colors matchncols <-20brksBeta <-seq(minmax(betaF)[1], minmax(betaF)[2], length.out = ncols +1)colsBeta <-viridis(ncols)# Plot the map and histogram.plot(betaF, breaks = brksBeta, col = colsBeta, axes =FALSE, legend =FALSE)hist(values(betaF), breaks = brksBeta, col = colsBeta, border =NA,xlab ="Local beta diversity", main =NA)```Beta diversity of 0.80 means that 80% of the species in the neighborhood are not shared among sites. Only about 20% of the regional species pool tends to appear in an average site. Put simply, nearby sites in the moving windows have very different species compositions.How are the patterns of beta diversity different than the patterns of alpha diversity? Why?Let's stack up alpha diversity, rarity-weighted richness, and beta diversity for later.```{r}# We will stack our output from above for later. st <-c(richness, rwr$sum, betaF)# It is always a good idea to take control of the names in a raster stacknames(st) <-c("alpha", "rwr", "beta")```Now, let's calculate mean alpha, gamma, and overall beta diversity in the `vegan` package. These values will provide estimates of biodiversity for the entire study area, in our case the contiguous United States. This will allow us to ask and answer "how many total species of trees occur in the contiguous United States?" and "on average, how many species occur in any one area?". We can also ask```{r}# We can turn our raster stack into a data frame # where pixel locations are rows and species are columns.# This is site x species matrix is a very common way of working with data # on ecological communities.trees_df <- trees %>%as.data.frame(xy = T)# Look at the first few rows of data use View(trees_df) if you want to look at the # entire dataset# head(trees_df)# remove NAs in the datasettrees_df <- trees_df %>%drop_na()# We need to remove the coordinates (x and y) before working in vegantrees_df_noXY <- trees_df %>% dplyr::select(-c(x, y))# Use vegan to calculate alpha diversity (mean richness per site)alpha <- vegan::specnumber(trees_df_noXY) # Plot a histogram and compare with the one you created above.# The should be the samehist(alpha)# Now, calculate mean alpha diversity for CONUSmean_alpha <-mean(alpha)# We can calculate gamma diversity (total richness across all sites). # colSums calculates how many locations each species is in. # If a species is completely absent from all sites then the sum is 0, of course.# summing the species with > 0 occurences calculates the total number of species# in the site x species matrix. This can sometimes be calculated easily # by the total number of species in the data! # However, it is sometimes necessary to check in case some species have no records.gamma <-sum(colSums(trees_df_noXY) >0)# Now, we will use gamma diversity and mean alpha diversity to calculate beta diversitybeta_mult <- gamma / mean_alpha -1# multiplicative betabeta_add <- gamma - mean_alpha # additive betabeta_N <- (gamma - mean_alpha) / gamma # normalized beta diversity```### Species accumulation curvesWe will use the `vegan` package to plot a species accumulation curve. This step is optional. Species accumulation curves plot how many species are encountered as sites are added (or accumulated). The default approach using `specaccum` in R uses a Monte Carlo-like sampling to create an accumulation curve. In other words, R will randomly draw multiple combinations of two sites (pixels) and assess how many total species occur in the two sites. It will randomly draw multiple combinations of three sites and assess how many species occur among the three sites. And so on. It will run through these random draws 100 times unless you specify another number of samples in `permutations`.Species accumulation curves have been used to assess biodiversity prioritization methods, decide on how many plots researchers need to ensure they sample a sufficient number of species, estimate total gamma diversity when it is unknown, and measure beta diversity. Species will "accumulate" faster when beta diversity is higher. Species accumulation curves are sometimes confused with species-area curves. Adding sites and accumulating species is similar to a species-area assessment, but researchers often differentiate species-area assessments based on nested sampling of different plot sizes. We will plot a species accumulation curve for trees in the contiguous US.```{r}# run species accumulation and store the output in an object called spec_accspec_acc <-specaccum(trees_df_noXY, method ="random", permutations =100)# Plot the species accumulation curve with a confidence interval based on the # variability among permutationsplot(spec_acc, ci.type ="poly", col ="darkgreen",lwd =2, ci.lty =0, ci.col ="lightgreen",xlab ="Number of grid cells sampled",ylab ="Species richness")```### How does alpha diversity, local beta diversity, and rarity-weighted richness vary among ecoregions?We created a raster stack of alpha diversity, rarity-weighted richness, and beta diversity above. We will bring in data on level 3 ecoregions, aggregate those to level 2 ecoregions, rasterize the polygons, and add to our stack. Then we will create some box and whisker plots sorted by the mean diversity of each plot. This will allow us to more easily assess and names the patterns you observed in the first part of this lab.```{r}#### Bring in ecoregion dataeco <-vect("data/Lab10/ecoregions_L3/us_eco_l3.shp")# We use "aggregate" to "disolve" level 3 ecoregions into level 2 ecoregionsecoL2 <- eco %>%aggregate("NA_L2NAME")# Convert the terra vector object to an sf objectecoL2 <-st_as_sf(ecoL2)# Turn the vector data into a raster dataset and assign the pixels tha level 2 name.ecoL2rast <-rasterize(ecoL2, st, field ="NA_L2NAME")# Stack the biodiversity data with the ecoregion data. # We create a stack above called "st". # We can stack this stack with the rasterized ecoregions.st_eco <-c(st, ecoL2rast)# Turn this raster stack into a data frame st_ecoDF <- st_eco %>%as.data.frame(xy = T)# We can create boxplots for each measure of biodiversity within ecoregions.# Alpha diversity among ecoregions.st_ecoDF %>%drop_na() %>%ggplot(aes(x =reorder(NA_L2NAME, alpha, FUN = mean), y = alpha)) +geom_boxplot(fill ="grey") +coord_flip() +# optional, makes it easier to read long nameslabs(x ="Ecoregion", y ="Alpha diversity") +theme_bw()# Local beta diversity among ecoregions.st_ecoDF %>%drop_na() %>%ggplot(aes(x =reorder(NA_L2NAME, beta, FUN = mean), y = beta)) +geom_boxplot(fill ="grey") +coord_flip() +# optional, makes it easier to read long nameslabs(x ="Ecoregion", y ="Beta diversity") +theme_bw()# Rarity-weighted richness among ecoregions.st_ecoDF %>%drop_na() %>%ggplot(aes(x =reorder(NA_L2NAME, rwr, FUN = mean), y = rwr)) +geom_boxplot(fill ="grey") +coord_flip() +# optional, makes it easier to read long nameslabs(x ="Ecoregion", y ="Rarity-weighted richness") +theme_bw()```::: {.callout-tip appearance="minimal"}**TASK 1.**I have shared coarse data on mammals, birds, amphibians, and reptiles. Choose one of these four taxonomic groups and redo the analysis above to investigate patterns of alpha diversity, rarity-weighted richness, and local beta diversity among ecoregions. What are the causes and consequences of these patterns? Why do some places host high alpha diversity but low beta diversity and vice versa? Investigate the distribution of range sizes, mean alpha, gamma diversity, and "global" beta diversity, too. Write up your results as an abstract for *Landscape Ecology*.:::# Data source(s)I coarsened the raster data for each of these datasets for ease of analysis in the lab.Tree species: <https://www.fs.usda.gov/rds/archive/catalog/RDS-2013-0013>Mammals, birds, amphibians, and reptiles: <https://www.usgs.gov/programs/gap-analysis-project/science/species-data-download>Ecoregions: <https://www.epa.gov/eco-research/level-iii-and-iv-ecoregions-continental-united-states>