In this code, we examine the relationship between catches of two shark species, Bull Shark and Lemon Shark, and environmental conditions. It is hypothesized that Bull Sharks will be found in lower salinity areas and the Lemon Sharks will be found in higher salinity areas. We also test alternative hypotheses for differences in distribution by examining catches in relationship to temperature, depth, and dissolved oxygen.
These analyses are based on a data set of drum line catches of large shark catches in the Shark River Slough in the Everglades National Park between May 2009 and May 2011. This dataset also includes environmental conditions they were caught in, including salinity, temperature, and dissolved oxygen. The study was conducted by [Florida International University] and can be downloaded here: (https://portal.edirepository.org/nis/mapbrowse?packageid=knb-lter-fce.1175.6).
Data collected by Michael Heithaus and Philip Matich from Florida International University
#install.packages("tidyverse")
#install.packages("rstatix")
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2 ✓ purrr 0.3.4
## ✓ tibble 3.0.4 ✓ dplyr 1.0.2
## ✓ tidyr 1.1.2 ✓ stringr 1.4.0
## ✓ readr 1.4.0 ✓ forcats 0.5.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(rstatix)
##
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
##
## filter
shark <- tibble(read.csv("data", header = TRUE))
#Here we are loading our dataset and making it a tibble for easier manipulation with Tidyverse
shark =
shark %>%
#Data filtered for the two study species: Lemon and Bull shark
filter(Species_CommonName %in% c("Lemon", "Bull")) %>%
# Data was filtered so that "No Data" values were assigned "NA" instead of -9999
mutate(Salinity = as.numeric(ifelse(Salinity == -9999, "NA", as.numeric(Salinity)))) %>%
mutate(DO_Saturation = as.numeric(ifelse(DO.. == -9999, "NA", as.numeric(DO..)))) %>%
mutate(WaterTemp = as.numeric(ifelse(WaterTemp == -9999, "NA", as.numeric(WaterTemp)))) %>%
mutate(Depth = as.numeric(ifelse(Depth == -9999, "NA", as.numeric(Depth)))) %>%
mutate(Species_CommonName = ifelse(Species_CommonName == -9999, "NA", as.character(Species_CommonName)))
## Warning: Problem with `mutate()` input `Salinity`.
## ℹ NAs introduced by coercion
## ℹ Input `Salinity` is `as.numeric(ifelse(Salinity == -9999, "NA", as.numeric(Salinity)))`.
## Warning in mask$eval_all_mutate(dots[[i]]): NAs introduced by coercion
## Warning: Problem with `mutate()` input `DO_Saturation`.
## ℹ NAs introduced by coercion
## ℹ Input `DO_Saturation` is `as.numeric(ifelse(DO.. == -9999, "NA", as.numeric(DO..)))`.
## Warning in mask$eval_all_mutate(dots[[i]]): NAs introduced by coercion
## Warning: Problem with `mutate()` input `WaterTemp`.
## ℹ NAs introduced by coercion
## ℹ Input `WaterTemp` is `as.numeric(ifelse(WaterTemp == -9999, "NA", as.numeric(WaterTemp)))`.
## Warning in mask$eval_all_mutate(dots[[i]]): NAs introduced by coercion
## Warning: Problem with `mutate()` input `Depth`.
## ℹ NAs introduced by coercion
## ℹ Input `Depth` is `as.numeric(ifelse(Depth == -9999, "NA", as.numeric(Depth)))`.
## Warning in mask$eval_all_mutate(dots[[i]]): NAs introduced by coercion
#Note - you will receive error messages due to the presence of NAs. Check your output dataframe (shark) to ensure that it looks as you expect it to
#t tests
shark %>%
t_test(DO_Saturation~Species_CommonName)
## # A tibble: 1 x 8
## .y. group1 group2 n1 n2 statistic df p
## * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl>
## 1 DO_Saturation Bull Lemon 29 23 0.420 38.9 0.677
shark %>%
t_test(Salinity~Species_CommonName)
## # A tibble: 1 x 8
## .y. group1 group2 n1 n2 statistic df p
## * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl>
## 1 Salinity Bull Lemon 29 23 -4.37 46.6 0.0000689
shark %>%
t_test(WaterTemp~Species_CommonName)
## # A tibble: 1 x 8
## .y. group1 group2 n1 n2 statistic df p
## * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl>
## 1 WaterTemp Bull Lemon 29 23 -3.58 48.6 0.000801
shark %>%
t_test(Depth~Species_CommonName)
## # A tibble: 1 x 8
## .y. group1 group2 n1 n2 statistic df p
## * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl>
## 1 Depth Bull Lemon 29 23 1.31 23.6 0.202
Result: Differences in shark abundance were statistically significant for salinity and temperature, but not for dissolved oxygen and depth.
shark %>%
ggplot(aes(x = Species_CommonName, y = Salinity)) + geom_boxplot()+ xlab("Shark Species") +labs(y= "Salinity (parts per thousand)")
## Warning: Removed 2 rows containing non-finite values (stat_boxplot).
shark %>%
ggplot(aes(x = Salinity, fill = Species_CommonName, group = Species_CommonName)) + geom_density() +xlab("Shark Species") +labs(y= "Density", x= "Salinity (parts per thousand)")
## Warning: Removed 2 rows containing non-finite values (stat_density).
shark %>%
gather(EnvironmentalFactor, Value, c("Salinity", "DO_Saturation", "WaterTemp", "Depth")) %>%
#puts together data from the four specified environmental factors and assigns category names
ggplot(aes(x = Value, fill = Species_CommonName, group = Species_CommonName)) + geom_density(alpha = 0.5) +
facet_wrap(~EnvironmentalFactor, scales = "free") + theme_bw()
## Warning: Removed 26 rows containing non-finite values (stat_density).
#aes assigns aesthetic mapping variables, including assigning the variable Value to x and assigning species to fill, and grouping each fill by species name
#geometric density assigns the appearance of the fill, and the alpha value indicates the transparency of the fill
#facet wrap allows one plot to consist of multiple related plots, which put the plots of the four environmental conditions next to each other with the same x and y axis units for easier viewing
Bull Sharks were found in much lower salinity and lower temperature waters than the Lemon Shark. There was little difference between abundance in dissolved oxygen and depth.
#central tendency
shark %>%
select(Species_CommonName, Salinity, DO_Saturation, WaterTemp, Depth) %>%
group_by(Species_CommonName) %>%
summarise_all(list(mean, sd), na.rm = TRUE)
## # A tibble: 2 x 9
## Species_CommonN… Salinity_fn1 DO_Saturation_f… WaterTemp_fn1 Depth_fn1
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Bull 27.3 59.8 25.1 9.94
## 2 Lemon 32.4 56.6 28.5 8.74
## # … with 4 more variables: Salinity_fn2 <dbl>, DO_Saturation_fn2 <dbl>,
## # WaterTemp_fn2 <dbl>, Depth_fn2 <dbl>
#Summzarizes the mean value for each of the four environmental conditions, grouped by species.
shark %>%
select(Species_CommonName, Salinity, DO_Saturation, WaterTemp, Depth) %>%
group_by(Species_CommonName) %>%
summarise_all(list(median), na.rm = TRUE)
## # A tibble: 2 x 5
## Species_CommonName Salinity DO_Saturation WaterTemp Depth
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Bull 27.9 57.2 23.3 9.6
## 2 Lemon 32.6 65.1 29.6 9.5
#Summarizes the median value for each of the four environmental conditions, grouped by species
shark %>%
ggplot(aes(x = Depth, y = DO_Saturation, group = Species_CommonName, color = Species_CommonName)) + geom_point() + stat_ellipse() + theme_bw() +labs(y= "Dissolved Oxygen (milligrams per liter)", x= "Depth (feet)")
## Warning: Removed 23 rows containing non-finite values (stat_ellipse).
## Warning: Removed 23 rows containing missing values (geom_point).
Niche overlap of dissolved oxygen and depth for Bull and Lemon Sharks. The complete overlap indicates no contribution to spatial segregation.
shark %>%
ggplot(aes(x = WaterTemp, y = Salinity, group = Species_CommonName, color = Species_CommonName)) + geom_point() + stat_ellipse() + theme_bw() +labs(y= "Salinity (parts per thousand)", x= "Water Temperature (degrees C)")
## Warning: Removed 2 rows containing non-finite values (stat_ellipse).
## Warning: Removed 2 rows containing missing values (geom_point).
Niche overlap of salinity and water temperature for Bull and Lemon Sharks.Little overlap indicates a strong contribution to spatial segregation.