Question 2: Sleep vs. Phone Usage

#Import dataset
q2 <- read_excel("A4Q2.xlsx")

#Scatterplot
ggscatter(
q2,
x = "phone",
y = "sleep",
add = "reg.line",
xlab = "Phone (hrs)",
ylab = "Sleep (hours)"
)

#Relationship is linear, negative, moderate, and contain outliers.

#Descriptive statistics (mean, standard deviation, median)

#Phone
mean(q2$phone)
## [1] 3.804609
sd(q2$phone)
## [1] 2.661866
median(q2$phone)
## [1] 3.270839
#Sleep
mean(q2$sleep)
## [1] 7.559076
sd(q2$sleep)
## [1] 1.208797
median(q2$sleep)
## [1] 7.524099
#Histograms

#Phone
hist(q2$phone,
     main = "Phone (hours)",
     breaks = 20,
     col = "lightblue",
     border = "white",
     cex.main = 1,
     cex.axis = 1,
     cex.lab = 1)

#The phone variable is not normally distributed. The data are positively skewed, meaning that most values are clustered at the lower end, with a smaller number of higher values extending the distribution to the right. As a result, the distribution does not follow the typical bell-shaped curve expected in a normal distribution.

#Sleep
hist(q2$sleep,
     main = "Sleep (hours)",
     breaks = 20,
     col = "lightcoral",
     border = "white",
     cex.main = 1,
     cex.axis = 1,
     cex.lab = 1)

#The sleep variable is not normally distributed. The data are negatively skewed, meaning that most values are clustered at the higher end, with a smaller number of lower values pulling the distribution to the left. Although the distribution shows a bell-shaped pattern, it does not meet the assumptions of a normal distribution because of this skewness.


#Normality tests - Shapiro-Wilk 
shapiro.test(q2$sleep)
## 
##  Shapiro-Wilk normality test
## 
## data:  q2$sleep
## W = 0.91407, p-value = 8.964e-08
shapiro.test(q2$phone)
## 
##  Shapiro-Wilk normality test
## 
## data:  q2$phone
## W = 0.89755, p-value = 9.641e-09

Normality Assessment:
A Shapiro-Wilk normality test was conducted for both variables. Sleep (p < 0.001) and phone usage (p < 0.001) were not normally distributed (p < 0.05). Therefore, the Spearman correlation test was selected.

# Spearman Correlation
cor.test(q2$phone,q2$sleep,method = "spearman")
## 
##  Spearman's rank correlation rho
## 
## data:  q2$phone and q2$sleep
## S = 908390, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
##        rho 
## -0.6149873

Interpretation:
A Spearman correlation analysis was conducted to examine the relationship between phone use (Mdn = 3.27) and sleep (Mdn = 7.52). The results showed a statistically significant relationship between the two variables, ρ = -.65, p < .001. This was a strong negative relationship, indicating that higher levels of phone use were associated with less sleep. In general, as phone use increased, the amount of sleep decreased.