library(readxl)
library(ggpubr)
## Loading required package: ggplot2
data2026 <- read_excel("C:/Users/siqoe/OneDrive - Saint Louis University/AA 5221/Assignment 5/A5Q2(Sheet1).xlsx")
ggscatter(
data2026,
x = "sleep",
y = "phone",
add = "reg.line",
xlab = "sleep",
ylab = "phone"
)

# The relationship is linear.
# The relationship is ne.
# There are outliers.
mean(data2026$sleep)
## [1] 7.559076
sd(data2026$phone)
## [1] 2.661866
median(data2026$sleep)
## [1] 7.524099
mean(data2026$phone)
## [1] 3.804609
sd(data2026$phone)
## [1] 2.661866
median(data2026$phone)
## [1] 3.270839
hist(data2026$sleep)

hist(data2026$phone)

# Variable 1: sleep
# The variable does not look normally distributed.
# The data is assymmetrical.
# The data has no proper bell curve.
# Variable 2: phone
# The variable does not look normally distributed.
# The data is assymmetrical.
# The data has no proper bell curve.
shapiro.test(data2026$sleep)
##
## Shapiro-Wilk normality test
##
## data: data2026$sleep
## W = 0.91407, p-value = 8.964e-08
shapiro.test(data2026$phone)
##
## Shapiro-Wilk normality test
##
## data: data2026$phone
## W = 0.89755, p-value = 9.641e-09
# Variable 1: sleep
# The variable is not normally distributed (p = 8.964e-08).
# Variable 2: phone
# The variable is not normally distributed (p = 9.641e-09).
cor.test(data2026$sleep, data2026$phone, method = "spearman")
##
## Spearman's rank correlation rho
##
## data: data2026$sleep and data2026$phone
## S = 908390, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## -0.6149873
# A Spearman correlation was conducted to test the relationship between sleep and phone.
# There was a statistically significant relationship between the variables,
# The relationship was negative and moderate.
# As sleep increased, phone decreased.