library(readxl)
library(ggpubr)
## Loading required package: ggplot2
A5Q1 <- read.csv("C:/Users/SHRUTI/Downloads/A5Q1(Sheet1).csv")
A5Q1
##           age education
## 1   42.010815 13.202944
## 2   38.042239 12.628337
## 3   16.425751 10.302881
## 4   33.785327 16.231618
## 5   33.405561 14.037926
## 6   14.326193 11.446056
## 7   29.677576 11.817360
## 8   50.037400 17.241625
## 9   43.595877 12.996000
## 10  40.208397 15.712449
## 11  20.703037  9.240544
## 12  30.300347 15.785575
## 13  29.731887 16.203421
## 14  34.858325  6.195770
## 15  41.514464 16.017839
## 16  13.676135  9.955240
## 17  29.261494 11.575734
## 18  58.411417 18.816164
## 19  26.776763 11.475297
## 20  40.805863 14.020375
## 21  47.729118 16.504184
## 22  37.638374 14.255077
## 23  47.293863 16.000886
## 24  44.521430 10.375646
## 25  42.225728 16.907979
## 26  54.829882 19.727083
## 27  24.965057 12.342799
## 28  33.273984 12.985066
## 29  48.811017 15.107772
## 30  19.793501 12.726836
## 31  29.495737 15.693948
## 32  39.001412 11.591570
## 33  24.135549 13.143598
## 34  24.150606 14.384594
## 35  25.059156 13.015557
## 36  26.668013 13.172809
## 37  28.762200 10.361224
## 38  35.773601 13.917296
## 39  38.945754 12.805366
## 40  39.380838 15.882712
## 41  43.411073 14.798070
## 42  37.375044 15.150356
## 43  50.212304 16.147553
## 44   8.657016 12.037701
## 45  20.031573 14.810798
## 46  49.201819 11.421379
## 47  40.052170 13.346278
## 48  40.139419 17.806718
## 49  25.421144 13.972210
## 50  35.566195 16.934860
## 51  32.766138  8.371692
## 52  35.822615 10.977155
## 53  35.417189 14.701768
## 54  18.783164 10.164260
## 55  37.556385 15.393933
## 56  16.636555 12.276969
## 57  53.287841 18.748281
## 58  27.770326 14.299185
## 59  34.118509  9.898377
## 60  32.390137 13.722325
## 61  30.490076 13.009674
## 62  41.114244 14.369319
## 63  39.447594 11.734956
## 64  47.028393 17.116776
## 65  47.492355 18.333197
## 66  31.972489  9.503858
## 67  29.462561 14.194884
## 68  34.099674 15.595624
## 69  23.485583 15.171022
## 70   9.940344 13.172910
## 71  40.679617 16.264772
## 72  62.923263 16.874999
## 73  23.342844  9.515429
## 74  43.765359 13.669281
## 75  43.119202 16.140601
## 76  22.720729 11.939725
## 77  38.157875 16.184766
## 78  49.379370 17.966761
## 79  33.149064 11.586918
## 80  36.294315 16.640600
## 81  35.646306  9.406001
## 82  30.345737 13.490332
## 83  39.524352 14.191124
## 84  27.000849 14.524614
## 85  37.434439 15.759193
## 86  30.538570 16.465875
## 87  21.777119 12.375118
## 88  29.933556 12.203097
## 89  39.028024 13.850087
## 90  20.934754 13.680958
## 91  22.794940 13.988349
## 92  28.238541 14.150366
## 93  32.683961 10.046248
## 94  42.115229 17.841494
## 95  18.614248 11.872088
## 96  42.895842 10.664758
## 97   8.727262 10.141247
## 98  16.119657 14.317892
## 99  37.583849 15.999531
## 100 47.488954 14.783895
## 101 43.383481 16.210538
## 102 31.713238 14.836063
## 103 37.833086 15.268033
## 104 39.201685 14.438595
## 105 46.999009 12.034854
## 106 35.507675 14.291904
## 107 44.809940 12.936218
## 108 55.236790 15.644473
## 109 39.519016 14.978286
## 110 23.416278 15.872444
## 111 41.710276 16.298745
## 112 27.528576 14.009938
## 113 54.422819 16.918702
## 114 36.142178 11.056367
## 115 29.609052  7.652517
## 116 31.954102  9.808609
## 117 33.683755 14.114244
## 118 42.042182 19.316920
## 119 45.049456 16.502238
## 120 47.316472 15.708419
## 121 33.898088 11.799016
## 122 46.716599 13.517833
## 123 41.134342 13.314471
## 124 37.561145 17.750014
## 125 13.194830  8.556095
## 126 42.656365 16.267404
## 127 32.240635 13.149538
## 128 34.092183 13.679283
## 129 46.693579 14.797303
## 130 35.864328 14.075675
## 131 17.063319 15.203865
## 132 29.853955 11.428284
## 133 34.646683 13.017952
## 134 39.970402 15.413746
## 135 59.670739 17.567453
## 136 21.479311 11.567562
## 137 52.600402 16.216750
## 138 26.725146  8.768423
## 139 12.021259 10.938957
## 140 52.380157 16.309519
## 141 27.010017  9.947328
## 142 38.530633 12.019925
## 143 54.276011 14.259098
## 144 52.956264 18.189562
## 145 54.942208 12.304808
## 146 41.392322 14.837692
## 147 53.215994 12.361010
## 148 26.254540 15.878498
## 149  9.818089 10.018690
## 150 50.894529 13.479964
ggscatter(
  A5Q1,
  x = "age",
  y = "education",
  add = "reg.line",
  xlab = "Age",
  ylab = "Education"
)

# Interpretation of Scatterplot:
# The relationship is linear.
# The relationship is positive.
# There are a few minor outliers, but none are extreme.


# Age statistics
mean(A5Q1$age)
## [1] 35.32634
sd(A5Q1$age)
## [1] 11.45344
median(A5Q1$age)
## [1] 35.79811
# Education statistics
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")

# Variable 1: Age
# The variable looks normally distributed.
# The data is symmetrical.
# The data has a proper bell curve.

hist(A5Q1$education,
     main = "Education",
     breaks = 20,
     col = "lightcoral",
     border = "white")

# 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
# Age is normally distributed because p > .05.

shapiro.test(A5Q1$education)
## 
##  Shapiro-Wilk normality test
## 
## data:  A5Q1$education
## W = 0.9908, p-value = 0.4385
# Education is normally distributed because p > .05.

#Because both variables are normally distributed, we should use Pearson correlation.
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
# Pearson Correlation 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.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.