load packages

# Install

if(!require("car")) install.packages("car")
if(!require("dplyr")) install.packages("dplyr")
if(!require("lmtest")) install.packages("lmtest")


# Load
library(car)
library(dplyr)
library(lmtest)

Prep/Read in Data

# Read in data
# Columns: Unit, Month, Site, Vegetation_Type, CPUE, av_temp, av_do, av_pH, av_turbidity, av_conductivity, 
Fyke_EF_LR = read.csv('C:/Users/hayde/OneDrive/Desktop/UMichigan/Masters project/code and anlysis/Electrofishing/Linear/final version/ef_linear2_final.csv')
str(Fyke_EF_LR)
## 'data.frame':    30 obs. of  13 variables:
##  $ site_ID           : chr  "MC106062022" "MC107192022" "MC108152022" "MC206072022" ...
##  $ Site              : int  1 1 1 2 2 2 3 3 3 1 ...
##  $ Unit              : chr  "MC" "MC" "MC" "MC" ...
##  $ month             : int  6 7 8 6 7 8 6 7 8 6 ...
##  $ Vegetation.Type   : chr  "Open Water" "Open Water" "Submerged Aquatic Vegetation" "Submerged Aquatic Vegetation" ...
##  $ av_temp           : num  18.9 25.6 20.9 19.9 26.9 ...
##  $ av_do             : num  9.39 4.15 3.55 10.57 5.94 ...
##  $ av_pH             : num  8.05 7.52 7.5 8.5 8.27 ...
##  $ av_turbidity      : num  20.86 35.34 9.34 24.65 119 ...
##  $ av_conductivity   : num  513 704 602 459 443 ...
##  $ effort_min        : num  3.93 10.02 8.48 10.05 10.17 ...
##  $ SumOfSPECIES_COUNT: int  32 25 15 27 19 42 25 20 71 41 ...
##  $ cpue              : num  8.14 2.5 1.77 2.69 1.87 ...

Perform the Linear Regressions

# Regression Analyses - CPUE:Temp, CPUE:DO, CPUE:pH, CPUE:Turb, CPUE:Cond
FishLRtemp = lm(cpue ~ av_temp, data=Fyke_EF_LR)
summary(FishLRtemp)
## 
## Call:
## lm(formula = cpue ~ av_temp, data = Fyke_EF_LR)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.5466 -0.6590 -0.1865  0.1991  4.7678 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  8.13788    2.01163   4.045 0.000372 ***
## av_temp     -0.25228    0.08771  -2.876 0.007610 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.534 on 28 degrees of freedom
## Multiple R-squared:  0.2281, Adjusted R-squared:  0.2005 
## F-statistic: 8.273 on 1 and 28 DF,  p-value: 0.00761
FishLRDO = lm(cpue ~ av_do, data=Fyke_EF_LR)
summary(FishLRDO)
## 
## Call:
## lm(formula = cpue ~ av_do, data = Fyke_EF_LR)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.2526 -0.7816 -0.3187  0.5417  5.7751 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  2.55615    0.95948   2.664   0.0127 *
## av_do       -0.02085    0.12743  -0.164   0.8712  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.745 on 28 degrees of freedom
## Multiple R-squared:  0.0009551,  Adjusted R-squared:  -0.03473 
## F-statistic: 0.02677 on 1 and 28 DF,  p-value: 0.8712
FishLRpH = lm(cpue ~ av_pH, data=Fyke_EF_LR)
summary(FishLRpH)
## 
## Call:
## lm(formula = cpue ~ av_pH, data = Fyke_EF_LR)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.0393 -0.7340 -0.3141  0.3974  5.7824 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)   9.0394     6.8192   1.326    0.196
## av_pH        -0.8306     0.8532  -0.973    0.339
## 
## Residual standard error: 1.717 on 28 degrees of freedom
## Multiple R-squared:  0.03274,    Adjusted R-squared:  -0.001808 
## F-statistic: 0.9477 on 1 and 28 DF,  p-value: 0.3386
FishLRTurb = lm(cpue ~ av_turbidity, data=Fyke_EF_LR)
summary(FishLRTurb)
## 
## Call:
## lm(formula = cpue ~ av_turbidity, data = Fyke_EF_LR)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.0600 -0.8537 -0.1779  0.4550  5.8003 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   2.06919    0.43583   4.748 5.53e-05 ***
## av_turbidity  0.01276    0.01146   1.113    0.275    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.708 on 28 degrees of freedom
## Multiple R-squared:  0.04239,    Adjusted R-squared:  0.008187 
## F-statistic: 1.239 on 1 and 28 DF,  p-value: 0.2751
FishLRCond = lm(cpue ~ av_conductivity, data=Fyke_EF_LR)
summary(FishLRCond)
## 
## Call:
## lm(formula = cpue ~ av_conductivity, data = Fyke_EF_LR)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.7053 -0.8482 -0.1219  0.3205  5.5926 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)   
## (Intercept)      3.854003   1.060064   3.636  0.00111 **
## av_conductivity -0.002556   0.001793  -1.425  0.16510   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.686 on 28 degrees of freedom
## Multiple R-squared:  0.06765,    Adjusted R-squared:  0.03436 
## F-statistic: 2.032 on 1 and 28 DF,  p-value: 0.1651

Time to plot!

# Temp
FishLRTempplot = plot(Fyke_EF_LR$av_temp, Fyke_EF_LR$cpue,col = "black",
       main = "Total Site CPUE & Average Temperature Regression",
       abline(lm(Fyke_EF_LR$cpue ~ Fyke_EF_LR$av_temp)),
       cex = 1.3,
       pch = 16,
       xlab = "Average Temperature (Celsius),
       ylab = Total Site CPUE")

# DO
FishLR_DOplot = plot(Fyke_EF_LR$av_do,Fyke_EF_LR$cpue,col = "black",
       main = "Total Site CPUE & Average Dissolved Oxygen Regression",
       abline(lm(Fyke_EF_LR$cpue~Fyke_EF_LR$av_do)),
       cex = 1.3,
       pch = 16,
       xlab = "Average Dissolved Oxygen (mg/L)",
       ylab = "Total Site CPUE")

# PH
FishLR_pHplot = plot(Fyke_EF_LR$av_pH,Fyke_EF_LR$cpue,col = "black",
       main = "Total Site CPUE & Average pH Regression",
       abline(lm(Fyke_EF_LR$cpue~Fyke_EF_LR$av_pH)),
       cex = 1.3,
       pch = 16,
       xlab = "Average pH",
       ylab = "Total Site CPUE" )

# TURB
FishLR_Turbplot = plot(Fyke_EF_LR$av_turbidity,Fyke_EF_LR$cpue,col = "black",
       main = "Total Site CPUE & Average Turbidity Regression",
       abline(lm(Fyke_EF_LR$cpue~Fyke_EF_LR$av_turbidity)),
       cex = 1.3,
       pch = 16,
       xlab = "Average Turbidity (FNU)",
       ylab = "Total Site CPUE")

# COND
FishLR_Condplot = plot(Fyke_EF_LR$av_conductivity,Fyke_EF_LR$cpue,col = "black",
       main = "Total Site CPUE & Average Conductivity Regression",
       abline(lm(Fyke_EF_LR$cpue~Fyke_EF_LR$av_conductivity)),
       cex = 1.3,
       pch = 16,
       xlab = "Average Conductivity (uS/cm2)",
       ylab = "Total Site CPUE")