Assignment 4

Question 1

Research Question

Is there a relationship between age and years of education?

Load Packages

library(readxl)
## Warning: package 'readxl' was built under R version 4.6.1
library(ggpubr)
## Warning: package 'ggpubr' was built under R version 4.6.1
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.6.1

Import Dataset

A4Q1 <- read_excel("C:/Users/rteno/Downloads/SLU/AA 5221-11 Applied Analytics and Methods - I/Week 4/Assignment 4/A4Q1.xlsx")

Descriptive Statistics

mean(A4Q1$age)
## [1] 35.32634
sd(A4Q1$age)
## [1] 11.45344
median(A4Q1$age)
## [1] 35.79811
mean(A4Q1$education)
## [1] 13.82705
sd(A4Q1$education)
## [1] 2.595901
median(A4Q1$education)
## [1] 14.02915

Sumarry Statistics

summary(A4Q1)
##       age           education     
##  Min.   : 8.657   Min.   : 6.196  
##  1st Qu.:27.887   1st Qu.:12.024  
##  Median :35.798   Median :14.029  
##  Mean   :35.326   Mean   :13.827  
##  3rd Qu.:42.549   3rd Qu.:15.851  
##  Max.   :62.923   Max.   :19.727

Histograms

hist(
  A4Q1$age,
  main = "Age",
  xlab = "Age",
  col = "lightblue",
  border = "white",
  breaks = 20
)

hist(
  A4Q1$education,
  main = "Years of Education",
  xlab = "Years of Education",
  col = "lightgreen",
  border = "white",
  breaks = 20)

### Scarterplot

ggscatter(
  A4Q1,
  x = "age",
  y = "education",
  add = "reg.line",
  xlab = "Age",
  ylab = "Years of Education")

### Shapiro-Wilk Tests

shapiro.test(A4Q1$age)
## 
##  Shapiro-Wilk normality test
## 
## data:  A4Q1$age
## W = 0.99194, p-value = 0.5581
shapiro.test(A4Q1$education)
## 
##  Shapiro-Wilk normality test
## 
## data:  A4Q1$education
## W = 0.9908, p-value = 0.4385

Pearson Correlation

cor.test(
  A4Q1$age,
  A4Q1$education,
  method = "pearson")
## 
##  Pearson's product-moment correlation
## 
## data:  A4Q1$age and A4Q1$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

Interpretation

To examine the relationship between age and years of education, a Pearson correlation test was conducted. Statistically, there was a significant positive relationship between age and years of education with r=0.52, p<0.001. It was also noticed that as age increase, years of education also increase and per the course’s reading, this represents a strong positive correlation.