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

#I fixed the code by swapping the independent and the dependent variables. Initially I had taken sleep as my #independent variable. Other than that throughout the code nothing was changed serve for the swap of independent and #dependent variables, the results of the experiment and tests remain the same.
# The relationship is linear.
# The relationship is negative.
# There are outliers.
#calculation of descriptive statistics
mean(PhoneSleep$phone)
## [1] 3.804609
sd(PhoneSleep$phone)
## [1] 2.661866
median(PhoneSleep$phone)
## [1] 3.270839
mean(PhoneSleep$sleep)
## [1] 7.559076
sd(PhoneSleep$sleep)
## [1] 1.208797
median(PhoneSleep$sleep)
## [1] 7.524099
#checking normality visually Histogram
hist(PhoneSleep$phone,
main = "phone",
breaks = 20,
col = "lightblue",
border = "white",
xlab = "Hours of Phone Usage",
cex.main = 1,
cex.axis = 1,
cex.lab = 1)

# Variable 1: phone
# The variable looks abnormally distributed.
hist(PhoneSleep$sleep,
main = "sleep",
breaks = 20,
col = "lightcoral",
border = "white",
xlab = "Hours of Sleep",
cex.main = 1,
cex.axis = 1,
cex.lab = 1)

# Variable 1: sleep hours
# The variable looks abnormally distributed.
shapiro.test(PhoneSleep$phone)
##
## Shapiro-Wilk normality test
##
## data: PhoneSleep$phone
## W = 0.89755, p-value = 9.641e-09
shapiro.test(PhoneSleep$sleep)
##
## Shapiro-Wilk normality test
##
## data: PhoneSleep$sleep
## W = 0.91407, p-value = 8.964e-08
# Variable 1: phone
# The variable is abnormally distributed p < 0.05.
# Variable 2: sleep
# The variable is abnormally distributed p < 0.05.
#conducting a spearman correlation
cor.test(
PhoneSleep$phone,
PhoneSleep$sleep,
method = "spearman"
)
##
## Spearman's rank correlation rho
##
## data: PhoneSleep$phone and PhoneSleep$sleep
## 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 phone use (M = 3.27) and sleep hours (M = 7.52).
# There was a statistically significant relationship between the two variables, rho = .61, p < .001.
# The relationship was negative and strong.
# As hours of phone usage increased, sleep hours decreased.