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

# The relationship is linear.
# The relationship is positive.
# There are no outliers.
#calculating descriptive statistics
mean(AgeEduation$age)
## [1] 35.32634
sd(AgeEduation$age)
## [1] 11.45344
median(AgeEduation$age)
## [1] 35.79811
mean(AgeEduation$education)
## [1] 13.82705
sd(AgeEduation$education)
## [1] 2.595901
median(AgeEduation$education)
## [1] 14.02915
#checking normality visually (Histogram)
hist(AgeEduation$age,
main = "Age",
breaks = 20,
col = "lightblue",
border = "white",
xlab = "Individual's Ages",
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.
hist(AgeEduation$education,
main = "Education",
breaks = 20,
col = "lightcoral",
border = "white",
xlab = "Years of Education",
cex.main = 1,
cex.axis = 1,
cex.lab = 1)

# Variable 2: Education
# The variable looks normally distributed.
# The data is symmetrical.
# The data has a proper bell curve.
#Check Normality Statistically (Shapiro-Wilk Test)
shapiro.test(AgeEduation$age)
##
## Shapiro-Wilk normality test
##
## data: AgeEduation$age
## W = 0.99194, p-value = 0.5581
shapiro.test(AgeEduation$education)
##
## Shapiro-Wilk normality test
##
## data: AgeEduation$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).
#Conducting Pearson correlation
cor.test(
AgeEduation$age,
AgeEduation$education,
method = "pearson"
)
##
## Pearson's product-moment correlation
##
## data: AgeEduation$age and AgeEduation$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 and (M = 35.33, SD = 11.45) and years of education (M = 13.82, SD = 2.59).
# There was a statistically significant relationship between the two variables, t(148) = .52, p < .05.
# The relationship was positive.
# As age increased, years of education increased.