#Open packages

library(readxl)
library(ggplot2)
library(ggpubr)

age <- read_excel("C:/Users/rmich/Desktop/Jen/Week 4/age.xlsx")

#create scatterplot

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

The relationship is linear.

The relationship is positive.

The relationship is moderate.

There are no outliers.

#4 Descriptive statistics

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

# Historgrams.

  hist(age$age,
       main = "Age",
       breaks = 20,
       col = "lightblue",
       border = "white",
       cex.main = 1,
       cex.axis = 1,
       cex.lab = 1)

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

#6 Interpret Histograms

#Age is normally distributed. It is symetrical. It has a proper bell curve. #Education is normally distributed. It is symetrical. It has a proper bell curve.

#7 Normality Tests

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

#8 Interpret Shapiro Test

# Variable 1: Age # The first variable is normally distributed # w = .99, p-value = .5581.

# Variable 2: Education # The second variable is normally distribute. # w = 0.9908, p-value = .4385

Age is normal.Education is normal.

#9 Determine normality - Histogram and Shapiro are normal.Use Pearson.

#10 Pearson Correlation

#11A Pearson Data

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