# Load data
q2 <- read_excel("A4Q2.xlsx")
head(q2)
## # A tibble: 6 × 2
## sleep phone
## <dbl> <dbl>
## 1 9.03 1.78
## 2 6.76 6.62
## 3 9.18 0.289
## 4 7.20 3.33
## 5 3 10
## 6 6.71 4.24
str(q2)
## tibble [150 × 2] (S3: tbl_df/tbl/data.frame)
## $ sleep: num [1:150] 9.03 6.76 9.18 7.2 3 ...
## $ phone: num [1:150] 1.784 6.624 0.289 3.325 10 ...
summary(q2)
## sleep phone
## Min. : 2.000 Min. : 0.2608
## 1st Qu.: 6.931 1st Qu.: 1.9057
## Median : 7.524 Median : 3.2708
## Mean : 7.559 Mean : 3.8046
## 3rd Qu.: 8.372 3rd Qu.: 4.8773
## Max. :10.089 Max. :15.0000
# Test for normality
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 test was conducted to examine the relationship
between hours of sleep and hours of phone use. There was a moderate
negative correlation between sleep and phone use (\(\rho = -0.615, p < 0.001\)). This
indicates that people who spend more time using their phones tend to
sleep fewer hours, and the relationship is statistically
significant.