library(readxl)
library(ggpubr)
## Loading required package: ggplot2
A5Q1 <- read_excel("A5Q1.xlsx")
ggscatter(
A5Q1,
x = "age",
y = "education",
add = "reg.line",
xlab = "Age",
ylab = "Years of Education"
)

# The relationship is linear.
# The relationship is positive.
# There are no outliers.
mean(A5Q1$age)
## [1] 35.32634
sd(A5Q1$age)
## [1] 11.45344
median(A5Q1$age)
## [1] 35.79811
mean(A5Q1$education)
## [1] 13.82705
sd(A5Q1$education)
## [1] 2.595901
median(A5Q1$education)
## [1] 14.02915
hist(A5Q1$age,
main = "Age",
breaks = 20,
col = "lightblue",
border = "white",
cex.main = 1,
cex.axis = 1,
cex.lab = 1)

hist(A5Q1$education,
main = "Education",
breaks = 20,
col = "lightcoral",
border = "white",
cex.main = 1,
cex.axis = 1,
cex.lab = 1)

# Variable 1: Age
# The variable looks normally distributed.
# The data is symmetrical.
# The data has a proper bell curve.
# Variable 2: Education
# The variable looks normally distributed.
# The data is symmetrical.
# The data has a proper bell curve.
shapiro.test(A5Q1$age)
##
## Shapiro-Wilk normality test
##
## data: A5Q1$age
## W = 0.99194, p-value = 0.5581
shapiro.test(A5Q1$education)
##
## Shapiro-Wilk normality test
##
## data: A5Q1$education
## W = 0.9908, p-value = 0.4385
# Variable 1: Age
# The variable is normally distributed (p = .56).
# Variable 2: Education
# The variable is normally distributed (p = .44).
cor.test(A5Q1$age, A5Q1$education, method = "pearson")
##
## Pearson's product-moment correlation
##
## data: A5Q1$age and A5Q1$education
## t = 7.4066, df = 148, p-value = 9.113e-12
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.3924728 0.6279534
## sample estimates:
## cor
## 0.5200256
# A Pearson correlation was conducted to test the relationship between age (M = 35.33, SD = 11.45) and education (M = 13.83, SD = 2.60).
# There was a statistically significant relationship between the two variables, r(148) = .52, p < .001.
# The relationship was positive and strong.
# As age increased, education increased.
# Research Question 2
library(readxl)
A5Q2 <- read_excel("A5Q2.xlsx")
library(ggpubr)
ggscatter(
A5Q2,
x = "phone",
y = "sleep",
add = "reg.line",
xlab = "Phone Use",
ylab = "Sleep Duration"
)

# The relationship is linear.
# The relationship is negative.
# There are outliers.
mean(A5Q2$phone)
## [1] 3.804609
sd(A5Q2$phone)
## [1] 2.661866
median(A5Q2$phone)
## [1] 3.270839
mean(A5Q2$sleep)
## [1] 7.559076
sd(A5Q2$sleep)
## [1] 1.208797
median(A5Q2$sleep)
## [1] 7.524099
hist(A5Q2$phone,
main = "Histogram of Phone Use",
xlab = "Phone Use")

# Variable 1: Phone Use
# The variable looks abnormally distributed.
# The data is positively skewed.
# The data does not have a proper bell curve.
hist(A5Q2$sleep,
main = "Histogram of Sleep Duration",
xlab = "Sleep Duration")

# Variable 2: Sleep Duration
# The variable looks abnormally distributed.
# The data is negatively skewed.
# The data does not have a proper bell curve.
shapiro.test(A5Q2$phone)
##
## Shapiro-Wilk normality test
##
## data: A5Q2$phone
## W = 0.89755, p-value = 9.641e-09
shapiro.test(A5Q2$sleep)
##
## Shapiro-Wilk normality test
##
## data: A5Q2$sleep
## W = 0.91407, p-value = 8.964e-08
# Variable 1: Phone Use
# The variable is abnormally distributed (p < .001).
# Variable 2: Sleep Duration
# The variable is abnormally distributed (p < .001).
cor.test(A5Q2$phone, A5Q2$sleep, method = "spearman")
##
## Spearman's rank correlation rho
##
## data: A5Q2$phone and A5Q2$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 (Mdn = 3.27) and sleep duration (Mdn = 7.52).
# There was a statistically significant relationship between the two variables, ρ = -.61, p < .001.
# The relationship was negative and strong.
# As phone use increased, sleep duration decreased.