── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)library(readxl)sharks <-read_excel("C:/Users/kathr/OneDrive/Documents/_NTU_/Research Methods and Data Analysis/ASSESSMENT/sharks.xlsx")sharksub <-read_excel("C:/Users/kathr/OneDrive/Documents/_NTU_/Research Methods and Data Analysis/ASSESSMENT/sharksub.xlsx")
1) Is there a correlation between air temperature and water temperature?
-> Visualisation of data (Scatterplot)
ggplot(sharks, aes(x= water, y=air))+geom_point() +geom_smooth(method ="lm", se =FALSE, color ="blue") +labs(title ="Scatterplot of Air vs. Water Temperature", x ="Water Temperature (°C)", y ="Air Temperature (°C)")
`geom_smooth()` using formula = 'y ~ x'
-> Pearson’s Correlation Test
cor(sharks$water, sharks$air, method ='pearson')
[1] -0.05524051
-> New column creation (Difference in temperature)
ggplot(shark.new, aes(x= tempdifference, y = blotch))+geom_point() +geom_smooth(method ="lm", se =FALSE, color ="blue") +labs( x ="Temperature Difference (°C)", y ="Blotch Time (Seconds)")
Paired t-test
data: sharksub$blotch2 and sharksub$blotch1
t = 17.39, df = 49, p-value < 2.2e-16
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
0.822301 1.037176
sample estimates:
mean difference
0.9297384
-> Visualisation (box plot showing difference in means between the two blotch times)
sharksub_long <- sharksub %>%pivot_longer(cols =c(blotch1, blotch2), names_to ="Capture", values_to ="Blotching_Time")ggplot(sharksub_long, aes(x = Capture, y = Blotching_Time, fill = Capture)) +geom_boxplot() +labs(title ="Comparison of Blotching Times for First and Second Captures",x ="Capture Event",y ="Blotching Time (seconds)" )
3) Can blotching time be predicted?
-> Multiple linear regression
model <-lm(blotch ~ BPM + weight + length + air + water + depth, data = sharks)