install.packages(“readxl”) install.packages(“ggpubr”)

library(readxl)
library(ggpubr)
## Loading required package: ggplot2
data1 <- read_excel("A4Q2.xlsx")
ggscatter(
  data1,
  x = "sleep",
  y = "phone",
  add = "reg.line",
  xlab = "sleep",
  ylab = "phone"
)

The relationship is linear. The relationship is negative. The relationship is moderate. There are no obvious outliers.

statstics

mean(data1$sleep)
## [1] 7.559076
sd(data1$sleep)
## [1] 1.208797
median(data1$sleep)
## [1] 7.524099
mean(data1$phone)
## [1] 3.804609
sd(data1$phone)
## [1] 2.661866
median(data1$phone)
## [1] 3.270839

Histograms

hist(data1$sleep, main="Sleep", col="lightblue")

hist(data1$phone, main="Phone Use", col="lightcoral")

sleep looks normally distributed. phone usage looks normally distributed.

shapiro

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

Correlation

cor.test(data1$sleep, data1$phone, method="pearson")
## 
##  Pearson's product-moment correlation
## 
## data:  data1$sleep and data1$phone
## t = -11.813, df = 148, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.7708489 -0.6038001
## sample estimates:
##        cor 
## -0.6966497

A Pearson correlation was conducted to test the relationship between sleep (m= 7.559, sd = 1.208) and phone (m = 3.804 , sd = 2.66) There was a statistically significant relationship between the two variables, r(df) = .148, p = < 2.2e-16 The relationship was negative As sleep increased, phone use decreased.