library(readxl)
library(ggpubr)
## Loading required package: ggplot2
data2026 <- read_excel("C:/Users/hp/Desktop/digital Forensics/AA 5221/Asignment_5/A5Q2(Sheet1).xlsx")
View(data2026)

ggscatter(
data2026,
x = "sleep",
y = "phone",
add = "reg.line",
xlab = "sleep",
ylab = "phone"
)

# The relationship is linear.
# The relationship is negative.
# There are outliers.

mean(data2026$sleep)
## [1] 7.559076
sd(data2026$sleep)
## [1] 1.208797
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 looks normally distributed.
# The data is symmetrical.
# The data has a proper bell curve.

# Variable 2: Phone
# The variable does not look normally distributed.
# The data is not symmetrical.
# The data has no 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
# A Shapiro-Wilk test indicated that sleep was not normally distributed,
# W = 0.914, p < .001.

# Variable 2: Phone
# A Shapiro-Wilk test indicated that phone use was not normally distributed,
# W = 0.898, p < .001.

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's rank-order correlation was conducted to test the relationship
# between sleep and phone use.

# There was a statistically significant relationship between the variables,
# rs = -.615, p < .001.

# The relationship was negative and moderate.

# As phone use increased, sleep decreased.