#Activation of relevant packages library(tidyverse)
── 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(dplyr)library(palmerpenguins)library(ggpubr)library(readr)#Creation of scatter plot to show data distribution of both air and water temperaturesharks1 <-read_csv("/Volumes/University/sharks1.csv")
Rows: 500 Columns: 10
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): ID, sex
dbl (8): blotch, BPM, weight, length, air, water, meta, depth
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(sharks1)ggplot(sharks1, aes(x = air,y = water)) +geom_point() +geom_smooth(method ="lm",se =FALSE) +labs(x ="Ambient Air Temperature°C",y ="Surface Water Temperature°C",title ="Air and Water Temperature Association")
`geom_smooth()` using formula = 'y ~ x'
# Spearman's rank correlation test command library(readr)sharks1 <-read_csv("/Volumes/University/sharks1.csv")
Rows: 500 Columns: 10
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): ID, sex
dbl (8): blotch, BPM, weight, length, air, water, meta, depth
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Spearman's rank correlation rho
data: sharks1$air and sharks1$water
S = 22007692, p-value = 0.2082
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
-0.05637344
Rows: 50 Columns: 4
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): ID, sex
dbl (2): blotch1, blotch2
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
t.test(sharksub2$blotch1, sharksub2$blotch2, paired =TRUE, alternative ="two.sided")
Paired t-test
data: sharksub2$blotch1 and sharksub2$blotch2
t = -17.39, df = 49, p-value < 2.2e-16
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
-1.037176 -0.822301
sample estimates:
mean difference
-0.9297384
Rows: 50 Columns: 4
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): ID, sex
dbl (2): blotch1, blotch2
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#Selecting only relevant data (blotch times) for ease of viewingsharksub2 %>%select(blotch1, blotch2)
# Creation of scatter plot to show data distribution for both blotch timesggplot(sharksub2, aes(x = blotch1,y = blotch2)) +geom_point() +geom_smooth(method ="lm",se =FALSE) +labs(x ="Capture 1",Y ="Capture 2",title ="Time for Blotching to Occur on 30% of the Ventral Surface (Seconds)")
`geom_smooth()` using formula = 'y ~ x'
#Creation of boxplot to determine if sex impacts blotch timeggplot(sharks1, aes(x = sex,y = blotch,colour = sex)) +geom_boxplot(show.legend =FALSE) +labs(x ="Shark Sex",y ="Blotch Time in Seconds",title ="Impact of Sex on Blotching Time") +scale_color_brewer(palette ="Dark2") +theme_minimal()
#Unpaired T-Test Command subset(sharks1, sex =="Male")
# A tibble: 264 × 10
ID sex blotch BPM weight length air water meta depth
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 SH004 Male 35.3 161 105. 171. 36.2 21.6 86.3 50.3
2 SH006 Male 33.5 126 110. 270. 36.4 20.9 109. 46.8
3 SH007 Male 36.7 166 101. 194. 33.1 21.8 99.7 49.1
4 SH009 Male 35.4 132 95.0 269. 35.3 22.2 79.0 49.9
5 SH013 Male 35.7 133 109. 244. 37.5 23.6 110. 50.3
6 SH014 Male 39.8 121 90.9 193. 34.4 23.4 99.8 55.3
7 SH016 Male 34.8 128 87.7 244. 33.9 24.8 85.7 50.7
8 SH019 Male 33.5 154 97.4 168. 35.1 21.1 104. 50.9
9 SH020 Male 35.1 125 93.3 291. 36.1 20.6 95.3 48.4
10 SH021 Male 35.8 136 67.2 269. 35.1 22.6 78.0 51.2
# ℹ 254 more rows
Welch Two Sample t-test
data: sharks1$blotch by sharks1$sex
t = -3.0282, df = 494.67, p-value = 0.002589
alternative hypothesis: true difference in means between group Female and group Male is not equal to 0
95 percent confidence interval:
-0.6322714 -0.1346620
sample estimates:
mean in group Female mean in group Male
34.92294 35.30641
#Linear Model Command + Summarymodel_lm <-lm(blotch ~ BPM + weight + length + air + water + meta + depth, data = sharks1)summary(model_lm)
Call:
lm(formula = blotch ~ BPM + weight + length + air + water + meta +
depth, data = sharks1)
Residuals:
Min 1Q Median 3Q Max
-2.83745 -0.66117 -0.00702 0.60110 2.74108
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 11.1405851 1.8958668 5.876 7.74e-09 ***
BPM -0.0019723 0.0031890 -0.618 0.537
weight 0.0016283 0.0033511 0.486 0.627
length 0.0012295 0.0009710 1.266 0.206
air -0.0281474 0.0318707 -0.883 0.378
water -0.0188934 0.0270782 -0.698 0.486
meta -0.0009712 0.0025951 -0.374 0.708
depth 0.5061285 0.0223191 22.677 < 2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.002 on 492 degrees of freedom
Multiple R-squared: 0.514, Adjusted R-squared: 0.507
F-statistic: 74.32 on 7 and 492 DF, p-value: < 2.2e-16
#Creation of Scatter Plot Displaying Linear Model Fitted to Dataggplot(sharks1, aes(x = depth,y = blotch)) +geom_point() +geom_smooth(method ="lm") +labs(x ="Depth of Capture (Metres)",y ="Blotching Time (Seconds)",title ="Linear Model Fitted to Data")
`geom_smooth()` using formula = 'y ~ x'
#Command for Linear Regression Model & Summarymodel <-lm(blotch ~ depth, data = sharks1)summary(model)
Call:
lm(formula = blotch ~ depth, data = sharks1)
Residuals:
Min 1Q Median 3Q Max
-2.81869 -0.65427 -0.01035 0.58825 2.83116
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 9.82178 1.11207 8.832 <2e-16 ***
depth 0.50467 0.02216 22.772 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1 on 498 degrees of freedom
Multiple R-squared: 0.5101, Adjusted R-squared: 0.5091
F-statistic: 518.6 on 1 and 498 DF, p-value: < 2.2e-16