--- title: "PART 2" author: "Eric Womack" date: "5/3/2020" output: word_document --- ```{r setup, include=FALSE} knitr::opts_chunk\$set(echo = TRUE) ``` ############# PART 2 ############## ######Creating a Boosted Regression Tree Model################### ```{r} # 1. Import the Data library(dismo) data <- read.csv("data.csv") ``` ```{r} #2. Create the Model fish.step<- gbm.step(data=data, gbm.x = 10:16, gbm.y = 9, family = "poisson", tree.complexity = 5, learning.rate = 0.003, bag.fraction = 0.6) ``` ```{r} #5. Examine the Residuals Plot plot(fish.step\$fitted, fish.step\$residuals) abline(0, 0) ``` ```{r} #6. Display relative influence summary(fish.step) ``` ```{r} #7. Plotting fitted functions gbm.plot(fish.step,n.plots=4,common.scale = TRUE, write.title = FALSE, plot.layout = c(2,4)) ``` ############### Creating a Multiple Regression Tree Model ###################### ```{r} #1. Load the Required Packages library(relaimpo) library(car) ``` ```{r} #2. Create the multiple regression model fish.glm<- glm(fish_rich ~ Reef.complexity + No.tall.corals + No.corals + Sponge.max.height + Octocoral.max.height + Slope.angle + Country, data = data) ``` ```{r} #3. Examine the diagnostic plots par(mfrow=c(2,2)) plot(fish.glm) ``` ```{r} #4. Check for multicollinearity vif(fish.glm) ``` ```{r} #5. Calculate the deviance explained summary(fish.glm) ``` ```{r} #6. Calculate relative influence calc.relimp(fish.glm, type = "lmg", rela = TRUE) ``` ################### Comparing the Predictive Power of our Models ########################## ```{r} #2. Root mean squared error RMSE <- function(error) { sqrt(mean(error^2)) } RMSE(fish.glm\$residuals) RMSE(fish.step\$residuals) ```