<-read.table('~/Equine Summative NEW/Copy of eqsub.txt', header = TRUE, sep = "\t")
eqsub <-read.table('~/Equine Summative NEW/Equine.txt', header = TRUE, sep = "\t") equine
Research Summative
Loading Data
1. Is there a Correlation Between IRT and Blood Cortisol Levels?
Testing for Normality (Practice)
<- equine$irt
X <- equine$cortisol
Y
# Histograms for both variables
par(mfrow = c(1, 2)) # Arrange plots side by side
hist(X, main = "Histogram of IRT", col = "lightblue", breaks = 30)
hist(Y, main = "Histogram of Cortisol", col = "lightgreen", breaks = 30)
# Calculate the differences between paired observations
<- X - Y
diff
# Visualize the differences
hist(diff, main = "Histogram of Differences", col = "lightpink", breaks = 30)
qqnorm(diff, main = "Q-Q Plot of Differences")
qqline(diff, col = "red")
# Shapiro-Wilk test for normality
shapiro.test(diff)
Shapiro-Wilk normality test
data: diff
W = 0.96699, p-value = 3.797e-09
# Anderson-Darling test for normality
library(nortest)
ad.test(diff)
Anderson-Darling normality test
data: diff
A = 3.7172, p-value = 2.776e-09
# P < 0.05 therefore the data is not normally distributed
Results
cor.test(equine$cortisol, equine$comp, method = "spearman")
Spearman's rank correlation rho
data: equine$cortisol and equine$comp
S = 21166080, p-value = 0.529
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
-0.02826584
# P > 0.05 therefore there is a not a significant correlation between compliance time and blood lactate levels.
library(ggplot2)
# Call Variables
<- equine$irt
X <- equine$cortisol
Y
# Plot
ggplot(equine, aes(x = irt, y = cortisol)) +
geom_point() +
# Labeling Axis' and Titles
labs(title = "Correlation between IRT and Cortisol Levels",
x = "Thermographic Eye Temperature (°C)",
y = "Blood Cortisol Levels (mcg/dl)")
2. Does Calming Spray have an effect on compliance time, if so what is it?
Testing for Normality
<- eqsub$Pre.Calming.Spray
X <- eqsub$Post.Calming.Spray
Y
# Calculate the differences between paired observations
<- X - Y
diff
# Visualize the differences
hist(diff, main = "Histogram of Differences", col = "lightpink", breaks = 30)
qqnorm(diff, main = "Q-Q Plot of Differences")
qqline(diff, col = "red")
# Shapiro-Wilk test for differences
shapiro.test(diff)
Shapiro-Wilk normality test
data: diff
W = 0.84738, p-value < 2.2e-16
# Anderson-Darling test for differences
library(nortest)
ad.test(diff)
Anderson-Darling normality test
data: diff
A = 13.248, p-value < 2.2e-16
# P < 0.05 therefore the data is not normally distributed
Results
# Non-normal distribution -> Wilcoxon Signed-Rank Test
<- wilcox.test(X, Y, paired = TRUE)
wilcox_test print(wilcox_test)
Wilcoxon signed rank test with continuity correction
data: X and Y
V = 124251, p-value < 2.2e-16
alternative hypothesis: true location shift is not equal to 0
# P < 0.05 therefore there is a significant difference
Box Plot
# Sample Data
<- data.frame(
df Pre.Calming.Spray = c(34.9, 35.1, 36.0, 34.5, 35.2),
Post.Calming.Spray = c(33.8, 36.1, 34.7, 35.5, 36.3)
)# Load necessary libraries
library(ggplot2)
library(tidyr)
# Reshape data to long format
<- df %>%
df_long pivot_longer(cols = c(Pre.Calming.Spray, Post.Calming.Spray), names_to = "Variable", values_to = "Value")
# Create the box plot
ggplot(df_long, aes(x = Variable, y = Value, fill = Variable)) +
geom_boxplot() +
# Labeling Axis' and Titles
labs(title = "The Difference in Compliance Time When Applying a Calming Spray",
x = "Treatment",
y = "Compliance Time (s)") +
# Add Colour to Variables
theme_minimal() +
scale_fill_manual(values = c("Post.Calming.Spray" = "skyblue", "Pre.Calming.Spray" = "lightpink"),name = "Treatment")