--- title: "QUBESLesson" author: "Maxcy Hill" date: "4/9/2022" output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` Before we get started, we need to load in the necessary packages that we will use. **YOU MAY NEED TO INSTALL PACKAGES!!** To do this, type install.packages() directly into the console, and add "" around the package name. For example: install.packages("tidyverse") The tidyverse package is one package that includes many! We will be using this package for cleaning up our data and for creating great graphics. We will use the lme4 package for our statistical analyses. The ggpubr package will allow us to enhance the graphics that we will be creating. ```{r} library(tidyverse) library(lme4) library(ggpubr) ``` Next, lets read in the data and take a look. It is important to take a look at the data to ensure that everything has been loaded in properly ```{r} env <- read_csv("EnvironmentData.csv") head(env) ``` If everything looks up to speed, let's go! WAIT!! Our first column says X1. What does that mean?! The first column should be site number, but because it was not named when the data was read in, it needs to be given a name. ```{r} env <- env %>% rename(Site = X1) head(env) ``` Now that our data are appropriately titled, we can begin our first analysis. The first hypothesis predicts that as natural habitat loss increases, relative exotic abundance will also increase. Here we will create a plot to visualize this relationship. ```{r} ggscatter(env, x = "Habitat", y = "Exotic", add = "reg.line", conf.int = TRUE, cor.coef = TRUE, cor.method = "pearson", color = "darkgoldenrod1", xlab = "Habitat Loss", ylab = "Relative Exotic Abundance", main = "The effects of natural habitat loss on relative exotic abundance") ``` This visualization allows us to see that there is a moderate, negative correlation between natural habitat loss and relative exotic abundance. **Why are we plotting relative exotic abundance as a function of natural habitat loss and not the other way around?** **What are the results of this analysis? Do these findings support our first hypothesis? Why might this contradict findings from previous studies?** Before we do any more analyses, it is important to visualize the data to see if it follows a normal distribution. This histogram will show the distribution of the total number of pollinator visits. ```{r} hist(env$Visits , xlab = "Pollinator visits", main = "Total number of pollinator visits", col = "darkgoldenrod1") ``` Since there is not a bell-curve shape to this graph, we can say our data are not normally distributed. This histogram will show the distribution of the pollinator species observed. ```{r} hist(env$Species , xlab = "Total species", main = "Total number of species visits", col = "darkgoldenrod1") ``` **Are our data normally distributed? Why or why not?** We will be using general linear models, with the family directive Poisson, to test our second hypothesis, which predicts that as relative exotic abundance increases, pollinator biodiversity and abundance will decrease. The first glm will model the biodiversity of pollinators as a function of relative exotic abundance. ```{r} envglm1 <- glm(env$Species~env$Exotic, family = poisson()) summary(envglm1) ``` To interpret this output, we will look at our p-value and coefficient estimate. Our p-value is 0.483, and our coefficient estimate is -0.12421. **Interpret the model. Do these findings support our hypothesis that as relative exotic abundance increases, pollinator biodiversity will decrease?** To further enhance our understanding of this relationship, we can create a graph visualize the data. ```{r} ggplot(env, aes( x = env$Exotic, y = env$Species,)) + labs( x = "Relative exotic abundance", y = "Total species visits", main = "The effects of relative exotic abundance on biodiversity") + geom_point( color = "darkgoldenrod1" ) + geom_smooth(method = "glm", se = FALSE, color = "darkgoldenrod1") ``` We can see a slight downward trend in the data; however, our slope is very flat, suggesting either a very weak relationship, or no relationship at all. Next, we will run another glm, this time analyzing the influence relative exotic abundance has on pollinator abundance. ```{r} envglm2 <- glm(env$Visits~env$Exotic, family = poisson()) summary(envglm2) ``` Interpret is model the same way you did for the biodiversity model. **Interpret the model. Do these findings support our hypothesis that as relative exotic abundance increases, pollinator abundance will decrease?** Create another graph to visualize this relationship. ```{r} ggplot(env, aes( x = env$Exotic, y = env$Visits,)) + labs( x = "Relative exotic abundance", y = "Total pollinator visits", main = "The effects of relative exotic abundance on pollinator abundance") + geom_point( color = "darkgoldenrod1" ) + geom_smooth(method = "glm", se = FALSE, color = "darkgoldenrod1") ``` The downward trend in this graph is much more noticeable than our previous graph.