library(readxl)
library(ggpubr)
## Loading required package: ggplot2
A5Q1_Sheet1_ <- read_excel("C:/Users/mercy/Downloads/A5Q1(Sheet1).xlsx")
View(A5Q1_Sheet1_)
#Create a Scatterplot

ggscatter(
  A5Q1_Sheet1_,
  x = "age",
  y = "education",
  add = "reg.line",
  xlab = "age",
  ylab = "education"
)

#Interpret the Scatterplot

# The relationship is linear .
# The relationship is positive.
# There is no outliers.

#Calculate Descriptive Statistics

mean(A5Q1_Sheet1_$age)
## [1] 35.32634
sd(A5Q1_Sheet1_$age)
## [1] 11.45344
median(A5Q1_Sheet1_$age)
## [1] 35.79811
mean(A5Q1_Sheet1_$education)
## [1] 13.82705
sd(A5Q1_Sheet1_$education)
## [1] 2.595901
median(A5Q1_Sheet1_$education)
## [1] 14.02915
#Create Histograms
hist(A5Q1_Sheet1_$age,
     main = "age",
     breaks = 20,
     col = "lightblue",
     border = "white",
     cex.main = 1,
     cex.axis = 1,
     cex.lab = 1)

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

#Interpret the Histograms

# 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 negatively skewed.
# The data has a proper bell curve.

#Check Normality Statistically (Shapiro-Wilk Test)
shapiro.test(A5Q1_Sheet1_$age)
## 
##  Shapiro-Wilk normality test
## 
## data:  A5Q1_Sheet1_$age
## W = 0.99194, p-value = 0.5581
shapiro.test(A5Q1_Sheet1_$education)
## 
##  Shapiro-Wilk normality test
## 
## data:  A5Q1_Sheet1_$education
## W = 0.9908, p-value = 0.4385
#Interpret the Shapiro-Wilk Test

# Variable 1: age
# The variable is normally distributed (p = 0.56).

# Variable 2: education
# The variable is normally distributed (p = 0.44).

#Determine Which Correlation to Use
#Use Pearson Correlation because both histograms appear normal and also the Shapiro-Wilk tests indicate normality.

# Conduct a Pearson Correlation
cor.test(
  A5Q1_Sheet1_$age,
  A5Q1_Sheet1_$education,
  method = "pearson"
)
## 
##  Pearson's product-moment correlation
## 
## data:  A5Q1_Sheet1_$age and A5Q1_Sheet1_$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
#Report the Results
# A Pearson correlation was conducted to test the relationship between age (M = 35.33, SD = 11.45) and education (M = 13.83, SD = 2.61).
# 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.