Run_Scripts/01_run_diversity.R

#' ---
#' title: 01 Species Richness and Simpson Diversity
#' author: Edie Bishop
#' ---

#' # Introduction
#' In this package we will use the ProgInRBCIfunc package to call on two functions, species_richness_1 and
#' simpson_diversity_1, which will calculate the species richness and the simpson diversity of a population.
#' We will also call on the script "create_datasets.R" which creates a number of vector
#' files, which contain populations generated from the BCI_2010 dataset (which we obtained from the BCI
#' package).
#'
#' For each population, we will first plot the population, so that we know what to expect when we
#' calculate the species richness and simpson diversity, and then calculate the richness and simpson
#' diversity values.
#'
#' Species richness is a count of the total number of species within a community. Simpson diversity is
#' a measure of the probability that two individuals randomly selected from a sample will be from the
#' same species, and therefore will provide a value between zero and one.
#'
#' # Load required packages and scripts

#' First set the working directory to the Run_scripts folder within the package so we we van access the
#' create_datasets.R file, which generatres the populations.
devtools::wd(".", "Run_Scripts")
# The ProgInRBCIfunc function contains functions which calculate various indices of diversity
library(ProgInRBCIfunc)
# the "create_datasets" script produces a list of populations
source("create_datasets.R")

#' #### Tree.pop
#' tree.pop is a vector which contains the count for each species in the entire BCI_2010 dataset
plot(sort(tree.pop))
#' There are a lot of species in the community which only have a few individuals, and there are only a few
#' species which have a lot of individuals within the community
species_richness_1(tree.pop)
# As we know that there are 301 different species in the community, the species richness = 301 as expected
simpson_diversity_1(tree.pop)
# 0.449 indicates that there is an almost 50% chance that two randomly selected individuals from the
# community will be from the same species.

#'
#'------------------------------------------------------------------------------------
#'
#' #### quadrat.pop
#' quadrat.pop was generated by selected one quadrat at random, and counting the number of individuals
#' from each species within that quadrat.
plot(sort(quadrat.pop))
#' As we might expect, the graph looks similar to that of tree-pop. There were a few species with many
#' individuals within this quadrat, and many species with only a few individuals.
species_richness_1(quadrat.pop)
# There are less species within the randomly selected quadrat than the whole of the community
simpson_diversity_1(quadrat.pop)
# As there are now a fewer number of species in our population, it makes sense that the chance of selecting
# two random individuals from the same species has gone up.

#'
#'--------------------------------------------------------------------------------------
#'
#' #### quadrat10.pop
#' quadrat10.pop is similar to quadrat.pop, although this time it has drawn from 10 random quadrats and
#' summed the number of each species within those 10 quadrats
plot(sort(quadrat10.pop))
#' The plot still looks fairly similar to the previous two
species_richness_1(quadrat10.pop)
# More species than quadrat.pop, which makes sense
simpson_diversity_1(quadrat10.pop)
# And were back to around 50% chance of randomly selecting two individuals from the same species

#'
#'-------------------------------------------------------------------------------------
#'
#' #### one.pop
#' one.pop is a population with are large number of individuals of only one sepcies
plot(sort(one.pop))
#' Values for all species are 0, except for the one species which contains 222718 individuals
species_richness_1(one.pop)
# Vlaue is 1, as there is only one species
simpson_diversity_1(one.pop)
# Value is 1, since two randomly selected individuals are always going to be from the same species

#'
#'-------------------------------------------------------------------------------------
#'
#' #### uneven.pop
#' uneven.pop contains one species with 111728 individuals, and 300 species with 369 individuals each
plot(sort(uneven.pop))
# The plot looks similar to the last one, since 369 is so much smaller a number than 111728
species_richness_1(uneven.pop)
# Species richness is again 301, as there are again 301 species present in the population
simpson_diversity_1(uneven.pop)
# There is around a 25% chance of selecting two individuals from the same species

#'
#'-------------------------------------------------------------------------------------
#'
#' #### mixed.pop
#' mixed.pop contains a population with a variable number of individuals for each species, no two species
#' have the same number of individuals
plot(sort(mixed.pop))
#' The plot shows a linear increase in the number of individuals of each species, when they are sorted
#' from lowest to huighest
species_richness_1(mixed.pop)
# Again there are 301 species present in the population
simpson_diversity_1(mixed.pop)
#' And now we see that there is a very small chance of random selecting two individuals from the same species

#'
#'----------------------------------------------------------------------------------
#'
#' #### even.pop
#' even.pop contains a population which has 739 individuals of every species
plot(sort(even.pop))
#' As we would expect, the graph shows a straight horizontal line, since all species have the same number
#' of individuals.
species_richness_1(even.pop)
# Same species richness
simpson_diversity_1(even.pop)
# And an even smaller chance of selecting two individuals from the same species

#'
#'----------------------------------------------------------------------------------
#'
#' #### rand.pop
#' rand.pop contains a random number of individuals of each species, drawn once from the BCI_2010 data
plot(sort(rand.pop))
#' This will change each time the population is generated
species_richness_1(rand.pop)
# also 301
simpson_diversity_1(rand.pop)
# Also small number

#'
#'----------------------------------------------------------------------------------
#'
#' #### rand50.pop
#' rand50.pop contains a population with a random number of individuals of each species, drawn from the
#' BCI_2010 data 50 times.
plot(sort(rand50.pop))
#' Another random curve which will change each time the population is generated
species_richness_1(rand50.pop)
# also 301
simpson_diversity_1(rand50.pop)
# also a very small number

#'
#' ----------------------------------------------------------------------------------
#'
#' # Conclsuion
#' Species richness is simply a count of the number of species present within a population, and does not
#' reflect diversity of the population. Simpson diversity index increases as the eveness of the
#' population goes down (ie more individuals of a smaller number of species) and vise versa. It can
#' be considered algebraically as 1/D2 (D being the measure of diversity)
EdieBishop/ProgInRBCIfunc documentation built on Dec. 23, 2019, 10:16 p.m.